[{"data":1,"prerenderedAt":5189},["ShallowReactive",2],{"article-en-multi-file-concurrency-server-mode-in-blite":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"tags":11,"body":20,"_type":5182,"_id":5183,"_source":5184,"_file":5185,"_stem":5186,"_extension":5187,"sitemap":5188},"\u002Fen\u002Fblog\u002Fmulti-file-concurrency-server-mode-in-blite","blog",false,"","Multi-File Storage: How BLite Handles Concurrent Server Access","How BLite splits a database across multiple memory-mapped files, uses ReaderWriterLockSlim with a fast-path\u002Fslow-path strategy to protect concurrent access, and provides per-connection session isolation — and what could go wrong with these choices.","2026-04-07",[12,13,14,15,16,17,18,19],".net","blite","concurrency","storage-engine","memory-mapped-files","server","transactions","open-source",{"type":21,"children":22,"toc":5159},"root",[23,31,36,40,47,61,74,79,88,93,96,102,107,231,242,722,751,754,760,795,808,868,875,888,1301,1328,1334,1339,1501,1520,1526,1562,1568,1610,1941,1953,1959,1979,2341,2346,2349,2355,2584,2589,2592,2598,2603,2615,3363,3368,3444,3820,3856,3859,3865,3877,4004,4009,4053,4058,4078,4412,4433,4436,4442,4471,4889,4903,4906,4912,4917,4923,4935,4948,4954,4988,4993,4999,5023,5029,5054,5059,5065,5089,5094,5097,5103,5108,5134,5139,5153],{"type":24,"tag":25,"props":26,"children":27},"element","p",{},[28],{"type":29,"value":30},"text","An embedded database that lives in a single file is fine for a desktop app, a CLI tool, or a mobile game. One process, one thread (usually), one file. But the moment you put a database behind a server — where dozens of connections read and write concurrently — the single-file model starts to crack.",{"type":24,"tag":25,"props":32,"children":33},{},[34],{"type":29,"value":35},"This post is about how BLite went from \"one file, one writer at a time\" to \"multiple files, concurrent readers and writers, per-connection transaction isolation.\" I'll cover the architecture, the locking strategy that makes it safe, the session model that gives each connection its own transaction context, and the migrations that let you convert between layouts. Then I'll take a step back and talk about where these choices might hurt.",{"type":24,"tag":37,"props":38,"children":39},"hr",{},[],{"type":24,"tag":41,"props":42,"children":44},"h2",{"id":43},"why-multi-file",[45],{"type":29,"value":46},"Why Multi-File?",{"type":24,"tag":25,"props":48,"children":49},{},[50,52,59],{"type":29,"value":51},"A single-file database has one memory-mapped file backing all I\u002FO. Every read and every write — whether it touches a B+Tree index node, a data page, or a WAL checkpoint — goes through the same ",{"type":24,"tag":53,"props":54,"children":56},"code",{"className":55},[],[57],{"type":29,"value":58},"MemoryMappedFile",{"type":29,"value":60},". When the file needs to grow, the OS-level mapping must be disposed and recreated. During that window, no reader can hold a reference to the old mapping or it risks accessing freed memory.",{"type":24,"tag":25,"props":62,"children":63},{},[64,66,72],{"type":29,"value":65},"The problem compounds under load. An index scan locks out a document insert because they share the same file. A checkpoint flushes every dirty page through one bottleneck. A ",{"type":24,"tag":53,"props":67,"children":69},{"className":68},[],[70],{"type":29,"value":71},"DROP COLLECTION",{"type":29,"value":73}," leaves a fragmentation hole that can only be reclaimed by rewriting the entire file.",{"type":24,"tag":25,"props":75,"children":76},{},[77],{"type":29,"value":78},"BLite's multi-file layout addresses each of these:",{"type":24,"tag":80,"props":81,"children":83},"pre",{"code":82},"mydb.db            ← main data file (pages, metadata, KV store)\nmydb.idx           ← separate index file (B+Trees, R-Trees, HNSW)\nwal\u002Fmydb.wal       ← write-ahead log (optionally on a different disk)\ncollections\u002Fmydb\u002F\n  ├── users.db     ← per-collection data file\n  ├── orders.db\n  └── .slots       ← slot→name registry\n",[84],{"type":24,"tag":53,"props":85,"children":86},{"__ignoreMap":7},[87],{"type":29,"value":82},{"type":24,"tag":25,"props":89,"children":90},{},[91],{"type":29,"value":92},"Index writes no longer block data writes — they go to different files with independent locks. Dropping a collection is a file delete, not a page-level defragmentation. The WAL can live on a dedicated disk for sequential I\u002FO while data and indexes benefit from random-access SSD performance.",{"type":24,"tag":37,"props":94,"children":95},{},[],{"type":24,"tag":41,"props":97,"children":99},{"id":98},"the-server-configuration",[100],{"type":29,"value":101},"The Server Configuration",{"type":24,"tag":25,"props":103,"children":104},{},[105],{"type":29,"value":106},"Enabling multi-file is a one-line change:",{"type":24,"tag":80,"props":108,"children":112},{"code":109,"language":110,"meta":7,"className":111,"style":7},"var config = PageFileConfig.Server(databasePath);\nusing var engine = new BLiteEngine(databasePath, config);\n","csharp","language-csharp shiki shiki-themes github-light one-dark-pro",[113],{"type":24,"tag":53,"props":114,"children":115},{"__ignoreMap":7},[116,174],{"type":24,"tag":117,"props":118,"children":121},"span",{"class":119,"line":120},"line",1,[122,128,134,140,146,152,158,163,169],{"type":24,"tag":117,"props":123,"children":125},{"style":124},"--shiki-default:#D73A49;--shiki-dark:#C678DD",[126],{"type":29,"value":127},"var",{"type":24,"tag":117,"props":129,"children":131},{"style":130},"--shiki-default:#6F42C1;--shiki-dark:#E06C75",[132],{"type":29,"value":133}," config",{"type":24,"tag":117,"props":135,"children":137},{"style":136},"--shiki-default:#D73A49;--shiki-dark:#56B6C2",[138],{"type":29,"value":139}," =",{"type":24,"tag":117,"props":141,"children":143},{"style":142},"--shiki-default:#24292E;--shiki-dark:#E5C07B",[144],{"type":29,"value":145}," PageFileConfig",{"type":24,"tag":117,"props":147,"children":149},{"style":148},"--shiki-default:#24292E;--shiki-dark:#ABB2BF",[150],{"type":29,"value":151},".",{"type":24,"tag":117,"props":153,"children":155},{"style":154},"--shiki-default:#6F42C1;--shiki-dark:#61AFEF",[156],{"type":29,"value":157},"Server",{"type":24,"tag":117,"props":159,"children":160},{"style":148},[161],{"type":29,"value":162},"(",{"type":24,"tag":117,"props":164,"children":166},{"style":165},"--shiki-default:#24292E;--shiki-dark:#E06C75",[167],{"type":29,"value":168},"databasePath",{"type":24,"tag":117,"props":170,"children":171},{"style":148},[172],{"type":29,"value":173},");\n",{"type":24,"tag":117,"props":175,"children":177},{"class":119,"line":176},2,[178,183,188,193,197,203,209,213,217,222,227],{"type":24,"tag":117,"props":179,"children":180},{"style":124},[181],{"type":29,"value":182},"using",{"type":24,"tag":117,"props":184,"children":185},{"style":124},[186],{"type":29,"value":187}," var",{"type":24,"tag":117,"props":189,"children":190},{"style":130},[191],{"type":29,"value":192}," engine",{"type":24,"tag":117,"props":194,"children":195},{"style":136},[196],{"type":29,"value":139},{"type":24,"tag":117,"props":198,"children":200},{"style":199},"--shiki-default:#D73A49;--shiki-dark:#ABB2BF",[201],{"type":29,"value":202}," new",{"type":24,"tag":117,"props":204,"children":206},{"style":205},"--shiki-default:#6F42C1;--shiki-dark:#E5C07B",[207],{"type":29,"value":208}," BLiteEngine",{"type":24,"tag":117,"props":210,"children":211},{"style":148},[212],{"type":29,"value":162},{"type":24,"tag":117,"props":214,"children":215},{"style":165},[216],{"type":29,"value":168},{"type":24,"tag":117,"props":218,"children":219},{"style":148},[220],{"type":29,"value":221},", ",{"type":24,"tag":117,"props":223,"children":224},{"style":165},[225],{"type":29,"value":226},"config",{"type":24,"tag":117,"props":228,"children":229},{"style":148},[230],{"type":29,"value":173},{"type":24,"tag":25,"props":232,"children":233},{},[234,240],{"type":24,"tag":53,"props":235,"children":237},{"className":236},[],[238],{"type":29,"value":239},"Server()",{"type":29,"value":241}," is a factory that derives all companion paths from the database path:",{"type":24,"tag":80,"props":243,"children":245},{"code":244,"language":110,"meta":7,"className":111,"style":7},"public static PageFileConfig Server(string databasePath, PageFileConfig? baseConfig = null)\n{\n    var @base = baseConfig ?? Default;\n    return @base with\n    {\n        WalPath = Path.Combine(\n            Path.GetDirectoryName(databasePath) ?? \".\",\n            \"wal\",\n            Path.GetFileNameWithoutExtension(databasePath) + \".wal\"),\n\n        IndexFilePath = Path.ChangeExtension(databasePath, \".idx\"),\n\n        CollectionDataDirectory = Path.Combine(\n            Path.GetDirectoryName(databasePath) ?? \".\",\n            \"collections\",\n            Path.GetFileNameWithoutExtension(databasePath))\n    };\n}\n",[246],{"type":24,"tag":53,"props":247,"children":248},{"__ignoreMap":7},[249,319,327,365,383,392,424,471,484,528,538,585,593,622,662,675,704,713],{"type":24,"tag":117,"props":250,"children":251},{"class":119,"line":120},[252,257,262,266,271,275,280,285,289,294,299,304,308,314],{"type":24,"tag":117,"props":253,"children":254},{"style":124},[255],{"type":29,"value":256},"public",{"type":24,"tag":117,"props":258,"children":259},{"style":124},[260],{"type":29,"value":261}," static",{"type":24,"tag":117,"props":263,"children":264},{"style":205},[265],{"type":29,"value":145},{"type":24,"tag":117,"props":267,"children":268},{"style":154},[269],{"type":29,"value":270}," Server",{"type":24,"tag":117,"props":272,"children":273},{"style":148},[274],{"type":29,"value":162},{"type":24,"tag":117,"props":276,"children":277},{"style":124},[278],{"type":29,"value":279},"string",{"type":24,"tag":117,"props":281,"children":282},{"style":205},[283],{"type":29,"value":284}," databasePath",{"type":24,"tag":117,"props":286,"children":287},{"style":148},[288],{"type":29,"value":221},{"type":24,"tag":117,"props":290,"children":291},{"style":205},[292],{"type":29,"value":293},"PageFileConfig",{"type":24,"tag":117,"props":295,"children":296},{"style":148},[297],{"type":29,"value":298},"? ",{"type":24,"tag":117,"props":300,"children":301},{"style":205},[302],{"type":29,"value":303},"baseConfig",{"type":24,"tag":117,"props":305,"children":306},{"style":136},[307],{"type":29,"value":139},{"type":24,"tag":117,"props":309,"children":311},{"style":310},"--shiki-default:#005CC5;--shiki-dark:#D19A66",[312],{"type":29,"value":313}," null",{"type":24,"tag":117,"props":315,"children":316},{"style":148},[317],{"type":29,"value":318},")\n",{"type":24,"tag":117,"props":320,"children":321},{"class":119,"line":176},[322],{"type":24,"tag":117,"props":323,"children":324},{"style":148},[325],{"type":29,"value":326},"{\n",{"type":24,"tag":117,"props":328,"children":330},{"class":119,"line":329},3,[331,336,341,345,350,355,360],{"type":24,"tag":117,"props":332,"children":333},{"style":124},[334],{"type":29,"value":335},"    var",{"type":24,"tag":117,"props":337,"children":338},{"style":130},[339],{"type":29,"value":340}," @base",{"type":24,"tag":117,"props":342,"children":343},{"style":136},[344],{"type":29,"value":139},{"type":24,"tag":117,"props":346,"children":347},{"style":165},[348],{"type":29,"value":349}," baseConfig",{"type":24,"tag":117,"props":351,"children":352},{"style":199},[353],{"type":29,"value":354}," ??",{"type":24,"tag":117,"props":356,"children":357},{"style":165},[358],{"type":29,"value":359}," Default",{"type":24,"tag":117,"props":361,"children":362},{"style":148},[363],{"type":29,"value":364},";\n",{"type":24,"tag":117,"props":366,"children":368},{"class":119,"line":367},4,[369,374,378],{"type":24,"tag":117,"props":370,"children":371},{"style":124},[372],{"type":29,"value":373},"    return",{"type":24,"tag":117,"props":375,"children":376},{"style":165},[377],{"type":29,"value":340},{"type":24,"tag":117,"props":379,"children":380},{"style":199},[381],{"type":29,"value":382}," with\n",{"type":24,"tag":117,"props":384,"children":386},{"class":119,"line":385},5,[387],{"type":24,"tag":117,"props":388,"children":389},{"style":148},[390],{"type":29,"value":391},"    {\n",{"type":24,"tag":117,"props":393,"children":395},{"class":119,"line":394},6,[396,401,405,410,414,419],{"type":24,"tag":117,"props":397,"children":398},{"style":165},[399],{"type":29,"value":400},"        WalPath",{"type":24,"tag":117,"props":402,"children":403},{"style":136},[404],{"type":29,"value":139},{"type":24,"tag":117,"props":406,"children":407},{"style":142},[408],{"type":29,"value":409}," Path",{"type":24,"tag":117,"props":411,"children":412},{"style":148},[413],{"type":29,"value":151},{"type":24,"tag":117,"props":415,"children":416},{"style":154},[417],{"type":29,"value":418},"Combine",{"type":24,"tag":117,"props":420,"children":421},{"style":148},[422],{"type":29,"value":423},"(\n",{"type":24,"tag":117,"props":425,"children":427},{"class":119,"line":426},7,[428,433,437,442,446,450,455,460,466],{"type":24,"tag":117,"props":429,"children":430},{"style":142},[431],{"type":29,"value":432},"            Path",{"type":24,"tag":117,"props":434,"children":435},{"style":148},[436],{"type":29,"value":151},{"type":24,"tag":117,"props":438,"children":439},{"style":154},[440],{"type":29,"value":441},"GetDirectoryName",{"type":24,"tag":117,"props":443,"children":444},{"style":148},[445],{"type":29,"value":162},{"type":24,"tag":117,"props":447,"children":448},{"style":165},[449],{"type":29,"value":168},{"type":24,"tag":117,"props":451,"children":452},{"style":148},[453],{"type":29,"value":454},") ",{"type":24,"tag":117,"props":456,"children":457},{"style":199},[458],{"type":29,"value":459},"??",{"type":24,"tag":117,"props":461,"children":463},{"style":462},"--shiki-default:#032F62;--shiki-dark:#98C379",[464],{"type":29,"value":465}," \".\"",{"type":24,"tag":117,"props":467,"children":468},{"style":148},[469],{"type":29,"value":470},",\n",{"type":24,"tag":117,"props":472,"children":474},{"class":119,"line":473},8,[475,480],{"type":24,"tag":117,"props":476,"children":477},{"style":462},[478],{"type":29,"value":479},"            \"wal\"",{"type":24,"tag":117,"props":481,"children":482},{"style":148},[483],{"type":29,"value":470},{"type":24,"tag":117,"props":485,"children":487},{"class":119,"line":486},9,[488,492,496,501,505,509,513,518,523],{"type":24,"tag":117,"props":489,"children":490},{"style":142},[491],{"type":29,"value":432},{"type":24,"tag":117,"props":493,"children":494},{"style":148},[495],{"type":29,"value":151},{"type":24,"tag":117,"props":497,"children":498},{"style":154},[499],{"type":29,"value":500},"GetFileNameWithoutExtension",{"type":24,"tag":117,"props":502,"children":503},{"style":148},[504],{"type":29,"value":162},{"type":24,"tag":117,"props":506,"children":507},{"style":165},[508],{"type":29,"value":168},{"type":24,"tag":117,"props":510,"children":511},{"style":148},[512],{"type":29,"value":454},{"type":24,"tag":117,"props":514,"children":515},{"style":136},[516],{"type":29,"value":517},"+",{"type":24,"tag":117,"props":519,"children":520},{"style":462},[521],{"type":29,"value":522}," \".wal\"",{"type":24,"tag":117,"props":524,"children":525},{"style":148},[526],{"type":29,"value":527},"),\n",{"type":24,"tag":117,"props":529,"children":531},{"class":119,"line":530},10,[532],{"type":24,"tag":117,"props":533,"children":535},{"emptyLinePlaceholder":534},true,[536],{"type":29,"value":537},"\n",{"type":24,"tag":117,"props":539,"children":541},{"class":119,"line":540},11,[542,547,551,555,559,564,568,572,576,581],{"type":24,"tag":117,"props":543,"children":544},{"style":165},[545],{"type":29,"value":546},"        IndexFilePath",{"type":24,"tag":117,"props":548,"children":549},{"style":136},[550],{"type":29,"value":139},{"type":24,"tag":117,"props":552,"children":553},{"style":142},[554],{"type":29,"value":409},{"type":24,"tag":117,"props":556,"children":557},{"style":148},[558],{"type":29,"value":151},{"type":24,"tag":117,"props":560,"children":561},{"style":154},[562],{"type":29,"value":563},"ChangeExtension",{"type":24,"tag":117,"props":565,"children":566},{"style":148},[567],{"type":29,"value":162},{"type":24,"tag":117,"props":569,"children":570},{"style":165},[571],{"type":29,"value":168},{"type":24,"tag":117,"props":573,"children":574},{"style":148},[575],{"type":29,"value":221},{"type":24,"tag":117,"props":577,"children":578},{"style":462},[579],{"type":29,"value":580},"\".idx\"",{"type":24,"tag":117,"props":582,"children":583},{"style":148},[584],{"type":29,"value":527},{"type":24,"tag":117,"props":586,"children":588},{"class":119,"line":587},12,[589],{"type":24,"tag":117,"props":590,"children":591},{"emptyLinePlaceholder":534},[592],{"type":29,"value":537},{"type":24,"tag":117,"props":594,"children":596},{"class":119,"line":595},13,[597,602,606,610,614,618],{"type":24,"tag":117,"props":598,"children":599},{"style":165},[600],{"type":29,"value":601},"        CollectionDataDirectory",{"type":24,"tag":117,"props":603,"children":604},{"style":136},[605],{"type":29,"value":139},{"type":24,"tag":117,"props":607,"children":608},{"style":142},[609],{"type":29,"value":409},{"type":24,"tag":117,"props":611,"children":612},{"style":148},[613],{"type":29,"value":151},{"type":24,"tag":117,"props":615,"children":616},{"style":154},[617],{"type":29,"value":418},{"type":24,"tag":117,"props":619,"children":620},{"style":148},[621],{"type":29,"value":423},{"type":24,"tag":117,"props":623,"children":625},{"class":119,"line":624},14,[626,630,634,638,642,646,650,654,658],{"type":24,"tag":117,"props":627,"children":628},{"style":142},[629],{"type":29,"value":432},{"type":24,"tag":117,"props":631,"children":632},{"style":148},[633],{"type":29,"value":151},{"type":24,"tag":117,"props":635,"children":636},{"style":154},[637],{"type":29,"value":441},{"type":24,"tag":117,"props":639,"children":640},{"style":148},[641],{"type":29,"value":162},{"type":24,"tag":117,"props":643,"children":644},{"style":165},[645],{"type":29,"value":168},{"type":24,"tag":117,"props":647,"children":648},{"style":148},[649],{"type":29,"value":454},{"type":24,"tag":117,"props":651,"children":652},{"style":199},[653],{"type":29,"value":459},{"type":24,"tag":117,"props":655,"children":656},{"style":462},[657],{"type":29,"value":465},{"type":24,"tag":117,"props":659,"children":660},{"style":148},[661],{"type":29,"value":470},{"type":24,"tag":117,"props":663,"children":665},{"class":119,"line":664},15,[666,671],{"type":24,"tag":117,"props":667,"children":668},{"style":462},[669],{"type":29,"value":670},"            \"collections\"",{"type":24,"tag":117,"props":672,"children":673},{"style":148},[674],{"type":29,"value":470},{"type":24,"tag":117,"props":676,"children":678},{"class":119,"line":677},16,[679,683,687,691,695,699],{"type":24,"tag":117,"props":680,"children":681},{"style":142},[682],{"type":29,"value":432},{"type":24,"tag":117,"props":684,"children":685},{"style":148},[686],{"type":29,"value":151},{"type":24,"tag":117,"props":688,"children":689},{"style":154},[690],{"type":29,"value":500},{"type":24,"tag":117,"props":692,"children":693},{"style":148},[694],{"type":29,"value":162},{"type":24,"tag":117,"props":696,"children":697},{"style":165},[698],{"type":29,"value":168},{"type":24,"tag":117,"props":700,"children":701},{"style":148},[702],{"type":29,"value":703},"))\n",{"type":24,"tag":117,"props":705,"children":707},{"class":119,"line":706},17,[708],{"type":24,"tag":117,"props":709,"children":710},{"style":148},[711],{"type":29,"value":712},"    };\n",{"type":24,"tag":117,"props":714,"children":716},{"class":119,"line":715},18,[717],{"type":24,"tag":117,"props":718,"children":719},{"style":148},[720],{"type":29,"value":721},"}\n",{"type":24,"tag":25,"props":723,"children":724},{},[725,727,733,735,741,743,749],{"type":29,"value":726},"On startup, the ",{"type":24,"tag":53,"props":728,"children":730},{"className":729},[],[731],{"type":29,"value":732},"StorageEngine",{"type":29,"value":734}," constructor checks each path, creates directories as needed, and opens a separate ",{"type":24,"tag":53,"props":736,"children":738},{"className":737},[],[739],{"type":29,"value":740},"PageFile",{"type":29,"value":742}," instance for each component. If a path is ",{"type":24,"tag":53,"props":744,"children":746},{"className":745},[],[747],{"type":29,"value":748},"null",{"type":29,"value":750},", that component stays in the main file — you can separate just the index, just the WAL, or everything.",{"type":24,"tag":37,"props":752,"children":753},{},[],{"type":24,"tag":41,"props":755,"children":757},{"id":756},"the-concurrency-challenge-protecting-a-memorymappedfile",[758],{"type":29,"value":759},"The Concurrency Challenge: Protecting a MemoryMappedFile",{"type":24,"tag":25,"props":761,"children":762},{},[763,765,770,772,778,780,785,787,793],{"type":29,"value":764},"Here's the core problem. A ",{"type":24,"tag":53,"props":766,"children":768},{"className":767},[],[769],{"type":29,"value":58},{"type":29,"value":771}," in .NET maps a region of a file into the process's virtual address space. Reading a page means creating a ",{"type":24,"tag":53,"props":773,"children":775},{"className":774},[],[776],{"type":29,"value":777},"ViewAccessor",{"type":29,"value":779}," over that mapping. But when the file must grow — say, a new page is allocated beyond the current file length — the mapping must be disposed and recreated with a larger capacity. If a reader is still holding a ",{"type":24,"tag":53,"props":781,"children":783},{"className":782},[],[784],{"type":29,"value":777},{"type":29,"value":786}," to the old mapping while the writer disposes it, the reader gets an ",{"type":24,"tag":53,"props":788,"children":790},{"className":789},[],[791],{"type":29,"value":792},"ObjectDisposedException",{"type":29,"value":794}," or, worse, reads stale memory.",{"type":24,"tag":25,"props":796,"children":797},{},[798,800,806],{"type":29,"value":799},"The naive solution is a mutex: one thread at a time, readers and writers alike. That kills throughput. The correct solution uses ",{"type":24,"tag":53,"props":801,"children":803},{"className":802},[],[804],{"type":29,"value":805},"ReaderWriterLockSlim",{"type":29,"value":807},":",{"type":24,"tag":80,"props":809,"children":811},{"code":810,"language":110,"meta":7,"className":111,"style":7},"private readonly ReaderWriterLockSlim _rwLock = new(LockRecursionPolicy.NoRecursion);\n",[812],{"type":24,"tag":53,"props":813,"children":814},{"__ignoreMap":7},[815],{"type":24,"tag":117,"props":816,"children":817},{"class":119,"line":120},[818,823,828,833,838,842,846,850,855,859,864],{"type":24,"tag":117,"props":819,"children":820},{"style":124},[821],{"type":29,"value":822},"private",{"type":24,"tag":117,"props":824,"children":825},{"style":124},[826],{"type":29,"value":827}," readonly",{"type":24,"tag":117,"props":829,"children":830},{"style":205},[831],{"type":29,"value":832}," ReaderWriterLockSlim",{"type":24,"tag":117,"props":834,"children":835},{"style":130},[836],{"type":29,"value":837}," _rwLock",{"type":24,"tag":117,"props":839,"children":840},{"style":136},[841],{"type":29,"value":139},{"type":24,"tag":117,"props":843,"children":844},{"style":199},[845],{"type":29,"value":202},{"type":24,"tag":117,"props":847,"children":848},{"style":148},[849],{"type":29,"value":162},{"type":24,"tag":117,"props":851,"children":852},{"style":142},[853],{"type":29,"value":854},"LockRecursionPolicy",{"type":24,"tag":117,"props":856,"children":857},{"style":148},[858],{"type":29,"value":151},{"type":24,"tag":117,"props":860,"children":861},{"style":142},[862],{"type":29,"value":863},"NoRecursion",{"type":24,"tag":117,"props":865,"children":866},{"style":148},[867],{"type":29,"value":173},{"type":24,"tag":869,"props":870,"children":872},"h3",{"id":871},"fast-path-read-lock-for-concurrent-access",[873],{"type":29,"value":874},"Fast Path: Read Lock for Concurrent Access",{"type":24,"tag":25,"props":876,"children":877},{},[878,880,886],{"type":29,"value":879},"Most writes don't require file growth — the file has already been pre-allocated in 1 MB blocks. When the file is large enough, both reads and writes acquire only a ",{"type":24,"tag":881,"props":882,"children":883},"strong",{},[884],{"type":29,"value":885},"read lock",{"type":29,"value":887},", which allows unlimited concurrency:",{"type":24,"tag":80,"props":889,"children":891},{"code":890,"language":110,"meta":7,"className":111,"style":7},"public void WritePage(uint pageId, ReadOnlySpan\u003Cbyte> source)\n{\n    \u002F\u002F Fast path: file already large enough — share the mapping with readers\n    if (offset + PageSize \u003C= _fileStream!.Length)\n    {\n        _rwLock.EnterReadLock();\n        try { WritePageCore(pageId, source); }\n        finally { _rwLock.ExitReadLock(); }\n        return;\n    }\n\n    \u002F\u002F Slow path: file must grow — exclusive lock\n    _rwLock.EnterWriteLock();\n    try\n    {\n        EnsureCapacityCore(offset);  \u002F\u002F Dispose old MMF, recreate with new size\n        WritePageCore(pageId, source);\n    }\n    finally { _rwLock.ExitWriteLock(); }\n}\n",[892],{"type":24,"tag":53,"props":893,"children":894},{"__ignoreMap":7},[895,959,966,975,1031,1038,1060,1100,1131,1143,1151,1158,1166,1187,1195,1202,1228,1256,1263,1293],{"type":24,"tag":117,"props":896,"children":897},{"class":119,"line":120},[898,902,907,912,916,921,926,930,935,940,945,950,955],{"type":24,"tag":117,"props":899,"children":900},{"style":124},[901],{"type":29,"value":256},{"type":24,"tag":117,"props":903,"children":904},{"style":124},[905],{"type":29,"value":906}," void",{"type":24,"tag":117,"props":908,"children":909},{"style":154},[910],{"type":29,"value":911}," WritePage",{"type":24,"tag":117,"props":913,"children":914},{"style":148},[915],{"type":29,"value":162},{"type":24,"tag":117,"props":917,"children":918},{"style":124},[919],{"type":29,"value":920},"uint",{"type":24,"tag":117,"props":922,"children":923},{"style":205},[924],{"type":29,"value":925}," pageId",{"type":24,"tag":117,"props":927,"children":928},{"style":148},[929],{"type":29,"value":221},{"type":24,"tag":117,"props":931,"children":932},{"style":205},[933],{"type":29,"value":934},"ReadOnlySpan",{"type":24,"tag":117,"props":936,"children":937},{"style":148},[938],{"type":29,"value":939},"\u003C",{"type":24,"tag":117,"props":941,"children":942},{"style":124},[943],{"type":29,"value":944},"byte",{"type":24,"tag":117,"props":946,"children":947},{"style":148},[948],{"type":29,"value":949},"> ",{"type":24,"tag":117,"props":951,"children":952},{"style":205},[953],{"type":29,"value":954},"source",{"type":24,"tag":117,"props":956,"children":957},{"style":148},[958],{"type":29,"value":318},{"type":24,"tag":117,"props":960,"children":961},{"class":119,"line":176},[962],{"type":24,"tag":117,"props":963,"children":964},{"style":148},[965],{"type":29,"value":326},{"type":24,"tag":117,"props":967,"children":968},{"class":119,"line":329},[969],{"type":24,"tag":117,"props":970,"children":972},{"style":971},"--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#7F848E;--shiki-dark-font-style:italic",[973],{"type":29,"value":974},"    \u002F\u002F Fast path: file already large enough — share the mapping with readers\n",{"type":24,"tag":117,"props":976,"children":977},{"class":119,"line":367},[978,983,988,993,998,1003,1008,1013,1018,1022,1027],{"type":24,"tag":117,"props":979,"children":980},{"style":124},[981],{"type":29,"value":982},"    if",{"type":24,"tag":117,"props":984,"children":985},{"style":148},[986],{"type":29,"value":987}," (",{"type":24,"tag":117,"props":989,"children":990},{"style":165},[991],{"type":29,"value":992},"offset",{"type":24,"tag":117,"props":994,"children":995},{"style":136},[996],{"type":29,"value":997}," +",{"type":24,"tag":117,"props":999,"children":1000},{"style":165},[1001],{"type":29,"value":1002}," PageSize",{"type":24,"tag":117,"props":1004,"children":1005},{"style":136},[1006],{"type":29,"value":1007}," \u003C=",{"type":24,"tag":117,"props":1009,"children":1010},{"style":165},[1011],{"type":29,"value":1012}," _fileStream",{"type":24,"tag":117,"props":1014,"children":1015},{"style":136},[1016],{"type":29,"value":1017},"!",{"type":24,"tag":117,"props":1019,"children":1020},{"style":148},[1021],{"type":29,"value":151},{"type":24,"tag":117,"props":1023,"children":1024},{"style":142},[1025],{"type":29,"value":1026},"Length",{"type":24,"tag":117,"props":1028,"children":1029},{"style":148},[1030],{"type":29,"value":318},{"type":24,"tag":117,"props":1032,"children":1033},{"class":119,"line":385},[1034],{"type":24,"tag":117,"props":1035,"children":1036},{"style":148},[1037],{"type":29,"value":391},{"type":24,"tag":117,"props":1039,"children":1040},{"class":119,"line":394},[1041,1046,1050,1055],{"type":24,"tag":117,"props":1042,"children":1043},{"style":142},[1044],{"type":29,"value":1045},"        _rwLock",{"type":24,"tag":117,"props":1047,"children":1048},{"style":148},[1049],{"type":29,"value":151},{"type":24,"tag":117,"props":1051,"children":1052},{"style":154},[1053],{"type":29,"value":1054},"EnterReadLock",{"type":24,"tag":117,"props":1056,"children":1057},{"style":148},[1058],{"type":29,"value":1059},"();\n",{"type":24,"tag":117,"props":1061,"children":1062},{"class":119,"line":426},[1063,1068,1073,1078,1082,1087,1091,1095],{"type":24,"tag":117,"props":1064,"children":1065},{"style":124},[1066],{"type":29,"value":1067},"        try",{"type":24,"tag":117,"props":1069,"children":1070},{"style":148},[1071],{"type":29,"value":1072}," { ",{"type":24,"tag":117,"props":1074,"children":1075},{"style":154},[1076],{"type":29,"value":1077},"WritePageCore",{"type":24,"tag":117,"props":1079,"children":1080},{"style":148},[1081],{"type":29,"value":162},{"type":24,"tag":117,"props":1083,"children":1084},{"style":165},[1085],{"type":29,"value":1086},"pageId",{"type":24,"tag":117,"props":1088,"children":1089},{"style":148},[1090],{"type":29,"value":221},{"type":24,"tag":117,"props":1092,"children":1093},{"style":165},[1094],{"type":29,"value":954},{"type":24,"tag":117,"props":1096,"children":1097},{"style":148},[1098],{"type":29,"value":1099},"); }\n",{"type":24,"tag":117,"props":1101,"children":1102},{"class":119,"line":473},[1103,1108,1112,1117,1121,1126],{"type":24,"tag":117,"props":1104,"children":1105},{"style":124},[1106],{"type":29,"value":1107},"        finally",{"type":24,"tag":117,"props":1109,"children":1110},{"style":148},[1111],{"type":29,"value":1072},{"type":24,"tag":117,"props":1113,"children":1114},{"style":142},[1115],{"type":29,"value":1116},"_rwLock",{"type":24,"tag":117,"props":1118,"children":1119},{"style":148},[1120],{"type":29,"value":151},{"type":24,"tag":117,"props":1122,"children":1123},{"style":154},[1124],{"type":29,"value":1125},"ExitReadLock",{"type":24,"tag":117,"props":1127,"children":1128},{"style":148},[1129],{"type":29,"value":1130},"(); }\n",{"type":24,"tag":117,"props":1132,"children":1133},{"class":119,"line":486},[1134,1139],{"type":24,"tag":117,"props":1135,"children":1136},{"style":124},[1137],{"type":29,"value":1138},"        return",{"type":24,"tag":117,"props":1140,"children":1141},{"style":148},[1142],{"type":29,"value":364},{"type":24,"tag":117,"props":1144,"children":1145},{"class":119,"line":530},[1146],{"type":24,"tag":117,"props":1147,"children":1148},{"style":148},[1149],{"type":29,"value":1150},"    }\n",{"type":24,"tag":117,"props":1152,"children":1153},{"class":119,"line":540},[1154],{"type":24,"tag":117,"props":1155,"children":1156},{"emptyLinePlaceholder":534},[1157],{"type":29,"value":537},{"type":24,"tag":117,"props":1159,"children":1160},{"class":119,"line":587},[1161],{"type":24,"tag":117,"props":1162,"children":1163},{"style":971},[1164],{"type":29,"value":1165},"    \u002F\u002F Slow path: file must grow — exclusive lock\n",{"type":24,"tag":117,"props":1167,"children":1168},{"class":119,"line":595},[1169,1174,1178,1183],{"type":24,"tag":117,"props":1170,"children":1171},{"style":142},[1172],{"type":29,"value":1173},"    _rwLock",{"type":24,"tag":117,"props":1175,"children":1176},{"style":148},[1177],{"type":29,"value":151},{"type":24,"tag":117,"props":1179,"children":1180},{"style":154},[1181],{"type":29,"value":1182},"EnterWriteLock",{"type":24,"tag":117,"props":1184,"children":1185},{"style":148},[1186],{"type":29,"value":1059},{"type":24,"tag":117,"props":1188,"children":1189},{"class":119,"line":624},[1190],{"type":24,"tag":117,"props":1191,"children":1192},{"style":124},[1193],{"type":29,"value":1194},"    try\n",{"type":24,"tag":117,"props":1196,"children":1197},{"class":119,"line":664},[1198],{"type":24,"tag":117,"props":1199,"children":1200},{"style":148},[1201],{"type":29,"value":391},{"type":24,"tag":117,"props":1203,"children":1204},{"class":119,"line":677},[1205,1210,1214,1218,1223],{"type":24,"tag":117,"props":1206,"children":1207},{"style":154},[1208],{"type":29,"value":1209},"        EnsureCapacityCore",{"type":24,"tag":117,"props":1211,"children":1212},{"style":148},[1213],{"type":29,"value":162},{"type":24,"tag":117,"props":1215,"children":1216},{"style":165},[1217],{"type":29,"value":992},{"type":24,"tag":117,"props":1219,"children":1220},{"style":148},[1221],{"type":29,"value":1222},");  ",{"type":24,"tag":117,"props":1224,"children":1225},{"style":971},[1226],{"type":29,"value":1227},"\u002F\u002F Dispose old MMF, recreate with new size\n",{"type":24,"tag":117,"props":1229,"children":1230},{"class":119,"line":706},[1231,1236,1240,1244,1248,1252],{"type":24,"tag":117,"props":1232,"children":1233},{"style":154},[1234],{"type":29,"value":1235},"        WritePageCore",{"type":24,"tag":117,"props":1237,"children":1238},{"style":148},[1239],{"type":29,"value":162},{"type":24,"tag":117,"props":1241,"children":1242},{"style":165},[1243],{"type":29,"value":1086},{"type":24,"tag":117,"props":1245,"children":1246},{"style":148},[1247],{"type":29,"value":221},{"type":24,"tag":117,"props":1249,"children":1250},{"style":165},[1251],{"type":29,"value":954},{"type":24,"tag":117,"props":1253,"children":1254},{"style":148},[1255],{"type":29,"value":173},{"type":24,"tag":117,"props":1257,"children":1258},{"class":119,"line":715},[1259],{"type":24,"tag":117,"props":1260,"children":1261},{"style":148},[1262],{"type":29,"value":1150},{"type":24,"tag":117,"props":1264,"children":1266},{"class":119,"line":1265},19,[1267,1272,1276,1280,1284,1289],{"type":24,"tag":117,"props":1268,"children":1269},{"style":124},[1270],{"type":29,"value":1271},"    finally",{"type":24,"tag":117,"props":1273,"children":1274},{"style":148},[1275],{"type":29,"value":1072},{"type":24,"tag":117,"props":1277,"children":1278},{"style":142},[1279],{"type":29,"value":1116},{"type":24,"tag":117,"props":1281,"children":1282},{"style":148},[1283],{"type":29,"value":151},{"type":24,"tag":117,"props":1285,"children":1286},{"style":154},[1287],{"type":29,"value":1288},"ExitWriteLock",{"type":24,"tag":117,"props":1290,"children":1291},{"style":148},[1292],{"type":29,"value":1130},{"type":24,"tag":117,"props":1294,"children":1296},{"class":119,"line":1295},20,[1297],{"type":24,"tag":117,"props":1298,"children":1299},{"style":148},[1300],{"type":29,"value":721},{"type":24,"tag":25,"props":1302,"children":1303},{},[1304,1306,1311,1313,1319,1321,1326],{"type":29,"value":1305},"The key insight: ",{"type":24,"tag":53,"props":1307,"children":1309},{"className":1308},[],[1310],{"type":29,"value":805},{"type":29,"value":1312}," allows any number of concurrent read-lock holders, but a write lock waits for all readers to release and then blocks new acquisitions. When a write forces file growth, the writer calls ",{"type":24,"tag":53,"props":1314,"children":1316},{"className":1315},[],[1317],{"type":29,"value":1318},"EnsureCapacityCore()",{"type":29,"value":1320},", which disposes the old ",{"type":24,"tag":53,"props":1322,"children":1324},{"className":1323},[],[1325],{"type":29,"value":58},{"type":29,"value":1327}," and creates a new one. During this, no reader can be holding a reference to the old mapping — the write lock guarantees it.",{"type":24,"tag":869,"props":1329,"children":1331},{"id":1330},"reads-under-read-lock",[1332],{"type":29,"value":1333},"Reads Under Read Lock",{"type":24,"tag":25,"props":1335,"children":1336},{},[1337],{"type":29,"value":1338},"The read path is simpler — it always takes a read lock:",{"type":24,"tag":80,"props":1340,"children":1342},{"code":1341,"language":110,"meta":7,"className":111,"style":7},"public void ReadPage(uint pageId, Span\u003Cbyte> destination)\n{\n    _rwLock.EnterReadLock();\n    try { ReadPageCore(pageId, destination); }\n    finally { _rwLock.ExitReadLock(); }\n}\n",[1343],{"type":24,"tag":53,"props":1344,"children":1345},{"__ignoreMap":7},[1346,1404,1411,1430,1467,1494],{"type":24,"tag":117,"props":1347,"children":1348},{"class":119,"line":120},[1349,1353,1357,1362,1366,1370,1374,1378,1383,1387,1391,1395,1400],{"type":24,"tag":117,"props":1350,"children":1351},{"style":124},[1352],{"type":29,"value":256},{"type":24,"tag":117,"props":1354,"children":1355},{"style":124},[1356],{"type":29,"value":906},{"type":24,"tag":117,"props":1358,"children":1359},{"style":154},[1360],{"type":29,"value":1361}," ReadPage",{"type":24,"tag":117,"props":1363,"children":1364},{"style":148},[1365],{"type":29,"value":162},{"type":24,"tag":117,"props":1367,"children":1368},{"style":124},[1369],{"type":29,"value":920},{"type":24,"tag":117,"props":1371,"children":1372},{"style":205},[1373],{"type":29,"value":925},{"type":24,"tag":117,"props":1375,"children":1376},{"style":148},[1377],{"type":29,"value":221},{"type":24,"tag":117,"props":1379,"children":1380},{"style":205},[1381],{"type":29,"value":1382},"Span",{"type":24,"tag":117,"props":1384,"children":1385},{"style":148},[1386],{"type":29,"value":939},{"type":24,"tag":117,"props":1388,"children":1389},{"style":124},[1390],{"type":29,"value":944},{"type":24,"tag":117,"props":1392,"children":1393},{"style":148},[1394],{"type":29,"value":949},{"type":24,"tag":117,"props":1396,"children":1397},{"style":205},[1398],{"type":29,"value":1399},"destination",{"type":24,"tag":117,"props":1401,"children":1402},{"style":148},[1403],{"type":29,"value":318},{"type":24,"tag":117,"props":1405,"children":1406},{"class":119,"line":176},[1407],{"type":24,"tag":117,"props":1408,"children":1409},{"style":148},[1410],{"type":29,"value":326},{"type":24,"tag":117,"props":1412,"children":1413},{"class":119,"line":329},[1414,1418,1422,1426],{"type":24,"tag":117,"props":1415,"children":1416},{"style":142},[1417],{"type":29,"value":1173},{"type":24,"tag":117,"props":1419,"children":1420},{"style":148},[1421],{"type":29,"value":151},{"type":24,"tag":117,"props":1423,"children":1424},{"style":154},[1425],{"type":29,"value":1054},{"type":24,"tag":117,"props":1427,"children":1428},{"style":148},[1429],{"type":29,"value":1059},{"type":24,"tag":117,"props":1431,"children":1432},{"class":119,"line":367},[1433,1438,1442,1447,1451,1455,1459,1463],{"type":24,"tag":117,"props":1434,"children":1435},{"style":124},[1436],{"type":29,"value":1437},"    try",{"type":24,"tag":117,"props":1439,"children":1440},{"style":148},[1441],{"type":29,"value":1072},{"type":24,"tag":117,"props":1443,"children":1444},{"style":154},[1445],{"type":29,"value":1446},"ReadPageCore",{"type":24,"tag":117,"props":1448,"children":1449},{"style":148},[1450],{"type":29,"value":162},{"type":24,"tag":117,"props":1452,"children":1453},{"style":165},[1454],{"type":29,"value":1086},{"type":24,"tag":117,"props":1456,"children":1457},{"style":148},[1458],{"type":29,"value":221},{"type":24,"tag":117,"props":1460,"children":1461},{"style":165},[1462],{"type":29,"value":1399},{"type":24,"tag":117,"props":1464,"children":1465},{"style":148},[1466],{"type":29,"value":1099},{"type":24,"tag":117,"props":1468,"children":1469},{"class":119,"line":385},[1470,1474,1478,1482,1486,1490],{"type":24,"tag":117,"props":1471,"children":1472},{"style":124},[1473],{"type":29,"value":1271},{"type":24,"tag":117,"props":1475,"children":1476},{"style":148},[1477],{"type":29,"value":1072},{"type":24,"tag":117,"props":1479,"children":1480},{"style":142},[1481],{"type":29,"value":1116},{"type":24,"tag":117,"props":1483,"children":1484},{"style":148},[1485],{"type":29,"value":151},{"type":24,"tag":117,"props":1487,"children":1488},{"style":154},[1489],{"type":29,"value":1125},{"type":24,"tag":117,"props":1491,"children":1492},{"style":148},[1493],{"type":29,"value":1130},{"type":24,"tag":117,"props":1495,"children":1496},{"class":119,"line":394},[1497],{"type":24,"tag":117,"props":1498,"children":1499},{"style":148},[1500],{"type":29,"value":721},{"type":24,"tag":25,"props":1502,"children":1503},{},[1504,1506,1511,1513,1518],{"type":29,"value":1505},"Multiple readers can execute ",{"type":24,"tag":53,"props":1507,"children":1509},{"className":1508},[],[1510],{"type":29,"value":1446},{"type":29,"value":1512}," simultaneously. They're all reading from the same ",{"type":24,"tag":53,"props":1514,"children":1516},{"className":1515},[],[1517],{"type":29,"value":58},{"type":29,"value":1519},". As long as no writer needs to grow the file, there's zero contention.",{"type":24,"tag":869,"props":1521,"children":1523},{"id":1522},"why-not-just-a-mutex",[1524],{"type":29,"value":1525},"Why Not Just a Mutex?",{"type":24,"tag":25,"props":1527,"children":1528},{},[1529,1531,1537,1539,1545,1547,1553,1555,1560],{"type":29,"value":1530},"A ",{"type":24,"tag":53,"props":1532,"children":1534},{"className":1533},[],[1535],{"type":29,"value":1536},"Monitor",{"type":29,"value":1538}," or ",{"type":24,"tag":53,"props":1540,"children":1542},{"className":1541},[],[1543],{"type":29,"value":1544},"lock",{"type":29,"value":1546}," statement serializes ",{"type":24,"tag":1548,"props":1549,"children":1550},"em",{},[1551],{"type":29,"value":1552},"all",{"type":29,"value":1554}," operations. With 50 concurrent client connections, that means 49 readers wait while 1 reader completes, even though they could all operate in parallel. ",{"type":24,"tag":53,"props":1556,"children":1558},{"className":1557},[],[1559],{"type":29,"value":805},{"type":29,"value":1561}," eliminates this bottleneck for read-heavy workloads — which is the common case for most databases.",{"type":24,"tag":869,"props":1563,"children":1565},{"id":1564},"the-async-boundary-semaphoreslim",[1566],{"type":29,"value":1567},"The Async Boundary: SemaphoreSlim",{"type":24,"tag":25,"props":1569,"children":1570},{},[1571,1576,1578,1584,1586,1592,1594,1600,1602,1608],{"type":24,"tag":53,"props":1572,"children":1574},{"className":1573},[],[1575],{"type":29,"value":805},{"type":29,"value":1577}," has a limitation: it requires the acquiring thread to be the releasing thread. That's incompatible with ",{"type":24,"tag":53,"props":1579,"children":1581},{"className":1580},[],[1582],{"type":29,"value":1583},"async\u002Fawait",{"type":29,"value":1585},", where the continuation can run on a different thread. For ",{"type":24,"tag":53,"props":1587,"children":1589},{"className":1588},[],[1590],{"type":29,"value":1591},"FlushAsync()",{"type":29,"value":1593}," and ",{"type":24,"tag":53,"props":1595,"children":1597},{"className":1596},[],[1598],{"type":29,"value":1599},"BackupAsync()",{"type":29,"value":1601},", BLite uses a ",{"type":24,"tag":53,"props":1603,"children":1605},{"className":1604},[],[1606],{"type":29,"value":1607},"SemaphoreSlim",{"type":29,"value":1609}," instead:",{"type":24,"tag":80,"props":1611,"children":1613},{"code":1612,"language":110,"meta":7,"className":111,"style":7},"private readonly SemaphoreSlim _asyncLock = new(1, 1);\n\npublic async Task BackupAsync(string destinationPath, CancellationToken ct = default)\n{\n    await _asyncLock.WaitAsync(ct);\n    try\n    {\n        _fileStream.Flush(flushToDisk: true);\n        await _fileStream.CopyToAsync(dst);\n        await dst.FlushAsync(ct);\n    }\n    finally { _asyncLock.Release(); }\n}\n",[1614],{"type":24,"tag":53,"props":1615,"children":1616},{"__ignoreMap":7},[1617,1667,1674,1736,1743,1777,1784,1791,1831,1865,1898,1905,1934],{"type":24,"tag":117,"props":1618,"children":1619},{"class":119,"line":120},[1620,1624,1628,1633,1638,1642,1646,1650,1655,1659,1663],{"type":24,"tag":117,"props":1621,"children":1622},{"style":124},[1623],{"type":29,"value":822},{"type":24,"tag":117,"props":1625,"children":1626},{"style":124},[1627],{"type":29,"value":827},{"type":24,"tag":117,"props":1629,"children":1630},{"style":205},[1631],{"type":29,"value":1632}," SemaphoreSlim",{"type":24,"tag":117,"props":1634,"children":1635},{"style":130},[1636],{"type":29,"value":1637}," _asyncLock",{"type":24,"tag":117,"props":1639,"children":1640},{"style":136},[1641],{"type":29,"value":139},{"type":24,"tag":117,"props":1643,"children":1644},{"style":199},[1645],{"type":29,"value":202},{"type":24,"tag":117,"props":1647,"children":1648},{"style":148},[1649],{"type":29,"value":162},{"type":24,"tag":117,"props":1651,"children":1652},{"style":310},[1653],{"type":29,"value":1654},"1",{"type":24,"tag":117,"props":1656,"children":1657},{"style":148},[1658],{"type":29,"value":221},{"type":24,"tag":117,"props":1660,"children":1661},{"style":310},[1662],{"type":29,"value":1654},{"type":24,"tag":117,"props":1664,"children":1665},{"style":148},[1666],{"type":29,"value":173},{"type":24,"tag":117,"props":1668,"children":1669},{"class":119,"line":176},[1670],{"type":24,"tag":117,"props":1671,"children":1672},{"emptyLinePlaceholder":534},[1673],{"type":29,"value":537},{"type":24,"tag":117,"props":1675,"children":1676},{"class":119,"line":329},[1677,1681,1686,1691,1696,1700,1704,1709,1713,1718,1723,1727,1732],{"type":24,"tag":117,"props":1678,"children":1679},{"style":124},[1680],{"type":29,"value":256},{"type":24,"tag":117,"props":1682,"children":1683},{"style":124},[1684],{"type":29,"value":1685}," async",{"type":24,"tag":117,"props":1687,"children":1688},{"style":205},[1689],{"type":29,"value":1690}," Task",{"type":24,"tag":117,"props":1692,"children":1693},{"style":154},[1694],{"type":29,"value":1695}," BackupAsync",{"type":24,"tag":117,"props":1697,"children":1698},{"style":148},[1699],{"type":29,"value":162},{"type":24,"tag":117,"props":1701,"children":1702},{"style":124},[1703],{"type":29,"value":279},{"type":24,"tag":117,"props":1705,"children":1706},{"style":205},[1707],{"type":29,"value":1708}," destinationPath",{"type":24,"tag":117,"props":1710,"children":1711},{"style":148},[1712],{"type":29,"value":221},{"type":24,"tag":117,"props":1714,"children":1715},{"style":205},[1716],{"type":29,"value":1717},"CancellationToken",{"type":24,"tag":117,"props":1719,"children":1720},{"style":205},[1721],{"type":29,"value":1722}," ct",{"type":24,"tag":117,"props":1724,"children":1725},{"style":136},[1726],{"type":29,"value":139},{"type":24,"tag":117,"props":1728,"children":1729},{"style":199},[1730],{"type":29,"value":1731}," default",{"type":24,"tag":117,"props":1733,"children":1734},{"style":148},[1735],{"type":29,"value":318},{"type":24,"tag":117,"props":1737,"children":1738},{"class":119,"line":367},[1739],{"type":24,"tag":117,"props":1740,"children":1741},{"style":148},[1742],{"type":29,"value":326},{"type":24,"tag":117,"props":1744,"children":1745},{"class":119,"line":385},[1746,1751,1755,1759,1764,1768,1773],{"type":24,"tag":117,"props":1747,"children":1748},{"style":199},[1749],{"type":29,"value":1750},"    await",{"type":24,"tag":117,"props":1752,"children":1753},{"style":142},[1754],{"type":29,"value":1637},{"type":24,"tag":117,"props":1756,"children":1757},{"style":148},[1758],{"type":29,"value":151},{"type":24,"tag":117,"props":1760,"children":1761},{"style":154},[1762],{"type":29,"value":1763},"WaitAsync",{"type":24,"tag":117,"props":1765,"children":1766},{"style":148},[1767],{"type":29,"value":162},{"type":24,"tag":117,"props":1769,"children":1770},{"style":165},[1771],{"type":29,"value":1772},"ct",{"type":24,"tag":117,"props":1774,"children":1775},{"style":148},[1776],{"type":29,"value":173},{"type":24,"tag":117,"props":1778,"children":1779},{"class":119,"line":394},[1780],{"type":24,"tag":117,"props":1781,"children":1782},{"style":124},[1783],{"type":29,"value":1194},{"type":24,"tag":117,"props":1785,"children":1786},{"class":119,"line":426},[1787],{"type":24,"tag":117,"props":1788,"children":1789},{"style":148},[1790],{"type":29,"value":391},{"type":24,"tag":117,"props":1792,"children":1793},{"class":119,"line":473},[1794,1799,1803,1808,1812,1817,1822,1827],{"type":24,"tag":117,"props":1795,"children":1796},{"style":142},[1797],{"type":29,"value":1798},"        _fileStream",{"type":24,"tag":117,"props":1800,"children":1801},{"style":148},[1802],{"type":29,"value":151},{"type":24,"tag":117,"props":1804,"children":1805},{"style":154},[1806],{"type":29,"value":1807},"Flush",{"type":24,"tag":117,"props":1809,"children":1810},{"style":148},[1811],{"type":29,"value":162},{"type":24,"tag":117,"props":1813,"children":1814},{"style":205},[1815],{"type":29,"value":1816},"flushToDisk",{"type":24,"tag":117,"props":1818,"children":1819},{"style":148},[1820],{"type":29,"value":1821},": ",{"type":24,"tag":117,"props":1823,"children":1824},{"style":310},[1825],{"type":29,"value":1826},"true",{"type":24,"tag":117,"props":1828,"children":1829},{"style":148},[1830],{"type":29,"value":173},{"type":24,"tag":117,"props":1832,"children":1833},{"class":119,"line":486},[1834,1839,1843,1847,1852,1856,1861],{"type":24,"tag":117,"props":1835,"children":1836},{"style":199},[1837],{"type":29,"value":1838},"        await",{"type":24,"tag":117,"props":1840,"children":1841},{"style":142},[1842],{"type":29,"value":1012},{"type":24,"tag":117,"props":1844,"children":1845},{"style":148},[1846],{"type":29,"value":151},{"type":24,"tag":117,"props":1848,"children":1849},{"style":154},[1850],{"type":29,"value":1851},"CopyToAsync",{"type":24,"tag":117,"props":1853,"children":1854},{"style":148},[1855],{"type":29,"value":162},{"type":24,"tag":117,"props":1857,"children":1858},{"style":165},[1859],{"type":29,"value":1860},"dst",{"type":24,"tag":117,"props":1862,"children":1863},{"style":148},[1864],{"type":29,"value":173},{"type":24,"tag":117,"props":1866,"children":1867},{"class":119,"line":530},[1868,1872,1877,1881,1886,1890,1894],{"type":24,"tag":117,"props":1869,"children":1870},{"style":199},[1871],{"type":29,"value":1838},{"type":24,"tag":117,"props":1873,"children":1874},{"style":142},[1875],{"type":29,"value":1876}," dst",{"type":24,"tag":117,"props":1878,"children":1879},{"style":148},[1880],{"type":29,"value":151},{"type":24,"tag":117,"props":1882,"children":1883},{"style":154},[1884],{"type":29,"value":1885},"FlushAsync",{"type":24,"tag":117,"props":1887,"children":1888},{"style":148},[1889],{"type":29,"value":162},{"type":24,"tag":117,"props":1891,"children":1892},{"style":165},[1893],{"type":29,"value":1772},{"type":24,"tag":117,"props":1895,"children":1896},{"style":148},[1897],{"type":29,"value":173},{"type":24,"tag":117,"props":1899,"children":1900},{"class":119,"line":540},[1901],{"type":24,"tag":117,"props":1902,"children":1903},{"style":148},[1904],{"type":29,"value":1150},{"type":24,"tag":117,"props":1906,"children":1907},{"class":119,"line":587},[1908,1912,1916,1921,1925,1930],{"type":24,"tag":117,"props":1909,"children":1910},{"style":124},[1911],{"type":29,"value":1271},{"type":24,"tag":117,"props":1913,"children":1914},{"style":148},[1915],{"type":29,"value":1072},{"type":24,"tag":117,"props":1917,"children":1918},{"style":142},[1919],{"type":29,"value":1920},"_asyncLock",{"type":24,"tag":117,"props":1922,"children":1923},{"style":148},[1924],{"type":29,"value":151},{"type":24,"tag":117,"props":1926,"children":1927},{"style":154},[1928],{"type":29,"value":1929},"Release",{"type":24,"tag":117,"props":1931,"children":1932},{"style":148},[1933],{"type":29,"value":1130},{"type":24,"tag":117,"props":1935,"children":1936},{"class":119,"line":595},[1937],{"type":24,"tag":117,"props":1938,"children":1939},{"style":148},[1940],{"type":29,"value":721},{"type":24,"tag":25,"props":1942,"children":1943},{},[1944,1946,1951],{"type":29,"value":1945},"This serializes backup and flush operations without requiring thread affinity. The trade-off is that ",{"type":24,"tag":53,"props":1947,"children":1949},{"className":1948},[],[1950],{"type":29,"value":1607},{"type":29,"value":1952}," doesn't distinguish readers from writers — but these operations are infrequent enough that the cost is negligible.",{"type":24,"tag":869,"props":1954,"children":1956},{"id":1955},"allocation-under-write-lock",[1957],{"type":29,"value":1958},"Allocation Under Write Lock",{"type":24,"tag":25,"props":1960,"children":1961},{},[1962,1964,1970,1971,1977],{"type":29,"value":1963},"Page allocation modifies shared mutable state — ",{"type":24,"tag":53,"props":1965,"children":1967},{"className":1966},[],[1968],{"type":29,"value":1969},"_nextPageId",{"type":29,"value":1593},{"type":24,"tag":53,"props":1972,"children":1974},{"className":1973},[],[1975],{"type":29,"value":1976},"_firstFreePageId",{"type":29,"value":1978}," — so it always needs exclusive access:",{"type":24,"tag":80,"props":1980,"children":1982},{"code":1981,"language":110,"meta":7,"className":111,"style":7},"public uint AllocatePage()\n{\n    _rwLock.EnterWriteLock();\n    try\n    {\n        if (_firstFreePageId != 0)\n        {\n            var recycledPageId = _firstFreePageId;\n            ReadPageCore(recycledPageId, buffer);\n            _firstFreePageId = header.NextPageId;\n            UpdateFileHeaderFreePtrCore(_firstFreePageId);\n            return recycledPageId;\n        }\n        var pageId = _nextPageId++;\n        EnsureCapacityCore((long)pageId * PageSize);\n        return pageId;\n    }\n    finally { _rwLock.ExitWriteLock(); }\n}\n",[1983],{"type":24,"tag":53,"props":1984,"children":1985},{"__ignoreMap":7},[1986,2008,2015,2034,2041,2048,2078,2086,2112,2142,2172,2192,2208,2216,2246,2285,2300,2307,2334],{"type":24,"tag":117,"props":1987,"children":1988},{"class":119,"line":120},[1989,1993,1998,2003],{"type":24,"tag":117,"props":1990,"children":1991},{"style":124},[1992],{"type":29,"value":256},{"type":24,"tag":117,"props":1994,"children":1995},{"style":124},[1996],{"type":29,"value":1997}," uint",{"type":24,"tag":117,"props":1999,"children":2000},{"style":154},[2001],{"type":29,"value":2002}," AllocatePage",{"type":24,"tag":117,"props":2004,"children":2005},{"style":148},[2006],{"type":29,"value":2007},"()\n",{"type":24,"tag":117,"props":2009,"children":2010},{"class":119,"line":176},[2011],{"type":24,"tag":117,"props":2012,"children":2013},{"style":148},[2014],{"type":29,"value":326},{"type":24,"tag":117,"props":2016,"children":2017},{"class":119,"line":329},[2018,2022,2026,2030],{"type":24,"tag":117,"props":2019,"children":2020},{"style":142},[2021],{"type":29,"value":1173},{"type":24,"tag":117,"props":2023,"children":2024},{"style":148},[2025],{"type":29,"value":151},{"type":24,"tag":117,"props":2027,"children":2028},{"style":154},[2029],{"type":29,"value":1182},{"type":24,"tag":117,"props":2031,"children":2032},{"style":148},[2033],{"type":29,"value":1059},{"type":24,"tag":117,"props":2035,"children":2036},{"class":119,"line":367},[2037],{"type":24,"tag":117,"props":2038,"children":2039},{"style":124},[2040],{"type":29,"value":1194},{"type":24,"tag":117,"props":2042,"children":2043},{"class":119,"line":385},[2044],{"type":24,"tag":117,"props":2045,"children":2046},{"style":148},[2047],{"type":29,"value":391},{"type":24,"tag":117,"props":2049,"children":2050},{"class":119,"line":394},[2051,2056,2060,2064,2069,2074],{"type":24,"tag":117,"props":2052,"children":2053},{"style":124},[2054],{"type":29,"value":2055},"        if",{"type":24,"tag":117,"props":2057,"children":2058},{"style":148},[2059],{"type":29,"value":987},{"type":24,"tag":117,"props":2061,"children":2062},{"style":165},[2063],{"type":29,"value":1976},{"type":24,"tag":117,"props":2065,"children":2066},{"style":136},[2067],{"type":29,"value":2068}," !=",{"type":24,"tag":117,"props":2070,"children":2071},{"style":310},[2072],{"type":29,"value":2073}," 0",{"type":24,"tag":117,"props":2075,"children":2076},{"style":148},[2077],{"type":29,"value":318},{"type":24,"tag":117,"props":2079,"children":2080},{"class":119,"line":426},[2081],{"type":24,"tag":117,"props":2082,"children":2083},{"style":148},[2084],{"type":29,"value":2085},"        {\n",{"type":24,"tag":117,"props":2087,"children":2088},{"class":119,"line":473},[2089,2094,2099,2103,2108],{"type":24,"tag":117,"props":2090,"children":2091},{"style":124},[2092],{"type":29,"value":2093},"            var",{"type":24,"tag":117,"props":2095,"children":2096},{"style":130},[2097],{"type":29,"value":2098}," recycledPageId",{"type":24,"tag":117,"props":2100,"children":2101},{"style":136},[2102],{"type":29,"value":139},{"type":24,"tag":117,"props":2104,"children":2105},{"style":165},[2106],{"type":29,"value":2107}," _firstFreePageId",{"type":24,"tag":117,"props":2109,"children":2110},{"style":148},[2111],{"type":29,"value":364},{"type":24,"tag":117,"props":2113,"children":2114},{"class":119,"line":486},[2115,2120,2124,2129,2133,2138],{"type":24,"tag":117,"props":2116,"children":2117},{"style":154},[2118],{"type":29,"value":2119},"            ReadPageCore",{"type":24,"tag":117,"props":2121,"children":2122},{"style":148},[2123],{"type":29,"value":162},{"type":24,"tag":117,"props":2125,"children":2126},{"style":165},[2127],{"type":29,"value":2128},"recycledPageId",{"type":24,"tag":117,"props":2130,"children":2131},{"style":148},[2132],{"type":29,"value":221},{"type":24,"tag":117,"props":2134,"children":2135},{"style":165},[2136],{"type":29,"value":2137},"buffer",{"type":24,"tag":117,"props":2139,"children":2140},{"style":148},[2141],{"type":29,"value":173},{"type":24,"tag":117,"props":2143,"children":2144},{"class":119,"line":530},[2145,2150,2154,2159,2163,2168],{"type":24,"tag":117,"props":2146,"children":2147},{"style":165},[2148],{"type":29,"value":2149},"            _firstFreePageId",{"type":24,"tag":117,"props":2151,"children":2152},{"style":136},[2153],{"type":29,"value":139},{"type":24,"tag":117,"props":2155,"children":2156},{"style":142},[2157],{"type":29,"value":2158}," header",{"type":24,"tag":117,"props":2160,"children":2161},{"style":148},[2162],{"type":29,"value":151},{"type":24,"tag":117,"props":2164,"children":2165},{"style":142},[2166],{"type":29,"value":2167},"NextPageId",{"type":24,"tag":117,"props":2169,"children":2170},{"style":148},[2171],{"type":29,"value":364},{"type":24,"tag":117,"props":2173,"children":2174},{"class":119,"line":540},[2175,2180,2184,2188],{"type":24,"tag":117,"props":2176,"children":2177},{"style":154},[2178],{"type":29,"value":2179},"            UpdateFileHeaderFreePtrCore",{"type":24,"tag":117,"props":2181,"children":2182},{"style":148},[2183],{"type":29,"value":162},{"type":24,"tag":117,"props":2185,"children":2186},{"style":165},[2187],{"type":29,"value":1976},{"type":24,"tag":117,"props":2189,"children":2190},{"style":148},[2191],{"type":29,"value":173},{"type":24,"tag":117,"props":2193,"children":2194},{"class":119,"line":587},[2195,2200,2204],{"type":24,"tag":117,"props":2196,"children":2197},{"style":124},[2198],{"type":29,"value":2199},"            return",{"type":24,"tag":117,"props":2201,"children":2202},{"style":165},[2203],{"type":29,"value":2098},{"type":24,"tag":117,"props":2205,"children":2206},{"style":148},[2207],{"type":29,"value":364},{"type":24,"tag":117,"props":2209,"children":2210},{"class":119,"line":595},[2211],{"type":24,"tag":117,"props":2212,"children":2213},{"style":148},[2214],{"type":29,"value":2215},"        }\n",{"type":24,"tag":117,"props":2217,"children":2218},{"class":119,"line":624},[2219,2224,2228,2232,2237,2242],{"type":24,"tag":117,"props":2220,"children":2221},{"style":124},[2222],{"type":29,"value":2223},"        var",{"type":24,"tag":117,"props":2225,"children":2226},{"style":130},[2227],{"type":29,"value":925},{"type":24,"tag":117,"props":2229,"children":2230},{"style":136},[2231],{"type":29,"value":139},{"type":24,"tag":117,"props":2233,"children":2234},{"style":165},[2235],{"type":29,"value":2236}," _nextPageId",{"type":24,"tag":117,"props":2238,"children":2239},{"style":136},[2240],{"type":29,"value":2241},"++",{"type":24,"tag":117,"props":2243,"children":2244},{"style":148},[2245],{"type":29,"value":364},{"type":24,"tag":117,"props":2247,"children":2248},{"class":119,"line":664},[2249,2253,2258,2263,2268,2272,2277,2281],{"type":24,"tag":117,"props":2250,"children":2251},{"style":154},[2252],{"type":29,"value":1209},{"type":24,"tag":117,"props":2254,"children":2255},{"style":148},[2256],{"type":29,"value":2257},"((",{"type":24,"tag":117,"props":2259,"children":2260},{"style":124},[2261],{"type":29,"value":2262},"long",{"type":24,"tag":117,"props":2264,"children":2265},{"style":148},[2266],{"type":29,"value":2267},")",{"type":24,"tag":117,"props":2269,"children":2270},{"style":165},[2271],{"type":29,"value":1086},{"type":24,"tag":117,"props":2273,"children":2274},{"style":136},[2275],{"type":29,"value":2276}," *",{"type":24,"tag":117,"props":2278,"children":2279},{"style":165},[2280],{"type":29,"value":1002},{"type":24,"tag":117,"props":2282,"children":2283},{"style":148},[2284],{"type":29,"value":173},{"type":24,"tag":117,"props":2286,"children":2287},{"class":119,"line":677},[2288,2292,2296],{"type":24,"tag":117,"props":2289,"children":2290},{"style":124},[2291],{"type":29,"value":1138},{"type":24,"tag":117,"props":2293,"children":2294},{"style":165},[2295],{"type":29,"value":925},{"type":24,"tag":117,"props":2297,"children":2298},{"style":148},[2299],{"type":29,"value":364},{"type":24,"tag":117,"props":2301,"children":2302},{"class":119,"line":706},[2303],{"type":24,"tag":117,"props":2304,"children":2305},{"style":148},[2306],{"type":29,"value":1150},{"type":24,"tag":117,"props":2308,"children":2309},{"class":119,"line":715},[2310,2314,2318,2322,2326,2330],{"type":24,"tag":117,"props":2311,"children":2312},{"style":124},[2313],{"type":29,"value":1271},{"type":24,"tag":117,"props":2315,"children":2316},{"style":148},[2317],{"type":29,"value":1072},{"type":24,"tag":117,"props":2319,"children":2320},{"style":142},[2321],{"type":29,"value":1116},{"type":24,"tag":117,"props":2323,"children":2324},{"style":148},[2325],{"type":29,"value":151},{"type":24,"tag":117,"props":2327,"children":2328},{"style":154},[2329],{"type":29,"value":1288},{"type":24,"tag":117,"props":2331,"children":2332},{"style":148},[2333],{"type":29,"value":1130},{"type":24,"tag":117,"props":2335,"children":2336},{"class":119,"line":1265},[2337],{"type":24,"tag":117,"props":2338,"children":2339},{"style":148},[2340],{"type":29,"value":721},{"type":24,"tag":25,"props":2342,"children":2343},{},[2344],{"type":29,"value":2345},"This is a contention point — two threads allocating pages at the exact same time will serialize. But allocation is rare compared to reads and writes, so the impact is proportional.",{"type":24,"tag":37,"props":2347,"children":2348},{},[],{"type":24,"tag":41,"props":2350,"children":2352},{"id":2351},"lock-summary",[2353],{"type":29,"value":2354},"Lock Summary",{"type":24,"tag":2356,"props":2357,"children":2358},"table",{},[2359,2388],{"type":24,"tag":2360,"props":2361,"children":2362},"thead",{},[2363],{"type":24,"tag":2364,"props":2365,"children":2366},"tr",{},[2367,2373,2378,2383],{"type":24,"tag":2368,"props":2369,"children":2370},"th",{},[2371],{"type":29,"value":2372},"Operation",{"type":24,"tag":2368,"props":2374,"children":2375},{},[2376],{"type":29,"value":2377},"Lock Type",{"type":24,"tag":2368,"props":2379,"children":2380},{},[2381],{"type":29,"value":2382},"Mode",{"type":24,"tag":2368,"props":2384,"children":2385},{},[2386],{"type":29,"value":2387},"Contention",{"type":24,"tag":2389,"props":2390,"children":2391},"tbody",{},[2392,2423,2454,2485,2522,2558],{"type":24,"tag":2364,"props":2393,"children":2394},{},[2395,2405,2413,2418],{"type":24,"tag":2396,"props":2397,"children":2398},"td",{},[2399],{"type":24,"tag":53,"props":2400,"children":2402},{"className":2401},[],[2403],{"type":29,"value":2404},"ReadPage",{"type":24,"tag":2396,"props":2406,"children":2407},{},[2408],{"type":24,"tag":53,"props":2409,"children":2411},{"className":2410},[],[2412],{"type":29,"value":805},{"type":24,"tag":2396,"props":2414,"children":2415},{},[2416],{"type":29,"value":2417},"Read",{"type":24,"tag":2396,"props":2419,"children":2420},{},[2421],{"type":29,"value":2422},"Zero (concurrent with other reads\u002Fwrites)",{"type":24,"tag":2364,"props":2424,"children":2425},{},[2426,2437,2445,2449],{"type":24,"tag":2396,"props":2427,"children":2428},{},[2429,2435],{"type":24,"tag":53,"props":2430,"children":2432},{"className":2431},[],[2433],{"type":29,"value":2434},"WritePage",{"type":29,"value":2436}," (no growth)",{"type":24,"tag":2396,"props":2438,"children":2439},{},[2440],{"type":24,"tag":53,"props":2441,"children":2443},{"className":2442},[],[2444],{"type":29,"value":805},{"type":24,"tag":2396,"props":2446,"children":2447},{},[2448],{"type":29,"value":2417},{"type":24,"tag":2396,"props":2450,"children":2451},{},[2452],{"type":29,"value":2453},"Zero (concurrent)",{"type":24,"tag":2364,"props":2455,"children":2456},{},[2457,2467,2475,2480],{"type":24,"tag":2396,"props":2458,"children":2459},{},[2460,2465],{"type":24,"tag":53,"props":2461,"children":2463},{"className":2462},[],[2464],{"type":29,"value":2434},{"type":29,"value":2466}," (growth)",{"type":24,"tag":2396,"props":2468,"children":2469},{},[2470],{"type":24,"tag":53,"props":2471,"children":2473},{"className":2472},[],[2474],{"type":29,"value":805},{"type":24,"tag":2396,"props":2476,"children":2477},{},[2478],{"type":29,"value":2479},"Write",{"type":24,"tag":2396,"props":2481,"children":2482},{},[2483],{"type":29,"value":2484},"Brief: blocks until all readers release",{"type":24,"tag":2364,"props":2486,"children":2487},{},[2488,2505,2513,2517],{"type":24,"tag":2396,"props":2489,"children":2490},{},[2491,2497,2499],{"type":24,"tag":53,"props":2492,"children":2494},{"className":2493},[],[2495],{"type":29,"value":2496},"AllocatePage",{"type":29,"value":2498}," \u002F ",{"type":24,"tag":53,"props":2500,"children":2502},{"className":2501},[],[2503],{"type":29,"value":2504},"FreePage",{"type":24,"tag":2396,"props":2506,"children":2507},{},[2508],{"type":24,"tag":53,"props":2509,"children":2511},{"className":2510},[],[2512],{"type":29,"value":805},{"type":24,"tag":2396,"props":2514,"children":2515},{},[2516],{"type":29,"value":2479},{"type":24,"tag":2396,"props":2518,"children":2519},{},[2520],{"type":29,"value":2521},"Rare: serialized per file",{"type":24,"tag":2364,"props":2523,"children":2524},{},[2525,2540,2548,2553],{"type":24,"tag":2396,"props":2526,"children":2527},{},[2528,2533,2534],{"type":24,"tag":53,"props":2529,"children":2531},{"className":2530},[],[2532],{"type":29,"value":1885},{"type":29,"value":2498},{"type":24,"tag":53,"props":2535,"children":2537},{"className":2536},[],[2538],{"type":29,"value":2539},"BackupAsync",{"type":24,"tag":2396,"props":2541,"children":2542},{},[2543],{"type":24,"tag":53,"props":2544,"children":2546},{"className":2545},[],[2547],{"type":29,"value":1607},{"type":24,"tag":2396,"props":2549,"children":2550},{},[2551],{"type":29,"value":2552},"Exclusive",{"type":24,"tag":2396,"props":2554,"children":2555},{},[2556],{"type":29,"value":2557},"Infrequent: serialized",{"type":24,"tag":2364,"props":2559,"children":2560},{},[2561,2570,2575,2579],{"type":24,"tag":2396,"props":2562,"children":2563},{},[2564],{"type":24,"tag":53,"props":2565,"children":2567},{"className":2566},[],[2568],{"type":29,"value":2569},"Dispose",{"type":24,"tag":2396,"props":2571,"children":2572},{},[2573],{"type":29,"value":2574},"Both",{"type":24,"tag":2396,"props":2576,"children":2577},{},[2578],{"type":29,"value":2552},{"type":24,"tag":2396,"props":2580,"children":2581},{},[2582],{"type":29,"value":2583},"Once: shutdown only",{"type":24,"tag":25,"props":2585,"children":2586},{},[2587],{"type":29,"value":2588},"The net effect: under normal load, reads and writes are fully concurrent. Contention only happens when the file must grow or a page is allocated — both of which are amortized by pre-allocation in 1 MB blocks.",{"type":24,"tag":37,"props":2590,"children":2591},{},[],{"type":24,"tag":41,"props":2593,"children":2595},{"id":2594},"session-isolation-one-connection-one-transaction",[2596],{"type":29,"value":2597},"Session Isolation: One Connection, One Transaction",{"type":24,"tag":25,"props":2599,"children":2600},{},[2601],{"type":29,"value":2602},"With the storage layer protected, the next question is how to give each client connection an independent transaction context. In server mode, multiple clients connect simultaneously, each running their own CRUD operations. They shouldn't see each other's uncommitted writes, and a rollback on one connection shouldn't affect another.",{"type":24,"tag":25,"props":2604,"children":2605},{},[2606,2608,2614],{"type":29,"value":2607},"BLite introduces ",{"type":24,"tag":53,"props":2609,"children":2611},{"className":2610},[],[2612],{"type":29,"value":2613},"BLiteSession",{"type":29,"value":807},{"type":24,"tag":80,"props":2616,"children":2618},{"code":2617,"language":110,"meta":7,"className":111,"style":7},"public sealed class BLiteSession : ITransactionHolder, IDisposable\n{\n    private readonly StorageEngine _storage;\n    private readonly ConcurrentDictionary\u003Cstring, Lazy\u003CDynamicCollection>> _collections = new();\n    private ITransaction? _currentTransaction;\n\n    internal BLiteSession(StorageEngine storage)\n    {\n        _storage = storage;\n    }\n\n    public ITransaction BeginTransaction()\n    {\n        if (CurrentTransaction != null) return CurrentTransaction;\n        CurrentTransaction = _storage.BeginTransaction();\n        return CurrentTransaction!;\n    }\n\n    public void Commit()\n    {\n        foreach (var lazy in _collections.Values)\n            lazy.Value.PersistIndexMetadata();\n        if (CurrentTransaction != null)\n        {\n            try { CurrentTransaction.Commit(); }\n            finally { CurrentTransaction = null; }\n        }\n    }\n\n    public void Rollback()\n    {\n        if (CurrentTransaction != null)\n        {\n            try { CurrentTransaction.Rollback(); }\n            finally { CurrentTransaction = null; }\n        }\n    }\n}\n",[2619],{"type":24,"tag":53,"props":2620,"children":2621},{"__ignoreMap":7},[2622,2663,2670,2696,2760,2785,2792,2821,2828,2848,2855,2862,2883,2890,2932,2961,2980,2987,2994,3014,3021,3066,3097,3125,3133,3163,3193,3201,3209,3217,3238,3246,3274,3282,3311,3339,3347,3355],{"type":24,"tag":117,"props":2623,"children":2624},{"class":119,"line":120},[2625,2629,2634,2639,2644,2649,2654,2658],{"type":24,"tag":117,"props":2626,"children":2627},{"style":124},[2628],{"type":29,"value":256},{"type":24,"tag":117,"props":2630,"children":2631},{"style":124},[2632],{"type":29,"value":2633}," sealed",{"type":24,"tag":117,"props":2635,"children":2636},{"style":124},[2637],{"type":29,"value":2638}," class",{"type":24,"tag":117,"props":2640,"children":2641},{"style":205},[2642],{"type":29,"value":2643}," BLiteSession",{"type":24,"tag":117,"props":2645,"children":2646},{"style":148},[2647],{"type":29,"value":2648}," : ",{"type":24,"tag":117,"props":2650,"children":2651},{"style":205},[2652],{"type":29,"value":2653},"ITransactionHolder",{"type":24,"tag":117,"props":2655,"children":2656},{"style":148},[2657],{"type":29,"value":221},{"type":24,"tag":117,"props":2659,"children":2660},{"style":205},[2661],{"type":29,"value":2662},"IDisposable\n",{"type":24,"tag":117,"props":2664,"children":2665},{"class":119,"line":176},[2666],{"type":24,"tag":117,"props":2667,"children":2668},{"style":148},[2669],{"type":29,"value":326},{"type":24,"tag":117,"props":2671,"children":2672},{"class":119,"line":329},[2673,2678,2682,2687,2692],{"type":24,"tag":117,"props":2674,"children":2675},{"style":124},[2676],{"type":29,"value":2677},"    private",{"type":24,"tag":117,"props":2679,"children":2680},{"style":124},[2681],{"type":29,"value":827},{"type":24,"tag":117,"props":2683,"children":2684},{"style":205},[2685],{"type":29,"value":2686}," StorageEngine",{"type":24,"tag":117,"props":2688,"children":2689},{"style":130},[2690],{"type":29,"value":2691}," _storage",{"type":24,"tag":117,"props":2693,"children":2694},{"style":148},[2695],{"type":29,"value":364},{"type":24,"tag":117,"props":2697,"children":2698},{"class":119,"line":367},[2699,2703,2707,2712,2716,2720,2724,2729,2733,2738,2743,2748,2752,2756],{"type":24,"tag":117,"props":2700,"children":2701},{"style":124},[2702],{"type":29,"value":2677},{"type":24,"tag":117,"props":2704,"children":2705},{"style":124},[2706],{"type":29,"value":827},{"type":24,"tag":117,"props":2708,"children":2709},{"style":205},[2710],{"type":29,"value":2711}," ConcurrentDictionary",{"type":24,"tag":117,"props":2713,"children":2714},{"style":148},[2715],{"type":29,"value":939},{"type":24,"tag":117,"props":2717,"children":2718},{"style":124},[2719],{"type":29,"value":279},{"type":24,"tag":117,"props":2721,"children":2722},{"style":148},[2723],{"type":29,"value":221},{"type":24,"tag":117,"props":2725,"children":2726},{"style":205},[2727],{"type":29,"value":2728},"Lazy",{"type":24,"tag":117,"props":2730,"children":2731},{"style":148},[2732],{"type":29,"value":939},{"type":24,"tag":117,"props":2734,"children":2735},{"style":205},[2736],{"type":29,"value":2737},"DynamicCollection",{"type":24,"tag":117,"props":2739,"children":2740},{"style":148},[2741],{"type":29,"value":2742},">> ",{"type":24,"tag":117,"props":2744,"children":2745},{"style":130},[2746],{"type":29,"value":2747},"_collections",{"type":24,"tag":117,"props":2749,"children":2750},{"style":136},[2751],{"type":29,"value":139},{"type":24,"tag":117,"props":2753,"children":2754},{"style":199},[2755],{"type":29,"value":202},{"type":24,"tag":117,"props":2757,"children":2758},{"style":148},[2759],{"type":29,"value":1059},{"type":24,"tag":117,"props":2761,"children":2762},{"class":119,"line":385},[2763,2767,2772,2776,2781],{"type":24,"tag":117,"props":2764,"children":2765},{"style":124},[2766],{"type":29,"value":2677},{"type":24,"tag":117,"props":2768,"children":2769},{"style":205},[2770],{"type":29,"value":2771}," ITransaction",{"type":24,"tag":117,"props":2773,"children":2774},{"style":148},[2775],{"type":29,"value":298},{"type":24,"tag":117,"props":2777,"children":2778},{"style":130},[2779],{"type":29,"value":2780},"_currentTransaction",{"type":24,"tag":117,"props":2782,"children":2783},{"style":148},[2784],{"type":29,"value":364},{"type":24,"tag":117,"props":2786,"children":2787},{"class":119,"line":394},[2788],{"type":24,"tag":117,"props":2789,"children":2790},{"emptyLinePlaceholder":534},[2791],{"type":29,"value":537},{"type":24,"tag":117,"props":2793,"children":2794},{"class":119,"line":426},[2795,2800,2804,2808,2812,2817],{"type":24,"tag":117,"props":2796,"children":2797},{"style":124},[2798],{"type":29,"value":2799},"    internal",{"type":24,"tag":117,"props":2801,"children":2802},{"style":154},[2803],{"type":29,"value":2643},{"type":24,"tag":117,"props":2805,"children":2806},{"style":148},[2807],{"type":29,"value":162},{"type":24,"tag":117,"props":2809,"children":2810},{"style":205},[2811],{"type":29,"value":732},{"type":24,"tag":117,"props":2813,"children":2814},{"style":205},[2815],{"type":29,"value":2816}," storage",{"type":24,"tag":117,"props":2818,"children":2819},{"style":148},[2820],{"type":29,"value":318},{"type":24,"tag":117,"props":2822,"children":2823},{"class":119,"line":473},[2824],{"type":24,"tag":117,"props":2825,"children":2826},{"style":148},[2827],{"type":29,"value":391},{"type":24,"tag":117,"props":2829,"children":2830},{"class":119,"line":486},[2831,2836,2840,2844],{"type":24,"tag":117,"props":2832,"children":2833},{"style":165},[2834],{"type":29,"value":2835},"        _storage",{"type":24,"tag":117,"props":2837,"children":2838},{"style":136},[2839],{"type":29,"value":139},{"type":24,"tag":117,"props":2841,"children":2842},{"style":165},[2843],{"type":29,"value":2816},{"type":24,"tag":117,"props":2845,"children":2846},{"style":148},[2847],{"type":29,"value":364},{"type":24,"tag":117,"props":2849,"children":2850},{"class":119,"line":530},[2851],{"type":24,"tag":117,"props":2852,"children":2853},{"style":148},[2854],{"type":29,"value":1150},{"type":24,"tag":117,"props":2856,"children":2857},{"class":119,"line":540},[2858],{"type":24,"tag":117,"props":2859,"children":2860},{"emptyLinePlaceholder":534},[2861],{"type":29,"value":537},{"type":24,"tag":117,"props":2863,"children":2864},{"class":119,"line":587},[2865,2870,2874,2879],{"type":24,"tag":117,"props":2866,"children":2867},{"style":124},[2868],{"type":29,"value":2869},"    public",{"type":24,"tag":117,"props":2871,"children":2872},{"style":205},[2873],{"type":29,"value":2771},{"type":24,"tag":117,"props":2875,"children":2876},{"style":154},[2877],{"type":29,"value":2878}," BeginTransaction",{"type":24,"tag":117,"props":2880,"children":2881},{"style":148},[2882],{"type":29,"value":2007},{"type":24,"tag":117,"props":2884,"children":2885},{"class":119,"line":595},[2886],{"type":24,"tag":117,"props":2887,"children":2888},{"style":148},[2889],{"type":29,"value":391},{"type":24,"tag":117,"props":2891,"children":2892},{"class":119,"line":624},[2893,2897,2901,2906,2910,2914,2918,2923,2928],{"type":24,"tag":117,"props":2894,"children":2895},{"style":124},[2896],{"type":29,"value":2055},{"type":24,"tag":117,"props":2898,"children":2899},{"style":148},[2900],{"type":29,"value":987},{"type":24,"tag":117,"props":2902,"children":2903},{"style":165},[2904],{"type":29,"value":2905},"CurrentTransaction",{"type":24,"tag":117,"props":2907,"children":2908},{"style":136},[2909],{"type":29,"value":2068},{"type":24,"tag":117,"props":2911,"children":2912},{"style":310},[2913],{"type":29,"value":313},{"type":24,"tag":117,"props":2915,"children":2916},{"style":148},[2917],{"type":29,"value":454},{"type":24,"tag":117,"props":2919,"children":2920},{"style":124},[2921],{"type":29,"value":2922},"return",{"type":24,"tag":117,"props":2924,"children":2925},{"style":165},[2926],{"type":29,"value":2927}," CurrentTransaction",{"type":24,"tag":117,"props":2929,"children":2930},{"style":148},[2931],{"type":29,"value":364},{"type":24,"tag":117,"props":2933,"children":2934},{"class":119,"line":664},[2935,2940,2944,2948,2952,2957],{"type":24,"tag":117,"props":2936,"children":2937},{"style":165},[2938],{"type":29,"value":2939},"        CurrentTransaction",{"type":24,"tag":117,"props":2941,"children":2942},{"style":136},[2943],{"type":29,"value":139},{"type":24,"tag":117,"props":2945,"children":2946},{"style":142},[2947],{"type":29,"value":2691},{"type":24,"tag":117,"props":2949,"children":2950},{"style":148},[2951],{"type":29,"value":151},{"type":24,"tag":117,"props":2953,"children":2954},{"style":154},[2955],{"type":29,"value":2956},"BeginTransaction",{"type":24,"tag":117,"props":2958,"children":2959},{"style":148},[2960],{"type":29,"value":1059},{"type":24,"tag":117,"props":2962,"children":2963},{"class":119,"line":677},[2964,2968,2972,2976],{"type":24,"tag":117,"props":2965,"children":2966},{"style":124},[2967],{"type":29,"value":1138},{"type":24,"tag":117,"props":2969,"children":2970},{"style":165},[2971],{"type":29,"value":2927},{"type":24,"tag":117,"props":2973,"children":2974},{"style":136},[2975],{"type":29,"value":1017},{"type":24,"tag":117,"props":2977,"children":2978},{"style":148},[2979],{"type":29,"value":364},{"type":24,"tag":117,"props":2981,"children":2982},{"class":119,"line":706},[2983],{"type":24,"tag":117,"props":2984,"children":2985},{"style":148},[2986],{"type":29,"value":1150},{"type":24,"tag":117,"props":2988,"children":2989},{"class":119,"line":715},[2990],{"type":24,"tag":117,"props":2991,"children":2992},{"emptyLinePlaceholder":534},[2993],{"type":29,"value":537},{"type":24,"tag":117,"props":2995,"children":2996},{"class":119,"line":1265},[2997,3001,3005,3010],{"type":24,"tag":117,"props":2998,"children":2999},{"style":124},[3000],{"type":29,"value":2869},{"type":24,"tag":117,"props":3002,"children":3003},{"style":124},[3004],{"type":29,"value":906},{"type":24,"tag":117,"props":3006,"children":3007},{"style":154},[3008],{"type":29,"value":3009}," Commit",{"type":24,"tag":117,"props":3011,"children":3012},{"style":148},[3013],{"type":29,"value":2007},{"type":24,"tag":117,"props":3015,"children":3016},{"class":119,"line":1295},[3017],{"type":24,"tag":117,"props":3018,"children":3019},{"style":148},[3020],{"type":29,"value":391},{"type":24,"tag":117,"props":3022,"children":3024},{"class":119,"line":3023},21,[3025,3030,3034,3038,3043,3048,3053,3057,3062],{"type":24,"tag":117,"props":3026,"children":3027},{"style":124},[3028],{"type":29,"value":3029},"        foreach",{"type":24,"tag":117,"props":3031,"children":3032},{"style":148},[3033],{"type":29,"value":987},{"type":24,"tag":117,"props":3035,"children":3036},{"style":124},[3037],{"type":29,"value":127},{"type":24,"tag":117,"props":3039,"children":3040},{"style":130},[3041],{"type":29,"value":3042}," lazy",{"type":24,"tag":117,"props":3044,"children":3045},{"style":124},[3046],{"type":29,"value":3047}," in",{"type":24,"tag":117,"props":3049,"children":3050},{"style":142},[3051],{"type":29,"value":3052}," _collections",{"type":24,"tag":117,"props":3054,"children":3055},{"style":148},[3056],{"type":29,"value":151},{"type":24,"tag":117,"props":3058,"children":3059},{"style":142},[3060],{"type":29,"value":3061},"Values",{"type":24,"tag":117,"props":3063,"children":3064},{"style":148},[3065],{"type":29,"value":318},{"type":24,"tag":117,"props":3067,"children":3069},{"class":119,"line":3068},22,[3070,3075,3079,3084,3088,3093],{"type":24,"tag":117,"props":3071,"children":3072},{"style":142},[3073],{"type":29,"value":3074},"            lazy",{"type":24,"tag":117,"props":3076,"children":3077},{"style":148},[3078],{"type":29,"value":151},{"type":24,"tag":117,"props":3080,"children":3081},{"style":142},[3082],{"type":29,"value":3083},"Value",{"type":24,"tag":117,"props":3085,"children":3086},{"style":148},[3087],{"type":29,"value":151},{"type":24,"tag":117,"props":3089,"children":3090},{"style":154},[3091],{"type":29,"value":3092},"PersistIndexMetadata",{"type":24,"tag":117,"props":3094,"children":3095},{"style":148},[3096],{"type":29,"value":1059},{"type":24,"tag":117,"props":3098,"children":3100},{"class":119,"line":3099},23,[3101,3105,3109,3113,3117,3121],{"type":24,"tag":117,"props":3102,"children":3103},{"style":124},[3104],{"type":29,"value":2055},{"type":24,"tag":117,"props":3106,"children":3107},{"style":148},[3108],{"type":29,"value":987},{"type":24,"tag":117,"props":3110,"children":3111},{"style":165},[3112],{"type":29,"value":2905},{"type":24,"tag":117,"props":3114,"children":3115},{"style":136},[3116],{"type":29,"value":2068},{"type":24,"tag":117,"props":3118,"children":3119},{"style":310},[3120],{"type":29,"value":313},{"type":24,"tag":117,"props":3122,"children":3123},{"style":148},[3124],{"type":29,"value":318},{"type":24,"tag":117,"props":3126,"children":3128},{"class":119,"line":3127},24,[3129],{"type":24,"tag":117,"props":3130,"children":3131},{"style":148},[3132],{"type":29,"value":2085},{"type":24,"tag":117,"props":3134,"children":3136},{"class":119,"line":3135},25,[3137,3142,3146,3150,3154,3159],{"type":24,"tag":117,"props":3138,"children":3139},{"style":124},[3140],{"type":29,"value":3141},"            try",{"type":24,"tag":117,"props":3143,"children":3144},{"style":148},[3145],{"type":29,"value":1072},{"type":24,"tag":117,"props":3147,"children":3148},{"style":142},[3149],{"type":29,"value":2905},{"type":24,"tag":117,"props":3151,"children":3152},{"style":148},[3153],{"type":29,"value":151},{"type":24,"tag":117,"props":3155,"children":3156},{"style":154},[3157],{"type":29,"value":3158},"Commit",{"type":24,"tag":117,"props":3160,"children":3161},{"style":148},[3162],{"type":29,"value":1130},{"type":24,"tag":117,"props":3164,"children":3166},{"class":119,"line":3165},26,[3167,3172,3176,3180,3184,3188],{"type":24,"tag":117,"props":3168,"children":3169},{"style":124},[3170],{"type":29,"value":3171},"            finally",{"type":24,"tag":117,"props":3173,"children":3174},{"style":148},[3175],{"type":29,"value":1072},{"type":24,"tag":117,"props":3177,"children":3178},{"style":165},[3179],{"type":29,"value":2905},{"type":24,"tag":117,"props":3181,"children":3182},{"style":136},[3183],{"type":29,"value":139},{"type":24,"tag":117,"props":3185,"children":3186},{"style":310},[3187],{"type":29,"value":313},{"type":24,"tag":117,"props":3189,"children":3190},{"style":148},[3191],{"type":29,"value":3192},"; }\n",{"type":24,"tag":117,"props":3194,"children":3196},{"class":119,"line":3195},27,[3197],{"type":24,"tag":117,"props":3198,"children":3199},{"style":148},[3200],{"type":29,"value":2215},{"type":24,"tag":117,"props":3202,"children":3204},{"class":119,"line":3203},28,[3205],{"type":24,"tag":117,"props":3206,"children":3207},{"style":148},[3208],{"type":29,"value":1150},{"type":24,"tag":117,"props":3210,"children":3212},{"class":119,"line":3211},29,[3213],{"type":24,"tag":117,"props":3214,"children":3215},{"emptyLinePlaceholder":534},[3216],{"type":29,"value":537},{"type":24,"tag":117,"props":3218,"children":3220},{"class":119,"line":3219},30,[3221,3225,3229,3234],{"type":24,"tag":117,"props":3222,"children":3223},{"style":124},[3224],{"type":29,"value":2869},{"type":24,"tag":117,"props":3226,"children":3227},{"style":124},[3228],{"type":29,"value":906},{"type":24,"tag":117,"props":3230,"children":3231},{"style":154},[3232],{"type":29,"value":3233}," Rollback",{"type":24,"tag":117,"props":3235,"children":3236},{"style":148},[3237],{"type":29,"value":2007},{"type":24,"tag":117,"props":3239,"children":3241},{"class":119,"line":3240},31,[3242],{"type":24,"tag":117,"props":3243,"children":3244},{"style":148},[3245],{"type":29,"value":391},{"type":24,"tag":117,"props":3247,"children":3249},{"class":119,"line":3248},32,[3250,3254,3258,3262,3266,3270],{"type":24,"tag":117,"props":3251,"children":3252},{"style":124},[3253],{"type":29,"value":2055},{"type":24,"tag":117,"props":3255,"children":3256},{"style":148},[3257],{"type":29,"value":987},{"type":24,"tag":117,"props":3259,"children":3260},{"style":165},[3261],{"type":29,"value":2905},{"type":24,"tag":117,"props":3263,"children":3264},{"style":136},[3265],{"type":29,"value":2068},{"type":24,"tag":117,"props":3267,"children":3268},{"style":310},[3269],{"type":29,"value":313},{"type":24,"tag":117,"props":3271,"children":3272},{"style":148},[3273],{"type":29,"value":318},{"type":24,"tag":117,"props":3275,"children":3277},{"class":119,"line":3276},33,[3278],{"type":24,"tag":117,"props":3279,"children":3280},{"style":148},[3281],{"type":29,"value":2085},{"type":24,"tag":117,"props":3283,"children":3285},{"class":119,"line":3284},34,[3286,3290,3294,3298,3302,3307],{"type":24,"tag":117,"props":3287,"children":3288},{"style":124},[3289],{"type":29,"value":3141},{"type":24,"tag":117,"props":3291,"children":3292},{"style":148},[3293],{"type":29,"value":1072},{"type":24,"tag":117,"props":3295,"children":3296},{"style":142},[3297],{"type":29,"value":2905},{"type":24,"tag":117,"props":3299,"children":3300},{"style":148},[3301],{"type":29,"value":151},{"type":24,"tag":117,"props":3303,"children":3304},{"style":154},[3305],{"type":29,"value":3306},"Rollback",{"type":24,"tag":117,"props":3308,"children":3309},{"style":148},[3310],{"type":29,"value":1130},{"type":24,"tag":117,"props":3312,"children":3314},{"class":119,"line":3313},35,[3315,3319,3323,3327,3331,3335],{"type":24,"tag":117,"props":3316,"children":3317},{"style":124},[3318],{"type":29,"value":3171},{"type":24,"tag":117,"props":3320,"children":3321},{"style":148},[3322],{"type":29,"value":1072},{"type":24,"tag":117,"props":3324,"children":3325},{"style":165},[3326],{"type":29,"value":2905},{"type":24,"tag":117,"props":3328,"children":3329},{"style":136},[3330],{"type":29,"value":139},{"type":24,"tag":117,"props":3332,"children":3333},{"style":310},[3334],{"type":29,"value":313},{"type":24,"tag":117,"props":3336,"children":3337},{"style":148},[3338],{"type":29,"value":3192},{"type":24,"tag":117,"props":3340,"children":3342},{"class":119,"line":3341},36,[3343],{"type":24,"tag":117,"props":3344,"children":3345},{"style":148},[3346],{"type":29,"value":2215},{"type":24,"tag":117,"props":3348,"children":3350},{"class":119,"line":3349},37,[3351],{"type":24,"tag":117,"props":3352,"children":3353},{"style":148},[3354],{"type":29,"value":1150},{"type":24,"tag":117,"props":3356,"children":3358},{"class":119,"line":3357},38,[3359],{"type":24,"tag":117,"props":3360,"children":3361},{"style":148},[3362],{"type":29,"value":721},{"type":24,"tag":25,"props":3364,"children":3365},{},[3366],{"type":29,"value":3367},"The model:",{"type":24,"tag":3369,"props":3370,"children":3371},"ul",{},[3372,3389,3410,3422,3433],{"type":24,"tag":3373,"props":3374,"children":3375},"li",{},[3376,3387],{"type":24,"tag":881,"props":3377,"children":3378},{},[3379,3381],{"type":29,"value":3380},"One ",{"type":24,"tag":53,"props":3382,"children":3384},{"className":3383},[],[3385],{"type":29,"value":3386},"BLiteEngine",{"type":29,"value":3388}," per database, shared across all connections.",{"type":24,"tag":3373,"props":3390,"children":3391},{},[3392,3401,3403,3409],{"type":24,"tag":881,"props":3393,"children":3394},{},[3395,3396],{"type":29,"value":3380},{"type":24,"tag":53,"props":3397,"children":3399},{"className":3398},[],[3400],{"type":29,"value":2613},{"type":29,"value":3402}," per client connection, created via ",{"type":24,"tag":53,"props":3404,"children":3406},{"className":3405},[],[3407],{"type":29,"value":3408},"engine.OpenSession()",{"type":29,"value":151},{"type":24,"tag":3373,"props":3411,"children":3412},{},[3413,3415,3420],{"type":29,"value":3414},"Each session has its own ",{"type":24,"tag":53,"props":3416,"children":3418},{"className":3417},[],[3419],{"type":29,"value":2780},{"type":29,"value":3421}," — uncommitted writes live in the per-transaction WAL cache, invisible to other sessions.",{"type":24,"tag":3373,"props":3423,"children":3424},{},[3425,3431],{"type":24,"tag":53,"props":3426,"children":3428},{"className":3427},[],[3429],{"type":29,"value":3430},"Commit()",{"type":29,"value":3432}," persists index metadata, commits the transaction, and clears the session's transaction reference.",{"type":24,"tag":3373,"props":3434,"children":3435},{},[3436,3442],{"type":24,"tag":53,"props":3437,"children":3439},{"className":3438},[],[3440],{"type":29,"value":3441},"Dispose()",{"type":29,"value":3443}," auto-rolls back any uncommitted transaction — if the connection drops, nothing leaks.",{"type":24,"tag":80,"props":3445,"children":3447},{"code":3446,"language":110,"meta":7,"className":111,"style":7},"\u002F\u002F Server connection handler:\nvar engine = new BLiteEngine(dbPath, PageFileConfig.Server(dbPath));\n\nvar session1 = engine.OpenSession();  \u002F\u002F Client 1\nvar session2 = engine.OpenSession();  \u002F\u002F Client 2\n\nsession1.BeginTransaction();\nsession1.GetOrCreateCollection(\"users\").Insert(doc1);\n\nsession2.BeginTransaction();\nsession2.GetOrCreateCollection(\"users\").Insert(doc2);\n\n\u002F\u002F doc1 is invisible to session2, doc2 is invisible to session1\n\nsession1.Commit();  \u002F\u002F doc1 is now visible to new reads\nsession2.Rollback(); \u002F\u002F doc2 disappears\n",[3448],{"type":24,"tag":53,"props":3449,"children":3450},{"__ignoreMap":7},[3451,3459,3520,3527,3566,3603,3610,3630,3678,3685,3705,3749,3756,3764,3771,3795],{"type":24,"tag":117,"props":3452,"children":3453},{"class":119,"line":120},[3454],{"type":24,"tag":117,"props":3455,"children":3456},{"style":971},[3457],{"type":29,"value":3458},"\u002F\u002F Server connection handler:\n",{"type":24,"tag":117,"props":3460,"children":3461},{"class":119,"line":176},[3462,3466,3470,3474,3478,3482,3486,3491,3495,3499,3503,3507,3511,3515],{"type":24,"tag":117,"props":3463,"children":3464},{"style":124},[3465],{"type":29,"value":127},{"type":24,"tag":117,"props":3467,"children":3468},{"style":130},[3469],{"type":29,"value":192},{"type":24,"tag":117,"props":3471,"children":3472},{"style":136},[3473],{"type":29,"value":139},{"type":24,"tag":117,"props":3475,"children":3476},{"style":199},[3477],{"type":29,"value":202},{"type":24,"tag":117,"props":3479,"children":3480},{"style":205},[3481],{"type":29,"value":208},{"type":24,"tag":117,"props":3483,"children":3484},{"style":148},[3485],{"type":29,"value":162},{"type":24,"tag":117,"props":3487,"children":3488},{"style":165},[3489],{"type":29,"value":3490},"dbPath",{"type":24,"tag":117,"props":3492,"children":3493},{"style":148},[3494],{"type":29,"value":221},{"type":24,"tag":117,"props":3496,"children":3497},{"style":142},[3498],{"type":29,"value":293},{"type":24,"tag":117,"props":3500,"children":3501},{"style":148},[3502],{"type":29,"value":151},{"type":24,"tag":117,"props":3504,"children":3505},{"style":154},[3506],{"type":29,"value":157},{"type":24,"tag":117,"props":3508,"children":3509},{"style":148},[3510],{"type":29,"value":162},{"type":24,"tag":117,"props":3512,"children":3513},{"style":165},[3514],{"type":29,"value":3490},{"type":24,"tag":117,"props":3516,"children":3517},{"style":148},[3518],{"type":29,"value":3519},"));\n",{"type":24,"tag":117,"props":3521,"children":3522},{"class":119,"line":329},[3523],{"type":24,"tag":117,"props":3524,"children":3525},{"emptyLinePlaceholder":534},[3526],{"type":29,"value":537},{"type":24,"tag":117,"props":3528,"children":3529},{"class":119,"line":367},[3530,3534,3539,3543,3547,3551,3556,3561],{"type":24,"tag":117,"props":3531,"children":3532},{"style":124},[3533],{"type":29,"value":127},{"type":24,"tag":117,"props":3535,"children":3536},{"style":130},[3537],{"type":29,"value":3538}," session1",{"type":24,"tag":117,"props":3540,"children":3541},{"style":136},[3542],{"type":29,"value":139},{"type":24,"tag":117,"props":3544,"children":3545},{"style":142},[3546],{"type":29,"value":192},{"type":24,"tag":117,"props":3548,"children":3549},{"style":148},[3550],{"type":29,"value":151},{"type":24,"tag":117,"props":3552,"children":3553},{"style":154},[3554],{"type":29,"value":3555},"OpenSession",{"type":24,"tag":117,"props":3557,"children":3558},{"style":148},[3559],{"type":29,"value":3560},"();  ",{"type":24,"tag":117,"props":3562,"children":3563},{"style":971},[3564],{"type":29,"value":3565},"\u002F\u002F Client 1\n",{"type":24,"tag":117,"props":3567,"children":3568},{"class":119,"line":385},[3569,3573,3578,3582,3586,3590,3594,3598],{"type":24,"tag":117,"props":3570,"children":3571},{"style":124},[3572],{"type":29,"value":127},{"type":24,"tag":117,"props":3574,"children":3575},{"style":130},[3576],{"type":29,"value":3577}," session2",{"type":24,"tag":117,"props":3579,"children":3580},{"style":136},[3581],{"type":29,"value":139},{"type":24,"tag":117,"props":3583,"children":3584},{"style":142},[3585],{"type":29,"value":192},{"type":24,"tag":117,"props":3587,"children":3588},{"style":148},[3589],{"type":29,"value":151},{"type":24,"tag":117,"props":3591,"children":3592},{"style":154},[3593],{"type":29,"value":3555},{"type":24,"tag":117,"props":3595,"children":3596},{"style":148},[3597],{"type":29,"value":3560},{"type":24,"tag":117,"props":3599,"children":3600},{"style":971},[3601],{"type":29,"value":3602},"\u002F\u002F Client 2\n",{"type":24,"tag":117,"props":3604,"children":3605},{"class":119,"line":394},[3606],{"type":24,"tag":117,"props":3607,"children":3608},{"emptyLinePlaceholder":534},[3609],{"type":29,"value":537},{"type":24,"tag":117,"props":3611,"children":3612},{"class":119,"line":426},[3613,3618,3622,3626],{"type":24,"tag":117,"props":3614,"children":3615},{"style":142},[3616],{"type":29,"value":3617},"session1",{"type":24,"tag":117,"props":3619,"children":3620},{"style":148},[3621],{"type":29,"value":151},{"type":24,"tag":117,"props":3623,"children":3624},{"style":154},[3625],{"type":29,"value":2956},{"type":24,"tag":117,"props":3627,"children":3628},{"style":148},[3629],{"type":29,"value":1059},{"type":24,"tag":117,"props":3631,"children":3632},{"class":119,"line":473},[3633,3637,3641,3646,3650,3655,3660,3665,3669,3674],{"type":24,"tag":117,"props":3634,"children":3635},{"style":142},[3636],{"type":29,"value":3617},{"type":24,"tag":117,"props":3638,"children":3639},{"style":148},[3640],{"type":29,"value":151},{"type":24,"tag":117,"props":3642,"children":3643},{"style":154},[3644],{"type":29,"value":3645},"GetOrCreateCollection",{"type":24,"tag":117,"props":3647,"children":3648},{"style":148},[3649],{"type":29,"value":162},{"type":24,"tag":117,"props":3651,"children":3652},{"style":462},[3653],{"type":29,"value":3654},"\"users\"",{"type":24,"tag":117,"props":3656,"children":3657},{"style":148},[3658],{"type":29,"value":3659},").",{"type":24,"tag":117,"props":3661,"children":3662},{"style":154},[3663],{"type":29,"value":3664},"Insert",{"type":24,"tag":117,"props":3666,"children":3667},{"style":148},[3668],{"type":29,"value":162},{"type":24,"tag":117,"props":3670,"children":3671},{"style":165},[3672],{"type":29,"value":3673},"doc1",{"type":24,"tag":117,"props":3675,"children":3676},{"style":148},[3677],{"type":29,"value":173},{"type":24,"tag":117,"props":3679,"children":3680},{"class":119,"line":486},[3681],{"type":24,"tag":117,"props":3682,"children":3683},{"emptyLinePlaceholder":534},[3684],{"type":29,"value":537},{"type":24,"tag":117,"props":3686,"children":3687},{"class":119,"line":530},[3688,3693,3697,3701],{"type":24,"tag":117,"props":3689,"children":3690},{"style":142},[3691],{"type":29,"value":3692},"session2",{"type":24,"tag":117,"props":3694,"children":3695},{"style":148},[3696],{"type":29,"value":151},{"type":24,"tag":117,"props":3698,"children":3699},{"style":154},[3700],{"type":29,"value":2956},{"type":24,"tag":117,"props":3702,"children":3703},{"style":148},[3704],{"type":29,"value":1059},{"type":24,"tag":117,"props":3706,"children":3707},{"class":119,"line":540},[3708,3712,3716,3720,3724,3728,3732,3736,3740,3745],{"type":24,"tag":117,"props":3709,"children":3710},{"style":142},[3711],{"type":29,"value":3692},{"type":24,"tag":117,"props":3713,"children":3714},{"style":148},[3715],{"type":29,"value":151},{"type":24,"tag":117,"props":3717,"children":3718},{"style":154},[3719],{"type":29,"value":3645},{"type":24,"tag":117,"props":3721,"children":3722},{"style":148},[3723],{"type":29,"value":162},{"type":24,"tag":117,"props":3725,"children":3726},{"style":462},[3727],{"type":29,"value":3654},{"type":24,"tag":117,"props":3729,"children":3730},{"style":148},[3731],{"type":29,"value":3659},{"type":24,"tag":117,"props":3733,"children":3734},{"style":154},[3735],{"type":29,"value":3664},{"type":24,"tag":117,"props":3737,"children":3738},{"style":148},[3739],{"type":29,"value":162},{"type":24,"tag":117,"props":3741,"children":3742},{"style":165},[3743],{"type":29,"value":3744},"doc2",{"type":24,"tag":117,"props":3746,"children":3747},{"style":148},[3748],{"type":29,"value":173},{"type":24,"tag":117,"props":3750,"children":3751},{"class":119,"line":587},[3752],{"type":24,"tag":117,"props":3753,"children":3754},{"emptyLinePlaceholder":534},[3755],{"type":29,"value":537},{"type":24,"tag":117,"props":3757,"children":3758},{"class":119,"line":595},[3759],{"type":24,"tag":117,"props":3760,"children":3761},{"style":971},[3762],{"type":29,"value":3763},"\u002F\u002F doc1 is invisible to session2, doc2 is invisible to session1\n",{"type":24,"tag":117,"props":3765,"children":3766},{"class":119,"line":624},[3767],{"type":24,"tag":117,"props":3768,"children":3769},{"emptyLinePlaceholder":534},[3770],{"type":29,"value":537},{"type":24,"tag":117,"props":3772,"children":3773},{"class":119,"line":664},[3774,3778,3782,3786,3790],{"type":24,"tag":117,"props":3775,"children":3776},{"style":142},[3777],{"type":29,"value":3617},{"type":24,"tag":117,"props":3779,"children":3780},{"style":148},[3781],{"type":29,"value":151},{"type":24,"tag":117,"props":3783,"children":3784},{"style":154},[3785],{"type":29,"value":3158},{"type":24,"tag":117,"props":3787,"children":3788},{"style":148},[3789],{"type":29,"value":3560},{"type":24,"tag":117,"props":3791,"children":3792},{"style":971},[3793],{"type":29,"value":3794},"\u002F\u002F doc1 is now visible to new reads\n",{"type":24,"tag":117,"props":3796,"children":3797},{"class":119,"line":677},[3798,3802,3806,3810,3815],{"type":24,"tag":117,"props":3799,"children":3800},{"style":142},[3801],{"type":29,"value":3692},{"type":24,"tag":117,"props":3803,"children":3804},{"style":148},[3805],{"type":29,"value":151},{"type":24,"tag":117,"props":3807,"children":3808},{"style":154},[3809],{"type":29,"value":3306},{"type":24,"tag":117,"props":3811,"children":3812},{"style":148},[3813],{"type":29,"value":3814},"(); ",{"type":24,"tag":117,"props":3816,"children":3817},{"style":971},[3818],{"type":29,"value":3819},"\u002F\u002F doc2 disappears\n",{"type":24,"tag":25,"props":3821,"children":3822},{},[3823,3825,3831,3833,3839,3841,3847,3849,3854],{"type":29,"value":3824},"Collections are lazy-loaded per session and cached with ",{"type":24,"tag":53,"props":3826,"children":3828},{"className":3827},[],[3829],{"type":29,"value":3830},"ConcurrentDictionary\u003Cstring, Lazy\u003CDynamicCollection>>",{"type":29,"value":3832},". The ",{"type":24,"tag":53,"props":3834,"children":3836},{"className":3835},[],[3837],{"type":29,"value":3838},"Lazy\u003CT>",{"type":29,"value":3840}," with ",{"type":24,"tag":53,"props":3842,"children":3844},{"className":3843},[],[3845],{"type":29,"value":3846},"LazyThreadSafetyMode.ExecutionAndPublication",{"type":29,"value":3848}," guarantees that even if a session creates the same collection from multiple threads (e.g., parallel API handlers), the ",{"type":24,"tag":53,"props":3850,"children":3852},{"className":3851},[],[3853],{"type":29,"value":2737},{"type":29,"value":3855}," is constructed exactly once.",{"type":24,"tag":37,"props":3857,"children":3858},{},[],{"type":24,"tag":41,"props":3860,"children":3862},{"id":3861},"migration-single-to-multi-and-back",[3863],{"type":29,"value":3864},"Migration: Single to Multi and Back",{"type":24,"tag":25,"props":3866,"children":3867},{},[3868,3870,3876],{"type":29,"value":3869},"Switching an existing single-file database to multi-file layout (or vice versa) happens through ",{"type":24,"tag":53,"props":3871,"children":3873},{"className":3872},[],[3874],{"type":29,"value":3875},"BLiteMigration",{"type":29,"value":807},{"type":24,"tag":80,"props":3878,"children":3880},{"code":3879,"language":110,"meta":7,"className":111,"style":7},"\u002F\u002F Single → multi-file\nBLiteMigration.ToMultiFile(dbPath, PageFileConfig.Server(dbPath));\n\n\u002F\u002F Multi-file → single-file\nBLiteMigration.ToSingleFile(dbPath, serverConfig, dbPath);\n",[3881],{"type":24,"tag":53,"props":3882,"children":3883},{"__ignoreMap":7},[3884,3892,3944,3951,3959],{"type":24,"tag":117,"props":3885,"children":3886},{"class":119,"line":120},[3887],{"type":24,"tag":117,"props":3888,"children":3889},{"style":971},[3890],{"type":29,"value":3891},"\u002F\u002F Single → multi-file\n",{"type":24,"tag":117,"props":3893,"children":3894},{"class":119,"line":176},[3895,3899,3903,3908,3912,3916,3920,3924,3928,3932,3936,3940],{"type":24,"tag":117,"props":3896,"children":3897},{"style":142},[3898],{"type":29,"value":3875},{"type":24,"tag":117,"props":3900,"children":3901},{"style":148},[3902],{"type":29,"value":151},{"type":24,"tag":117,"props":3904,"children":3905},{"style":154},[3906],{"type":29,"value":3907},"ToMultiFile",{"type":24,"tag":117,"props":3909,"children":3910},{"style":148},[3911],{"type":29,"value":162},{"type":24,"tag":117,"props":3913,"children":3914},{"style":165},[3915],{"type":29,"value":3490},{"type":24,"tag":117,"props":3917,"children":3918},{"style":148},[3919],{"type":29,"value":221},{"type":24,"tag":117,"props":3921,"children":3922},{"style":142},[3923],{"type":29,"value":293},{"type":24,"tag":117,"props":3925,"children":3926},{"style":148},[3927],{"type":29,"value":151},{"type":24,"tag":117,"props":3929,"children":3930},{"style":154},[3931],{"type":29,"value":157},{"type":24,"tag":117,"props":3933,"children":3934},{"style":148},[3935],{"type":29,"value":162},{"type":24,"tag":117,"props":3937,"children":3938},{"style":165},[3939],{"type":29,"value":3490},{"type":24,"tag":117,"props":3941,"children":3942},{"style":148},[3943],{"type":29,"value":3519},{"type":24,"tag":117,"props":3945,"children":3946},{"class":119,"line":329},[3947],{"type":24,"tag":117,"props":3948,"children":3949},{"emptyLinePlaceholder":534},[3950],{"type":29,"value":537},{"type":24,"tag":117,"props":3952,"children":3953},{"class":119,"line":367},[3954],{"type":24,"tag":117,"props":3955,"children":3956},{"style":971},[3957],{"type":29,"value":3958},"\u002F\u002F Multi-file → single-file\n",{"type":24,"tag":117,"props":3960,"children":3961},{"class":119,"line":385},[3962,3966,3970,3975,3979,3983,3987,3992,3996,4000],{"type":24,"tag":117,"props":3963,"children":3964},{"style":142},[3965],{"type":29,"value":3875},{"type":24,"tag":117,"props":3967,"children":3968},{"style":148},[3969],{"type":29,"value":151},{"type":24,"tag":117,"props":3971,"children":3972},{"style":154},[3973],{"type":29,"value":3974},"ToSingleFile",{"type":24,"tag":117,"props":3976,"children":3977},{"style":148},[3978],{"type":29,"value":162},{"type":24,"tag":117,"props":3980,"children":3981},{"style":165},[3982],{"type":29,"value":3490},{"type":24,"tag":117,"props":3984,"children":3985},{"style":148},[3986],{"type":29,"value":221},{"type":24,"tag":117,"props":3988,"children":3989},{"style":165},[3990],{"type":29,"value":3991},"serverConfig",{"type":24,"tag":117,"props":3993,"children":3994},{"style":148},[3995],{"type":29,"value":221},{"type":24,"tag":117,"props":3997,"children":3998},{"style":165},[3999],{"type":29,"value":3490},{"type":24,"tag":117,"props":4001,"children":4002},{"style":148},[4003],{"type":29,"value":173},{"type":24,"tag":25,"props":4005,"children":4006},{},[4007],{"type":29,"value":4008},"The migration:",{"type":24,"tag":4010,"props":4011,"children":4012},"ol",{},[4013,4018,4023,4028,4033],{"type":24,"tag":3373,"props":4014,"children":4015},{},[4016],{"type":29,"value":4017},"Opens the source database with single-file config.",{"type":24,"tag":3373,"props":4019,"children":4020},{},[4021],{"type":29,"value":4022},"Opens a temporary target with multi-file config.",{"type":24,"tag":3373,"props":4024,"children":4025},{},[4026],{"type":29,"value":4027},"Copies all collections (docs + indexes), KV store entries, and the C-BSON dictionary.",{"type":24,"tag":3373,"props":4029,"children":4030},{},[4031],{"type":29,"value":4032},"Checkpoints the target to flush everything to page files.",{"type":24,"tag":3373,"props":4034,"children":4035},{},[4036,4038,4044,4046,4052],{"type":29,"value":4037},"Atomically replaces the source: ",{"type":24,"tag":53,"props":4039,"children":4041},{"className":4040},[],[4042],{"type":29,"value":4043},"File.Delete(source)",{"type":29,"value":4045}," → ",{"type":24,"tag":53,"props":4047,"children":4049},{"className":4048},[],[4050],{"type":29,"value":4051},"File.Move(temp, source)",{"type":29,"value":151},{"type":24,"tag":25,"props":4054,"children":4055},{},[4056],{"type":29,"value":4057},"If anything fails mid-migration, the catch block deletes the temp file and re-throws. The original database is untouched until the final atomic swap.",{"type":24,"tag":25,"props":4059,"children":4060},{},[4061,4063,4068,4070,4076],{"type":29,"value":4062},"The reverse migration (",{"type":24,"tag":53,"props":4064,"children":4066},{"className":4065},[],[4067],{"type":29,"value":3974},{"type":29,"value":4069},") is symmetric: it consolidates all per-collection files and the separate index back into a single ",{"type":24,"tag":53,"props":4071,"children":4073},{"className":4072},[],[4074],{"type":29,"value":4075},".db",{"type":29,"value":4077}," file, then cleans up the multi-file components.",{"type":24,"tag":80,"props":4079,"children":4081},{"code":4080,"language":110,"meta":7,"className":111,"style":7},"var tempDbPath = sourcePath + \".migrating\";\ntry\n{\n    using (var source = new BLiteEngine(sourcePath, sourceConfig))\n    using (var target = new BLiteEngine(tempDbPath, targetConfig))\n    {\n        CopyAll(source, target);\n    }\n    File.Delete(sourcePath);\n    File.Move(tempDbPath, sourcePath);\n}\ncatch\n{\n    SafeDelete(tempDbPath);\n    throw;\n}\n",[4082],{"type":24,"tag":53,"props":4083,"children":4084},{"__ignoreMap":7},[4085,4119,4127,4134,4189,4243,4250,4279,4286,4315,4351,4358,4366,4373,4393,4405],{"type":24,"tag":117,"props":4086,"children":4087},{"class":119,"line":120},[4088,4092,4097,4101,4106,4110,4115],{"type":24,"tag":117,"props":4089,"children":4090},{"style":124},[4091],{"type":29,"value":127},{"type":24,"tag":117,"props":4093,"children":4094},{"style":130},[4095],{"type":29,"value":4096}," tempDbPath",{"type":24,"tag":117,"props":4098,"children":4099},{"style":136},[4100],{"type":29,"value":139},{"type":24,"tag":117,"props":4102,"children":4103},{"style":165},[4104],{"type":29,"value":4105}," sourcePath",{"type":24,"tag":117,"props":4107,"children":4108},{"style":136},[4109],{"type":29,"value":997},{"type":24,"tag":117,"props":4111,"children":4112},{"style":462},[4113],{"type":29,"value":4114}," \".migrating\"",{"type":24,"tag":117,"props":4116,"children":4117},{"style":148},[4118],{"type":29,"value":364},{"type":24,"tag":117,"props":4120,"children":4121},{"class":119,"line":176},[4122],{"type":24,"tag":117,"props":4123,"children":4124},{"style":124},[4125],{"type":29,"value":4126},"try\n",{"type":24,"tag":117,"props":4128,"children":4129},{"class":119,"line":329},[4130],{"type":24,"tag":117,"props":4131,"children":4132},{"style":148},[4133],{"type":29,"value":326},{"type":24,"tag":117,"props":4135,"children":4136},{"class":119,"line":367},[4137,4142,4146,4150,4155,4159,4163,4167,4171,4176,4180,4185],{"type":24,"tag":117,"props":4138,"children":4139},{"style":124},[4140],{"type":29,"value":4141},"    using",{"type":24,"tag":117,"props":4143,"children":4144},{"style":148},[4145],{"type":29,"value":987},{"type":24,"tag":117,"props":4147,"children":4148},{"style":124},[4149],{"type":29,"value":127},{"type":24,"tag":117,"props":4151,"children":4152},{"style":130},[4153],{"type":29,"value":4154}," source",{"type":24,"tag":117,"props":4156,"children":4157},{"style":136},[4158],{"type":29,"value":139},{"type":24,"tag":117,"props":4160,"children":4161},{"style":199},[4162],{"type":29,"value":202},{"type":24,"tag":117,"props":4164,"children":4165},{"style":205},[4166],{"type":29,"value":208},{"type":24,"tag":117,"props":4168,"children":4169},{"style":148},[4170],{"type":29,"value":162},{"type":24,"tag":117,"props":4172,"children":4173},{"style":165},[4174],{"type":29,"value":4175},"sourcePath",{"type":24,"tag":117,"props":4177,"children":4178},{"style":148},[4179],{"type":29,"value":221},{"type":24,"tag":117,"props":4181,"children":4182},{"style":165},[4183],{"type":29,"value":4184},"sourceConfig",{"type":24,"tag":117,"props":4186,"children":4187},{"style":148},[4188],{"type":29,"value":703},{"type":24,"tag":117,"props":4190,"children":4191},{"class":119,"line":385},[4192,4196,4200,4204,4209,4213,4217,4221,4225,4230,4234,4239],{"type":24,"tag":117,"props":4193,"children":4194},{"style":124},[4195],{"type":29,"value":4141},{"type":24,"tag":117,"props":4197,"children":4198},{"style":148},[4199],{"type":29,"value":987},{"type":24,"tag":117,"props":4201,"children":4202},{"style":124},[4203],{"type":29,"value":127},{"type":24,"tag":117,"props":4205,"children":4206},{"style":130},[4207],{"type":29,"value":4208}," target",{"type":24,"tag":117,"props":4210,"children":4211},{"style":136},[4212],{"type":29,"value":139},{"type":24,"tag":117,"props":4214,"children":4215},{"style":199},[4216],{"type":29,"value":202},{"type":24,"tag":117,"props":4218,"children":4219},{"style":205},[4220],{"type":29,"value":208},{"type":24,"tag":117,"props":4222,"children":4223},{"style":148},[4224],{"type":29,"value":162},{"type":24,"tag":117,"props":4226,"children":4227},{"style":165},[4228],{"type":29,"value":4229},"tempDbPath",{"type":24,"tag":117,"props":4231,"children":4232},{"style":148},[4233],{"type":29,"value":221},{"type":24,"tag":117,"props":4235,"children":4236},{"style":165},[4237],{"type":29,"value":4238},"targetConfig",{"type":24,"tag":117,"props":4240,"children":4241},{"style":148},[4242],{"type":29,"value":703},{"type":24,"tag":117,"props":4244,"children":4245},{"class":119,"line":394},[4246],{"type":24,"tag":117,"props":4247,"children":4248},{"style":148},[4249],{"type":29,"value":391},{"type":24,"tag":117,"props":4251,"children":4252},{"class":119,"line":426},[4253,4258,4262,4266,4270,4275],{"type":24,"tag":117,"props":4254,"children":4255},{"style":154},[4256],{"type":29,"value":4257},"        CopyAll",{"type":24,"tag":117,"props":4259,"children":4260},{"style":148},[4261],{"type":29,"value":162},{"type":24,"tag":117,"props":4263,"children":4264},{"style":165},[4265],{"type":29,"value":954},{"type":24,"tag":117,"props":4267,"children":4268},{"style":148},[4269],{"type":29,"value":221},{"type":24,"tag":117,"props":4271,"children":4272},{"style":165},[4273],{"type":29,"value":4274},"target",{"type":24,"tag":117,"props":4276,"children":4277},{"style":148},[4278],{"type":29,"value":173},{"type":24,"tag":117,"props":4280,"children":4281},{"class":119,"line":473},[4282],{"type":24,"tag":117,"props":4283,"children":4284},{"style":148},[4285],{"type":29,"value":1150},{"type":24,"tag":117,"props":4287,"children":4288},{"class":119,"line":486},[4289,4294,4298,4303,4307,4311],{"type":24,"tag":117,"props":4290,"children":4291},{"style":142},[4292],{"type":29,"value":4293},"    File",{"type":24,"tag":117,"props":4295,"children":4296},{"style":148},[4297],{"type":29,"value":151},{"type":24,"tag":117,"props":4299,"children":4300},{"style":154},[4301],{"type":29,"value":4302},"Delete",{"type":24,"tag":117,"props":4304,"children":4305},{"style":148},[4306],{"type":29,"value":162},{"type":24,"tag":117,"props":4308,"children":4309},{"style":165},[4310],{"type":29,"value":4175},{"type":24,"tag":117,"props":4312,"children":4313},{"style":148},[4314],{"type":29,"value":173},{"type":24,"tag":117,"props":4316,"children":4317},{"class":119,"line":530},[4318,4322,4326,4331,4335,4339,4343,4347],{"type":24,"tag":117,"props":4319,"children":4320},{"style":142},[4321],{"type":29,"value":4293},{"type":24,"tag":117,"props":4323,"children":4324},{"style":148},[4325],{"type":29,"value":151},{"type":24,"tag":117,"props":4327,"children":4328},{"style":154},[4329],{"type":29,"value":4330},"Move",{"type":24,"tag":117,"props":4332,"children":4333},{"style":148},[4334],{"type":29,"value":162},{"type":24,"tag":117,"props":4336,"children":4337},{"style":165},[4338],{"type":29,"value":4229},{"type":24,"tag":117,"props":4340,"children":4341},{"style":148},[4342],{"type":29,"value":221},{"type":24,"tag":117,"props":4344,"children":4345},{"style":165},[4346],{"type":29,"value":4175},{"type":24,"tag":117,"props":4348,"children":4349},{"style":148},[4350],{"type":29,"value":173},{"type":24,"tag":117,"props":4352,"children":4353},{"class":119,"line":540},[4354],{"type":24,"tag":117,"props":4355,"children":4356},{"style":148},[4357],{"type":29,"value":721},{"type":24,"tag":117,"props":4359,"children":4360},{"class":119,"line":587},[4361],{"type":24,"tag":117,"props":4362,"children":4363},{"style":124},[4364],{"type":29,"value":4365},"catch\n",{"type":24,"tag":117,"props":4367,"children":4368},{"class":119,"line":595},[4369],{"type":24,"tag":117,"props":4370,"children":4371},{"style":148},[4372],{"type":29,"value":326},{"type":24,"tag":117,"props":4374,"children":4375},{"class":119,"line":624},[4376,4381,4385,4389],{"type":24,"tag":117,"props":4377,"children":4378},{"style":154},[4379],{"type":29,"value":4380},"    SafeDelete",{"type":24,"tag":117,"props":4382,"children":4383},{"style":148},[4384],{"type":29,"value":162},{"type":24,"tag":117,"props":4386,"children":4387},{"style":165},[4388],{"type":29,"value":4229},{"type":24,"tag":117,"props":4390,"children":4391},{"style":148},[4392],{"type":29,"value":173},{"type":24,"tag":117,"props":4394,"children":4395},{"class":119,"line":664},[4396,4401],{"type":24,"tag":117,"props":4397,"children":4398},{"style":124},[4399],{"type":29,"value":4400},"    throw",{"type":24,"tag":117,"props":4402,"children":4403},{"style":148},[4404],{"type":29,"value":364},{"type":24,"tag":117,"props":4406,"children":4407},{"class":119,"line":677},[4408],{"type":24,"tag":117,"props":4409,"children":4410},{"style":148},[4411],{"type":29,"value":721},{"type":24,"tag":25,"props":4413,"children":4414},{},[4415,4417,4423,4425,4431],{"type":29,"value":4416},"One subtle detail: ",{"type":24,"tag":53,"props":4418,"children":4420},{"className":4419},[],[4421],{"type":29,"value":4422},"CopyAll",{"type":29,"value":4424}," calls ",{"type":24,"tag":53,"props":4426,"children":4428},{"className":4427},[],[4429],{"type":29,"value":4430},"target.ImportDictionary(source.GetKeyReverseMap())",{"type":29,"value":4432}," before copying documents. BLite's C-BSON format compresses field names via a shared dictionary. Without syncing the dictionary first, raw BSON bytes in the new file would reference dictionary entries that don't exist.",{"type":24,"tag":37,"props":4434,"children":4435},{},[],{"type":24,"tag":41,"props":4437,"children":4439},{"id":4438},"checkpoint-and-recovery-across-files",[4440],{"type":29,"value":4441},"Checkpoint and Recovery Across Files",{"type":24,"tag":25,"props":4443,"children":4444},{},[4445,4447,4453,4455,4461,4463,4469],{"type":29,"value":4446},"The WAL is still a single file, even in multi-file mode. But the pages it records carry encoded page IDs — an index page has its ",{"type":24,"tag":53,"props":4448,"children":4450},{"className":4449},[],[4451],{"type":29,"value":4452},"0x80000000",{"type":29,"value":4454}," marker, a collection page has ",{"type":24,"tag":53,"props":4456,"children":4458},{"className":4457},[],[4459],{"type":29,"value":4460},"0xC0000000 | slot | localId",{"type":29,"value":4462},". During checkpoint, ",{"type":24,"tag":53,"props":4464,"children":4466},{"className":4465},[],[4467],{"type":29,"value":4468},"GetPageFile()",{"type":29,"value":4470}," decodes each page ID and routes the write to the correct file:",{"type":24,"tag":80,"props":4472,"children":4474},{"code":4473,"language":110,"meta":7,"className":111,"style":7},"private void CheckpointInternal()\n{\n    if (_walIndex.IsEmpty) return;\n\n    foreach (var kvp in _walIndex)\n    {\n        GetPageFile(kvp.Key, out var physId).WritePage(physId, kvp.Value);\n    }\n\n    _pageFile.Flush();\n    _indexFile?.Flush();\n    if (_collectionFiles != null)\n    {\n        foreach (var pf in _collectionFiles.Values)\n            pf.Flush();\n    }\n\n    _walIndex.Clear();\n    _wal.Truncate();\n}\n",[4475],{"type":24,"tag":53,"props":4476,"children":4477},{"__ignoreMap":7},[4478,4498,4505,4542,4549,4583,4590,4671,4678,4685,4705,4730,4758,4765,4806,4826,4833,4840,4861,4882],{"type":24,"tag":117,"props":4479,"children":4480},{"class":119,"line":120},[4481,4485,4489,4494],{"type":24,"tag":117,"props":4482,"children":4483},{"style":124},[4484],{"type":29,"value":822},{"type":24,"tag":117,"props":4486,"children":4487},{"style":124},[4488],{"type":29,"value":906},{"type":24,"tag":117,"props":4490,"children":4491},{"style":154},[4492],{"type":29,"value":4493}," CheckpointInternal",{"type":24,"tag":117,"props":4495,"children":4496},{"style":148},[4497],{"type":29,"value":2007},{"type":24,"tag":117,"props":4499,"children":4500},{"class":119,"line":176},[4501],{"type":24,"tag":117,"props":4502,"children":4503},{"style":148},[4504],{"type":29,"value":326},{"type":24,"tag":117,"props":4506,"children":4507},{"class":119,"line":329},[4508,4512,4516,4521,4525,4530,4534,4538],{"type":24,"tag":117,"props":4509,"children":4510},{"style":124},[4511],{"type":29,"value":982},{"type":24,"tag":117,"props":4513,"children":4514},{"style":148},[4515],{"type":29,"value":987},{"type":24,"tag":117,"props":4517,"children":4518},{"style":142},[4519],{"type":29,"value":4520},"_walIndex",{"type":24,"tag":117,"props":4522,"children":4523},{"style":148},[4524],{"type":29,"value":151},{"type":24,"tag":117,"props":4526,"children":4527},{"style":142},[4528],{"type":29,"value":4529},"IsEmpty",{"type":24,"tag":117,"props":4531,"children":4532},{"style":148},[4533],{"type":29,"value":454},{"type":24,"tag":117,"props":4535,"children":4536},{"style":124},[4537],{"type":29,"value":2922},{"type":24,"tag":117,"props":4539,"children":4540},{"style":148},[4541],{"type":29,"value":364},{"type":24,"tag":117,"props":4543,"children":4544},{"class":119,"line":367},[4545],{"type":24,"tag":117,"props":4546,"children":4547},{"emptyLinePlaceholder":534},[4548],{"type":29,"value":537},{"type":24,"tag":117,"props":4550,"children":4551},{"class":119,"line":385},[4552,4557,4561,4565,4570,4574,4579],{"type":24,"tag":117,"props":4553,"children":4554},{"style":124},[4555],{"type":29,"value":4556},"    foreach",{"type":24,"tag":117,"props":4558,"children":4559},{"style":148},[4560],{"type":29,"value":987},{"type":24,"tag":117,"props":4562,"children":4563},{"style":124},[4564],{"type":29,"value":127},{"type":24,"tag":117,"props":4566,"children":4567},{"style":130},[4568],{"type":29,"value":4569}," kvp",{"type":24,"tag":117,"props":4571,"children":4572},{"style":124},[4573],{"type":29,"value":3047},{"type":24,"tag":117,"props":4575,"children":4576},{"style":165},[4577],{"type":29,"value":4578}," _walIndex",{"type":24,"tag":117,"props":4580,"children":4581},{"style":148},[4582],{"type":29,"value":318},{"type":24,"tag":117,"props":4584,"children":4585},{"class":119,"line":394},[4586],{"type":24,"tag":117,"props":4587,"children":4588},{"style":148},[4589],{"type":29,"value":391},{"type":24,"tag":117,"props":4591,"children":4592},{"class":119,"line":426},[4593,4598,4602,4607,4611,4616,4620,4625,4629,4634,4638,4642,4646,4651,4655,4659,4663,4667],{"type":24,"tag":117,"props":4594,"children":4595},{"style":154},[4596],{"type":29,"value":4597},"        GetPageFile",{"type":24,"tag":117,"props":4599,"children":4600},{"style":148},[4601],{"type":29,"value":162},{"type":24,"tag":117,"props":4603,"children":4604},{"style":142},[4605],{"type":29,"value":4606},"kvp",{"type":24,"tag":117,"props":4608,"children":4609},{"style":148},[4610],{"type":29,"value":151},{"type":24,"tag":117,"props":4612,"children":4613},{"style":142},[4614],{"type":29,"value":4615},"Key",{"type":24,"tag":117,"props":4617,"children":4618},{"style":148},[4619],{"type":29,"value":221},{"type":24,"tag":117,"props":4621,"children":4622},{"style":124},[4623],{"type":29,"value":4624},"out",{"type":24,"tag":117,"props":4626,"children":4627},{"style":124},[4628],{"type":29,"value":187},{"type":24,"tag":117,"props":4630,"children":4631},{"style":130},[4632],{"type":29,"value":4633}," physId",{"type":24,"tag":117,"props":4635,"children":4636},{"style":148},[4637],{"type":29,"value":3659},{"type":24,"tag":117,"props":4639,"children":4640},{"style":154},[4641],{"type":29,"value":2434},{"type":24,"tag":117,"props":4643,"children":4644},{"style":148},[4645],{"type":29,"value":162},{"type":24,"tag":117,"props":4647,"children":4648},{"style":165},[4649],{"type":29,"value":4650},"physId",{"type":24,"tag":117,"props":4652,"children":4653},{"style":148},[4654],{"type":29,"value":221},{"type":24,"tag":117,"props":4656,"children":4657},{"style":142},[4658],{"type":29,"value":4606},{"type":24,"tag":117,"props":4660,"children":4661},{"style":148},[4662],{"type":29,"value":151},{"type":24,"tag":117,"props":4664,"children":4665},{"style":142},[4666],{"type":29,"value":3083},{"type":24,"tag":117,"props":4668,"children":4669},{"style":148},[4670],{"type":29,"value":173},{"type":24,"tag":117,"props":4672,"children":4673},{"class":119,"line":473},[4674],{"type":24,"tag":117,"props":4675,"children":4676},{"style":148},[4677],{"type":29,"value":1150},{"type":24,"tag":117,"props":4679,"children":4680},{"class":119,"line":486},[4681],{"type":24,"tag":117,"props":4682,"children":4683},{"emptyLinePlaceholder":534},[4684],{"type":29,"value":537},{"type":24,"tag":117,"props":4686,"children":4687},{"class":119,"line":530},[4688,4693,4697,4701],{"type":24,"tag":117,"props":4689,"children":4690},{"style":142},[4691],{"type":29,"value":4692},"    _pageFile",{"type":24,"tag":117,"props":4694,"children":4695},{"style":148},[4696],{"type":29,"value":151},{"type":24,"tag":117,"props":4698,"children":4699},{"style":154},[4700],{"type":29,"value":1807},{"type":24,"tag":117,"props":4702,"children":4703},{"style":148},[4704],{"type":29,"value":1059},{"type":24,"tag":117,"props":4706,"children":4707},{"class":119,"line":540},[4708,4713,4718,4722,4726],{"type":24,"tag":117,"props":4709,"children":4710},{"style":142},[4711],{"type":29,"value":4712},"    _indexFile",{"type":24,"tag":117,"props":4714,"children":4715},{"style":199},[4716],{"type":29,"value":4717},"?",{"type":24,"tag":117,"props":4719,"children":4720},{"style":148},[4721],{"type":29,"value":151},{"type":24,"tag":117,"props":4723,"children":4724},{"style":154},[4725],{"type":29,"value":1807},{"type":24,"tag":117,"props":4727,"children":4728},{"style":148},[4729],{"type":29,"value":1059},{"type":24,"tag":117,"props":4731,"children":4732},{"class":119,"line":587},[4733,4737,4741,4746,4750,4754],{"type":24,"tag":117,"props":4734,"children":4735},{"style":124},[4736],{"type":29,"value":982},{"type":24,"tag":117,"props":4738,"children":4739},{"style":148},[4740],{"type":29,"value":987},{"type":24,"tag":117,"props":4742,"children":4743},{"style":165},[4744],{"type":29,"value":4745},"_collectionFiles",{"type":24,"tag":117,"props":4747,"children":4748},{"style":136},[4749],{"type":29,"value":2068},{"type":24,"tag":117,"props":4751,"children":4752},{"style":310},[4753],{"type":29,"value":313},{"type":24,"tag":117,"props":4755,"children":4756},{"style":148},[4757],{"type":29,"value":318},{"type":24,"tag":117,"props":4759,"children":4760},{"class":119,"line":595},[4761],{"type":24,"tag":117,"props":4762,"children":4763},{"style":148},[4764],{"type":29,"value":391},{"type":24,"tag":117,"props":4766,"children":4767},{"class":119,"line":624},[4768,4772,4776,4780,4785,4789,4794,4798,4802],{"type":24,"tag":117,"props":4769,"children":4770},{"style":124},[4771],{"type":29,"value":3029},{"type":24,"tag":117,"props":4773,"children":4774},{"style":148},[4775],{"type":29,"value":987},{"type":24,"tag":117,"props":4777,"children":4778},{"style":124},[4779],{"type":29,"value":127},{"type":24,"tag":117,"props":4781,"children":4782},{"style":130},[4783],{"type":29,"value":4784}," pf",{"type":24,"tag":117,"props":4786,"children":4787},{"style":124},[4788],{"type":29,"value":3047},{"type":24,"tag":117,"props":4790,"children":4791},{"style":142},[4792],{"type":29,"value":4793}," _collectionFiles",{"type":24,"tag":117,"props":4795,"children":4796},{"style":148},[4797],{"type":29,"value":151},{"type":24,"tag":117,"props":4799,"children":4800},{"style":142},[4801],{"type":29,"value":3061},{"type":24,"tag":117,"props":4803,"children":4804},{"style":148},[4805],{"type":29,"value":318},{"type":24,"tag":117,"props":4807,"children":4808},{"class":119,"line":664},[4809,4814,4818,4822],{"type":24,"tag":117,"props":4810,"children":4811},{"style":142},[4812],{"type":29,"value":4813},"            pf",{"type":24,"tag":117,"props":4815,"children":4816},{"style":148},[4817],{"type":29,"value":151},{"type":24,"tag":117,"props":4819,"children":4820},{"style":154},[4821],{"type":29,"value":1807},{"type":24,"tag":117,"props":4823,"children":4824},{"style":148},[4825],{"type":29,"value":1059},{"type":24,"tag":117,"props":4827,"children":4828},{"class":119,"line":677},[4829],{"type":24,"tag":117,"props":4830,"children":4831},{"style":148},[4832],{"type":29,"value":1150},{"type":24,"tag":117,"props":4834,"children":4835},{"class":119,"line":706},[4836],{"type":24,"tag":117,"props":4837,"children":4838},{"emptyLinePlaceholder":534},[4839],{"type":29,"value":537},{"type":24,"tag":117,"props":4841,"children":4842},{"class":119,"line":715},[4843,4848,4852,4857],{"type":24,"tag":117,"props":4844,"children":4845},{"style":142},[4846],{"type":29,"value":4847},"    _walIndex",{"type":24,"tag":117,"props":4849,"children":4850},{"style":148},[4851],{"type":29,"value":151},{"type":24,"tag":117,"props":4853,"children":4854},{"style":154},[4855],{"type":29,"value":4856},"Clear",{"type":24,"tag":117,"props":4858,"children":4859},{"style":148},[4860],{"type":29,"value":1059},{"type":24,"tag":117,"props":4862,"children":4863},{"class":119,"line":1265},[4864,4869,4873,4878],{"type":24,"tag":117,"props":4865,"children":4866},{"style":142},[4867],{"type":29,"value":4868},"    _wal",{"type":24,"tag":117,"props":4870,"children":4871},{"style":148},[4872],{"type":29,"value":151},{"type":24,"tag":117,"props":4874,"children":4875},{"style":154},[4876],{"type":29,"value":4877},"Truncate",{"type":24,"tag":117,"props":4879,"children":4880},{"style":148},[4881],{"type":29,"value":1059},{"type":24,"tag":117,"props":4883,"children":4884},{"class":119,"line":1295},[4885],{"type":24,"tag":117,"props":4886,"children":4887},{"style":148},[4888],{"type":29,"value":721},{"type":24,"tag":25,"props":4890,"children":4891},{},[4892,4894,4901],{"type":29,"value":4893},"Crash recovery works the same way: on startup, the engine reads the WAL, identifies committed transactions, and replays their writes through the same routing function. Because the page IDs are self-describing, the recovery code doesn't need a separate mapping of \"which pages belong to which file\" — it's encoded in the ID itself. (I covered the bit encoding in detail in ",{"type":24,"tag":4895,"props":4896,"children":4898},"a",{"href":4897},"\u002Fblog\u002Fbitwise-page-routing-blite-storage-engine",[4899],{"type":29,"value":4900},"the bitwise page routing post",{"type":29,"value":4902},".)",{"type":24,"tag":37,"props":4904,"children":4905},{},[],{"type":24,"tag":41,"props":4907,"children":4909},{"id":4908},"what-could-go-wrong",[4910],{"type":29,"value":4911},"What Could Go Wrong",{"type":24,"tag":25,"props":4913,"children":4914},{},[4915],{"type":29,"value":4916},"Design decisions have consequences. Here are the ones that I think about most:",{"type":24,"tag":869,"props":4918,"children":4920},{"id":4919},"_1-readerwriterlockslim-has-a-thundering-herd-problem",[4921],{"type":29,"value":4922},"1. ReaderWriterLockSlim Has a Thundering Herd Problem",{"type":24,"tag":25,"props":4924,"children":4925},{},[4926,4928,4933],{"type":29,"value":4927},"When a ",{"type":24,"tag":53,"props":4929,"children":4931},{"className":4930},[],[4932],{"type":29,"value":2434},{"type":29,"value":4934}," call triggers file growth, every pending reader waits. When the write lock is released, all of them rush to re-acquire the read lock simultaneously. Under heavy load with frequent growths (e.g., bulk insert into a new database), this creates a thundering herd effect. The pre-allocation in 1 MB blocks mitigates this — once allocated, the file won't need to grow again for hundreds of pages — but the first growth event on each collection file still triggers the stampede.",{"type":24,"tag":25,"props":4936,"children":4937},{},[4938,4940,4946],{"type":29,"value":4939},"An alternative would be a concurrent slot array that readers check with ",{"type":24,"tag":53,"props":4941,"children":4943},{"className":4942},[],[4944],{"type":29,"value":4945},"Volatile.Read",{"type":29,"value":4947}," — no lock on the hot path at all. This is what LMDB does with its reader table. The complexity is higher, but the latency tail is shorter.",{"type":24,"tag":869,"props":4949,"children":4951},{"id":4950},"_2-per-collection-files-multiply-file-descriptors",[4952],{"type":29,"value":4953},"2. Per-Collection Files Multiply File Descriptors",{"type":24,"tag":25,"props":4955,"children":4956},{},[4957,4959,4964,4966,4972,4973,4978,4980,4986],{"type":29,"value":4958},"Each collection gets its own ",{"type":24,"tag":53,"props":4960,"children":4962},{"className":4961},[],[4963],{"type":29,"value":740},{"type":29,"value":4965},", which means its own ",{"type":24,"tag":53,"props":4967,"children":4969},{"className":4968},[],[4970],{"type":29,"value":4971},"FileStream",{"type":29,"value":1593},{"type":24,"tag":53,"props":4974,"children":4976},{"className":4975},[],[4977],{"type":29,"value":58},{"type":29,"value":4979},". A database with 50 collections has 50 open file handles plus the main file, the index, and the WAL — 53 total. On Linux under default ",{"type":24,"tag":53,"props":4981,"children":4983},{"className":4982},[],[4984],{"type":29,"value":4985},"ulimit",{"type":29,"value":4987}," settings (1024 file descriptors), this becomes a concern. On Windows it's less of an issue, but handles are still a finite resource.",{"type":24,"tag":25,"props":4989,"children":4990},{},[4991],{"type":29,"value":4992},"The 64-collection limit (6-bit slot) acts as a natural cap, but it's a hard limit, not a configurable one. If you need 65 collections, you need a second database.",{"type":24,"tag":869,"props":4994,"children":4996},{"id":4995},"_3-backup-is-inconsistent-in-multi-file-mode",[4997],{"type":29,"value":4998},"3. Backup Is Inconsistent in Multi-File Mode",{"type":24,"tag":25,"props":5000,"children":5001},{},[5002,5007,5009,5014,5016,5021],{"type":24,"tag":53,"props":5003,"children":5005},{"className":5004},[],[5006],{"type":29,"value":2539},{"type":29,"value":5008}," currently checkpoints and copies the main file. It does ",{"type":24,"tag":1548,"props":5010,"children":5011},{},[5012],{"type":29,"value":5013},"not",{"type":29,"value":5015}," copy the index file or per-collection files. A backup taken mid-operation captures the main file state but leaves the other files out of the snapshot. This is a known limitation: a complete backup requires stopping writes and copying all files, or implementing a coordinated snapshot across all ",{"type":24,"tag":53,"props":5017,"children":5019},{"className":5018},[],[5020],{"type":29,"value":740},{"type":29,"value":5022}," instances.",{"type":24,"tag":869,"props":5024,"children":5026},{"id":5025},"_4-the-commit-lock-is-global",[5027],{"type":29,"value":5028},"4. The Commit Lock is Global",{"type":24,"tag":25,"props":5030,"children":5031},{},[5032,5038,5040,5045,5047,5052],{"type":24,"tag":53,"props":5033,"children":5035},{"className":5034},[],[5036],{"type":29,"value":5037},"_commitLock",{"type":29,"value":5039}," serializes all commits and checkpoints across all sessions. Two sessions committing to ",{"type":24,"tag":1548,"props":5041,"children":5042},{},[5043],{"type":29,"value":5044},"different",{"type":29,"value":5046}," collections still contend on the same ",{"type":24,"tag":53,"props":5048,"children":5050},{"className":5049},[],[5051],{"type":29,"value":1607},{"type":29,"value":5053},". With the group commit batcher, this is less painful — dozens of commits can be batched into one WAL flush — but the serialization point remains.",{"type":24,"tag":25,"props":5055,"children":5056},{},[5057],{"type":29,"value":5058},"A per-collection commit pathway would eliminate this contention at the cost of a more complex WAL format. The current sequence — write BEGIN, data records, COMMIT for each transaction in order — would need to support interleaved records from concurrent commits. Most production databases do this (WAL records carry transaction IDs for exactly this reason), but it significantly complicates recovery.",{"type":24,"tag":869,"props":5060,"children":5062},{"id":5061},"_5-no-read-snapshots-across-sessions",[5063],{"type":29,"value":5064},"5. No Read Snapshots Across Sessions",{"type":24,"tag":25,"props":5066,"children":5067},{},[5068,5070,5075,5077,5082,5083,5088],{"type":29,"value":5069},"BLite's transaction isolation is based on WAL cache separation: a session sees its own uncommitted writes, plus the latest committed state. But there's no snapshot isolation — if session A reads page X, then session B commits a change to page X, then session A reads page X again, it sees the new version. This is ",{"type":24,"tag":1548,"props":5071,"children":5072},{},[5073],{"type":29,"value":5074},"Read Committed",{"type":29,"value":5076},", not ",{"type":24,"tag":1548,"props":5078,"children":5079},{},[5080],{"type":29,"value":5081},"Repeatable Read",{"type":29,"value":1538},{"type":24,"tag":1548,"props":5084,"children":5085},{},[5086],{"type":29,"value":5087},"Serializable",{"type":29,"value":151},{"type":24,"tag":25,"props":5090,"children":5091},{},[5092],{"type":29,"value":5093},"For many server workloads, Read Committed is sufficient. For workloads that need consistent snapshots across a multi-step read (e.g., a report that scans thousands of documents), this could produce inconsistent results if concurrent writes modify the data mid-scan.",{"type":24,"tag":37,"props":5095,"children":5096},{},[],{"type":24,"tag":41,"props":5098,"children":5100},{"id":5099},"the-bottom-line",[5101],{"type":29,"value":5102},"The Bottom Line",{"type":24,"tag":25,"props":5104,"children":5105},{},[5106],{"type":29,"value":5107},"Multi-file storage in BLite is not about making the engine more complex. It's about removing the shared bottleneck — one file, one lock, one I\u002FO queue — and replacing it with independent files that can be read, written, grown, and deleted independently.",{"type":24,"tag":25,"props":5109,"children":5110},{},[5111,5113,5118,5120,5125,5127,5132],{"type":29,"value":5112},"The ",{"type":24,"tag":53,"props":5114,"children":5116},{"className":5115},[],[5117],{"type":29,"value":805},{"type":29,"value":5119}," fast-path strategy makes reads and writes concurrent under normal load. ",{"type":24,"tag":53,"props":5121,"children":5123},{"className":5122},[],[5124],{"type":29,"value":2613},{"type":29,"value":5126}," gives each connection its own transaction scope. ",{"type":24,"tag":53,"props":5128,"children":5130},{"className":5129},[],[5131],{"type":29,"value":3875},{"type":29,"value":5133}," lets you switch between layouts without rewriting your application code. And the bit-tagged page IDs tie it all together with zero-allocation routing that survives restarts and crashes.",{"type":24,"tag":25,"props":5135,"children":5136},{},[5137],{"type":29,"value":5138},"The limitations are real — backup consistency, global commit serialization, Read Committed semantics — but they're the kind of trade-offs you make consciously when you want to keep an embedded database simple enough to fit in your head.",{"type":24,"tag":25,"props":5140,"children":5141},{},[5142,5144,5152],{"type":29,"value":5143},"The complete source is on ",{"type":24,"tag":4895,"props":5145,"children":5149},{"href":5146,"rel":5147},"https:\u002F\u002Fgithub.com\u002Fnicholasosaka\u002FBLite",[5148],"nofollow",[5150],{"type":29,"value":5151},"GitHub",{"type":29,"value":151},{"type":24,"tag":5154,"props":5155,"children":5156},"style",{},[5157],{"type":29,"value":5158},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":7,"searchDepth":176,"depth":176,"links":5160},[5161,5162,5163,5170,5171,5172,5173,5174,5181],{"id":43,"depth":176,"text":46},{"id":98,"depth":176,"text":101},{"id":756,"depth":176,"text":759,"children":5164},[5165,5166,5167,5168,5169],{"id":871,"depth":329,"text":874},{"id":1330,"depth":329,"text":1333},{"id":1522,"depth":329,"text":1525},{"id":1564,"depth":329,"text":1567},{"id":1955,"depth":329,"text":1958},{"id":2351,"depth":176,"text":2354},{"id":2594,"depth":176,"text":2597},{"id":3861,"depth":176,"text":3864},{"id":4438,"depth":176,"text":4441},{"id":4908,"depth":176,"text":4911,"children":5175},[5176,5177,5178,5179,5180],{"id":4919,"depth":329,"text":4922},{"id":4950,"depth":329,"text":4953},{"id":4995,"depth":329,"text":4998},{"id":5025,"depth":329,"text":5028},{"id":5061,"depth":329,"text":5064},{"id":5099,"depth":176,"text":5102},"markdown","content:en:blog:multi-file-concurrency-server-mode-in-blite.md","content","en\u002Fblog\u002Fmulti-file-concurrency-server-mode-in-blite.md","en\u002Fblog\u002Fmulti-file-concurrency-server-mode-in-blite","md",{"loc":4},1793182386020]