[{"data":1,"prerenderedAt":5188},["ShallowReactive",2],{"article-it-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":5181,"_id":5182,"_source":5183,"_file":5184,"_stem":5185,"_extension":5186,"sitemap":5187},"\u002Fit\u002Fblog\u002Fmulti-file-concurrency-server-mode-in-blite","blog",false,"","Storage Multi-File: Come BLite Gestisce l'Accesso Concorrente Server","Come BLite suddivide un database su più file memory-mapped, usa ReaderWriterLockSlim con una strategia fast-path\u002Fslow-path per proteggere l'accesso concorrente, e fornisce isolamento a sessione per connessione — e cosa potrebbe andare storto con queste scelte.","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":5158},"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,1609,1940,1952,1958,1978,2340,2345,2348,2354,2583,2588,2591,2597,2602,2614,3362,3367,3443,3819,3855,3858,3864,3876,4003,4008,4052,4057,4077,4411,4432,4435,4441,4470,4888,4902,4905,4911,4916,4922,4934,4947,4953,4987,4992,4998,5021,5027,5052,5057,5063,5088,5093,5096,5102,5107,5133,5138,5152],{"type":24,"tag":25,"props":26,"children":27},"element","p",{},[28],{"type":29,"value":30},"text","Un database embedded che vive in un singolo file va bene per un'app desktop, un tool CLI o un gioco mobile. Un processo, un thread (di solito), un file. Ma nel momento in cui metti un database dietro un server — dove decine di connessioni leggono e scrivono contemporaneamente — il modello a singolo file inizia a scricchiolare.",{"type":24,"tag":25,"props":32,"children":33},{},[34],{"type":29,"value":35},"Questo post riguarda come BLite è passato da \"un file, uno scrittore alla volta\" a \"più file, lettori e scrittori concorrenti, isolamento transazionale per connessione.\" Coprirò l'architettura, la strategia di locking che lo rende sicuro, il modello a sessioni che dà a ogni connessione il proprio contesto transazionale, e le migrazioni che permettono di convertire tra layout. Poi farò un passo indietro e parlerò di dove queste scelte potrebbero fare male.",{"type":24,"tag":37,"props":38,"children":39},"hr",{},[],{"type":24,"tag":41,"props":42,"children":44},"h2",{"id":43},"perché-multi-file",[45],{"type":29,"value":46},"Perché Multi-File?",{"type":24,"tag":25,"props":48,"children":49},{},[50,52,59],{"type":29,"value":51},"Un database a singolo file ha un unico ",{"type":24,"tag":53,"props":54,"children":56},"code",{"className":55},[],[57],{"type":29,"value":58},"MemoryMappedFile",{"type":29,"value":60}," che gestisce tutto l'I\u002FO. Ogni lettura e ogni scrittura — che tocchi un nodo B+Tree dell'indice, una pagina dati o un checkpoint del WAL — passa attraverso lo stesso mapping. Quando il file deve crescere, il mapping a livello OS deve essere disposto e ricreato. Durante quella finestra, nessun lettore può mantenere un riferimento al vecchio mapping o rischia di accedere a memoria liberata.",{"type":24,"tag":25,"props":62,"children":63},{},[64,66,72],{"type":29,"value":65},"Il problema si aggrava sotto carico. Una scansione dell'indice blocca un inserimento di documento perché condividono lo stesso file. Un checkpoint scarica ogni pagina sporca attraverso un unico collo di bottiglia. Un ",{"type":24,"tag":53,"props":67,"children":69},{"className":68},[],[70],{"type":29,"value":71},"DROP COLLECTION",{"type":29,"value":73}," lascia un buco di frammentazione che può essere recuperato solo riscrivendo l'intero file.",{"type":24,"tag":25,"props":75,"children":76},{},[77],{"type":29,"value":78},"Il layout multi-file di BLite affronta ciascuno di questi problemi:",{"type":24,"tag":80,"props":81,"children":83},"pre",{"code":82},"mydb.db            ← file dati principale (pagine, metadati, KV store)\nmydb.idx           ← file indice separato (B+Trees, R-Trees, HNSW)\nwal\u002Fmydb.wal       ← write-ahead log (opzionalmente su un disco diverso)\ncollections\u002Fmydb\u002F\n  ├── users.db     ← file dati per-collection\n  ├── orders.db\n  └── .slots       ← registro slot→nome\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},"Le scritture dell'indice non bloccano più le scritture dei dati — vanno su file diversi con lock indipendenti. Eliminare una collection è una cancellazione di file, non una deframmentazione a livello di pagina. Il WAL può vivere su un disco dedicato per I\u002FO sequenziale mentre dati e indici beneficiano delle performance ad accesso casuale degli SSD.",{"type":24,"tag":37,"props":94,"children":95},{},[],{"type":24,"tag":41,"props":97,"children":99},{"id":98},"la-configurazione-server",[100],{"type":29,"value":101},"La Configurazione Server",{"type":24,"tag":25,"props":103,"children":104},{},[105],{"type":29,"value":106},"Abilitare il multi-file è una modifica di una riga:",{"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}," è una factory che deriva tutti i percorsi companion dal percorso del database:",{"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},"All'avvio, il costruttore di ",{"type":24,"tag":53,"props":728,"children":730},{"className":729},[],[731],{"type":29,"value":732},"StorageEngine",{"type":29,"value":734}," controlla ogni percorso, crea le directory necessarie e apre un'istanza ",{"type":24,"tag":53,"props":736,"children":738},{"className":737},[],[739],{"type":29,"value":740},"PageFile",{"type":29,"value":742}," separata per ogni componente. Se un percorso è ",{"type":24,"tag":53,"props":744,"children":746},{"className":745},[],[747],{"type":29,"value":748},"null",{"type":29,"value":750},", quel componente resta nel file principale — puoi separare solo l'indice, solo il WAL, o tutto quanto.",{"type":24,"tag":37,"props":752,"children":753},{},[],{"type":24,"tag":41,"props":755,"children":757},{"id":756},"la-sfida-della-concorrenza-proteggere-un-memorymappedfile",[758],{"type":29,"value":759},"La Sfida della Concorrenza: Proteggere un MemoryMappedFile",{"type":24,"tag":25,"props":761,"children":762},{},[763,765,770,772,778,780,785,787,793],{"type":29,"value":764},"Ecco il problema centrale. Un ",{"type":24,"tag":53,"props":766,"children":768},{"className":767},[],[769],{"type":29,"value":58},{"type":29,"value":771}," in .NET mappa una regione di un file nello spazio di indirizzi virtuali del processo. Leggere una pagina significa creare un ",{"type":24,"tag":53,"props":773,"children":775},{"className":774},[],[776],{"type":29,"value":777},"ViewAccessor",{"type":29,"value":779}," su quel mapping. Ma quando il file deve crescere — ad esempio, viene allocata una nuova pagina oltre la lunghezza corrente del file — il mapping deve essere disposto e ricreato con una capacità maggiore. Se un lettore sta ancora mantenendo un ",{"type":24,"tag":53,"props":781,"children":783},{"className":782},[],[784],{"type":29,"value":777},{"type":29,"value":786}," al vecchio mapping mentre lo scrittore lo dispone, il lettore ottiene un ",{"type":24,"tag":53,"props":788,"children":790},{"className":789},[],[791],{"type":29,"value":792},"ObjectDisposedException",{"type":29,"value":794}," o, peggio, legge memoria obsoleta.",{"type":24,"tag":25,"props":796,"children":797},{},[798,800,806],{"type":29,"value":799},"La soluzione naïve è un mutex: un thread alla volta, lettori e scrittori allo stesso modo. Questo uccide il throughput. La soluzione corretta usa ",{"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-per-accesso-concorrente",[873],{"type":29,"value":874},"Fast Path: Read Lock per Accesso Concorrente",{"type":24,"tag":25,"props":876,"children":877},{},[878,880,886],{"type":29,"value":879},"La maggior parte delle scritture non richiede crescita del file — il file è già stato pre-allocato in blocchi da 1 MB. Quando il file è abbastanza grande, sia le letture che le scritture acquisiscono solo un ",{"type":24,"tag":881,"props":882,"children":883},"strong",{},[884],{"type":29,"value":885},"read lock",{"type":29,"value":887},", che permette concorrenza illimitata:",{"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 già abbastanza grande — condividi il mapping con i lettori\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: il file deve crescere — lock esclusivo\n    _rwLock.EnterWriteLock();\n    try\n    {\n        EnsureCapacityCore(offset);  \u002F\u002F Dispone il vecchio MMF, ricrea con nuova dimensione\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 già abbastanza grande — condividi il mapping con i lettori\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: il file deve crescere — lock esclusivo\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 Dispone il vecchio MMF, ricrea con nuova dimensione\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},"L'intuizione chiave: ",{"type":24,"tag":53,"props":1307,"children":1309},{"className":1308},[],[1310],{"type":29,"value":805},{"type":29,"value":1312}," permette un numero qualsiasi di possessori concorrenti del read lock, ma un write lock attende che tutti i lettori rilascino e poi blocca nuove acquisizioni. Quando una scrittura forza la crescita del file, lo scrittore chiama ",{"type":24,"tag":53,"props":1314,"children":1316},{"className":1315},[],[1317],{"type":29,"value":1318},"EnsureCapacityCore()",{"type":29,"value":1320},", che dispone il vecchio ",{"type":24,"tag":53,"props":1322,"children":1324},{"className":1323},[],[1325],{"type":29,"value":58},{"type":29,"value":1327}," e ne crea uno nuovo. Durante questo, nessun lettore può mantenere un riferimento al vecchio mapping — il write lock lo garantisce.",{"type":24,"tag":869,"props":1329,"children":1331},{"id":1330},"letture-sotto-read-lock",[1332],{"type":29,"value":1333},"Letture Sotto Read Lock",{"type":24,"tag":25,"props":1335,"children":1336},{},[1337],{"type":29,"value":1338},"Il percorso di lettura è più semplice — prende sempre un 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},"Più lettori possono eseguire ",{"type":24,"tag":53,"props":1507,"children":1509},{"className":1508},[],[1510],{"type":29,"value":1446},{"type":29,"value":1512}," contemporaneamente. Stanno tutti leggendo dallo stesso ",{"type":24,"tag":53,"props":1514,"children":1516},{"className":1515},[],[1517],{"type":29,"value":58},{"type":29,"value":1519},". Finché nessuno scrittore ha bisogno di far crescere il file, la contesa è zero.",{"type":24,"tag":869,"props":1521,"children":1523},{"id":1522},"perché-non-un-semplice-mutex",[1524],{"type":29,"value":1525},"Perché Non un Semplice Mutex?",{"type":24,"tag":25,"props":1527,"children":1528},{},[1529,1531,1537,1539,1545,1547,1553,1555,1560],{"type":29,"value":1530},"Un ",{"type":24,"tag":53,"props":1532,"children":1534},{"className":1533},[],[1535],{"type":29,"value":1536},"Monitor",{"type":29,"value":1538}," o un'istruzione ",{"type":24,"tag":53,"props":1540,"children":1542},{"className":1541},[],[1543],{"type":29,"value":1544},"lock",{"type":29,"value":1546}," serializza ",{"type":24,"tag":1548,"props":1549,"children":1550},"em",{},[1551],{"type":29,"value":1552},"tutte",{"type":29,"value":1554}," le operazioni. Con 50 connessioni client concorrenti, questo significa che 49 lettori aspettano mentre 1 lettore completa, anche se potrebbero tutti operare in parallelo. ",{"type":24,"tag":53,"props":1556,"children":1558},{"className":1557},[],[1559],{"type":29,"value":805},{"type":29,"value":1561}," elimina questo collo di bottiglia per i carichi di lavoro a prevalenza di lettura — che è il caso comune per la maggior parte dei database.",{"type":24,"tag":869,"props":1563,"children":1565},{"id":1564},"il-confine-asincrono-semaphoreslim",[1566],{"type":29,"value":1567},"Il Confine Asincrono: 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}," ha una limitazione: richiede che il thread acquisente sia anche il thread rilasciante. Questo è incompatibile con ",{"type":24,"tag":53,"props":1579,"children":1581},{"className":1580},[],[1582],{"type":29,"value":1583},"async\u002Fawait",{"type":29,"value":1585},", dove la continuazione può girare su un thread diverso. Per ",{"type":24,"tag":53,"props":1587,"children":1589},{"className":1588},[],[1590],{"type":29,"value":1591},"FlushAsync()",{"type":29,"value":1593}," e ",{"type":24,"tag":53,"props":1595,"children":1597},{"className":1596},[],[1598],{"type":29,"value":1599},"BackupAsync()",{"type":29,"value":1601},", BLite usa un ",{"type":24,"tag":53,"props":1603,"children":1605},{"className":1604},[],[1606],{"type":29,"value":1607},"SemaphoreSlim",{"type":29,"value":807},{"type":24,"tag":80,"props":1610,"children":1612},{"code":1611,"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",[1613],{"type":24,"tag":53,"props":1614,"children":1615},{"__ignoreMap":7},[1616,1666,1673,1735,1742,1776,1783,1790,1830,1864,1897,1904,1933],{"type":24,"tag":117,"props":1617,"children":1618},{"class":119,"line":120},[1619,1623,1627,1632,1637,1641,1645,1649,1654,1658,1662],{"type":24,"tag":117,"props":1620,"children":1621},{"style":124},[1622],{"type":29,"value":822},{"type":24,"tag":117,"props":1624,"children":1625},{"style":124},[1626],{"type":29,"value":827},{"type":24,"tag":117,"props":1628,"children":1629},{"style":205},[1630],{"type":29,"value":1631}," SemaphoreSlim",{"type":24,"tag":117,"props":1633,"children":1634},{"style":130},[1635],{"type":29,"value":1636}," _asyncLock",{"type":24,"tag":117,"props":1638,"children":1639},{"style":136},[1640],{"type":29,"value":139},{"type":24,"tag":117,"props":1642,"children":1643},{"style":199},[1644],{"type":29,"value":202},{"type":24,"tag":117,"props":1646,"children":1647},{"style":148},[1648],{"type":29,"value":162},{"type":24,"tag":117,"props":1650,"children":1651},{"style":310},[1652],{"type":29,"value":1653},"1",{"type":24,"tag":117,"props":1655,"children":1656},{"style":148},[1657],{"type":29,"value":221},{"type":24,"tag":117,"props":1659,"children":1660},{"style":310},[1661],{"type":29,"value":1653},{"type":24,"tag":117,"props":1663,"children":1664},{"style":148},[1665],{"type":29,"value":173},{"type":24,"tag":117,"props":1667,"children":1668},{"class":119,"line":176},[1669],{"type":24,"tag":117,"props":1670,"children":1671},{"emptyLinePlaceholder":534},[1672],{"type":29,"value":537},{"type":24,"tag":117,"props":1674,"children":1675},{"class":119,"line":329},[1676,1680,1685,1690,1695,1699,1703,1708,1712,1717,1722,1726,1731],{"type":24,"tag":117,"props":1677,"children":1678},{"style":124},[1679],{"type":29,"value":256},{"type":24,"tag":117,"props":1681,"children":1682},{"style":124},[1683],{"type":29,"value":1684}," async",{"type":24,"tag":117,"props":1686,"children":1687},{"style":205},[1688],{"type":29,"value":1689}," Task",{"type":24,"tag":117,"props":1691,"children":1692},{"style":154},[1693],{"type":29,"value":1694}," BackupAsync",{"type":24,"tag":117,"props":1696,"children":1697},{"style":148},[1698],{"type":29,"value":162},{"type":24,"tag":117,"props":1700,"children":1701},{"style":124},[1702],{"type":29,"value":279},{"type":24,"tag":117,"props":1704,"children":1705},{"style":205},[1706],{"type":29,"value":1707}," destinationPath",{"type":24,"tag":117,"props":1709,"children":1710},{"style":148},[1711],{"type":29,"value":221},{"type":24,"tag":117,"props":1713,"children":1714},{"style":205},[1715],{"type":29,"value":1716},"CancellationToken",{"type":24,"tag":117,"props":1718,"children":1719},{"style":205},[1720],{"type":29,"value":1721}," ct",{"type":24,"tag":117,"props":1723,"children":1724},{"style":136},[1725],{"type":29,"value":139},{"type":24,"tag":117,"props":1727,"children":1728},{"style":199},[1729],{"type":29,"value":1730}," default",{"type":24,"tag":117,"props":1732,"children":1733},{"style":148},[1734],{"type":29,"value":318},{"type":24,"tag":117,"props":1736,"children":1737},{"class":119,"line":367},[1738],{"type":24,"tag":117,"props":1739,"children":1740},{"style":148},[1741],{"type":29,"value":326},{"type":24,"tag":117,"props":1743,"children":1744},{"class":119,"line":385},[1745,1750,1754,1758,1763,1767,1772],{"type":24,"tag":117,"props":1746,"children":1747},{"style":199},[1748],{"type":29,"value":1749},"    await",{"type":24,"tag":117,"props":1751,"children":1752},{"style":142},[1753],{"type":29,"value":1636},{"type":24,"tag":117,"props":1755,"children":1756},{"style":148},[1757],{"type":29,"value":151},{"type":24,"tag":117,"props":1759,"children":1760},{"style":154},[1761],{"type":29,"value":1762},"WaitAsync",{"type":24,"tag":117,"props":1764,"children":1765},{"style":148},[1766],{"type":29,"value":162},{"type":24,"tag":117,"props":1768,"children":1769},{"style":165},[1770],{"type":29,"value":1771},"ct",{"type":24,"tag":117,"props":1773,"children":1774},{"style":148},[1775],{"type":29,"value":173},{"type":24,"tag":117,"props":1777,"children":1778},{"class":119,"line":394},[1779],{"type":24,"tag":117,"props":1780,"children":1781},{"style":124},[1782],{"type":29,"value":1194},{"type":24,"tag":117,"props":1784,"children":1785},{"class":119,"line":426},[1786],{"type":24,"tag":117,"props":1787,"children":1788},{"style":148},[1789],{"type":29,"value":391},{"type":24,"tag":117,"props":1791,"children":1792},{"class":119,"line":473},[1793,1798,1802,1807,1811,1816,1821,1826],{"type":24,"tag":117,"props":1794,"children":1795},{"style":142},[1796],{"type":29,"value":1797},"        _fileStream",{"type":24,"tag":117,"props":1799,"children":1800},{"style":148},[1801],{"type":29,"value":151},{"type":24,"tag":117,"props":1803,"children":1804},{"style":154},[1805],{"type":29,"value":1806},"Flush",{"type":24,"tag":117,"props":1808,"children":1809},{"style":148},[1810],{"type":29,"value":162},{"type":24,"tag":117,"props":1812,"children":1813},{"style":205},[1814],{"type":29,"value":1815},"flushToDisk",{"type":24,"tag":117,"props":1817,"children":1818},{"style":148},[1819],{"type":29,"value":1820},": ",{"type":24,"tag":117,"props":1822,"children":1823},{"style":310},[1824],{"type":29,"value":1825},"true",{"type":24,"tag":117,"props":1827,"children":1828},{"style":148},[1829],{"type":29,"value":173},{"type":24,"tag":117,"props":1831,"children":1832},{"class":119,"line":486},[1833,1838,1842,1846,1851,1855,1860],{"type":24,"tag":117,"props":1834,"children":1835},{"style":199},[1836],{"type":29,"value":1837},"        await",{"type":24,"tag":117,"props":1839,"children":1840},{"style":142},[1841],{"type":29,"value":1012},{"type":24,"tag":117,"props":1843,"children":1844},{"style":148},[1845],{"type":29,"value":151},{"type":24,"tag":117,"props":1847,"children":1848},{"style":154},[1849],{"type":29,"value":1850},"CopyToAsync",{"type":24,"tag":117,"props":1852,"children":1853},{"style":148},[1854],{"type":29,"value":162},{"type":24,"tag":117,"props":1856,"children":1857},{"style":165},[1858],{"type":29,"value":1859},"dst",{"type":24,"tag":117,"props":1861,"children":1862},{"style":148},[1863],{"type":29,"value":173},{"type":24,"tag":117,"props":1865,"children":1866},{"class":119,"line":530},[1867,1871,1876,1880,1885,1889,1893],{"type":24,"tag":117,"props":1868,"children":1869},{"style":199},[1870],{"type":29,"value":1837},{"type":24,"tag":117,"props":1872,"children":1873},{"style":142},[1874],{"type":29,"value":1875}," dst",{"type":24,"tag":117,"props":1877,"children":1878},{"style":148},[1879],{"type":29,"value":151},{"type":24,"tag":117,"props":1881,"children":1882},{"style":154},[1883],{"type":29,"value":1884},"FlushAsync",{"type":24,"tag":117,"props":1886,"children":1887},{"style":148},[1888],{"type":29,"value":162},{"type":24,"tag":117,"props":1890,"children":1891},{"style":165},[1892],{"type":29,"value":1771},{"type":24,"tag":117,"props":1894,"children":1895},{"style":148},[1896],{"type":29,"value":173},{"type":24,"tag":117,"props":1898,"children":1899},{"class":119,"line":540},[1900],{"type":24,"tag":117,"props":1901,"children":1902},{"style":148},[1903],{"type":29,"value":1150},{"type":24,"tag":117,"props":1905,"children":1906},{"class":119,"line":587},[1907,1911,1915,1920,1924,1929],{"type":24,"tag":117,"props":1908,"children":1909},{"style":124},[1910],{"type":29,"value":1271},{"type":24,"tag":117,"props":1912,"children":1913},{"style":148},[1914],{"type":29,"value":1072},{"type":24,"tag":117,"props":1916,"children":1917},{"style":142},[1918],{"type":29,"value":1919},"_asyncLock",{"type":24,"tag":117,"props":1921,"children":1922},{"style":148},[1923],{"type":29,"value":151},{"type":24,"tag":117,"props":1925,"children":1926},{"style":154},[1927],{"type":29,"value":1928},"Release",{"type":24,"tag":117,"props":1930,"children":1931},{"style":148},[1932],{"type":29,"value":1130},{"type":24,"tag":117,"props":1934,"children":1935},{"class":119,"line":595},[1936],{"type":24,"tag":117,"props":1937,"children":1938},{"style":148},[1939],{"type":29,"value":721},{"type":24,"tag":25,"props":1941,"children":1942},{},[1943,1945,1950],{"type":29,"value":1944},"Questo serializza le operazioni di backup e flush senza richiedere affinità di thread. Il trade-off è che ",{"type":24,"tag":53,"props":1946,"children":1948},{"className":1947},[],[1949],{"type":29,"value":1607},{"type":29,"value":1951}," non distingue lettori da scrittori — ma queste operazioni sono abbastanza infrequenti che il costo è trascurabile.",{"type":24,"tag":869,"props":1953,"children":1955},{"id":1954},"allocazione-sotto-write-lock",[1956],{"type":29,"value":1957},"Allocazione Sotto Write Lock",{"type":24,"tag":25,"props":1959,"children":1960},{},[1961,1963,1969,1970,1976],{"type":29,"value":1962},"L'allocazione delle pagine modifica stato mutabile condiviso — ",{"type":24,"tag":53,"props":1964,"children":1966},{"className":1965},[],[1967],{"type":29,"value":1968},"_nextPageId",{"type":29,"value":1593},{"type":24,"tag":53,"props":1971,"children":1973},{"className":1972},[],[1974],{"type":29,"value":1975},"_firstFreePageId",{"type":29,"value":1977}," — quindi ha sempre bisogno di accesso esclusivo:",{"type":24,"tag":80,"props":1979,"children":1981},{"code":1980,"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",[1982],{"type":24,"tag":53,"props":1983,"children":1984},{"__ignoreMap":7},[1985,2007,2014,2033,2040,2047,2077,2085,2111,2141,2171,2191,2207,2215,2245,2284,2299,2306,2333],{"type":24,"tag":117,"props":1986,"children":1987},{"class":119,"line":120},[1988,1992,1997,2002],{"type":24,"tag":117,"props":1989,"children":1990},{"style":124},[1991],{"type":29,"value":256},{"type":24,"tag":117,"props":1993,"children":1994},{"style":124},[1995],{"type":29,"value":1996}," uint",{"type":24,"tag":117,"props":1998,"children":1999},{"style":154},[2000],{"type":29,"value":2001}," AllocatePage",{"type":24,"tag":117,"props":2003,"children":2004},{"style":148},[2005],{"type":29,"value":2006},"()\n",{"type":24,"tag":117,"props":2008,"children":2009},{"class":119,"line":176},[2010],{"type":24,"tag":117,"props":2011,"children":2012},{"style":148},[2013],{"type":29,"value":326},{"type":24,"tag":117,"props":2015,"children":2016},{"class":119,"line":329},[2017,2021,2025,2029],{"type":24,"tag":117,"props":2018,"children":2019},{"style":142},[2020],{"type":29,"value":1173},{"type":24,"tag":117,"props":2022,"children":2023},{"style":148},[2024],{"type":29,"value":151},{"type":24,"tag":117,"props":2026,"children":2027},{"style":154},[2028],{"type":29,"value":1182},{"type":24,"tag":117,"props":2030,"children":2031},{"style":148},[2032],{"type":29,"value":1059},{"type":24,"tag":117,"props":2034,"children":2035},{"class":119,"line":367},[2036],{"type":24,"tag":117,"props":2037,"children":2038},{"style":124},[2039],{"type":29,"value":1194},{"type":24,"tag":117,"props":2041,"children":2042},{"class":119,"line":385},[2043],{"type":24,"tag":117,"props":2044,"children":2045},{"style":148},[2046],{"type":29,"value":391},{"type":24,"tag":117,"props":2048,"children":2049},{"class":119,"line":394},[2050,2055,2059,2063,2068,2073],{"type":24,"tag":117,"props":2051,"children":2052},{"style":124},[2053],{"type":29,"value":2054},"        if",{"type":24,"tag":117,"props":2056,"children":2057},{"style":148},[2058],{"type":29,"value":987},{"type":24,"tag":117,"props":2060,"children":2061},{"style":165},[2062],{"type":29,"value":1975},{"type":24,"tag":117,"props":2064,"children":2065},{"style":136},[2066],{"type":29,"value":2067}," !=",{"type":24,"tag":117,"props":2069,"children":2070},{"style":310},[2071],{"type":29,"value":2072}," 0",{"type":24,"tag":117,"props":2074,"children":2075},{"style":148},[2076],{"type":29,"value":318},{"type":24,"tag":117,"props":2078,"children":2079},{"class":119,"line":426},[2080],{"type":24,"tag":117,"props":2081,"children":2082},{"style":148},[2083],{"type":29,"value":2084},"        {\n",{"type":24,"tag":117,"props":2086,"children":2087},{"class":119,"line":473},[2088,2093,2098,2102,2107],{"type":24,"tag":117,"props":2089,"children":2090},{"style":124},[2091],{"type":29,"value":2092},"            var",{"type":24,"tag":117,"props":2094,"children":2095},{"style":130},[2096],{"type":29,"value":2097}," recycledPageId",{"type":24,"tag":117,"props":2099,"children":2100},{"style":136},[2101],{"type":29,"value":139},{"type":24,"tag":117,"props":2103,"children":2104},{"style":165},[2105],{"type":29,"value":2106}," _firstFreePageId",{"type":24,"tag":117,"props":2108,"children":2109},{"style":148},[2110],{"type":29,"value":364},{"type":24,"tag":117,"props":2112,"children":2113},{"class":119,"line":486},[2114,2119,2123,2128,2132,2137],{"type":24,"tag":117,"props":2115,"children":2116},{"style":154},[2117],{"type":29,"value":2118},"            ReadPageCore",{"type":24,"tag":117,"props":2120,"children":2121},{"style":148},[2122],{"type":29,"value":162},{"type":24,"tag":117,"props":2124,"children":2125},{"style":165},[2126],{"type":29,"value":2127},"recycledPageId",{"type":24,"tag":117,"props":2129,"children":2130},{"style":148},[2131],{"type":29,"value":221},{"type":24,"tag":117,"props":2133,"children":2134},{"style":165},[2135],{"type":29,"value":2136},"buffer",{"type":24,"tag":117,"props":2138,"children":2139},{"style":148},[2140],{"type":29,"value":173},{"type":24,"tag":117,"props":2142,"children":2143},{"class":119,"line":530},[2144,2149,2153,2158,2162,2167],{"type":24,"tag":117,"props":2145,"children":2146},{"style":165},[2147],{"type":29,"value":2148},"            _firstFreePageId",{"type":24,"tag":117,"props":2150,"children":2151},{"style":136},[2152],{"type":29,"value":139},{"type":24,"tag":117,"props":2154,"children":2155},{"style":142},[2156],{"type":29,"value":2157}," header",{"type":24,"tag":117,"props":2159,"children":2160},{"style":148},[2161],{"type":29,"value":151},{"type":24,"tag":117,"props":2163,"children":2164},{"style":142},[2165],{"type":29,"value":2166},"NextPageId",{"type":24,"tag":117,"props":2168,"children":2169},{"style":148},[2170],{"type":29,"value":364},{"type":24,"tag":117,"props":2172,"children":2173},{"class":119,"line":540},[2174,2179,2183,2187],{"type":24,"tag":117,"props":2175,"children":2176},{"style":154},[2177],{"type":29,"value":2178},"            UpdateFileHeaderFreePtrCore",{"type":24,"tag":117,"props":2180,"children":2181},{"style":148},[2182],{"type":29,"value":162},{"type":24,"tag":117,"props":2184,"children":2185},{"style":165},[2186],{"type":29,"value":1975},{"type":24,"tag":117,"props":2188,"children":2189},{"style":148},[2190],{"type":29,"value":173},{"type":24,"tag":117,"props":2192,"children":2193},{"class":119,"line":587},[2194,2199,2203],{"type":24,"tag":117,"props":2195,"children":2196},{"style":124},[2197],{"type":29,"value":2198},"            return",{"type":24,"tag":117,"props":2200,"children":2201},{"style":165},[2202],{"type":29,"value":2097},{"type":24,"tag":117,"props":2204,"children":2205},{"style":148},[2206],{"type":29,"value":364},{"type":24,"tag":117,"props":2208,"children":2209},{"class":119,"line":595},[2210],{"type":24,"tag":117,"props":2211,"children":2212},{"style":148},[2213],{"type":29,"value":2214},"        }\n",{"type":24,"tag":117,"props":2216,"children":2217},{"class":119,"line":624},[2218,2223,2227,2231,2236,2241],{"type":24,"tag":117,"props":2219,"children":2220},{"style":124},[2221],{"type":29,"value":2222},"        var",{"type":24,"tag":117,"props":2224,"children":2225},{"style":130},[2226],{"type":29,"value":925},{"type":24,"tag":117,"props":2228,"children":2229},{"style":136},[2230],{"type":29,"value":139},{"type":24,"tag":117,"props":2232,"children":2233},{"style":165},[2234],{"type":29,"value":2235}," _nextPageId",{"type":24,"tag":117,"props":2237,"children":2238},{"style":136},[2239],{"type":29,"value":2240},"++",{"type":24,"tag":117,"props":2242,"children":2243},{"style":148},[2244],{"type":29,"value":364},{"type":24,"tag":117,"props":2246,"children":2247},{"class":119,"line":664},[2248,2252,2257,2262,2267,2271,2276,2280],{"type":24,"tag":117,"props":2249,"children":2250},{"style":154},[2251],{"type":29,"value":1209},{"type":24,"tag":117,"props":2253,"children":2254},{"style":148},[2255],{"type":29,"value":2256},"((",{"type":24,"tag":117,"props":2258,"children":2259},{"style":124},[2260],{"type":29,"value":2261},"long",{"type":24,"tag":117,"props":2263,"children":2264},{"style":148},[2265],{"type":29,"value":2266},")",{"type":24,"tag":117,"props":2268,"children":2269},{"style":165},[2270],{"type":29,"value":1086},{"type":24,"tag":117,"props":2272,"children":2273},{"style":136},[2274],{"type":29,"value":2275}," *",{"type":24,"tag":117,"props":2277,"children":2278},{"style":165},[2279],{"type":29,"value":1002},{"type":24,"tag":117,"props":2281,"children":2282},{"style":148},[2283],{"type":29,"value":173},{"type":24,"tag":117,"props":2285,"children":2286},{"class":119,"line":677},[2287,2291,2295],{"type":24,"tag":117,"props":2288,"children":2289},{"style":124},[2290],{"type":29,"value":1138},{"type":24,"tag":117,"props":2292,"children":2293},{"style":165},[2294],{"type":29,"value":925},{"type":24,"tag":117,"props":2296,"children":2297},{"style":148},[2298],{"type":29,"value":364},{"type":24,"tag":117,"props":2300,"children":2301},{"class":119,"line":706},[2302],{"type":24,"tag":117,"props":2303,"children":2304},{"style":148},[2305],{"type":29,"value":1150},{"type":24,"tag":117,"props":2307,"children":2308},{"class":119,"line":715},[2309,2313,2317,2321,2325,2329],{"type":24,"tag":117,"props":2310,"children":2311},{"style":124},[2312],{"type":29,"value":1271},{"type":24,"tag":117,"props":2314,"children":2315},{"style":148},[2316],{"type":29,"value":1072},{"type":24,"tag":117,"props":2318,"children":2319},{"style":142},[2320],{"type":29,"value":1116},{"type":24,"tag":117,"props":2322,"children":2323},{"style":148},[2324],{"type":29,"value":151},{"type":24,"tag":117,"props":2326,"children":2327},{"style":154},[2328],{"type":29,"value":1288},{"type":24,"tag":117,"props":2330,"children":2331},{"style":148},[2332],{"type":29,"value":1130},{"type":24,"tag":117,"props":2334,"children":2335},{"class":119,"line":1265},[2336],{"type":24,"tag":117,"props":2337,"children":2338},{"style":148},[2339],{"type":29,"value":721},{"type":24,"tag":25,"props":2341,"children":2342},{},[2343],{"type":29,"value":2344},"Questo è un punto di contesa — due thread che allocano pagine esattamente nello stesso momento verranno serializzati. Ma l'allocazione è rara rispetto a letture e scritture, quindi l'impatto è proporzionale.",{"type":24,"tag":37,"props":2346,"children":2347},{},[],{"type":24,"tag":41,"props":2349,"children":2351},{"id":2350},"riepilogo-dei-lock",[2352],{"type":29,"value":2353},"Riepilogo dei Lock",{"type":24,"tag":2355,"props":2356,"children":2357},"table",{},[2358,2387],{"type":24,"tag":2359,"props":2360,"children":2361},"thead",{},[2362],{"type":24,"tag":2363,"props":2364,"children":2365},"tr",{},[2366,2372,2377,2382],{"type":24,"tag":2367,"props":2368,"children":2369},"th",{},[2370],{"type":29,"value":2371},"Operazione",{"type":24,"tag":2367,"props":2373,"children":2374},{},[2375],{"type":29,"value":2376},"Tipo di Lock",{"type":24,"tag":2367,"props":2378,"children":2379},{},[2380],{"type":29,"value":2381},"Modalità",{"type":24,"tag":2367,"props":2383,"children":2384},{},[2385],{"type":29,"value":2386},"Contesa",{"type":24,"tag":2388,"props":2389,"children":2390},"tbody",{},[2391,2422,2453,2484,2521,2557],{"type":24,"tag":2363,"props":2392,"children":2393},{},[2394,2404,2412,2417],{"type":24,"tag":2395,"props":2396,"children":2397},"td",{},[2398],{"type":24,"tag":53,"props":2399,"children":2401},{"className":2400},[],[2402],{"type":29,"value":2403},"ReadPage",{"type":24,"tag":2395,"props":2405,"children":2406},{},[2407],{"type":24,"tag":53,"props":2408,"children":2410},{"className":2409},[],[2411],{"type":29,"value":805},{"type":24,"tag":2395,"props":2413,"children":2414},{},[2415],{"type":29,"value":2416},"Read",{"type":24,"tag":2395,"props":2418,"children":2419},{},[2420],{"type":29,"value":2421},"Zero (concorrente con altre letture\u002Fscritture)",{"type":24,"tag":2363,"props":2423,"children":2424},{},[2425,2436,2444,2448],{"type":24,"tag":2395,"props":2426,"children":2427},{},[2428,2434],{"type":24,"tag":53,"props":2429,"children":2431},{"className":2430},[],[2432],{"type":29,"value":2433},"WritePage",{"type":29,"value":2435}," (senza crescita)",{"type":24,"tag":2395,"props":2437,"children":2438},{},[2439],{"type":24,"tag":53,"props":2440,"children":2442},{"className":2441},[],[2443],{"type":29,"value":805},{"type":24,"tag":2395,"props":2445,"children":2446},{},[2447],{"type":29,"value":2416},{"type":24,"tag":2395,"props":2449,"children":2450},{},[2451],{"type":29,"value":2452},"Zero (concorrente)",{"type":24,"tag":2363,"props":2454,"children":2455},{},[2456,2466,2474,2479],{"type":24,"tag":2395,"props":2457,"children":2458},{},[2459,2464],{"type":24,"tag":53,"props":2460,"children":2462},{"className":2461},[],[2463],{"type":29,"value":2433},{"type":29,"value":2465}," (con crescita)",{"type":24,"tag":2395,"props":2467,"children":2468},{},[2469],{"type":24,"tag":53,"props":2470,"children":2472},{"className":2471},[],[2473],{"type":29,"value":805},{"type":24,"tag":2395,"props":2475,"children":2476},{},[2477],{"type":29,"value":2478},"Write",{"type":24,"tag":2395,"props":2480,"children":2481},{},[2482],{"type":29,"value":2483},"Breve: blocca fino al rilascio di tutti i lettori",{"type":24,"tag":2363,"props":2485,"children":2486},{},[2487,2504,2512,2516],{"type":24,"tag":2395,"props":2488,"children":2489},{},[2490,2496,2498],{"type":24,"tag":53,"props":2491,"children":2493},{"className":2492},[],[2494],{"type":29,"value":2495},"AllocatePage",{"type":29,"value":2497}," \u002F ",{"type":24,"tag":53,"props":2499,"children":2501},{"className":2500},[],[2502],{"type":29,"value":2503},"FreePage",{"type":24,"tag":2395,"props":2505,"children":2506},{},[2507],{"type":24,"tag":53,"props":2508,"children":2510},{"className":2509},[],[2511],{"type":29,"value":805},{"type":24,"tag":2395,"props":2513,"children":2514},{},[2515],{"type":29,"value":2478},{"type":24,"tag":2395,"props":2517,"children":2518},{},[2519],{"type":29,"value":2520},"Rara: serializzata per file",{"type":24,"tag":2363,"props":2522,"children":2523},{},[2524,2539,2547,2552],{"type":24,"tag":2395,"props":2525,"children":2526},{},[2527,2532,2533],{"type":24,"tag":53,"props":2528,"children":2530},{"className":2529},[],[2531],{"type":29,"value":1884},{"type":29,"value":2497},{"type":24,"tag":53,"props":2534,"children":2536},{"className":2535},[],[2537],{"type":29,"value":2538},"BackupAsync",{"type":24,"tag":2395,"props":2540,"children":2541},{},[2542],{"type":24,"tag":53,"props":2543,"children":2545},{"className":2544},[],[2546],{"type":29,"value":1607},{"type":24,"tag":2395,"props":2548,"children":2549},{},[2550],{"type":29,"value":2551},"Esclusivo",{"type":24,"tag":2395,"props":2553,"children":2554},{},[2555],{"type":29,"value":2556},"Infrequente: serializzata",{"type":24,"tag":2363,"props":2558,"children":2559},{},[2560,2569,2574,2578],{"type":24,"tag":2395,"props":2561,"children":2562},{},[2563],{"type":24,"tag":53,"props":2564,"children":2566},{"className":2565},[],[2567],{"type":29,"value":2568},"Dispose",{"type":24,"tag":2395,"props":2570,"children":2571},{},[2572],{"type":29,"value":2573},"Entrambi",{"type":24,"tag":2395,"props":2575,"children":2576},{},[2577],{"type":29,"value":2551},{"type":24,"tag":2395,"props":2579,"children":2580},{},[2581],{"type":29,"value":2582},"Una volta: solo allo shutdown",{"type":24,"tag":25,"props":2584,"children":2585},{},[2586],{"type":29,"value":2587},"L'effetto netto: sotto carico normale, letture e scritture sono completamente concorrenti. La contesa avviene solo quando il file deve crescere o una pagina viene allocata — entrambe ammortizzate dalla pre-allocazione in blocchi da 1 MB.",{"type":24,"tag":37,"props":2589,"children":2590},{},[],{"type":24,"tag":41,"props":2592,"children":2594},{"id":2593},"isolamento-a-sessioni-una-connessione-una-transazione",[2595],{"type":29,"value":2596},"Isolamento a Sessioni: Una Connessione, Una Transazione",{"type":24,"tag":25,"props":2598,"children":2599},{},[2600],{"type":29,"value":2601},"Con il livello storage protetto, la domanda successiva è come dare a ogni connessione client un contesto transazionale indipendente. In modalità server, più client si connettono simultaneamente, ciascuno eseguendo le proprie operazioni CRUD. Non dovrebbero vedere le scritture non committate degli altri, e un rollback su una connessione non dovrebbe influenzare le altre.",{"type":24,"tag":25,"props":2603,"children":2604},{},[2605,2607,2613],{"type":29,"value":2606},"BLite introduce ",{"type":24,"tag":53,"props":2608,"children":2610},{"className":2609},[],[2611],{"type":29,"value":2612},"BLiteSession",{"type":29,"value":807},{"type":24,"tag":80,"props":2615,"children":2617},{"code":2616,"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",[2618],{"type":24,"tag":53,"props":2619,"children":2620},{"__ignoreMap":7},[2621,2662,2669,2695,2759,2784,2791,2820,2827,2847,2854,2861,2882,2889,2931,2960,2979,2986,2993,3013,3020,3065,3096,3124,3132,3162,3192,3200,3208,3216,3237,3245,3273,3281,3310,3338,3346,3354],{"type":24,"tag":117,"props":2622,"children":2623},{"class":119,"line":120},[2624,2628,2633,2638,2643,2648,2653,2657],{"type":24,"tag":117,"props":2625,"children":2626},{"style":124},[2627],{"type":29,"value":256},{"type":24,"tag":117,"props":2629,"children":2630},{"style":124},[2631],{"type":29,"value":2632}," sealed",{"type":24,"tag":117,"props":2634,"children":2635},{"style":124},[2636],{"type":29,"value":2637}," class",{"type":24,"tag":117,"props":2639,"children":2640},{"style":205},[2641],{"type":29,"value":2642}," BLiteSession",{"type":24,"tag":117,"props":2644,"children":2645},{"style":148},[2646],{"type":29,"value":2647}," : ",{"type":24,"tag":117,"props":2649,"children":2650},{"style":205},[2651],{"type":29,"value":2652},"ITransactionHolder",{"type":24,"tag":117,"props":2654,"children":2655},{"style":148},[2656],{"type":29,"value":221},{"type":24,"tag":117,"props":2658,"children":2659},{"style":205},[2660],{"type":29,"value":2661},"IDisposable\n",{"type":24,"tag":117,"props":2663,"children":2664},{"class":119,"line":176},[2665],{"type":24,"tag":117,"props":2666,"children":2667},{"style":148},[2668],{"type":29,"value":326},{"type":24,"tag":117,"props":2670,"children":2671},{"class":119,"line":329},[2672,2677,2681,2686,2691],{"type":24,"tag":117,"props":2673,"children":2674},{"style":124},[2675],{"type":29,"value":2676},"    private",{"type":24,"tag":117,"props":2678,"children":2679},{"style":124},[2680],{"type":29,"value":827},{"type":24,"tag":117,"props":2682,"children":2683},{"style":205},[2684],{"type":29,"value":2685}," StorageEngine",{"type":24,"tag":117,"props":2687,"children":2688},{"style":130},[2689],{"type":29,"value":2690}," _storage",{"type":24,"tag":117,"props":2692,"children":2693},{"style":148},[2694],{"type":29,"value":364},{"type":24,"tag":117,"props":2696,"children":2697},{"class":119,"line":367},[2698,2702,2706,2711,2715,2719,2723,2728,2732,2737,2742,2747,2751,2755],{"type":24,"tag":117,"props":2699,"children":2700},{"style":124},[2701],{"type":29,"value":2676},{"type":24,"tag":117,"props":2703,"children":2704},{"style":124},[2705],{"type":29,"value":827},{"type":24,"tag":117,"props":2707,"children":2708},{"style":205},[2709],{"type":29,"value":2710}," ConcurrentDictionary",{"type":24,"tag":117,"props":2712,"children":2713},{"style":148},[2714],{"type":29,"value":939},{"type":24,"tag":117,"props":2716,"children":2717},{"style":124},[2718],{"type":29,"value":279},{"type":24,"tag":117,"props":2720,"children":2721},{"style":148},[2722],{"type":29,"value":221},{"type":24,"tag":117,"props":2724,"children":2725},{"style":205},[2726],{"type":29,"value":2727},"Lazy",{"type":24,"tag":117,"props":2729,"children":2730},{"style":148},[2731],{"type":29,"value":939},{"type":24,"tag":117,"props":2733,"children":2734},{"style":205},[2735],{"type":29,"value":2736},"DynamicCollection",{"type":24,"tag":117,"props":2738,"children":2739},{"style":148},[2740],{"type":29,"value":2741},">> ",{"type":24,"tag":117,"props":2743,"children":2744},{"style":130},[2745],{"type":29,"value":2746},"_collections",{"type":24,"tag":117,"props":2748,"children":2749},{"style":136},[2750],{"type":29,"value":139},{"type":24,"tag":117,"props":2752,"children":2753},{"style":199},[2754],{"type":29,"value":202},{"type":24,"tag":117,"props":2756,"children":2757},{"style":148},[2758],{"type":29,"value":1059},{"type":24,"tag":117,"props":2760,"children":2761},{"class":119,"line":385},[2762,2766,2771,2775,2780],{"type":24,"tag":117,"props":2763,"children":2764},{"style":124},[2765],{"type":29,"value":2676},{"type":24,"tag":117,"props":2767,"children":2768},{"style":205},[2769],{"type":29,"value":2770}," ITransaction",{"type":24,"tag":117,"props":2772,"children":2773},{"style":148},[2774],{"type":29,"value":298},{"type":24,"tag":117,"props":2776,"children":2777},{"style":130},[2778],{"type":29,"value":2779},"_currentTransaction",{"type":24,"tag":117,"props":2781,"children":2782},{"style":148},[2783],{"type":29,"value":364},{"type":24,"tag":117,"props":2785,"children":2786},{"class":119,"line":394},[2787],{"type":24,"tag":117,"props":2788,"children":2789},{"emptyLinePlaceholder":534},[2790],{"type":29,"value":537},{"type":24,"tag":117,"props":2792,"children":2793},{"class":119,"line":426},[2794,2799,2803,2807,2811,2816],{"type":24,"tag":117,"props":2795,"children":2796},{"style":124},[2797],{"type":29,"value":2798},"    internal",{"type":24,"tag":117,"props":2800,"children":2801},{"style":154},[2802],{"type":29,"value":2642},{"type":24,"tag":117,"props":2804,"children":2805},{"style":148},[2806],{"type":29,"value":162},{"type":24,"tag":117,"props":2808,"children":2809},{"style":205},[2810],{"type":29,"value":732},{"type":24,"tag":117,"props":2812,"children":2813},{"style":205},[2814],{"type":29,"value":2815}," storage",{"type":24,"tag":117,"props":2817,"children":2818},{"style":148},[2819],{"type":29,"value":318},{"type":24,"tag":117,"props":2821,"children":2822},{"class":119,"line":473},[2823],{"type":24,"tag":117,"props":2824,"children":2825},{"style":148},[2826],{"type":29,"value":391},{"type":24,"tag":117,"props":2828,"children":2829},{"class":119,"line":486},[2830,2835,2839,2843],{"type":24,"tag":117,"props":2831,"children":2832},{"style":165},[2833],{"type":29,"value":2834},"        _storage",{"type":24,"tag":117,"props":2836,"children":2837},{"style":136},[2838],{"type":29,"value":139},{"type":24,"tag":117,"props":2840,"children":2841},{"style":165},[2842],{"type":29,"value":2815},{"type":24,"tag":117,"props":2844,"children":2845},{"style":148},[2846],{"type":29,"value":364},{"type":24,"tag":117,"props":2848,"children":2849},{"class":119,"line":530},[2850],{"type":24,"tag":117,"props":2851,"children":2852},{"style":148},[2853],{"type":29,"value":1150},{"type":24,"tag":117,"props":2855,"children":2856},{"class":119,"line":540},[2857],{"type":24,"tag":117,"props":2858,"children":2859},{"emptyLinePlaceholder":534},[2860],{"type":29,"value":537},{"type":24,"tag":117,"props":2862,"children":2863},{"class":119,"line":587},[2864,2869,2873,2878],{"type":24,"tag":117,"props":2865,"children":2866},{"style":124},[2867],{"type":29,"value":2868},"    public",{"type":24,"tag":117,"props":2870,"children":2871},{"style":205},[2872],{"type":29,"value":2770},{"type":24,"tag":117,"props":2874,"children":2875},{"style":154},[2876],{"type":29,"value":2877}," BeginTransaction",{"type":24,"tag":117,"props":2879,"children":2880},{"style":148},[2881],{"type":29,"value":2006},{"type":24,"tag":117,"props":2883,"children":2884},{"class":119,"line":595},[2885],{"type":24,"tag":117,"props":2886,"children":2887},{"style":148},[2888],{"type":29,"value":391},{"type":24,"tag":117,"props":2890,"children":2891},{"class":119,"line":624},[2892,2896,2900,2905,2909,2913,2917,2922,2927],{"type":24,"tag":117,"props":2893,"children":2894},{"style":124},[2895],{"type":29,"value":2054},{"type":24,"tag":117,"props":2897,"children":2898},{"style":148},[2899],{"type":29,"value":987},{"type":24,"tag":117,"props":2901,"children":2902},{"style":165},[2903],{"type":29,"value":2904},"CurrentTransaction",{"type":24,"tag":117,"props":2906,"children":2907},{"style":136},[2908],{"type":29,"value":2067},{"type":24,"tag":117,"props":2910,"children":2911},{"style":310},[2912],{"type":29,"value":313},{"type":24,"tag":117,"props":2914,"children":2915},{"style":148},[2916],{"type":29,"value":454},{"type":24,"tag":117,"props":2918,"children":2919},{"style":124},[2920],{"type":29,"value":2921},"return",{"type":24,"tag":117,"props":2923,"children":2924},{"style":165},[2925],{"type":29,"value":2926}," CurrentTransaction",{"type":24,"tag":117,"props":2928,"children":2929},{"style":148},[2930],{"type":29,"value":364},{"type":24,"tag":117,"props":2932,"children":2933},{"class":119,"line":664},[2934,2939,2943,2947,2951,2956],{"type":24,"tag":117,"props":2935,"children":2936},{"style":165},[2937],{"type":29,"value":2938},"        CurrentTransaction",{"type":24,"tag":117,"props":2940,"children":2941},{"style":136},[2942],{"type":29,"value":139},{"type":24,"tag":117,"props":2944,"children":2945},{"style":142},[2946],{"type":29,"value":2690},{"type":24,"tag":117,"props":2948,"children":2949},{"style":148},[2950],{"type":29,"value":151},{"type":24,"tag":117,"props":2952,"children":2953},{"style":154},[2954],{"type":29,"value":2955},"BeginTransaction",{"type":24,"tag":117,"props":2957,"children":2958},{"style":148},[2959],{"type":29,"value":1059},{"type":24,"tag":117,"props":2961,"children":2962},{"class":119,"line":677},[2963,2967,2971,2975],{"type":24,"tag":117,"props":2964,"children":2965},{"style":124},[2966],{"type":29,"value":1138},{"type":24,"tag":117,"props":2968,"children":2969},{"style":165},[2970],{"type":29,"value":2926},{"type":24,"tag":117,"props":2972,"children":2973},{"style":136},[2974],{"type":29,"value":1017},{"type":24,"tag":117,"props":2976,"children":2977},{"style":148},[2978],{"type":29,"value":364},{"type":24,"tag":117,"props":2980,"children":2981},{"class":119,"line":706},[2982],{"type":24,"tag":117,"props":2983,"children":2984},{"style":148},[2985],{"type":29,"value":1150},{"type":24,"tag":117,"props":2987,"children":2988},{"class":119,"line":715},[2989],{"type":24,"tag":117,"props":2990,"children":2991},{"emptyLinePlaceholder":534},[2992],{"type":29,"value":537},{"type":24,"tag":117,"props":2994,"children":2995},{"class":119,"line":1265},[2996,3000,3004,3009],{"type":24,"tag":117,"props":2997,"children":2998},{"style":124},[2999],{"type":29,"value":2868},{"type":24,"tag":117,"props":3001,"children":3002},{"style":124},[3003],{"type":29,"value":906},{"type":24,"tag":117,"props":3005,"children":3006},{"style":154},[3007],{"type":29,"value":3008}," Commit",{"type":24,"tag":117,"props":3010,"children":3011},{"style":148},[3012],{"type":29,"value":2006},{"type":24,"tag":117,"props":3014,"children":3015},{"class":119,"line":1295},[3016],{"type":24,"tag":117,"props":3017,"children":3018},{"style":148},[3019],{"type":29,"value":391},{"type":24,"tag":117,"props":3021,"children":3023},{"class":119,"line":3022},21,[3024,3029,3033,3037,3042,3047,3052,3056,3061],{"type":24,"tag":117,"props":3025,"children":3026},{"style":124},[3027],{"type":29,"value":3028},"        foreach",{"type":24,"tag":117,"props":3030,"children":3031},{"style":148},[3032],{"type":29,"value":987},{"type":24,"tag":117,"props":3034,"children":3035},{"style":124},[3036],{"type":29,"value":127},{"type":24,"tag":117,"props":3038,"children":3039},{"style":130},[3040],{"type":29,"value":3041}," lazy",{"type":24,"tag":117,"props":3043,"children":3044},{"style":124},[3045],{"type":29,"value":3046}," in",{"type":24,"tag":117,"props":3048,"children":3049},{"style":142},[3050],{"type":29,"value":3051}," _collections",{"type":24,"tag":117,"props":3053,"children":3054},{"style":148},[3055],{"type":29,"value":151},{"type":24,"tag":117,"props":3057,"children":3058},{"style":142},[3059],{"type":29,"value":3060},"Values",{"type":24,"tag":117,"props":3062,"children":3063},{"style":148},[3064],{"type":29,"value":318},{"type":24,"tag":117,"props":3066,"children":3068},{"class":119,"line":3067},22,[3069,3074,3078,3083,3087,3092],{"type":24,"tag":117,"props":3070,"children":3071},{"style":142},[3072],{"type":29,"value":3073},"            lazy",{"type":24,"tag":117,"props":3075,"children":3076},{"style":148},[3077],{"type":29,"value":151},{"type":24,"tag":117,"props":3079,"children":3080},{"style":142},[3081],{"type":29,"value":3082},"Value",{"type":24,"tag":117,"props":3084,"children":3085},{"style":148},[3086],{"type":29,"value":151},{"type":24,"tag":117,"props":3088,"children":3089},{"style":154},[3090],{"type":29,"value":3091},"PersistIndexMetadata",{"type":24,"tag":117,"props":3093,"children":3094},{"style":148},[3095],{"type":29,"value":1059},{"type":24,"tag":117,"props":3097,"children":3099},{"class":119,"line":3098},23,[3100,3104,3108,3112,3116,3120],{"type":24,"tag":117,"props":3101,"children":3102},{"style":124},[3103],{"type":29,"value":2054},{"type":24,"tag":117,"props":3105,"children":3106},{"style":148},[3107],{"type":29,"value":987},{"type":24,"tag":117,"props":3109,"children":3110},{"style":165},[3111],{"type":29,"value":2904},{"type":24,"tag":117,"props":3113,"children":3114},{"style":136},[3115],{"type":29,"value":2067},{"type":24,"tag":117,"props":3117,"children":3118},{"style":310},[3119],{"type":29,"value":313},{"type":24,"tag":117,"props":3121,"children":3122},{"style":148},[3123],{"type":29,"value":318},{"type":24,"tag":117,"props":3125,"children":3127},{"class":119,"line":3126},24,[3128],{"type":24,"tag":117,"props":3129,"children":3130},{"style":148},[3131],{"type":29,"value":2084},{"type":24,"tag":117,"props":3133,"children":3135},{"class":119,"line":3134},25,[3136,3141,3145,3149,3153,3158],{"type":24,"tag":117,"props":3137,"children":3138},{"style":124},[3139],{"type":29,"value":3140},"            try",{"type":24,"tag":117,"props":3142,"children":3143},{"style":148},[3144],{"type":29,"value":1072},{"type":24,"tag":117,"props":3146,"children":3147},{"style":142},[3148],{"type":29,"value":2904},{"type":24,"tag":117,"props":3150,"children":3151},{"style":148},[3152],{"type":29,"value":151},{"type":24,"tag":117,"props":3154,"children":3155},{"style":154},[3156],{"type":29,"value":3157},"Commit",{"type":24,"tag":117,"props":3159,"children":3160},{"style":148},[3161],{"type":29,"value":1130},{"type":24,"tag":117,"props":3163,"children":3165},{"class":119,"line":3164},26,[3166,3171,3175,3179,3183,3187],{"type":24,"tag":117,"props":3167,"children":3168},{"style":124},[3169],{"type":29,"value":3170},"            finally",{"type":24,"tag":117,"props":3172,"children":3173},{"style":148},[3174],{"type":29,"value":1072},{"type":24,"tag":117,"props":3176,"children":3177},{"style":165},[3178],{"type":29,"value":2904},{"type":24,"tag":117,"props":3180,"children":3181},{"style":136},[3182],{"type":29,"value":139},{"type":24,"tag":117,"props":3184,"children":3185},{"style":310},[3186],{"type":29,"value":313},{"type":24,"tag":117,"props":3188,"children":3189},{"style":148},[3190],{"type":29,"value":3191},"; }\n",{"type":24,"tag":117,"props":3193,"children":3195},{"class":119,"line":3194},27,[3196],{"type":24,"tag":117,"props":3197,"children":3198},{"style":148},[3199],{"type":29,"value":2214},{"type":24,"tag":117,"props":3201,"children":3203},{"class":119,"line":3202},28,[3204],{"type":24,"tag":117,"props":3205,"children":3206},{"style":148},[3207],{"type":29,"value":1150},{"type":24,"tag":117,"props":3209,"children":3211},{"class":119,"line":3210},29,[3212],{"type":24,"tag":117,"props":3213,"children":3214},{"emptyLinePlaceholder":534},[3215],{"type":29,"value":537},{"type":24,"tag":117,"props":3217,"children":3219},{"class":119,"line":3218},30,[3220,3224,3228,3233],{"type":24,"tag":117,"props":3221,"children":3222},{"style":124},[3223],{"type":29,"value":2868},{"type":24,"tag":117,"props":3225,"children":3226},{"style":124},[3227],{"type":29,"value":906},{"type":24,"tag":117,"props":3229,"children":3230},{"style":154},[3231],{"type":29,"value":3232}," Rollback",{"type":24,"tag":117,"props":3234,"children":3235},{"style":148},[3236],{"type":29,"value":2006},{"type":24,"tag":117,"props":3238,"children":3240},{"class":119,"line":3239},31,[3241],{"type":24,"tag":117,"props":3242,"children":3243},{"style":148},[3244],{"type":29,"value":391},{"type":24,"tag":117,"props":3246,"children":3248},{"class":119,"line":3247},32,[3249,3253,3257,3261,3265,3269],{"type":24,"tag":117,"props":3250,"children":3251},{"style":124},[3252],{"type":29,"value":2054},{"type":24,"tag":117,"props":3254,"children":3255},{"style":148},[3256],{"type":29,"value":987},{"type":24,"tag":117,"props":3258,"children":3259},{"style":165},[3260],{"type":29,"value":2904},{"type":24,"tag":117,"props":3262,"children":3263},{"style":136},[3264],{"type":29,"value":2067},{"type":24,"tag":117,"props":3266,"children":3267},{"style":310},[3268],{"type":29,"value":313},{"type":24,"tag":117,"props":3270,"children":3271},{"style":148},[3272],{"type":29,"value":318},{"type":24,"tag":117,"props":3274,"children":3276},{"class":119,"line":3275},33,[3277],{"type":24,"tag":117,"props":3278,"children":3279},{"style":148},[3280],{"type":29,"value":2084},{"type":24,"tag":117,"props":3282,"children":3284},{"class":119,"line":3283},34,[3285,3289,3293,3297,3301,3306],{"type":24,"tag":117,"props":3286,"children":3287},{"style":124},[3288],{"type":29,"value":3140},{"type":24,"tag":117,"props":3290,"children":3291},{"style":148},[3292],{"type":29,"value":1072},{"type":24,"tag":117,"props":3294,"children":3295},{"style":142},[3296],{"type":29,"value":2904},{"type":24,"tag":117,"props":3298,"children":3299},{"style":148},[3300],{"type":29,"value":151},{"type":24,"tag":117,"props":3302,"children":3303},{"style":154},[3304],{"type":29,"value":3305},"Rollback",{"type":24,"tag":117,"props":3307,"children":3308},{"style":148},[3309],{"type":29,"value":1130},{"type":24,"tag":117,"props":3311,"children":3313},{"class":119,"line":3312},35,[3314,3318,3322,3326,3330,3334],{"type":24,"tag":117,"props":3315,"children":3316},{"style":124},[3317],{"type":29,"value":3170},{"type":24,"tag":117,"props":3319,"children":3320},{"style":148},[3321],{"type":29,"value":1072},{"type":24,"tag":117,"props":3323,"children":3324},{"style":165},[3325],{"type":29,"value":2904},{"type":24,"tag":117,"props":3327,"children":3328},{"style":136},[3329],{"type":29,"value":139},{"type":24,"tag":117,"props":3331,"children":3332},{"style":310},[3333],{"type":29,"value":313},{"type":24,"tag":117,"props":3335,"children":3336},{"style":148},[3337],{"type":29,"value":3191},{"type":24,"tag":117,"props":3339,"children":3341},{"class":119,"line":3340},36,[3342],{"type":24,"tag":117,"props":3343,"children":3344},{"style":148},[3345],{"type":29,"value":2214},{"type":24,"tag":117,"props":3347,"children":3349},{"class":119,"line":3348},37,[3350],{"type":24,"tag":117,"props":3351,"children":3352},{"style":148},[3353],{"type":29,"value":1150},{"type":24,"tag":117,"props":3355,"children":3357},{"class":119,"line":3356},38,[3358],{"type":24,"tag":117,"props":3359,"children":3360},{"style":148},[3361],{"type":29,"value":721},{"type":24,"tag":25,"props":3363,"children":3364},{},[3365],{"type":29,"value":3366},"Il modello:",{"type":24,"tag":3368,"props":3369,"children":3370},"ul",{},[3371,3387,3409,3421,3432],{"type":24,"tag":3372,"props":3373,"children":3374},"li",{},[3375,3385],{"type":24,"tag":881,"props":3376,"children":3377},{},[3378,3379],{"type":29,"value":1530},{"type":24,"tag":53,"props":3380,"children":3382},{"className":3381},[],[3383],{"type":29,"value":3384},"BLiteEngine",{"type":29,"value":3386}," per database, condiviso tra tutte le connessioni.",{"type":24,"tag":3372,"props":3388,"children":3389},{},[3390,3400,3402,3408],{"type":24,"tag":881,"props":3391,"children":3392},{},[3393,3395],{"type":29,"value":3394},"Una ",{"type":24,"tag":53,"props":3396,"children":3398},{"className":3397},[],[3399],{"type":29,"value":2612},{"type":29,"value":3401}," per connessione client, creata tramite ",{"type":24,"tag":53,"props":3403,"children":3405},{"className":3404},[],[3406],{"type":29,"value":3407},"engine.OpenSession()",{"type":29,"value":151},{"type":24,"tag":3372,"props":3410,"children":3411},{},[3412,3414,3419],{"type":29,"value":3413},"Ogni sessione ha la propria ",{"type":24,"tag":53,"props":3415,"children":3417},{"className":3416},[],[3418],{"type":29,"value":2779},{"type":29,"value":3420}," — le scritture non committate vivono nella cache WAL per-transazione, invisibili alle altre sessioni.",{"type":24,"tag":3372,"props":3422,"children":3423},{},[3424,3430],{"type":24,"tag":53,"props":3425,"children":3427},{"className":3426},[],[3428],{"type":29,"value":3429},"Commit()",{"type":29,"value":3431}," persiste i metadati degli indici, committa la transazione e cancella il riferimento alla transazione della sessione.",{"type":24,"tag":3372,"props":3433,"children":3434},{},[3435,3441],{"type":24,"tag":53,"props":3436,"children":3438},{"className":3437},[],[3439],{"type":29,"value":3440},"Dispose()",{"type":29,"value":3442}," fa auto-rollback di qualsiasi transazione non committata — se la connessione cade, niente va perso.",{"type":24,"tag":80,"props":3444,"children":3446},{"code":3445,"language":110,"meta":7,"className":111,"style":7},"\u002F\u002F Gestore connessione server:\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 è invisibile a session2, doc2 è invisibile a session1\n\nsession1.Commit();  \u002F\u002F doc1 ora è visibile alle nuove letture\nsession2.Rollback(); \u002F\u002F doc2 scompare\n",[3447],{"type":24,"tag":53,"props":3448,"children":3449},{"__ignoreMap":7},[3450,3458,3519,3526,3565,3602,3609,3629,3677,3684,3704,3748,3755,3763,3770,3794],{"type":24,"tag":117,"props":3451,"children":3452},{"class":119,"line":120},[3453],{"type":24,"tag":117,"props":3454,"children":3455},{"style":971},[3456],{"type":29,"value":3457},"\u002F\u002F Gestore connessione server:\n",{"type":24,"tag":117,"props":3459,"children":3460},{"class":119,"line":176},[3461,3465,3469,3473,3477,3481,3485,3490,3494,3498,3502,3506,3510,3514],{"type":24,"tag":117,"props":3462,"children":3463},{"style":124},[3464],{"type":29,"value":127},{"type":24,"tag":117,"props":3466,"children":3467},{"style":130},[3468],{"type":29,"value":192},{"type":24,"tag":117,"props":3470,"children":3471},{"style":136},[3472],{"type":29,"value":139},{"type":24,"tag":117,"props":3474,"children":3475},{"style":199},[3476],{"type":29,"value":202},{"type":24,"tag":117,"props":3478,"children":3479},{"style":205},[3480],{"type":29,"value":208},{"type":24,"tag":117,"props":3482,"children":3483},{"style":148},[3484],{"type":29,"value":162},{"type":24,"tag":117,"props":3486,"children":3487},{"style":165},[3488],{"type":29,"value":3489},"dbPath",{"type":24,"tag":117,"props":3491,"children":3492},{"style":148},[3493],{"type":29,"value":221},{"type":24,"tag":117,"props":3495,"children":3496},{"style":142},[3497],{"type":29,"value":293},{"type":24,"tag":117,"props":3499,"children":3500},{"style":148},[3501],{"type":29,"value":151},{"type":24,"tag":117,"props":3503,"children":3504},{"style":154},[3505],{"type":29,"value":157},{"type":24,"tag":117,"props":3507,"children":3508},{"style":148},[3509],{"type":29,"value":162},{"type":24,"tag":117,"props":3511,"children":3512},{"style":165},[3513],{"type":29,"value":3489},{"type":24,"tag":117,"props":3515,"children":3516},{"style":148},[3517],{"type":29,"value":3518},"));\n",{"type":24,"tag":117,"props":3520,"children":3521},{"class":119,"line":329},[3522],{"type":24,"tag":117,"props":3523,"children":3524},{"emptyLinePlaceholder":534},[3525],{"type":29,"value":537},{"type":24,"tag":117,"props":3527,"children":3528},{"class":119,"line":367},[3529,3533,3538,3542,3546,3550,3555,3560],{"type":24,"tag":117,"props":3530,"children":3531},{"style":124},[3532],{"type":29,"value":127},{"type":24,"tag":117,"props":3534,"children":3535},{"style":130},[3536],{"type":29,"value":3537}," session1",{"type":24,"tag":117,"props":3539,"children":3540},{"style":136},[3541],{"type":29,"value":139},{"type":24,"tag":117,"props":3543,"children":3544},{"style":142},[3545],{"type":29,"value":192},{"type":24,"tag":117,"props":3547,"children":3548},{"style":148},[3549],{"type":29,"value":151},{"type":24,"tag":117,"props":3551,"children":3552},{"style":154},[3553],{"type":29,"value":3554},"OpenSession",{"type":24,"tag":117,"props":3556,"children":3557},{"style":148},[3558],{"type":29,"value":3559},"();  ",{"type":24,"tag":117,"props":3561,"children":3562},{"style":971},[3563],{"type":29,"value":3564},"\u002F\u002F Client 1\n",{"type":24,"tag":117,"props":3566,"children":3567},{"class":119,"line":385},[3568,3572,3577,3581,3585,3589,3593,3597],{"type":24,"tag":117,"props":3569,"children":3570},{"style":124},[3571],{"type":29,"value":127},{"type":24,"tag":117,"props":3573,"children":3574},{"style":130},[3575],{"type":29,"value":3576}," session2",{"type":24,"tag":117,"props":3578,"children":3579},{"style":136},[3580],{"type":29,"value":139},{"type":24,"tag":117,"props":3582,"children":3583},{"style":142},[3584],{"type":29,"value":192},{"type":24,"tag":117,"props":3586,"children":3587},{"style":148},[3588],{"type":29,"value":151},{"type":24,"tag":117,"props":3590,"children":3591},{"style":154},[3592],{"type":29,"value":3554},{"type":24,"tag":117,"props":3594,"children":3595},{"style":148},[3596],{"type":29,"value":3559},{"type":24,"tag":117,"props":3598,"children":3599},{"style":971},[3600],{"type":29,"value":3601},"\u002F\u002F Client 2\n",{"type":24,"tag":117,"props":3603,"children":3604},{"class":119,"line":394},[3605],{"type":24,"tag":117,"props":3606,"children":3607},{"emptyLinePlaceholder":534},[3608],{"type":29,"value":537},{"type":24,"tag":117,"props":3610,"children":3611},{"class":119,"line":426},[3612,3617,3621,3625],{"type":24,"tag":117,"props":3613,"children":3614},{"style":142},[3615],{"type":29,"value":3616},"session1",{"type":24,"tag":117,"props":3618,"children":3619},{"style":148},[3620],{"type":29,"value":151},{"type":24,"tag":117,"props":3622,"children":3623},{"style":154},[3624],{"type":29,"value":2955},{"type":24,"tag":117,"props":3626,"children":3627},{"style":148},[3628],{"type":29,"value":1059},{"type":24,"tag":117,"props":3630,"children":3631},{"class":119,"line":473},[3632,3636,3640,3645,3649,3654,3659,3664,3668,3673],{"type":24,"tag":117,"props":3633,"children":3634},{"style":142},[3635],{"type":29,"value":3616},{"type":24,"tag":117,"props":3637,"children":3638},{"style":148},[3639],{"type":29,"value":151},{"type":24,"tag":117,"props":3641,"children":3642},{"style":154},[3643],{"type":29,"value":3644},"GetOrCreateCollection",{"type":24,"tag":117,"props":3646,"children":3647},{"style":148},[3648],{"type":29,"value":162},{"type":24,"tag":117,"props":3650,"children":3651},{"style":462},[3652],{"type":29,"value":3653},"\"users\"",{"type":24,"tag":117,"props":3655,"children":3656},{"style":148},[3657],{"type":29,"value":3658},").",{"type":24,"tag":117,"props":3660,"children":3661},{"style":154},[3662],{"type":29,"value":3663},"Insert",{"type":24,"tag":117,"props":3665,"children":3666},{"style":148},[3667],{"type":29,"value":162},{"type":24,"tag":117,"props":3669,"children":3670},{"style":165},[3671],{"type":29,"value":3672},"doc1",{"type":24,"tag":117,"props":3674,"children":3675},{"style":148},[3676],{"type":29,"value":173},{"type":24,"tag":117,"props":3678,"children":3679},{"class":119,"line":486},[3680],{"type":24,"tag":117,"props":3681,"children":3682},{"emptyLinePlaceholder":534},[3683],{"type":29,"value":537},{"type":24,"tag":117,"props":3685,"children":3686},{"class":119,"line":530},[3687,3692,3696,3700],{"type":24,"tag":117,"props":3688,"children":3689},{"style":142},[3690],{"type":29,"value":3691},"session2",{"type":24,"tag":117,"props":3693,"children":3694},{"style":148},[3695],{"type":29,"value":151},{"type":24,"tag":117,"props":3697,"children":3698},{"style":154},[3699],{"type":29,"value":2955},{"type":24,"tag":117,"props":3701,"children":3702},{"style":148},[3703],{"type":29,"value":1059},{"type":24,"tag":117,"props":3705,"children":3706},{"class":119,"line":540},[3707,3711,3715,3719,3723,3727,3731,3735,3739,3744],{"type":24,"tag":117,"props":3708,"children":3709},{"style":142},[3710],{"type":29,"value":3691},{"type":24,"tag":117,"props":3712,"children":3713},{"style":148},[3714],{"type":29,"value":151},{"type":24,"tag":117,"props":3716,"children":3717},{"style":154},[3718],{"type":29,"value":3644},{"type":24,"tag":117,"props":3720,"children":3721},{"style":148},[3722],{"type":29,"value":162},{"type":24,"tag":117,"props":3724,"children":3725},{"style":462},[3726],{"type":29,"value":3653},{"type":24,"tag":117,"props":3728,"children":3729},{"style":148},[3730],{"type":29,"value":3658},{"type":24,"tag":117,"props":3732,"children":3733},{"style":154},[3734],{"type":29,"value":3663},{"type":24,"tag":117,"props":3736,"children":3737},{"style":148},[3738],{"type":29,"value":162},{"type":24,"tag":117,"props":3740,"children":3741},{"style":165},[3742],{"type":29,"value":3743},"doc2",{"type":24,"tag":117,"props":3745,"children":3746},{"style":148},[3747],{"type":29,"value":173},{"type":24,"tag":117,"props":3749,"children":3750},{"class":119,"line":587},[3751],{"type":24,"tag":117,"props":3752,"children":3753},{"emptyLinePlaceholder":534},[3754],{"type":29,"value":537},{"type":24,"tag":117,"props":3756,"children":3757},{"class":119,"line":595},[3758],{"type":24,"tag":117,"props":3759,"children":3760},{"style":971},[3761],{"type":29,"value":3762},"\u002F\u002F doc1 è invisibile a session2, doc2 è invisibile a session1\n",{"type":24,"tag":117,"props":3764,"children":3765},{"class":119,"line":624},[3766],{"type":24,"tag":117,"props":3767,"children":3768},{"emptyLinePlaceholder":534},[3769],{"type":29,"value":537},{"type":24,"tag":117,"props":3771,"children":3772},{"class":119,"line":664},[3773,3777,3781,3785,3789],{"type":24,"tag":117,"props":3774,"children":3775},{"style":142},[3776],{"type":29,"value":3616},{"type":24,"tag":117,"props":3778,"children":3779},{"style":148},[3780],{"type":29,"value":151},{"type":24,"tag":117,"props":3782,"children":3783},{"style":154},[3784],{"type":29,"value":3157},{"type":24,"tag":117,"props":3786,"children":3787},{"style":148},[3788],{"type":29,"value":3559},{"type":24,"tag":117,"props":3790,"children":3791},{"style":971},[3792],{"type":29,"value":3793},"\u002F\u002F doc1 ora è visibile alle nuove letture\n",{"type":24,"tag":117,"props":3795,"children":3796},{"class":119,"line":677},[3797,3801,3805,3809,3814],{"type":24,"tag":117,"props":3798,"children":3799},{"style":142},[3800],{"type":29,"value":3691},{"type":24,"tag":117,"props":3802,"children":3803},{"style":148},[3804],{"type":29,"value":151},{"type":24,"tag":117,"props":3806,"children":3807},{"style":154},[3808],{"type":29,"value":3305},{"type":24,"tag":117,"props":3810,"children":3811},{"style":148},[3812],{"type":29,"value":3813},"(); ",{"type":24,"tag":117,"props":3815,"children":3816},{"style":971},[3817],{"type":29,"value":3818},"\u002F\u002F doc2 scompare\n",{"type":24,"tag":25,"props":3820,"children":3821},{},[3822,3824,3830,3832,3838,3840,3846,3848,3853],{"type":29,"value":3823},"Le collection vengono caricate lazy per sessione e cache con ",{"type":24,"tag":53,"props":3825,"children":3827},{"className":3826},[],[3828],{"type":29,"value":3829},"ConcurrentDictionary\u003Cstring, Lazy\u003CDynamicCollection>>",{"type":29,"value":3831},". Il ",{"type":24,"tag":53,"props":3833,"children":3835},{"className":3834},[],[3836],{"type":29,"value":3837},"Lazy\u003CT>",{"type":29,"value":3839}," con ",{"type":24,"tag":53,"props":3841,"children":3843},{"className":3842},[],[3844],{"type":29,"value":3845},"LazyThreadSafetyMode.ExecutionAndPublication",{"type":29,"value":3847}," garantisce che anche se una sessione crea la stessa collection da più thread (ad esempio, handler API paralleli), la ",{"type":24,"tag":53,"props":3849,"children":3851},{"className":3850},[],[3852],{"type":29,"value":2736},{"type":29,"value":3854}," viene costruita esattamente una volta.",{"type":24,"tag":37,"props":3856,"children":3857},{},[],{"type":24,"tag":41,"props":3859,"children":3861},{"id":3860},"migrazione-da-singolo-a-multi-e-ritorno",[3862],{"type":29,"value":3863},"Migrazione: Da Singolo a Multi e Ritorno",{"type":24,"tag":25,"props":3865,"children":3866},{},[3867,3869,3875],{"type":29,"value":3868},"Convertire un database single-file esistente in layout multi-file (o viceversa) avviene tramite ",{"type":24,"tag":53,"props":3870,"children":3872},{"className":3871},[],[3873],{"type":29,"value":3874},"BLiteMigration",{"type":29,"value":807},{"type":24,"tag":80,"props":3877,"children":3879},{"code":3878,"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",[3880],{"type":24,"tag":53,"props":3881,"children":3882},{"__ignoreMap":7},[3883,3891,3943,3950,3958],{"type":24,"tag":117,"props":3884,"children":3885},{"class":119,"line":120},[3886],{"type":24,"tag":117,"props":3887,"children":3888},{"style":971},[3889],{"type":29,"value":3890},"\u002F\u002F Single → multi-file\n",{"type":24,"tag":117,"props":3892,"children":3893},{"class":119,"line":176},[3894,3898,3902,3907,3911,3915,3919,3923,3927,3931,3935,3939],{"type":24,"tag":117,"props":3895,"children":3896},{"style":142},[3897],{"type":29,"value":3874},{"type":24,"tag":117,"props":3899,"children":3900},{"style":148},[3901],{"type":29,"value":151},{"type":24,"tag":117,"props":3903,"children":3904},{"style":154},[3905],{"type":29,"value":3906},"ToMultiFile",{"type":24,"tag":117,"props":3908,"children":3909},{"style":148},[3910],{"type":29,"value":162},{"type":24,"tag":117,"props":3912,"children":3913},{"style":165},[3914],{"type":29,"value":3489},{"type":24,"tag":117,"props":3916,"children":3917},{"style":148},[3918],{"type":29,"value":221},{"type":24,"tag":117,"props":3920,"children":3921},{"style":142},[3922],{"type":29,"value":293},{"type":24,"tag":117,"props":3924,"children":3925},{"style":148},[3926],{"type":29,"value":151},{"type":24,"tag":117,"props":3928,"children":3929},{"style":154},[3930],{"type":29,"value":157},{"type":24,"tag":117,"props":3932,"children":3933},{"style":148},[3934],{"type":29,"value":162},{"type":24,"tag":117,"props":3936,"children":3937},{"style":165},[3938],{"type":29,"value":3489},{"type":24,"tag":117,"props":3940,"children":3941},{"style":148},[3942],{"type":29,"value":3518},{"type":24,"tag":117,"props":3944,"children":3945},{"class":119,"line":329},[3946],{"type":24,"tag":117,"props":3947,"children":3948},{"emptyLinePlaceholder":534},[3949],{"type":29,"value":537},{"type":24,"tag":117,"props":3951,"children":3952},{"class":119,"line":367},[3953],{"type":24,"tag":117,"props":3954,"children":3955},{"style":971},[3956],{"type":29,"value":3957},"\u002F\u002F Multi-file → single-file\n",{"type":24,"tag":117,"props":3959,"children":3960},{"class":119,"line":385},[3961,3965,3969,3974,3978,3982,3986,3991,3995,3999],{"type":24,"tag":117,"props":3962,"children":3963},{"style":142},[3964],{"type":29,"value":3874},{"type":24,"tag":117,"props":3966,"children":3967},{"style":148},[3968],{"type":29,"value":151},{"type":24,"tag":117,"props":3970,"children":3971},{"style":154},[3972],{"type":29,"value":3973},"ToSingleFile",{"type":24,"tag":117,"props":3975,"children":3976},{"style":148},[3977],{"type":29,"value":162},{"type":24,"tag":117,"props":3979,"children":3980},{"style":165},[3981],{"type":29,"value":3489},{"type":24,"tag":117,"props":3983,"children":3984},{"style":148},[3985],{"type":29,"value":221},{"type":24,"tag":117,"props":3987,"children":3988},{"style":165},[3989],{"type":29,"value":3990},"serverConfig",{"type":24,"tag":117,"props":3992,"children":3993},{"style":148},[3994],{"type":29,"value":221},{"type":24,"tag":117,"props":3996,"children":3997},{"style":165},[3998],{"type":29,"value":3489},{"type":24,"tag":117,"props":4000,"children":4001},{"style":148},[4002],{"type":29,"value":173},{"type":24,"tag":25,"props":4004,"children":4005},{},[4006],{"type":29,"value":4007},"La migrazione:",{"type":24,"tag":4009,"props":4010,"children":4011},"ol",{},[4012,4017,4022,4027,4032],{"type":24,"tag":3372,"props":4013,"children":4014},{},[4015],{"type":29,"value":4016},"Apre il database sorgente con configurazione single-file.",{"type":24,"tag":3372,"props":4018,"children":4019},{},[4020],{"type":29,"value":4021},"Apre un target temporaneo con configurazione multi-file.",{"type":24,"tag":3372,"props":4023,"children":4024},{},[4025],{"type":29,"value":4026},"Copia tutte le collection (documenti + indici), le entry del KV store e il dizionario C-BSON.",{"type":24,"tag":3372,"props":4028,"children":4029},{},[4030],{"type":29,"value":4031},"Fa checkpoint del target per scaricare tutto sui page file.",{"type":24,"tag":3372,"props":4033,"children":4034},{},[4035,4037,4043,4045,4051],{"type":29,"value":4036},"Sostituisce atomicamente il sorgente: ",{"type":24,"tag":53,"props":4038,"children":4040},{"className":4039},[],[4041],{"type":29,"value":4042},"File.Delete(source)",{"type":29,"value":4044}," → ",{"type":24,"tag":53,"props":4046,"children":4048},{"className":4047},[],[4049],{"type":29,"value":4050},"File.Move(temp, source)",{"type":29,"value":151},{"type":24,"tag":25,"props":4053,"children":4054},{},[4055],{"type":29,"value":4056},"Se qualcosa fallisce durante la migrazione, il blocco catch cancella il file temporaneo e rilancia l'eccezione. Il database originale resta intatto fino allo swap atomico finale.",{"type":24,"tag":25,"props":4058,"children":4059},{},[4060,4062,4067,4069,4075],{"type":29,"value":4061},"La migrazione inversa (",{"type":24,"tag":53,"props":4063,"children":4065},{"className":4064},[],[4066],{"type":29,"value":3973},{"type":29,"value":4068},") è simmetrica: consolida tutti i file per-collection e l'indice separato in un singolo file ",{"type":24,"tag":53,"props":4070,"children":4072},{"className":4071},[],[4073],{"type":29,"value":4074},".db",{"type":29,"value":4076},", poi pulisce i componenti multi-file.",{"type":24,"tag":80,"props":4078,"children":4080},{"code":4079,"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",[4081],{"type":24,"tag":53,"props":4082,"children":4083},{"__ignoreMap":7},[4084,4118,4126,4133,4188,4242,4249,4278,4285,4314,4350,4357,4365,4372,4392,4404],{"type":24,"tag":117,"props":4085,"children":4086},{"class":119,"line":120},[4087,4091,4096,4100,4105,4109,4114],{"type":24,"tag":117,"props":4088,"children":4089},{"style":124},[4090],{"type":29,"value":127},{"type":24,"tag":117,"props":4092,"children":4093},{"style":130},[4094],{"type":29,"value":4095}," tempDbPath",{"type":24,"tag":117,"props":4097,"children":4098},{"style":136},[4099],{"type":29,"value":139},{"type":24,"tag":117,"props":4101,"children":4102},{"style":165},[4103],{"type":29,"value":4104}," sourcePath",{"type":24,"tag":117,"props":4106,"children":4107},{"style":136},[4108],{"type":29,"value":997},{"type":24,"tag":117,"props":4110,"children":4111},{"style":462},[4112],{"type":29,"value":4113}," \".migrating\"",{"type":24,"tag":117,"props":4115,"children":4116},{"style":148},[4117],{"type":29,"value":364},{"type":24,"tag":117,"props":4119,"children":4120},{"class":119,"line":176},[4121],{"type":24,"tag":117,"props":4122,"children":4123},{"style":124},[4124],{"type":29,"value":4125},"try\n",{"type":24,"tag":117,"props":4127,"children":4128},{"class":119,"line":329},[4129],{"type":24,"tag":117,"props":4130,"children":4131},{"style":148},[4132],{"type":29,"value":326},{"type":24,"tag":117,"props":4134,"children":4135},{"class":119,"line":367},[4136,4141,4145,4149,4154,4158,4162,4166,4170,4175,4179,4184],{"type":24,"tag":117,"props":4137,"children":4138},{"style":124},[4139],{"type":29,"value":4140},"    using",{"type":24,"tag":117,"props":4142,"children":4143},{"style":148},[4144],{"type":29,"value":987},{"type":24,"tag":117,"props":4146,"children":4147},{"style":124},[4148],{"type":29,"value":127},{"type":24,"tag":117,"props":4150,"children":4151},{"style":130},[4152],{"type":29,"value":4153}," source",{"type":24,"tag":117,"props":4155,"children":4156},{"style":136},[4157],{"type":29,"value":139},{"type":24,"tag":117,"props":4159,"children":4160},{"style":199},[4161],{"type":29,"value":202},{"type":24,"tag":117,"props":4163,"children":4164},{"style":205},[4165],{"type":29,"value":208},{"type":24,"tag":117,"props":4167,"children":4168},{"style":148},[4169],{"type":29,"value":162},{"type":24,"tag":117,"props":4171,"children":4172},{"style":165},[4173],{"type":29,"value":4174},"sourcePath",{"type":24,"tag":117,"props":4176,"children":4177},{"style":148},[4178],{"type":29,"value":221},{"type":24,"tag":117,"props":4180,"children":4181},{"style":165},[4182],{"type":29,"value":4183},"sourceConfig",{"type":24,"tag":117,"props":4185,"children":4186},{"style":148},[4187],{"type":29,"value":703},{"type":24,"tag":117,"props":4189,"children":4190},{"class":119,"line":385},[4191,4195,4199,4203,4208,4212,4216,4220,4224,4229,4233,4238],{"type":24,"tag":117,"props":4192,"children":4193},{"style":124},[4194],{"type":29,"value":4140},{"type":24,"tag":117,"props":4196,"children":4197},{"style":148},[4198],{"type":29,"value":987},{"type":24,"tag":117,"props":4200,"children":4201},{"style":124},[4202],{"type":29,"value":127},{"type":24,"tag":117,"props":4204,"children":4205},{"style":130},[4206],{"type":29,"value":4207}," target",{"type":24,"tag":117,"props":4209,"children":4210},{"style":136},[4211],{"type":29,"value":139},{"type":24,"tag":117,"props":4213,"children":4214},{"style":199},[4215],{"type":29,"value":202},{"type":24,"tag":117,"props":4217,"children":4218},{"style":205},[4219],{"type":29,"value":208},{"type":24,"tag":117,"props":4221,"children":4222},{"style":148},[4223],{"type":29,"value":162},{"type":24,"tag":117,"props":4225,"children":4226},{"style":165},[4227],{"type":29,"value":4228},"tempDbPath",{"type":24,"tag":117,"props":4230,"children":4231},{"style":148},[4232],{"type":29,"value":221},{"type":24,"tag":117,"props":4234,"children":4235},{"style":165},[4236],{"type":29,"value":4237},"targetConfig",{"type":24,"tag":117,"props":4239,"children":4240},{"style":148},[4241],{"type":29,"value":703},{"type":24,"tag":117,"props":4243,"children":4244},{"class":119,"line":394},[4245],{"type":24,"tag":117,"props":4246,"children":4247},{"style":148},[4248],{"type":29,"value":391},{"type":24,"tag":117,"props":4250,"children":4251},{"class":119,"line":426},[4252,4257,4261,4265,4269,4274],{"type":24,"tag":117,"props":4253,"children":4254},{"style":154},[4255],{"type":29,"value":4256},"        CopyAll",{"type":24,"tag":117,"props":4258,"children":4259},{"style":148},[4260],{"type":29,"value":162},{"type":24,"tag":117,"props":4262,"children":4263},{"style":165},[4264],{"type":29,"value":954},{"type":24,"tag":117,"props":4266,"children":4267},{"style":148},[4268],{"type":29,"value":221},{"type":24,"tag":117,"props":4270,"children":4271},{"style":165},[4272],{"type":29,"value":4273},"target",{"type":24,"tag":117,"props":4275,"children":4276},{"style":148},[4277],{"type":29,"value":173},{"type":24,"tag":117,"props":4279,"children":4280},{"class":119,"line":473},[4281],{"type":24,"tag":117,"props":4282,"children":4283},{"style":148},[4284],{"type":29,"value":1150},{"type":24,"tag":117,"props":4286,"children":4287},{"class":119,"line":486},[4288,4293,4297,4302,4306,4310],{"type":24,"tag":117,"props":4289,"children":4290},{"style":142},[4291],{"type":29,"value":4292},"    File",{"type":24,"tag":117,"props":4294,"children":4295},{"style":148},[4296],{"type":29,"value":151},{"type":24,"tag":117,"props":4298,"children":4299},{"style":154},[4300],{"type":29,"value":4301},"Delete",{"type":24,"tag":117,"props":4303,"children":4304},{"style":148},[4305],{"type":29,"value":162},{"type":24,"tag":117,"props":4307,"children":4308},{"style":165},[4309],{"type":29,"value":4174},{"type":24,"tag":117,"props":4311,"children":4312},{"style":148},[4313],{"type":29,"value":173},{"type":24,"tag":117,"props":4315,"children":4316},{"class":119,"line":530},[4317,4321,4325,4330,4334,4338,4342,4346],{"type":24,"tag":117,"props":4318,"children":4319},{"style":142},[4320],{"type":29,"value":4292},{"type":24,"tag":117,"props":4322,"children":4323},{"style":148},[4324],{"type":29,"value":151},{"type":24,"tag":117,"props":4326,"children":4327},{"style":154},[4328],{"type":29,"value":4329},"Move",{"type":24,"tag":117,"props":4331,"children":4332},{"style":148},[4333],{"type":29,"value":162},{"type":24,"tag":117,"props":4335,"children":4336},{"style":165},[4337],{"type":29,"value":4228},{"type":24,"tag":117,"props":4339,"children":4340},{"style":148},[4341],{"type":29,"value":221},{"type":24,"tag":117,"props":4343,"children":4344},{"style":165},[4345],{"type":29,"value":4174},{"type":24,"tag":117,"props":4347,"children":4348},{"style":148},[4349],{"type":29,"value":173},{"type":24,"tag":117,"props":4351,"children":4352},{"class":119,"line":540},[4353],{"type":24,"tag":117,"props":4354,"children":4355},{"style":148},[4356],{"type":29,"value":721},{"type":24,"tag":117,"props":4358,"children":4359},{"class":119,"line":587},[4360],{"type":24,"tag":117,"props":4361,"children":4362},{"style":124},[4363],{"type":29,"value":4364},"catch\n",{"type":24,"tag":117,"props":4366,"children":4367},{"class":119,"line":595},[4368],{"type":24,"tag":117,"props":4369,"children":4370},{"style":148},[4371],{"type":29,"value":326},{"type":24,"tag":117,"props":4373,"children":4374},{"class":119,"line":624},[4375,4380,4384,4388],{"type":24,"tag":117,"props":4376,"children":4377},{"style":154},[4378],{"type":29,"value":4379},"    SafeDelete",{"type":24,"tag":117,"props":4381,"children":4382},{"style":148},[4383],{"type":29,"value":162},{"type":24,"tag":117,"props":4385,"children":4386},{"style":165},[4387],{"type":29,"value":4228},{"type":24,"tag":117,"props":4389,"children":4390},{"style":148},[4391],{"type":29,"value":173},{"type":24,"tag":117,"props":4393,"children":4394},{"class":119,"line":664},[4395,4400],{"type":24,"tag":117,"props":4396,"children":4397},{"style":124},[4398],{"type":29,"value":4399},"    throw",{"type":24,"tag":117,"props":4401,"children":4402},{"style":148},[4403],{"type":29,"value":364},{"type":24,"tag":117,"props":4405,"children":4406},{"class":119,"line":677},[4407],{"type":24,"tag":117,"props":4408,"children":4409},{"style":148},[4410],{"type":29,"value":721},{"type":24,"tag":25,"props":4412,"children":4413},{},[4414,4416,4422,4424,4430],{"type":29,"value":4415},"Un dettaglio sottile: ",{"type":24,"tag":53,"props":4417,"children":4419},{"className":4418},[],[4420],{"type":29,"value":4421},"CopyAll",{"type":29,"value":4423}," chiama ",{"type":24,"tag":53,"props":4425,"children":4427},{"className":4426},[],[4428],{"type":29,"value":4429},"target.ImportDictionary(source.GetKeyReverseMap())",{"type":29,"value":4431}," prima di copiare i documenti. Il formato C-BSON di BLite comprime i nomi dei campi tramite un dizionario condiviso. Senza sincronizzare il dizionario prima, i byte BSON grezzi nel nuovo file farebbero riferimento a entry del dizionario inesistenti.",{"type":24,"tag":37,"props":4433,"children":4434},{},[],{"type":24,"tag":41,"props":4436,"children":4438},{"id":4437},"checkpoint-e-recovery-attraverso-i-file",[4439],{"type":29,"value":4440},"Checkpoint e Recovery Attraverso i File",{"type":24,"tag":25,"props":4442,"children":4443},{},[4444,4446,4452,4454,4460,4462,4468],{"type":29,"value":4445},"Il WAL è ancora un singolo file, anche in modalità multi-file. Ma le pagine che registra portano page ID codificati — una pagina indice ha il suo marker ",{"type":24,"tag":53,"props":4447,"children":4449},{"className":4448},[],[4450],{"type":29,"value":4451},"0x80000000",{"type":29,"value":4453},", una pagina collection ha ",{"type":24,"tag":53,"props":4455,"children":4457},{"className":4456},[],[4458],{"type":29,"value":4459},"0xC0000000 | slot | localId",{"type":29,"value":4461},". Durante il checkpoint, ",{"type":24,"tag":53,"props":4463,"children":4465},{"className":4464},[],[4466],{"type":29,"value":4467},"GetPageFile()",{"type":29,"value":4469}," decodifica ogni page ID e instrada la scrittura al file corretto:",{"type":24,"tag":80,"props":4471,"children":4473},{"code":4472,"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",[4474],{"type":24,"tag":53,"props":4475,"children":4476},{"__ignoreMap":7},[4477,4497,4504,4541,4548,4582,4589,4670,4677,4684,4704,4729,4757,4764,4805,4825,4832,4839,4860,4881],{"type":24,"tag":117,"props":4478,"children":4479},{"class":119,"line":120},[4480,4484,4488,4493],{"type":24,"tag":117,"props":4481,"children":4482},{"style":124},[4483],{"type":29,"value":822},{"type":24,"tag":117,"props":4485,"children":4486},{"style":124},[4487],{"type":29,"value":906},{"type":24,"tag":117,"props":4489,"children":4490},{"style":154},[4491],{"type":29,"value":4492}," CheckpointInternal",{"type":24,"tag":117,"props":4494,"children":4495},{"style":148},[4496],{"type":29,"value":2006},{"type":24,"tag":117,"props":4498,"children":4499},{"class":119,"line":176},[4500],{"type":24,"tag":117,"props":4501,"children":4502},{"style":148},[4503],{"type":29,"value":326},{"type":24,"tag":117,"props":4505,"children":4506},{"class":119,"line":329},[4507,4511,4515,4520,4524,4529,4533,4537],{"type":24,"tag":117,"props":4508,"children":4509},{"style":124},[4510],{"type":29,"value":982},{"type":24,"tag":117,"props":4512,"children":4513},{"style":148},[4514],{"type":29,"value":987},{"type":24,"tag":117,"props":4516,"children":4517},{"style":142},[4518],{"type":29,"value":4519},"_walIndex",{"type":24,"tag":117,"props":4521,"children":4522},{"style":148},[4523],{"type":29,"value":151},{"type":24,"tag":117,"props":4525,"children":4526},{"style":142},[4527],{"type":29,"value":4528},"IsEmpty",{"type":24,"tag":117,"props":4530,"children":4531},{"style":148},[4532],{"type":29,"value":454},{"type":24,"tag":117,"props":4534,"children":4535},{"style":124},[4536],{"type":29,"value":2921},{"type":24,"tag":117,"props":4538,"children":4539},{"style":148},[4540],{"type":29,"value":364},{"type":24,"tag":117,"props":4542,"children":4543},{"class":119,"line":367},[4544],{"type":24,"tag":117,"props":4545,"children":4546},{"emptyLinePlaceholder":534},[4547],{"type":29,"value":537},{"type":24,"tag":117,"props":4549,"children":4550},{"class":119,"line":385},[4551,4556,4560,4564,4569,4573,4578],{"type":24,"tag":117,"props":4552,"children":4553},{"style":124},[4554],{"type":29,"value":4555},"    foreach",{"type":24,"tag":117,"props":4557,"children":4558},{"style":148},[4559],{"type":29,"value":987},{"type":24,"tag":117,"props":4561,"children":4562},{"style":124},[4563],{"type":29,"value":127},{"type":24,"tag":117,"props":4565,"children":4566},{"style":130},[4567],{"type":29,"value":4568}," kvp",{"type":24,"tag":117,"props":4570,"children":4571},{"style":124},[4572],{"type":29,"value":3046},{"type":24,"tag":117,"props":4574,"children":4575},{"style":165},[4576],{"type":29,"value":4577}," _walIndex",{"type":24,"tag":117,"props":4579,"children":4580},{"style":148},[4581],{"type":29,"value":318},{"type":24,"tag":117,"props":4583,"children":4584},{"class":119,"line":394},[4585],{"type":24,"tag":117,"props":4586,"children":4587},{"style":148},[4588],{"type":29,"value":391},{"type":24,"tag":117,"props":4590,"children":4591},{"class":119,"line":426},[4592,4597,4601,4606,4610,4615,4619,4624,4628,4633,4637,4641,4645,4650,4654,4658,4662,4666],{"type":24,"tag":117,"props":4593,"children":4594},{"style":154},[4595],{"type":29,"value":4596},"        GetPageFile",{"type":24,"tag":117,"props":4598,"children":4599},{"style":148},[4600],{"type":29,"value":162},{"type":24,"tag":117,"props":4602,"children":4603},{"style":142},[4604],{"type":29,"value":4605},"kvp",{"type":24,"tag":117,"props":4607,"children":4608},{"style":148},[4609],{"type":29,"value":151},{"type":24,"tag":117,"props":4611,"children":4612},{"style":142},[4613],{"type":29,"value":4614},"Key",{"type":24,"tag":117,"props":4616,"children":4617},{"style":148},[4618],{"type":29,"value":221},{"type":24,"tag":117,"props":4620,"children":4621},{"style":124},[4622],{"type":29,"value":4623},"out",{"type":24,"tag":117,"props":4625,"children":4626},{"style":124},[4627],{"type":29,"value":187},{"type":24,"tag":117,"props":4629,"children":4630},{"style":130},[4631],{"type":29,"value":4632}," physId",{"type":24,"tag":117,"props":4634,"children":4635},{"style":148},[4636],{"type":29,"value":3658},{"type":24,"tag":117,"props":4638,"children":4639},{"style":154},[4640],{"type":29,"value":2433},{"type":24,"tag":117,"props":4642,"children":4643},{"style":148},[4644],{"type":29,"value":162},{"type":24,"tag":117,"props":4646,"children":4647},{"style":165},[4648],{"type":29,"value":4649},"physId",{"type":24,"tag":117,"props":4651,"children":4652},{"style":148},[4653],{"type":29,"value":221},{"type":24,"tag":117,"props":4655,"children":4656},{"style":142},[4657],{"type":29,"value":4605},{"type":24,"tag":117,"props":4659,"children":4660},{"style":148},[4661],{"type":29,"value":151},{"type":24,"tag":117,"props":4663,"children":4664},{"style":142},[4665],{"type":29,"value":3082},{"type":24,"tag":117,"props":4667,"children":4668},{"style":148},[4669],{"type":29,"value":173},{"type":24,"tag":117,"props":4671,"children":4672},{"class":119,"line":473},[4673],{"type":24,"tag":117,"props":4674,"children":4675},{"style":148},[4676],{"type":29,"value":1150},{"type":24,"tag":117,"props":4678,"children":4679},{"class":119,"line":486},[4680],{"type":24,"tag":117,"props":4681,"children":4682},{"emptyLinePlaceholder":534},[4683],{"type":29,"value":537},{"type":24,"tag":117,"props":4685,"children":4686},{"class":119,"line":530},[4687,4692,4696,4700],{"type":24,"tag":117,"props":4688,"children":4689},{"style":142},[4690],{"type":29,"value":4691},"    _pageFile",{"type":24,"tag":117,"props":4693,"children":4694},{"style":148},[4695],{"type":29,"value":151},{"type":24,"tag":117,"props":4697,"children":4698},{"style":154},[4699],{"type":29,"value":1806},{"type":24,"tag":117,"props":4701,"children":4702},{"style":148},[4703],{"type":29,"value":1059},{"type":24,"tag":117,"props":4705,"children":4706},{"class":119,"line":540},[4707,4712,4717,4721,4725],{"type":24,"tag":117,"props":4708,"children":4709},{"style":142},[4710],{"type":29,"value":4711},"    _indexFile",{"type":24,"tag":117,"props":4713,"children":4714},{"style":199},[4715],{"type":29,"value":4716},"?",{"type":24,"tag":117,"props":4718,"children":4719},{"style":148},[4720],{"type":29,"value":151},{"type":24,"tag":117,"props":4722,"children":4723},{"style":154},[4724],{"type":29,"value":1806},{"type":24,"tag":117,"props":4726,"children":4727},{"style":148},[4728],{"type":29,"value":1059},{"type":24,"tag":117,"props":4730,"children":4731},{"class":119,"line":587},[4732,4736,4740,4745,4749,4753],{"type":24,"tag":117,"props":4733,"children":4734},{"style":124},[4735],{"type":29,"value":982},{"type":24,"tag":117,"props":4737,"children":4738},{"style":148},[4739],{"type":29,"value":987},{"type":24,"tag":117,"props":4741,"children":4742},{"style":165},[4743],{"type":29,"value":4744},"_collectionFiles",{"type":24,"tag":117,"props":4746,"children":4747},{"style":136},[4748],{"type":29,"value":2067},{"type":24,"tag":117,"props":4750,"children":4751},{"style":310},[4752],{"type":29,"value":313},{"type":24,"tag":117,"props":4754,"children":4755},{"style":148},[4756],{"type":29,"value":318},{"type":24,"tag":117,"props":4758,"children":4759},{"class":119,"line":595},[4760],{"type":24,"tag":117,"props":4761,"children":4762},{"style":148},[4763],{"type":29,"value":391},{"type":24,"tag":117,"props":4765,"children":4766},{"class":119,"line":624},[4767,4771,4775,4779,4784,4788,4793,4797,4801],{"type":24,"tag":117,"props":4768,"children":4769},{"style":124},[4770],{"type":29,"value":3028},{"type":24,"tag":117,"props":4772,"children":4773},{"style":148},[4774],{"type":29,"value":987},{"type":24,"tag":117,"props":4776,"children":4777},{"style":124},[4778],{"type":29,"value":127},{"type":24,"tag":117,"props":4780,"children":4781},{"style":130},[4782],{"type":29,"value":4783}," pf",{"type":24,"tag":117,"props":4785,"children":4786},{"style":124},[4787],{"type":29,"value":3046},{"type":24,"tag":117,"props":4789,"children":4790},{"style":142},[4791],{"type":29,"value":4792}," _collectionFiles",{"type":24,"tag":117,"props":4794,"children":4795},{"style":148},[4796],{"type":29,"value":151},{"type":24,"tag":117,"props":4798,"children":4799},{"style":142},[4800],{"type":29,"value":3060},{"type":24,"tag":117,"props":4802,"children":4803},{"style":148},[4804],{"type":29,"value":318},{"type":24,"tag":117,"props":4806,"children":4807},{"class":119,"line":664},[4808,4813,4817,4821],{"type":24,"tag":117,"props":4809,"children":4810},{"style":142},[4811],{"type":29,"value":4812},"            pf",{"type":24,"tag":117,"props":4814,"children":4815},{"style":148},[4816],{"type":29,"value":151},{"type":24,"tag":117,"props":4818,"children":4819},{"style":154},[4820],{"type":29,"value":1806},{"type":24,"tag":117,"props":4822,"children":4823},{"style":148},[4824],{"type":29,"value":1059},{"type":24,"tag":117,"props":4826,"children":4827},{"class":119,"line":677},[4828],{"type":24,"tag":117,"props":4829,"children":4830},{"style":148},[4831],{"type":29,"value":1150},{"type":24,"tag":117,"props":4833,"children":4834},{"class":119,"line":706},[4835],{"type":24,"tag":117,"props":4836,"children":4837},{"emptyLinePlaceholder":534},[4838],{"type":29,"value":537},{"type":24,"tag":117,"props":4840,"children":4841},{"class":119,"line":715},[4842,4847,4851,4856],{"type":24,"tag":117,"props":4843,"children":4844},{"style":142},[4845],{"type":29,"value":4846},"    _walIndex",{"type":24,"tag":117,"props":4848,"children":4849},{"style":148},[4850],{"type":29,"value":151},{"type":24,"tag":117,"props":4852,"children":4853},{"style":154},[4854],{"type":29,"value":4855},"Clear",{"type":24,"tag":117,"props":4857,"children":4858},{"style":148},[4859],{"type":29,"value":1059},{"type":24,"tag":117,"props":4861,"children":4862},{"class":119,"line":1265},[4863,4868,4872,4877],{"type":24,"tag":117,"props":4864,"children":4865},{"style":142},[4866],{"type":29,"value":4867},"    _wal",{"type":24,"tag":117,"props":4869,"children":4870},{"style":148},[4871],{"type":29,"value":151},{"type":24,"tag":117,"props":4873,"children":4874},{"style":154},[4875],{"type":29,"value":4876},"Truncate",{"type":24,"tag":117,"props":4878,"children":4879},{"style":148},[4880],{"type":29,"value":1059},{"type":24,"tag":117,"props":4882,"children":4883},{"class":119,"line":1295},[4884],{"type":24,"tag":117,"props":4885,"children":4886},{"style":148},[4887],{"type":29,"value":721},{"type":24,"tag":25,"props":4889,"children":4890},{},[4891,4893,4900],{"type":29,"value":4892},"Il crash recovery funziona allo stesso modo: all'avvio, l'engine legge il WAL, identifica le transazioni committate e riproduce le loro scritture attraverso la stessa funzione di routing. Poiché i page ID sono auto-descrittivi, il codice di recovery non ha bisogno di un mapping separato di \"quali pagine appartengono a quale file\" — è codificato nell'ID stesso. (Ho coperto la codifica bit in dettaglio nel ",{"type":24,"tag":4894,"props":4895,"children":4897},"a",{"href":4896},"\u002Fblog\u002Fbitwise-page-routing-blite-storage-engine",[4898],{"type":29,"value":4899},"post sul bitwise page routing",{"type":29,"value":4901},".)",{"type":24,"tag":37,"props":4903,"children":4904},{},[],{"type":24,"tag":41,"props":4906,"children":4908},{"id":4907},"cosa-potrebbe-andare-storto",[4909],{"type":29,"value":4910},"Cosa Potrebbe Andare Storto",{"type":24,"tag":25,"props":4912,"children":4913},{},[4914],{"type":29,"value":4915},"Le decisioni di design hanno conseguenze. Ecco quelle a cui penso di più:",{"type":24,"tag":869,"props":4917,"children":4919},{"id":4918},"_1-readerwriterlockslim-ha-un-problema-di-thundering-herd",[4920],{"type":29,"value":4921},"1. ReaderWriterLockSlim Ha un Problema di Thundering Herd",{"type":24,"tag":25,"props":4923,"children":4924},{},[4925,4927,4932],{"type":29,"value":4926},"Quando una chiamata a ",{"type":24,"tag":53,"props":4928,"children":4930},{"className":4929},[],[4931],{"type":29,"value":2433},{"type":29,"value":4933}," innesca la crescita del file, ogni lettore in attesa si blocca. Quando il write lock viene rilasciato, tutti corrono a riacquisire il read lock contemporaneamente. Sotto carico pesante con crescite frequenti (ad esempio, bulk insert in un nuovo database), questo crea un effetto thundering herd. La pre-allocazione in blocchi da 1 MB mitiga questo — una volta allocato, il file non avrà bisogno di crescere di nuovo per centinaia di pagine — ma il primo evento di crescita su ogni file collection innesca comunque la valanga.",{"type":24,"tag":25,"props":4935,"children":4936},{},[4937,4939,4945],{"type":29,"value":4938},"Un'alternativa sarebbe un array di slot concorrente che i lettori controllano con ",{"type":24,"tag":53,"props":4940,"children":4942},{"className":4941},[],[4943],{"type":29,"value":4944},"Volatile.Read",{"type":29,"value":4946}," — nessun lock sull'hot path. Questo è ciò che fa LMDB con la sua tabella lettori. La complessità è maggiore, ma la coda di latenza è più corta.",{"type":24,"tag":869,"props":4948,"children":4950},{"id":4949},"_2-i-file-per-collection-moltiplicano-i-file-descriptor",[4951],{"type":29,"value":4952},"2. I File Per-Collection Moltiplicano i File Descriptor",{"type":24,"tag":25,"props":4954,"children":4955},{},[4956,4958,4963,4965,4971,4972,4977,4979,4985],{"type":29,"value":4957},"Ogni collection ottiene il proprio ",{"type":24,"tag":53,"props":4959,"children":4961},{"className":4960},[],[4962],{"type":29,"value":740},{"type":29,"value":4964},", il che significa il proprio ",{"type":24,"tag":53,"props":4966,"children":4968},{"className":4967},[],[4969],{"type":29,"value":4970},"FileStream",{"type":29,"value":1593},{"type":24,"tag":53,"props":4973,"children":4975},{"className":4974},[],[4976],{"type":29,"value":58},{"type":29,"value":4978},". Un database con 50 collection ha 50 handle di file aperti più il file principale, l'indice e il WAL — 53 in totale. Su Linux con impostazioni ",{"type":24,"tag":53,"props":4980,"children":4982},{"className":4981},[],[4983],{"type":29,"value":4984},"ulimit",{"type":29,"value":4986}," predefinite (1024 file descriptor), questo diventa una preoccupazione. Su Windows è meno problematico, ma gli handle sono comunque una risorsa finita.",{"type":24,"tag":25,"props":4988,"children":4989},{},[4990],{"type":29,"value":4991},"Il limite di 64 collection (slot a 6 bit) agisce come un tetto naturale, ma è un limite rigido, non configurabile. Se hai bisogno di 65 collection, ti serve un secondo database.",{"type":24,"tag":869,"props":4993,"children":4995},{"id":4994},"_3-il-backup-è-inconsistente-in-modalità-multi-file",[4996],{"type":29,"value":4997},"3. Il Backup È Inconsistente in Modalità Multi-File",{"type":24,"tag":25,"props":4999,"children":5000},{},[5001,5006,5008,5013,5015,5020],{"type":24,"tag":53,"props":5002,"children":5004},{"className":5003},[],[5005],{"type":29,"value":2538},{"type":29,"value":5007}," attualmente fa checkpoint e copia il file principale. ",{"type":24,"tag":1548,"props":5009,"children":5010},{},[5011],{"type":29,"value":5012},"Non",{"type":29,"value":5014}," copia il file indice né i file per-collection. Un backup preso durante un'operazione cattura lo stato del file principale ma lascia gli altri file fuori dallo snapshot. Questa è una limitazione nota: un backup completo richiede di fermare le scritture e copiare tutti i file, o implementare uno snapshot coordinato su tutte le istanze ",{"type":24,"tag":53,"props":5016,"children":5018},{"className":5017},[],[5019],{"type":29,"value":740},{"type":29,"value":151},{"type":24,"tag":869,"props":5022,"children":5024},{"id":5023},"_4-il-commit-lock-è-globale",[5025],{"type":29,"value":5026},"4. Il Commit Lock È Globale",{"type":24,"tag":25,"props":5028,"children":5029},{},[5030,5036,5038,5043,5045,5050],{"type":24,"tag":53,"props":5031,"children":5033},{"className":5032},[],[5034],{"type":29,"value":5035},"_commitLock",{"type":29,"value":5037}," serializza tutti i commit e i checkpoint attraverso tutte le sessioni. Due sessioni che committano su collection ",{"type":24,"tag":1548,"props":5039,"children":5040},{},[5041],{"type":29,"value":5042},"diverse",{"type":29,"value":5044}," contendono comunque sullo stesso ",{"type":24,"tag":53,"props":5046,"children":5048},{"className":5047},[],[5049],{"type":29,"value":1607},{"type":29,"value":5051},". Con il batcher del group commit, questo è meno doloroso — decine di commit possono essere raggruppate in un unico flush WAL — ma il punto di serializzazione resta.",{"type":24,"tag":25,"props":5053,"children":5054},{},[5055],{"type":29,"value":5056},"Un percorso di commit per-collection eliminerebbe questa contesa al costo di un formato WAL più complesso. La sequenza attuale — scrivere BEGIN, record dati, COMMIT per ogni transazione in ordine — dovrebbe supportare record interleaved da commit concorrenti. La maggior parte dei database di produzione fa questo (i record WAL portano transaction ID esattamente per questa ragione), ma complica significativamente il recovery.",{"type":24,"tag":869,"props":5058,"children":5060},{"id":5059},"_5-nessun-read-snapshot-tra-sessioni",[5061],{"type":29,"value":5062},"5. Nessun Read Snapshot Tra Sessioni",{"type":24,"tag":25,"props":5064,"children":5065},{},[5066,5068,5073,5075,5080,5082,5087],{"type":29,"value":5067},"L'isolamento transazionale di BLite è basato sulla separazione della cache WAL: una sessione vede le sue scritture non committate, più l'ultimo stato committato. Ma non c'è snapshot isolation — se la sessione A legge la pagina X, poi la sessione B committa una modifica alla pagina X, poi la sessione A legge di nuovo la pagina X, vede la nuova versione. Questo è ",{"type":24,"tag":1548,"props":5069,"children":5070},{},[5071],{"type":29,"value":5072},"Read Committed",{"type":29,"value":5074},", non ",{"type":24,"tag":1548,"props":5076,"children":5077},{},[5078],{"type":29,"value":5079},"Repeatable Read",{"type":29,"value":5081}," o ",{"type":24,"tag":1548,"props":5083,"children":5084},{},[5085],{"type":29,"value":5086},"Serializable",{"type":29,"value":151},{"type":24,"tag":25,"props":5089,"children":5090},{},[5091],{"type":29,"value":5092},"Per molti carichi di lavoro server, Read Committed è sufficiente. Per carichi che necessitano di snapshot consistenti attraverso una lettura multi-step (ad esempio, un report che scansiona migliaia di documenti), questo potrebbe produrre risultati inconsistenti se scritture concorrenti modificano i dati durante la scansione.",{"type":24,"tag":37,"props":5094,"children":5095},{},[],{"type":24,"tag":41,"props":5097,"children":5099},{"id":5098},"in-conclusione",[5100],{"type":29,"value":5101},"In Conclusione",{"type":24,"tag":25,"props":5103,"children":5104},{},[5105],{"type":29,"value":5106},"Lo storage multi-file in BLite non riguarda il rendere l'engine più complesso. Riguarda il rimuovere il collo di bottiglia condiviso — un file, un lock, una coda I\u002FO — e sostituirlo con file indipendenti che possono essere letti, scritti, fatti crescere e cancellati indipendentemente.",{"type":24,"tag":25,"props":5108,"children":5109},{},[5110,5112,5117,5119,5124,5126,5131],{"type":29,"value":5111},"La strategia fast-path di ",{"type":24,"tag":53,"props":5113,"children":5115},{"className":5114},[],[5116],{"type":29,"value":805},{"type":29,"value":5118}," rende letture e scritture concorrenti sotto carico normale. ",{"type":24,"tag":53,"props":5120,"children":5122},{"className":5121},[],[5123],{"type":29,"value":2612},{"type":29,"value":5125}," dà a ogni connessione il proprio ambito transazionale. ",{"type":24,"tag":53,"props":5127,"children":5129},{"className":5128},[],[5130],{"type":29,"value":3874},{"type":29,"value":5132}," permette di passare tra layout senza riscrivere il codice applicativo. E i page ID bit-tagged legano tutto insieme con un routing a zero allocazioni che sopravvive a restart e crash.",{"type":24,"tag":25,"props":5134,"children":5135},{},[5136],{"type":29,"value":5137},"Le limitazioni sono reali — consistenza del backup, serializzazione globale dei commit, semantica Read Committed — ma sono il tipo di trade-off che fai consciamente quando vuoi mantenere un database embedded abbastanza semplice da contenerlo nella testa.",{"type":24,"tag":25,"props":5139,"children":5140},{},[5141,5143,5151],{"type":29,"value":5142},"Il codice sorgente completo è su ",{"type":24,"tag":4894,"props":5144,"children":5148},{"href":5145,"rel":5146},"https:\u002F\u002Fgithub.com\u002Fnicholasosaka\u002FBLite",[5147],"nofollow",[5149],{"type":29,"value":5150},"GitHub",{"type":29,"value":151},{"type":24,"tag":5153,"props":5154,"children":5155},"style",{},[5156],{"type":29,"value":5157},"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":5159},[5160,5161,5162,5169,5170,5171,5172,5173,5180],{"id":43,"depth":176,"text":46},{"id":98,"depth":176,"text":101},{"id":756,"depth":176,"text":759,"children":5163},[5164,5165,5166,5167,5168],{"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":1954,"depth":329,"text":1957},{"id":2350,"depth":176,"text":2353},{"id":2593,"depth":176,"text":2596},{"id":3860,"depth":176,"text":3863},{"id":4437,"depth":176,"text":4440},{"id":4907,"depth":176,"text":4910,"children":5174},[5175,5176,5177,5178,5179],{"id":4918,"depth":329,"text":4921},{"id":4949,"depth":329,"text":4952},{"id":4994,"depth":329,"text":4997},{"id":5023,"depth":329,"text":5026},{"id":5059,"depth":329,"text":5062},{"id":5098,"depth":176,"text":5101},"markdown","content:it:blog:multi-file-concurrency-server-mode-in-blite.md","content","it\u002Fblog\u002Fmulti-file-concurrency-server-mode-in-blite.md","it\u002Fblog\u002Fmulti-file-concurrency-server-mode-in-blite","md",{"loc":4},1793182386256]