@delali/narsil 0.3.1-next.157 → 0.3.1-next.161
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/filesystem.mjs +3 -3
- package/dist/adapters/gcs.mjs +3 -3
- package/dist/adapters/indexeddb.mjs +1 -1
- package/dist/adapters/s3.mjs +3 -3
- package/dist/browser/{chunk-N23GL72Q.mjs → chunk-4RNSFVWI.mjs} +20777 -19056
- package/dist/browser/chunk-MMHIIL5B.mjs +564 -0
- package/dist/browser/chunk-MZHQ65VI.mjs +1228 -0
- package/dist/browser/chunk-WC2DEXWU.mjs +29 -0
- package/dist/browser/{chunk-VLJQW4J6.mjs → core-leaf-TJAGWPZZ.mjs} +4674 -3102
- package/dist/{react-native/chunks/durability-config-QXVZEO7T.mjs → browser/durability-config-SGB5ZP5K.mjs} +8 -3
- package/dist/browser/embed-RF2MPGAO.mjs +222 -0
- package/dist/{react-native/chunks/geo-index-PX3BIHAH.mjs → browser/geo-index-GNHY4PUB.mjs} +190 -93
- package/dist/{react-native/chunks/module-TTEVPRCW.mjs → browser/module-362VSIGR.mjs} +1570 -275
- package/dist/browser/msgpack-leaf-44XNWSSY.mjs +302 -0
- package/dist/browser/optional-reads-XMVPG6HG.mjs +3230 -0
- package/dist/browser/optional-writes-WMZX4OEC.mjs +3196 -0
- package/dist/browser/phrase-module-22TKMXWI.mjs +616 -0
- package/dist/browser/resolve-vector-text-KI65IHMD.mjs +60 -0
- package/dist/browser/{restore-hooks-IE3GGYHG.mjs → restore-queue-S4BWOGMU.mjs} +98 -24
- package/dist/{react-native/chunks/runtime-R5E3TB3J.mjs → browser/runtime-NU6VOVH2.mjs} +61 -25
- package/dist/browser/segment-codec-leaf-A427QJUX.mjs +554 -0
- package/dist/browser/segment-merge-leaf-7BZ54JPI.mjs +1636 -0
- package/dist/browser/storage-leaf-X6CNRHJS.mjs +18221 -0
- package/dist/browser/store-leaf-AEMTAVHX.mjs +2069 -0
- package/dist/browser/{chunk-GFAZPSWK.mjs → suggestions-leaf-3Y6MR6OF.mjs} +441 -119
- package/dist/browser/worker-copies-WQCPP3TS.mjs +2750 -0
- package/dist/{capabilities-D3AoBJoF.d.ts → capabilities-BKDrry0z.d.ts} +2 -2
- package/dist/chunk-2JRERUNZ.mjs +217 -0
- package/dist/chunk-2RIS76RJ.mjs +212 -0
- package/dist/chunk-3B775F3C.mjs +252 -0
- package/dist/{chunk-24FNVRKB.mjs → chunk-3D6RZGJH.mjs} +3 -3
- package/dist/{chunk-INJYO3BU.mjs → chunk-4CAMH7FO.mjs} +1 -1
- package/dist/{chunk-U476IXKQ.mjs → chunk-4PY4JYMY.mjs} +2 -1
- package/dist/chunk-6EZW2GQL.mjs +978 -0
- package/dist/chunk-75UNINFA.mjs +271 -0
- package/dist/chunk-77AUVDQ5.mjs +7 -0
- package/dist/{chunk-JTYPJF3T.mjs → chunk-7MWYORQC.mjs} +2 -2
- package/dist/{chunk-TGP5M5R7.mjs → chunk-7T4LAYT4.mjs} +1 -1
- package/dist/{chunk-XIHUI4KB.mjs → chunk-AB27FWZM.mjs} +8 -3
- package/dist/{chunk-FUD5XSZ5.mjs → chunk-BXM7XM4G.mjs} +7 -3
- package/dist/{chunk-HJJI72X7.mjs → chunk-C7YQHCSO.mjs} +1 -1
- package/dist/{chunk-RVGRFOGN.mjs → chunk-D456ZFPQ.mjs} +2 -1
- package/dist/{chunk-KKQC526K.mjs → chunk-E2F6LZR3.mjs} +19 -21
- package/dist/{chunk-SMOOSIAW.mjs → chunk-FE3MRIBN.mjs} +104 -13
- package/dist/{chunk-KYYABCSW.mjs → chunk-FETZYCH7.mjs} +15 -1
- package/dist/{chunk-XXJZMTZT.mjs → chunk-FVZ5DB6Y.mjs} +3 -2
- package/dist/{chunk-EYD7K3H6.mjs → chunk-GF4K7IUK.mjs} +317 -120
- package/dist/chunk-GXCDWLQI.mjs +193 -0
- package/dist/{chunk-IIRIG7H5.mjs → chunk-H64YDF5M.mjs} +3 -3
- package/dist/{browser/chunk-VY5KW3HN.mjs → chunk-HOOR4CP5.mjs} +63 -7
- package/dist/chunk-IB4BYLE3.mjs +127 -0
- package/dist/{chunk-3C7MTCCI.mjs → chunk-IE3Q62QD.mjs} +2 -2
- package/dist/chunk-IH3G6SJO.mjs +40 -0
- package/dist/chunk-JV74RKCY.mjs +3041 -0
- package/dist/{chunk-ZPZ3YGXV.mjs → chunk-K67I3RF4.mjs} +261 -101
- package/dist/chunk-KLVMK3R5.mjs +47 -0
- package/dist/{chunk-5VV4R6P7.mjs → chunk-LAWIJRMJ.mjs} +4154 -2577
- package/dist/chunk-LF4GB4PO.mjs +281 -0
- package/dist/chunk-NC4QLCZC.mjs +59 -0
- package/dist/chunk-OOO54OVC.mjs +627 -0
- package/dist/chunk-OUWZKNO3.mjs +207 -0
- package/dist/{chunk-FJKKCV4D.mjs → chunk-P5YLI5ED.mjs} +343 -182
- package/dist/{chunk-4ZTHGTVX.mjs → chunk-PTTMGRG5.mjs} +9 -10
- package/dist/{react-native/chunks/chunk-DZ7H7D2C.mjs → chunk-Q3ZZH5Z7.mjs} +6 -0
- package/dist/{browser/chunk-EKMGCRSR.mjs → chunk-QBVTYY4J.mjs} +2 -9
- package/dist/{chunk-W5EB5XKI.mjs → chunk-R4CE4IVU.mjs} +341 -183
- package/dist/chunk-S2POFTLN.mjs +10 -0
- package/dist/{chunk-KJ3RTZDJ.mjs → chunk-S3BSDBF7.mjs} +10 -3
- package/dist/{chunk-4LMSZAK6.mjs → chunk-SHGN3QIF.mjs} +69 -13
- package/dist/chunk-SXIRM4MX.mjs +3549 -0
- package/dist/{chunk-TBC3XUL2.mjs → chunk-TGPKS2UM.mjs} +47 -1
- package/dist/chunk-TINW4BSH.mjs +31301 -0
- package/dist/{cold-module-VOJXMNZB.mjs → chunk-TSLV5P2J.mjs} +397 -80
- package/dist/{chunk-HHBUCIUY.mjs → chunk-TW543F33.mjs} +3 -3
- package/dist/chunk-U6B7DUQW.mjs +788 -0
- package/dist/{chunk-OQLD2BSW.mjs → chunk-V3SGPXWQ.mjs} +8 -9
- package/dist/chunk-W34VJXY7.mjs +4723 -0
- package/dist/chunk-YETKPX5M.mjs +5 -0
- package/dist/chunk-ZQ6QY42L.mjs +59 -0
- package/dist/{client-kqSMevVi.d.ts → client-CTp8RRiK.d.ts} +4 -4
- package/dist/client.d.ts +8 -8
- package/dist/client.mjs +66 -18
- package/dist/{config-B4v_Htpu.d.ts → config-PCNzWjHL.d.ts} +6 -3
- package/dist/{config-CTP01fns.d.ts → config-_WT5grSL.d.ts} +3 -3
- package/dist/core-leaf-KXFGP74A.mjs +7 -0
- package/dist/digest-leaf-KXBGKYHZ.mjs +1 -0
- package/dist/direct-executor-MKTZBR26.mjs +16 -0
- package/dist/distribution/coordinator/etcd.d.ts +2 -2
- package/dist/distribution/coordinator/etcd.mjs +7 -4
- package/dist/distribution/coordinator/in-memory.d.ts +2 -2
- package/dist/distribution/coordinator/in-memory.mjs +1 -2
- package/dist/distribution/transport/grpc.mjs +7 -2
- package/dist/distribution/transport/tcp.mjs +7 -1
- package/dist/distribution.d.ts +7 -7
- package/dist/distribution.mjs +1199 -1092
- package/dist/{browser/durability-config-TIYKW6XX.mjs → durability-config-XV4XR7Y4.mjs} +7 -3
- package/dist/embed-4H7RTBVL.mjs +221 -0
- package/dist/embeddings/openai.mjs +2 -2
- package/dist/{engine-CkPn2PWE.d.ts → engine-DBRVR_d-.d.ts} +1252 -1239
- package/dist/{browser/geo-index-OTV7VPIR.mjs → geo-index-2ZMMWWSK.mjs} +190 -93
- package/dist/{index-C4AmUnl1.d.ts → index-Ck9w5WHz.d.ts} +1 -1
- package/dist/index.browser.mjs +4 -16
- package/dist/index.d.ts +1495 -78
- package/dist/index.mjs +14 -50
- package/dist/index.react-native.mjs +11 -28
- package/dist/invalidation/filesystem.mjs +1 -2
- package/dist/languages/albanian.mjs +1 -1
- package/dist/languages/amharic.mjs +1 -1
- package/dist/languages/arabic.mjs +1 -1
- package/dist/languages/armenian.mjs +1 -1
- package/dist/languages/azerbaijani.mjs +1 -1
- package/dist/languages/bambara.mjs +1 -1
- package/dist/languages/basque.mjs +1 -1
- package/dist/languages/belarusian.mjs +1 -1
- package/dist/languages/bengali.mjs +1 -1
- package/dist/languages/bosnian.mjs +1 -1
- package/dist/languages/breton.mjs +1 -1
- package/dist/languages/bulgarian.mjs +1 -1
- package/dist/languages/burmese.mjs +1 -1
- package/dist/languages/catalan.mjs +1 -1
- package/dist/languages/chinese.mjs +1 -1
- package/dist/languages/croatian.mjs +1 -1
- package/dist/languages/czech.mjs +1 -1
- package/dist/languages/dagbani.mjs +1 -1
- package/dist/languages/danish.mjs +1 -1
- package/dist/languages/dutch.mjs +1 -1
- package/dist/languages/english.mjs +1 -1
- package/dist/languages/esperanto.mjs +1 -1
- package/dist/languages/estonian.mjs +1 -1
- package/dist/languages/ewe.mjs +1 -1
- package/dist/languages/faroese.mjs +1 -1
- package/dist/languages/fijian.mjs +1 -1
- package/dist/languages/finnish.mjs +1 -1
- package/dist/languages/french.mjs +1 -1
- package/dist/languages/ga.mjs +1 -1
- package/dist/languages/galician.mjs +1 -1
- package/dist/languages/georgian.mjs +1 -1
- package/dist/languages/german.mjs +1 -1
- package/dist/languages/greek.mjs +1 -1
- package/dist/languages/guarani.mjs +1 -1
- package/dist/languages/gujarati.mjs +1 -1
- package/dist/languages/haitian-creole.mjs +1 -1
- package/dist/languages/hausa.mjs +1 -1
- package/dist/languages/hawaiian.mjs +1 -1
- package/dist/languages/hebrew.mjs +1 -1
- package/dist/languages/hindi.mjs +1 -1
- package/dist/languages/hungarian.mjs +1 -1
- package/dist/languages/icelandic.mjs +1 -1
- package/dist/languages/igbo.mjs +1 -1
- package/dist/languages/indonesian.mjs +1 -1
- package/dist/languages/irish.mjs +1 -1
- package/dist/languages/italian.mjs +1 -1
- package/dist/languages/japanese.mjs +1 -1
- package/dist/languages/kannada.mjs +1 -1
- package/dist/languages/kazakh.mjs +1 -1
- package/dist/languages/khmer.mjs +1 -1
- package/dist/languages/kinyarwanda.mjs +1 -1
- package/dist/languages/kirundi.mjs +1 -1
- package/dist/languages/korean.mjs +1 -1
- package/dist/languages/kurmanji.mjs +1 -1
- package/dist/languages/kyrgyz.mjs +1 -1
- package/dist/languages/lao.mjs +1 -1
- package/dist/languages/latin.mjs +1 -1
- package/dist/languages/latvian.mjs +1 -1
- package/dist/languages/lingala.mjs +1 -1
- package/dist/languages/lithuanian.mjs +1 -1
- package/dist/languages/luxembourgish.mjs +1 -1
- package/dist/languages/macedonian.mjs +1 -1
- package/dist/languages/malagasy.mjs +1 -1
- package/dist/languages/malay.mjs +1 -1
- package/dist/languages/malayalam.mjs +1 -1
- package/dist/languages/maltese.mjs +1 -1
- package/dist/languages/maori.mjs +1 -1
- package/dist/languages/marathi.mjs +1 -1
- package/dist/languages/nepali.mjs +1 -1
- package/dist/languages/norwegian.mjs +1 -1
- package/dist/languages/oromo.mjs +1 -1
- package/dist/languages/persian.mjs +1 -1
- package/dist/languages/polish.mjs +1 -1
- package/dist/languages/portuguese.mjs +1 -1
- package/dist/languages/punjabi.mjs +1 -1
- package/dist/languages/romanian.mjs +1 -1
- package/dist/languages/russian.mjs +1 -1
- package/dist/languages/samoan.mjs +1 -1
- package/dist/languages/sanskrit.mjs +1 -1
- package/dist/languages/scottish-gaelic.mjs +1 -1
- package/dist/languages/serbian.mjs +1 -1
- package/dist/languages/shona.mjs +1 -1
- package/dist/languages/sinhala.mjs +1 -1
- package/dist/languages/slovak.mjs +1 -1
- package/dist/languages/slovenian.mjs +1 -1
- package/dist/languages/sorani.mjs +1 -1
- package/dist/languages/spanish.mjs +1 -1
- package/dist/languages/swahili.mjs +1 -1
- package/dist/languages/swedish.mjs +1 -1
- package/dist/languages/tagalog.mjs +1 -1
- package/dist/languages/tamil.mjs +1 -1
- package/dist/languages/tatar.mjs +1 -1
- package/dist/languages/telugu.mjs +1 -1
- package/dist/languages/thai.mjs +1 -1
- package/dist/languages/tibetan.mjs +1 -1
- package/dist/languages/tigrinya.mjs +1 -1
- package/dist/languages/tongan.mjs +1 -1
- package/dist/languages/turkish.mjs +1 -1
- package/dist/languages/twi.mjs +1 -1
- package/dist/languages/ukrainian.mjs +1 -1
- package/dist/languages/urdu.mjs +1 -1
- package/dist/languages/vietnamese.mjs +1 -1
- package/dist/languages/welsh.mjs +1 -1
- package/dist/languages/wolof.mjs +1 -1
- package/dist/languages/xhosa.mjs +1 -1
- package/dist/languages/yoruba.mjs +1 -1
- package/dist/languages/zulu.mjs +1 -1
- package/dist/{long-query-thread-QDFQSJD6.mjs → long-query-thread-JMGNGF6V.mjs} +74 -58
- package/dist/{module-N55W4Q5C.mjs → module-ZJ6ARG6V.mjs} +444 -111
- package/dist/msgpack-leaf-5WFRP6JM.mjs +9 -0
- package/dist/optional-reads-BR3BOVZW.mjs +3373 -0
- package/dist/optional-writes-DDFHYUOH.mjs +218 -0
- package/dist/{paged-partition-archive-RLRGOXDX.mjs → paged-partition-archive-G576XGVE.mjs} +29 -69
- package/dist/partial-words.browser.mjs +1649 -0
- package/dist/partial-words.mjs +15 -14
- package/dist/{chunk-CITFCZKF.mjs → pattern.browser.mjs} +153 -186
- package/dist/pattern.mjs +6 -8
- package/dist/persistence/durability/checkpoint-worker.d.ts +32 -24
- package/dist/persistence/durability/checkpoint-worker.mjs +27 -59
- package/dist/phrase-module-XK3T44VU.mjs +634 -0
- package/dist/query-actions-OMXJEC2J.mjs +118 -0
- package/dist/query-suggestions/merge-worker.mjs +18 -54
- package/dist/query-suggestions.browser.mjs +26 -227
- package/dist/query-suggestions.d.ts +2 -2
- package/dist/query-suggestions.mjs +16 -67
- package/dist/react-native/chunks/chunk-4EXKQ2IB.mjs +565 -0
- package/dist/react-native/chunks/chunk-52QD7CBJ.mjs +52 -0
- package/dist/react-native/chunks/chunk-72OKYHZL.mjs +969 -0
- package/dist/react-native/chunks/chunk-AQOWRH2C.mjs +802 -0
- package/dist/react-native/chunks/{chunk-4COWCEY7.mjs → chunk-FTQ7JNMU.mjs} +341 -180
- package/dist/react-native/chunks/chunk-G3CUQ333.mjs +42 -0
- package/dist/react-native/chunks/{chunk-EJ33LCHV.mjs → chunk-HRDMIQ63.mjs} +53 -1
- package/dist/react-native/chunks/{chunk-4AV5PPH6.mjs → chunk-IY6U6HRA.mjs} +63 -7
- package/dist/react-native/chunks/chunk-J2NQW353.mjs +212 -0
- package/dist/react-native/chunks/chunk-L4R5ITVG.mjs +29047 -0
- package/dist/react-native/chunks/{chunk-OXM66LO6.mjs → chunk-OK3WUA6N.mjs} +2 -10
- package/dist/react-native/chunks/{chunk-MVXELMJX.mjs → chunk-PVMEHBQO.mjs} +1 -1
- package/dist/{browser/chunk-SRMZXJSL.mjs → react-native/chunks/chunk-TQ26BKBH.mjs} +6 -0
- package/dist/{browser/chunk-GPPOG6PT.mjs → react-native/chunks/chunk-VUJCSQG5.mjs} +3 -1
- package/dist/react-native/chunks/{chunk-ENLMYKSX.mjs → chunk-XEGKQKLY.mjs} +5385 -3114
- package/dist/react-native/chunks/chunk-YOTP2FPE.mjs +232 -0
- package/dist/react-native/chunks/chunk-ZIU6TWXG.mjs +127 -0
- package/dist/react-native/chunks/core-leaf-5B4JXCVA.mjs +6 -0
- package/dist/react-native/chunks/digest-leaf-X6OIFDIU.mjs +1 -0
- package/dist/{durability-config-GE4U7MCZ.mjs → react-native/chunks/durability-config-3IOXIPYZ.mjs} +7 -3
- package/dist/react-native/chunks/embed-3WQ2CCR5.mjs +221 -0
- package/dist/{geo-index-MRH5JMIR.mjs → react-native/chunks/geo-index-QEYKEVPH.mjs} +190 -93
- package/dist/react-native/chunks/{chunk-CKNRFDTZ.mjs → gzip.react-native-DLO4WW27.mjs} +2 -1
- package/dist/{browser/module-TCT66FWA.mjs → react-native/chunks/module-VUA27HZZ.mjs} +1018 -540
- package/dist/react-native/chunks/msgpack-leaf-TR66ZVAX.mjs +7 -0
- package/dist/react-native/chunks/optional-reads-WDTLLHUT.mjs +3364 -0
- package/dist/react-native/chunks/optional-writes-FZV3QW34.mjs +267 -0
- package/dist/react-native/chunks/phrase-module-KCQWVXYZ.mjs +635 -0
- package/dist/react-native/chunks/resolve-vector-text-LXRYXF7M.mjs +59 -0
- package/dist/react-native/chunks/restore-queue-EI2V2I4S.mjs +179 -0
- package/dist/{browser/runtime-OTAGEFQW.mjs → react-native/chunks/runtime-BUCSAK4U.mjs} +61 -25
- package/dist/react-native/chunks/segment-codec-leaf-6ULP7H3I.mjs +12 -0
- package/dist/react-native/chunks/segment-merge-leaf-F4GQZNK6.mjs +13 -0
- package/dist/react-native/chunks/storage-leaf-OAXBU2L6.mjs +18042 -0
- package/dist/react-native/chunks/store-leaf-GY2ZZFXB.mjs +14 -0
- package/dist/react-native/chunks/{chunk-WW2X2AEI.mjs → suggestions-leaf-SQEZ4IBS.mjs} +332 -118
- package/dist/react-native/chunks/worker-copies-EEHSCFJW.mjs +2627 -0
- package/dist/react-native/partial-words.mjs +954 -35
- package/dist/react-native/pattern.mjs +238 -111
- package/dist/react-native/query-suggestions.mjs +33 -239
- package/dist/react-native/sync.mjs +95 -52
- package/dist/react-native/synonyms.mjs +256 -112
- package/dist/react.d.ts +9 -9
- package/dist/react.mjs +6 -0
- package/dist/{rerank-MQ37IYRV.mjs → rerank-Y6MWBMTT.mjs} +17 -8
- package/dist/rerankers/http.mjs +2 -2
- package/dist/resolve-vector-text-4PDRTPNQ.mjs +2 -0
- package/dist/restore-queue-KPYSRJ4A.mjs +184 -0
- package/dist/runtime-4GKUIAKV.mjs +595 -0
- package/dist/{schema-Jwt928nJ.d.ts → schema-C_7yRJLt.d.ts} +1 -1
- package/dist/segment-codec-leaf-6IFBSBPN.mjs +17 -0
- package/dist/segment-merge-leaf-VE3FUSVE.mjs +17 -0
- package/dist/server.d.ts +33 -13
- package/dist/server.mjs +81 -100
- package/dist/{browser/durability-wiring-GVZEE46O.mjs → storage-leaf-HMIIOUYN.mjs} +2334 -931
- package/dist/store-leaf-M7T7SUZJ.mjs +19 -0
- package/dist/stored-values-BWIMpiT_.d.ts +25 -0
- package/dist/suggestions-leaf-Q3Q5D6XV.mjs +53 -0
- package/dist/sync/filesystem.d.ts +3 -3
- package/dist/sync/filesystem.mjs +27 -11
- package/dist/sync/indexeddb.browser.mjs +287 -0
- package/dist/sync/indexeddb.d.ts +3 -3
- package/dist/sync/indexeddb.mjs +7 -2
- package/dist/sync.browser.mjs +88 -72
- package/dist/sync.d.ts +4 -4
- package/dist/sync.mjs +89 -59
- package/dist/{chunk-I5B7RXU7.mjs → synonyms.browser.mjs} +248 -135
- package/dist/synonyms.mjs +15 -11
- package/dist/{tasks-CoNjxbop.d.ts → tasks-B4tT4vmP.d.ts} +4 -4
- package/dist/thread-SNILJXX3.mjs +30 -0
- package/dist/{types-DPMjfOr_.d.ts → types-CTg0KaMy.d.ts} +2 -2
- package/dist/vector/search-worker.d.ts +7 -1
- package/dist/vector/search-worker.mjs +9 -13
- package/dist/worker-copies-ZLZS2CUM.mjs +2152 -0
- package/dist/workers/entry.mjs +60 -30
- package/openapi.json +66 -50
- package/package.json +233 -8
- package/dist/analysis-change-CKEMM2MC.mjs +0 -55
- package/dist/analysis-change-entry-SEDMJ6MW.mjs +0 -1
- package/dist/archive-history-E4R73RWD.mjs +0 -29
- package/dist/browser/analysis-change-ZKGJFENM.mjs +0 -942
- package/dist/browser/analysis-change-entry-5BFUVMHJ.mjs +0 -1
- package/dist/browser/archive-history-4IP5XQZY.mjs +0 -29
- package/dist/browser/chunk-25MTVDYD.mjs +0 -432
- package/dist/browser/chunk-3I27KXQD.mjs +0 -34
- package/dist/browser/chunk-3NLMB5CC.mjs +0 -217
- package/dist/browser/chunk-4RD3AFSB.mjs +0 -32
- package/dist/browser/chunk-5W3MMTLG.mjs +0 -19
- package/dist/browser/chunk-5YWB3E2W.mjs +0 -92
- package/dist/browser/chunk-7IGKGWSQ.mjs +0 -79
- package/dist/browser/chunk-AI5UI46D.mjs +0 -12
- package/dist/browser/chunk-ATEBYXP6.mjs +0 -10
- package/dist/browser/chunk-BLT4RHCJ.mjs +0 -241
- package/dist/browser/chunk-C26SPCGQ.mjs +0 -2636
- package/dist/browser/chunk-C4FJ3WDY.mjs +0 -177
- package/dist/browser/chunk-CXNTHHA7.mjs +0 -63
- package/dist/browser/chunk-DSXIBE6N.mjs +0 -78
- package/dist/browser/chunk-DUH6QUVU.mjs +0 -2374
- package/dist/browser/chunk-ELV4OZOI.mjs +0 -29
- package/dist/browser/chunk-EXQZGUQH.mjs +0 -193
- package/dist/browser/chunk-G64Q6OJF.mjs +0 -96
- package/dist/browser/chunk-HOZW3PKP.mjs +0 -9
- package/dist/browser/chunk-HUCSHDTB.mjs +0 -100
- package/dist/browser/chunk-JPTQZWJQ.mjs +0 -10
- package/dist/browser/chunk-K3IPRX6D.mjs +0 -2559
- package/dist/browser/chunk-ML7THVLJ.mjs +0 -38
- package/dist/browser/chunk-MY2XKH22.mjs +0 -40
- package/dist/browser/chunk-NLWTBAGB.mjs +0 -111
- package/dist/browser/chunk-NXQG7DRA.mjs +0 -318
- package/dist/browser/chunk-OEDCEZXJ.mjs +0 -92
- package/dist/browser/chunk-OIZS5KIX.mjs +0 -6
- package/dist/browser/chunk-RA6LSBCM.mjs +0 -43
- package/dist/browser/chunk-TK63WFXK.mjs +0 -90
- package/dist/browser/chunk-TY7L6OXO.mjs +0 -69
- package/dist/browser/chunk-U3JOQGWX.mjs +0 -19
- package/dist/browser/chunk-U4YDIBUT.mjs +0 -653
- package/dist/browser/chunk-UATIJ4KU.mjs +0 -21
- package/dist/browser/chunk-UKOWD2K5.mjs +0 -315
- package/dist/browser/chunk-UTMHUHUV.mjs +0 -150
- package/dist/browser/chunk-V43N6TZO.mjs +0 -857
- package/dist/browser/chunk-VI7BQR4U.mjs +0 -21
- package/dist/browser/chunk-WN464PTL.mjs +0 -375
- package/dist/browser/chunk-WXLBZJMT.mjs +0 -25
- package/dist/browser/chunk-X7TXYUKO.mjs +0 -86
- package/dist/browser/chunk-XAWNZ4G2.mjs +0 -151
- package/dist/browser/chunk-Y6IBAUNO.mjs +0 -561
- package/dist/browser/chunk-ZI2V4VD7.mjs +0 -21
- package/dist/browser/cold-module-YNUUDNOM.mjs +0 -761
- package/dist/browser/engine-hooks-HBVS6YM4.mjs +0 -18
- package/dist/browser/gzip-5S7ROJFJ.mjs +0 -1
- package/dist/browser/import-5ESVMFDJ.mjs +0 -20
- package/dist/browser/methods-KTQCSIN4.mjs +0 -30
- package/dist/browser/module-NDSQLPMQ.mjs +0 -25
- package/dist/browser/operations-OJ3BXS55.mjs +0 -5
- package/dist/browser/phrase-module-HAT3TLZN.mjs +0 -328
- package/dist/browser/pool-3JLET5RO.mjs +0 -297
- package/dist/browser/release-HYXPVJVS.mjs +0 -32
- package/dist/browser/restore-queue-LQBBTODR.mjs +0 -55
- package/dist/browser/retention-TY3L3BFN.mjs +0 -211
- package/dist/browser/snapshot-5FHPPCNZ.mjs +0 -965
- package/dist/browser/start-2UZTOBG5.mjs +0 -26
- package/dist/browser/sync-state-P5XG6LTQ.mjs +0 -15
- package/dist/browser/write-ULXAN5B4.mjs +0 -196
- package/dist/chunk-2NE7VCYE.mjs +0 -212
- package/dist/chunk-2ROUFMQX.mjs +0 -543
- package/dist/chunk-37CD3OKS.mjs +0 -87
- package/dist/chunk-3MXV3VHR.mjs +0 -46
- package/dist/chunk-3OH67G7R.mjs +0 -214
- package/dist/chunk-4B7JIGQD.mjs +0 -106
- package/dist/chunk-5YNRKI2C.mjs +0 -81
- package/dist/chunk-6HTGOXIK.mjs +0 -875
- package/dist/chunk-6OEGXLBX.mjs +0 -57
- package/dist/chunk-6RC4K46J.mjs +0 -86
- package/dist/chunk-7GFE3PEY.mjs +0 -40
- package/dist/chunk-7GXJUJ24.mjs +0 -49
- package/dist/chunk-7V5IUP2T.mjs +0 -63
- package/dist/chunk-A4L7YTKX.mjs +0 -458
- package/dist/chunk-BEZH7VEH.mjs +0 -23
- package/dist/chunk-BNL5OPRV.mjs +0 -634
- package/dist/chunk-BTPGQC6Z.mjs +0 -27
- package/dist/chunk-C7XQYG6U.mjs +0 -50
- package/dist/chunk-CQZXZ75V.mjs +0 -562
- package/dist/chunk-CWS55TEX.mjs +0 -242
- package/dist/chunk-CZQ33DLW.mjs +0 -78
- package/dist/chunk-EEBCDP36.mjs +0 -32
- package/dist/chunk-FB6463IN.mjs +0 -1499
- package/dist/chunk-FCJ553HS.mjs +0 -655
- package/dist/chunk-FEZVDOWX.mjs +0 -6996
- package/dist/chunk-FOCV4CBZ.mjs +0 -87
- package/dist/chunk-FQBFZAWG.mjs +0 -27
- package/dist/chunk-G6HRSGOU.mjs +0 -74
- package/dist/chunk-GES7U2PM.mjs +0 -68
- package/dist/chunk-GH4WQ22V.mjs +0 -34
- package/dist/chunk-GPWMUPCA.mjs +0 -1126
- package/dist/chunk-GQPTDQCL.mjs +0 -54
- package/dist/chunk-HJSN7UYG.mjs +0 -10
- package/dist/chunk-I54T6CQP.mjs +0 -117
- package/dist/chunk-IPN7S4KX.mjs +0 -130
- package/dist/chunk-J4IJTTEX.mjs +0 -226
- package/dist/chunk-JSV6OQ4C.mjs +0 -74
- package/dist/chunk-K4ZIGL2O.mjs +0 -290
- package/dist/chunk-KAKQ74LS.mjs +0 -53
- package/dist/chunk-KCQYFO4K.mjs +0 -62
- package/dist/chunk-KHKIRS5D.mjs +0 -113
- package/dist/chunk-KOKM4PQN.mjs +0 -52
- package/dist/chunk-KP7TYHWT.mjs +0 -92
- package/dist/chunk-KZ3NX2P7.mjs +0 -21
- package/dist/chunk-L5ORED7V.mjs +0 -25
- package/dist/chunk-LDNCLRZU.mjs +0 -218
- package/dist/chunk-LHKOSI2J.mjs +0 -58
- package/dist/chunk-LQG5G2LY.mjs +0 -39
- package/dist/chunk-MATMVH65.mjs +0 -9
- package/dist/chunk-MP7ABPTD.mjs +0 -189
- package/dist/chunk-MW6BR4QP.mjs +0 -316
- package/dist/chunk-MWD5VPN7.mjs +0 -21
- package/dist/chunk-ODYKO5TO.mjs +0 -101
- package/dist/chunk-OG7UGJ6F.mjs +0 -63
- package/dist/chunk-ORN5BLL7.mjs +0 -11
- package/dist/chunk-OYABFKTW.mjs +0 -1974
- package/dist/chunk-P5LANSH6.mjs +0 -121
- package/dist/chunk-PELHVTO7.mjs +0 -24
- package/dist/chunk-PIH5SJ4N.mjs +0 -7481
- package/dist/chunk-PSZI4O24.mjs +0 -253
- package/dist/chunk-PV2CG7EJ.mjs +0 -886
- package/dist/chunk-PWGYQXML.mjs +0 -470
- package/dist/chunk-Q2UL2TPC.mjs +0 -21
- package/dist/chunk-QHPYS427.mjs +0 -66
- package/dist/chunk-QJVOLKU6.mjs +0 -111
- package/dist/chunk-QLDABJZM.mjs +0 -20
- package/dist/chunk-QYRNLLLI.mjs +0 -99
- package/dist/chunk-RCX4WNLC.mjs +0 -151
- package/dist/chunk-RFBLQLLZ.mjs +0 -16
- package/dist/chunk-RIHIVFIQ.mjs +0 -240
- package/dist/chunk-RLOES5SX.mjs +0 -31
- package/dist/chunk-RWURUDSP.mjs +0 -2639
- package/dist/chunk-RZWWB2XR.mjs +0 -96
- package/dist/chunk-S5LN746F.mjs +0 -10
- package/dist/chunk-SOI6LTHM.mjs +0 -216
- package/dist/chunk-SQJWAIF4.mjs +0 -12
- package/dist/chunk-TDIK6NTV.mjs +0 -10
- package/dist/chunk-TQXHPFWT.mjs +0 -177
- package/dist/chunk-U55XJEIG.mjs +0 -18
- package/dist/chunk-UD5HIS4U.mjs +0 -382
- package/dist/chunk-UHICS3JI.mjs +0 -83
- package/dist/chunk-UJDJB3NE.mjs +0 -913
- package/dist/chunk-VD7J552I.mjs +0 -28
- package/dist/chunk-VSLSGASN.mjs +0 -30
- package/dist/chunk-VZ2ONHEE.mjs +0 -3715
- package/dist/chunk-W7OSSKH5.mjs +0 -1427
- package/dist/chunk-WZ7YV54N.mjs +0 -152
- package/dist/chunk-X5CV2E2B.mjs +0 -1
- package/dist/chunk-Y4WPNHMC.mjs +0 -50
- package/dist/chunk-YEKL4JBK.mjs +0 -96
- package/dist/chunk-ZXNQEW43.mjs +0 -18
- package/dist/chunk-ZYAY26KG.mjs +0 -29
- package/dist/direct-executor-V5DRIECI.mjs +0 -34
- package/dist/durability-wiring-3TD62MBI.mjs +0 -4072
- package/dist/engine-hooks-HA3SBOBR.mjs +0 -54
- package/dist/gzip-F4HMIEEQ.mjs +0 -1
- package/dist/import-GPKLTSKA.mjs +0 -56
- package/dist/methods-7IOINERF.mjs +0 -30
- package/dist/module-JYHFTVPS.mjs +0 -63
- package/dist/operations-G5EP6JPX.mjs +0 -5
- package/dist/phrase-module-XW5MKWP5.mjs +0 -330
- package/dist/pool-Y4A46T36.mjs +0 -298
- package/dist/react-native/chunks/analysis-change-QUVDNABS.mjs +0 -934
- package/dist/react-native/chunks/analysis-change-entry-OC4XASBF.mjs +0 -1
- package/dist/react-native/chunks/archive-history-MJKUQLSU.mjs +0 -29
- package/dist/react-native/chunks/chunk-2PRHILX3.mjs +0 -529
- package/dist/react-native/chunks/chunk-3NQOVO3K.mjs +0 -1
- package/dist/react-native/chunks/chunk-3WI35N75.mjs +0 -226
- package/dist/react-native/chunks/chunk-4DII3ZSM.mjs +0 -73
- package/dist/react-native/chunks/chunk-4J74WHQM.mjs +0 -177
- package/dist/react-native/chunks/chunk-4NWR3NGS.mjs +0 -151
- package/dist/react-native/chunks/chunk-5CQX3XXV.mjs +0 -17
- package/dist/react-native/chunks/chunk-5MSX5FRT.mjs +0 -858
- package/dist/react-native/chunks/chunk-6OFDUYVX.mjs +0 -92
- package/dist/react-native/chunks/chunk-6VBXNFLE.mjs +0 -9
- package/dist/react-native/chunks/chunk-6ZELFCK5.mjs +0 -315
- package/dist/react-native/chunks/chunk-AAAETEJK.mjs +0 -27
- package/dist/react-native/chunks/chunk-AM7RSBPF.mjs +0 -32
- package/dist/react-native/chunks/chunk-BITYFZSZ.mjs +0 -242
- package/dist/react-native/chunks/chunk-C5G6TJ7A.mjs +0 -140
- package/dist/react-native/chunks/chunk-CHPTFFJM.mjs +0 -43
- package/dist/react-native/chunks/chunk-DIYDOIM4.mjs +0 -10
- package/dist/react-native/chunks/chunk-DMIFXZ3Q.mjs +0 -432
- package/dist/react-native/chunks/chunk-DVDX4SDR.mjs +0 -375
- package/dist/react-native/chunks/chunk-DXRSEWA2.mjs +0 -12
- package/dist/react-native/chunks/chunk-F753DA54.mjs +0 -23
- package/dist/react-native/chunks/chunk-FHPW7P2O.mjs +0 -40
- package/dist/react-native/chunks/chunk-FTZHMRD2.mjs +0 -18
- package/dist/react-native/chunks/chunk-HJBJBH26.mjs +0 -34
- package/dist/react-native/chunks/chunk-IAENKE2D.mjs +0 -21
- package/dist/react-native/chunks/chunk-IO2SMUQD.mjs +0 -10
- package/dist/react-native/chunks/chunk-IYNT75CE.mjs +0 -111
- package/dist/react-native/chunks/chunk-JDOEEMEF.mjs +0 -38
- package/dist/react-native/chunks/chunk-JWUCMVRK.mjs +0 -15
- package/dist/react-native/chunks/chunk-KSBYEMCB.mjs +0 -100
- package/dist/react-native/chunks/chunk-KU646XXT.mjs +0 -164
- package/dist/react-native/chunks/chunk-LU3Y3P63.mjs +0 -68
- package/dist/react-native/chunks/chunk-LVIKKAA6.mjs +0 -93
- package/dist/react-native/chunks/chunk-LZSLNSUN.mjs +0 -193
- package/dist/react-native/chunks/chunk-MJDQU5MW.mjs +0 -1225
- package/dist/react-native/chunks/chunk-NNE4VDMM.mjs +0 -8
- package/dist/react-native/chunks/chunk-NVVRSRX5.mjs +0 -78
- package/dist/react-native/chunks/chunk-OCSLSH27.mjs +0 -22723
- package/dist/react-native/chunks/chunk-PB2YXVQW.mjs +0 -29
- package/dist/react-native/chunks/chunk-PJHAB5ZY.mjs +0 -79
- package/dist/react-native/chunks/chunk-PSWKQVVT.mjs +0 -9
- package/dist/react-native/chunks/chunk-RDWG33MM.mjs +0 -79
- package/dist/react-native/chunks/chunk-SK2PWYDH.mjs +0 -654
- package/dist/react-native/chunks/chunk-SUPXRTMD.mjs +0 -96
- package/dist/react-native/chunks/chunk-TORU2OHQ.mjs +0 -218
- package/dist/react-native/chunks/chunk-U4KSKA4Z.mjs +0 -23
- package/dist/react-native/chunks/chunk-UNUFZ2QY.mjs +0 -68
- package/dist/react-native/chunks/chunk-WBYQRHDY.mjs +0 -86
- package/dist/react-native/chunks/chunk-WVWJNUMN.mjs +0 -2562
- package/dist/react-native/chunks/chunk-YH7QY657.mjs +0 -288
- package/dist/react-native/chunks/chunk-YZW4CHM6.mjs +0 -562
- package/dist/react-native/chunks/chunk-ZNZ6CPAZ.mjs +0 -562
- package/dist/react-native/chunks/chunk-ZVQMBF2H.mjs +0 -63
- package/dist/react-native/chunks/chunk-ZWAIN4GG.mjs +0 -2636
- package/dist/react-native/chunks/chunk-ZZT7CEN7.mjs +0 -92
- package/dist/react-native/chunks/cold-module-N6KFNNZA.mjs +0 -773
- package/dist/react-native/chunks/durability-wiring-RN64S2TL.mjs +0 -4984
- package/dist/react-native/chunks/engine-hooks-CWA5CKCA.mjs +0 -30
- package/dist/react-native/chunks/gzip.react-native-HLEPDKZ3.mjs +0 -3
- package/dist/react-native/chunks/import-5UAWBRJP.mjs +0 -32
- package/dist/react-native/chunks/methods-6W5U4C3H.mjs +0 -30
- package/dist/react-native/chunks/module-6RP4ZCBW.mjs +0 -37
- package/dist/react-native/chunks/operations-GNRMD6EX.mjs +0 -5
- package/dist/react-native/chunks/phrase-module-QK22HSQ2.mjs +0 -329
- package/dist/react-native/chunks/pool-JR3NJCAF.mjs +0 -297
- package/dist/react-native/chunks/release-2SIHZWDO.mjs +0 -32
- package/dist/react-native/chunks/restore-hooks-ENFMDTWC.mjs +0 -127
- package/dist/react-native/chunks/restore-queue-4R6AASE5.mjs +0 -55
- package/dist/react-native/chunks/retention-5GTFT3GR.mjs +0 -223
- package/dist/react-native/chunks/snapshot-5LGPQXFS.mjs +0 -976
- package/dist/react-native/chunks/start-ZQJVZ5DN.mjs +0 -38
- package/dist/react-native/chunks/sync-state-PASCIHHT.mjs +0 -15
- package/dist/react-native/chunks/write-6BRYIIZ7.mjs +0 -208
- package/dist/release-SMR4WJD4.mjs +0 -32
- package/dist/restore-hooks-HXLIEB4A.mjs +0 -153
- package/dist/restore-queue-LZH7LMLR.mjs +0 -55
- package/dist/retention-3K7ARGAG.mjs +0 -66
- package/dist/runtime-COIUORCN.mjs +0 -177
- package/dist/snapshot-O7ICP7NJ.mjs +0 -783
- package/dist/start-S4PFP6RS.mjs +0 -66
- package/dist/sync-state-ZWHLAFLE.mjs +0 -15
- package/dist/thread-YLJ3ZPQ3.mjs +0 -50
- package/dist/write-2OBJGLFS.mjs +0 -233
- /package/dist/browser/{chunk-M3MQE2X7.mjs → digest-leaf-64IPRPZD.mjs} +0 -0
- /package/dist/browser/{chunk-JNOAKDUM.mjs → gzip-JF3S6PPT.mjs} +0 -0
- /package/dist/{chunk-ZXNNR73R.mjs → gzip-2UCZW2MM.mjs} +0 -0
package/dist/chunk-GPWMUPCA.mjs
DELETED
|
@@ -1,1126 +0,0 @@
|
|
|
1
|
-
import { encodeSegmentManifest } from './chunk-C7XQYG6U.mjs';
|
|
2
|
-
import { writeSegmentsOf, readSegmentFile, MERGED_SEGMENT_GROWTH_ALLOWANCE, MERGED_SEGMENT_TARGET_BYTES } from './chunk-BNL5OPRV.mjs';
|
|
3
|
-
import { ReplicationMessageTypes } from './chunk-5FLRXF73.mjs';
|
|
4
|
-
import { WIRE_BATCH_BUDGET } from './chunk-JDDXV6UF.mjs';
|
|
5
|
-
import { restoreVectorFields } from './chunk-KCQYFO4K.mjs';
|
|
6
|
-
import { SEGMENT_MANIFEST_VERSION, manifestKey, manifestReferencedKeys, segmentsPrefix, snapshotBundleKey, MAX_SEGMENTS_PER_PARTITION } from './chunk-JTYPJF3T.mjs';
|
|
7
|
-
import { DEFAULT_COMPACTION_THRESHOLD, COMPACTION_LARGEST_MERGED_DOCUMENT_COUNT, SEGMENT_FILE_FRAMING_SLACK_BYTES } from './chunk-QDZJM7NI.mjs';
|
|
8
|
-
import { reconstructSchemaFromMetadata, prepareDocumentVectors } from './chunk-FEZVDOWX.mjs';
|
|
9
|
-
import { generateId, freezeSegmentShared, createSharedFrozenSegment, createFrozenSegment, createPartitionManager, createPartitionRouter, buildSegmentPayload, resolvePartitionInsertOptions, decodeMapWithoutFields, shareSegmentArrays } from './chunk-VZ2ONHEE.mjs';
|
|
10
|
-
import { isCompositePartition, survivorDocumentsOf, partitionStateOf } from './chunk-PIH5SJ4N.mjs';
|
|
11
|
-
import { crc32 } from './chunk-7GXJUJ24.mjs';
|
|
12
|
-
import { extractVectorFieldsFromSchema, partialFieldsOf } from './chunk-W5EB5XKI.mjs';
|
|
13
|
-
import { getLanguage, resolveIndexAnalysis } from './chunk-RZWWB2XR.mjs';
|
|
14
|
-
import { MAX_FILE_BYTES } from './chunk-U476IXKQ.mjs';
|
|
15
|
-
import { ErrorCodes, NarsilError } from './chunk-MP7ABPTD.mjs';
|
|
16
|
-
import { encode, decode } from '@msgpack/msgpack';
|
|
17
|
-
|
|
18
|
-
// src/persistence/durability/segment/captured-partition.ts
|
|
19
|
-
function keepMaskOf(segment) {
|
|
20
|
-
const keep = new Uint8Array(segment.arrays.documentCount);
|
|
21
|
-
for (let ordinal = 0; ordinal < keep.length; ordinal++) keep[ordinal] = segment.isTombstoned(ordinal) ? 0 : 1;
|
|
22
|
-
return keep;
|
|
23
|
-
}
|
|
24
|
-
function selectionOfMask(segment, keep) {
|
|
25
|
-
return { segment, keep: (ordinal) => keep[ordinal] === 1 };
|
|
26
|
-
}
|
|
27
|
-
function frozenLiveTail(live, shared) {
|
|
28
|
-
if (live.count() === 0) return null;
|
|
29
|
-
const payload = live.encodeSegment();
|
|
30
|
-
const documents = survivorDocumentsOf(partitionStateOf(live), payload);
|
|
31
|
-
if (shared) {
|
|
32
|
-
const snapshot = freezeSegmentShared(payload, documents);
|
|
33
|
-
if (snapshot !== null) return createSharedFrozenSegment(snapshot);
|
|
34
|
-
}
|
|
35
|
-
return createFrozenSegment(payload, documents);
|
|
36
|
-
}
|
|
37
|
-
function frozenSegmentsOf(partition, shared) {
|
|
38
|
-
const segments = [];
|
|
39
|
-
const live = isCompositePartition(partition) ? partition.live : partition;
|
|
40
|
-
if (isCompositePartition(partition)) {
|
|
41
|
-
const ids = partition.frozenSegmentSizes().map((size) => size.segmentId);
|
|
42
|
-
segments.push(...partition.frozenSegmentsById(ids));
|
|
43
|
-
}
|
|
44
|
-
const tail = frozenLiveTail(live, shared);
|
|
45
|
-
if (tail !== null) segments.push(tail);
|
|
46
|
-
return segments;
|
|
47
|
-
}
|
|
48
|
-
function partitionContentsOf(manager, partitionId, captureRecords) {
|
|
49
|
-
const partition = manager.getPartition(partitionId);
|
|
50
|
-
const segments = frozenSegmentsOf(partition, false);
|
|
51
|
-
const selections = segments.map((segment) => selectionOfMask(segment, keepMaskOf(segment)));
|
|
52
|
-
const contents = { partitionId, docCount: partition.count(), selections };
|
|
53
|
-
if (captureRecords !== void 0) contents.writeRecords = captureRecords(segments);
|
|
54
|
-
return contents;
|
|
55
|
-
}
|
|
56
|
-
function captureWholePartition(manager, partitionId, captureRecords) {
|
|
57
|
-
if (typeof SharedArrayBuffer !== "function") return null;
|
|
58
|
-
const partition = manager.getPartition(partitionId);
|
|
59
|
-
if (!isCompositePartition(partition) || partition.frozenSegmentCount() === 0) return null;
|
|
60
|
-
const frozen = frozenSegmentsOf(partition, true);
|
|
61
|
-
const records = captureRecords?.(frozen);
|
|
62
|
-
const segments = [];
|
|
63
|
-
for (const segment of frozen) {
|
|
64
|
-
if (segment.sharedSnapshot === null) return null;
|
|
65
|
-
const captured = { snapshot: segment.sharedSnapshot, keep: keepMaskOf(segment) };
|
|
66
|
-
const held = records?.get(segment);
|
|
67
|
-
if (held !== void 0) captured.writeRecords = held;
|
|
68
|
-
segments.push(captured);
|
|
69
|
-
}
|
|
70
|
-
return { partitionId, docCount: partition.count(), segments };
|
|
71
|
-
}
|
|
72
|
-
function contentsOfCaptured(captured) {
|
|
73
|
-
const writeRecords = /* @__PURE__ */ new Map();
|
|
74
|
-
const selections = captured.segments.map(({ snapshot, keep, writeRecords: held }) => {
|
|
75
|
-
const segment = createSharedFrozenSegment(snapshot);
|
|
76
|
-
if (held !== void 0) writeRecords.set(segment, held);
|
|
77
|
-
return selectionOfMask(segment, keep);
|
|
78
|
-
});
|
|
79
|
-
const contents = { partitionId: captured.partitionId, docCount: captured.docCount, selections };
|
|
80
|
-
if (writeRecords.size > 0) contents.writeRecords = writeRecords;
|
|
81
|
-
return contents;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// src/persistence/durability/partition-checkpoint.ts
|
|
85
|
-
function checkpointLastSeqNo(checkpoint, partitionId) {
|
|
86
|
-
for (const c of checkpoint) {
|
|
87
|
-
if (c.partitionId === partitionId) {
|
|
88
|
-
return c.lastSeqNo;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return 0;
|
|
92
|
-
}
|
|
93
|
-
function checkpointPrimaryTerm(checkpoint, partitionId) {
|
|
94
|
-
for (const c of checkpoint) {
|
|
95
|
-
if (c.partitionId === partitionId) {
|
|
96
|
-
return c.primaryTerm;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return 0;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// src/persistence/durability/commit-marker.ts
|
|
103
|
-
var COMMIT_MARKER_SLOT_SIZE = 36;
|
|
104
|
-
var COMMIT_MARKER_SLOT_COUNT = 2;
|
|
105
|
-
var CRC_OFFSET = 32;
|
|
106
|
-
function encodeMarkerSlot(state) {
|
|
107
|
-
const slot = new Uint8Array(COMMIT_MARKER_SLOT_SIZE);
|
|
108
|
-
const view = new DataView(slot.buffer);
|
|
109
|
-
view.setBigUint64(0, BigInt(state.writeSeq), false);
|
|
110
|
-
view.setBigUint64(8, BigInt(state.activeSegmentSeqNo), false);
|
|
111
|
-
view.setBigUint64(16, BigInt(state.durableByteLength), false);
|
|
112
|
-
view.setBigUint64(24, BigInt(state.highestDurableSeqNo), false);
|
|
113
|
-
view.setUint32(CRC_OFFSET, crc32(slot.subarray(0, CRC_OFFSET)), false);
|
|
114
|
-
return slot;
|
|
115
|
-
}
|
|
116
|
-
function decodeSlot(data, slotIndex) {
|
|
117
|
-
const base = slotIndex * COMMIT_MARKER_SLOT_SIZE;
|
|
118
|
-
if (base + COMMIT_MARKER_SLOT_SIZE > data.length) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
const slot = data.subarray(base, base + COMMIT_MARKER_SLOT_SIZE);
|
|
122
|
-
const view = new DataView(slot.buffer, slot.byteOffset, slot.byteLength);
|
|
123
|
-
const storedCrc = view.getUint32(CRC_OFFSET, false);
|
|
124
|
-
if (crc32(slot.subarray(0, CRC_OFFSET)) !== storedCrc) {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
const writeSeq = view.getBigUint64(0, false);
|
|
128
|
-
const activeSegmentSeqNo = view.getBigUint64(8, false);
|
|
129
|
-
const durableByteLength = view.getBigUint64(16, false);
|
|
130
|
-
const highestDurableSeqNo = view.getBigUint64(24, false);
|
|
131
|
-
if (writeSeq > BigInt(Number.MAX_SAFE_INTEGER) || activeSegmentSeqNo > BigInt(Number.MAX_SAFE_INTEGER) || durableByteLength > BigInt(Number.MAX_SAFE_INTEGER) || highestDurableSeqNo > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
writeSeq: Number(writeSeq),
|
|
136
|
-
activeSegmentSeqNo: Number(activeSegmentSeqNo),
|
|
137
|
-
durableByteLength: Number(durableByteLength),
|
|
138
|
-
highestDurableSeqNo: Number(highestDurableSeqNo)
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
function readCommitMarker(data) {
|
|
142
|
-
let best = null;
|
|
143
|
-
for (let slotIndex = 0; slotIndex < COMMIT_MARKER_SLOT_COUNT; slotIndex += 1) {
|
|
144
|
-
const state = decodeSlot(data, slotIndex);
|
|
145
|
-
if (state === null) {
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
if (best === null || state.writeSeq > best.state.writeSeq) {
|
|
149
|
-
best = { state, slotIndex };
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return best;
|
|
153
|
-
}
|
|
154
|
-
function nextMarkerSlot(lastWrittenSlot) {
|
|
155
|
-
if (lastWrittenSlot === null) {
|
|
156
|
-
return 0;
|
|
157
|
-
}
|
|
158
|
-
return (lastWrittenSlot + 1) % COMMIT_MARKER_SLOT_COUNT;
|
|
159
|
-
}
|
|
160
|
-
function markerSlotOffset(slotIndex) {
|
|
161
|
-
return slotIndex * COMMIT_MARKER_SLOT_SIZE;
|
|
162
|
-
}
|
|
163
|
-
function createEntryMessage(entry, sourceId, indexUuid, previousPrimaryTerm) {
|
|
164
|
-
const payload = { entry };
|
|
165
|
-
if (indexUuid !== void 0) payload.indexUuid = indexUuid;
|
|
166
|
-
if (previousPrimaryTerm !== void 0) payload.previousPrimaryTerm = previousPrimaryTerm;
|
|
167
|
-
return {
|
|
168
|
-
type: ReplicationMessageTypes.ENTRY,
|
|
169
|
-
sourceId,
|
|
170
|
-
requestId: generateId(),
|
|
171
|
-
payload: encode(payload)
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
function createEntryBatchMessage(entries, sourceId, indexUuid, previousPrimaryTerm) {
|
|
175
|
-
const payload = { entries };
|
|
176
|
-
if (indexUuid !== void 0) payload.indexUuid = indexUuid;
|
|
177
|
-
if (previousPrimaryTerm !== void 0) payload.previousPrimaryTerm = previousPrimaryTerm;
|
|
178
|
-
return {
|
|
179
|
-
type: ReplicationMessageTypes.ENTRY_BATCH,
|
|
180
|
-
sourceId,
|
|
181
|
-
requestId: generateId(),
|
|
182
|
-
payload: encode(payload)
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
function createAckMessage(seqNo, partitionId, indexName, sourceId, requestId) {
|
|
186
|
-
const payload = { seqNo, partitionId, indexName };
|
|
187
|
-
return {
|
|
188
|
-
type: ReplicationMessageTypes.ACK,
|
|
189
|
-
sourceId,
|
|
190
|
-
requestId,
|
|
191
|
-
payload: encode(payload)
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
function createForwardMessage(payload, sourceId) {
|
|
195
|
-
return {
|
|
196
|
-
type: ReplicationMessageTypes.FORWARD,
|
|
197
|
-
sourceId,
|
|
198
|
-
requestId: generateId(),
|
|
199
|
-
payload: encode(payload)
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
var MAX_FORWARD_BATCH_OPERATIONS = WIRE_BATCH_BUDGET.maxCount;
|
|
203
|
-
function createForwardBatchMessage(payload, sourceId) {
|
|
204
|
-
return {
|
|
205
|
-
type: ReplicationMessageTypes.FORWARD_BATCH,
|
|
206
|
-
sourceId,
|
|
207
|
-
requestId: generateId(),
|
|
208
|
-
payload: encode(payload)
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
function createForwardBatchResultMessage(payload, sourceId, requestId) {
|
|
212
|
-
return {
|
|
213
|
-
type: ReplicationMessageTypes.FORWARD_BATCH,
|
|
214
|
-
sourceId,
|
|
215
|
-
requestId,
|
|
216
|
-
payload: encode(payload)
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
function createInsyncAddMessage(payload, sourceId) {
|
|
220
|
-
return {
|
|
221
|
-
type: ReplicationMessageTypes.INSYNC_ADD,
|
|
222
|
-
sourceId,
|
|
223
|
-
requestId: generateId(),
|
|
224
|
-
payload: encode(payload)
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
function createInsyncRemoveMessage(payload, sourceId) {
|
|
228
|
-
return {
|
|
229
|
-
type: ReplicationMessageTypes.INSYNC_REMOVE,
|
|
230
|
-
sourceId,
|
|
231
|
-
requestId: generateId(),
|
|
232
|
-
payload: encode(payload)
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
function createPrimaryResignMessage(payload, sourceId) {
|
|
236
|
-
return {
|
|
237
|
-
type: ReplicationMessageTypes.PRIMARY_RESIGN,
|
|
238
|
-
sourceId,
|
|
239
|
-
requestId: generateId(),
|
|
240
|
-
payload: encode(payload)
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
function createInsyncConfirmMessage(payload, sourceId, requestId) {
|
|
244
|
-
return {
|
|
245
|
-
type: ReplicationMessageTypes.INSYNC_CONFIRM,
|
|
246
|
-
sourceId,
|
|
247
|
-
requestId,
|
|
248
|
-
payload: encode(payload)
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
function isRecord(value) {
|
|
252
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
253
|
-
}
|
|
254
|
-
function optionalIndexUuid(value, payloadName) {
|
|
255
|
-
if (value === void 0 || value === null) {
|
|
256
|
-
return void 0;
|
|
257
|
-
}
|
|
258
|
-
if (typeof value !== "string" || value.length === 0) {
|
|
259
|
-
throw new Error(`Invalid ${payloadName}: "indexUuid" must be a non-empty string or absent`);
|
|
260
|
-
}
|
|
261
|
-
return value;
|
|
262
|
-
}
|
|
263
|
-
function optionalPreviousPrimaryTerm(value, payloadName) {
|
|
264
|
-
if (value === void 0 || value === null) {
|
|
265
|
-
return void 0;
|
|
266
|
-
}
|
|
267
|
-
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
268
|
-
throw new Error(`Invalid ${payloadName}: "previousPrimaryTerm" must be a non-negative integer or absent`);
|
|
269
|
-
}
|
|
270
|
-
return value;
|
|
271
|
-
}
|
|
272
|
-
function isPlainObject(value) {
|
|
273
|
-
if (!isRecord(value)) {
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
const prototype = Object.getPrototypeOf(value);
|
|
277
|
-
return prototype === Object.prototype || prototype === null;
|
|
278
|
-
}
|
|
279
|
-
function validateEntryPayload(decoded) {
|
|
280
|
-
if (!isRecord(decoded) || !isRecord(decoded.entry)) {
|
|
281
|
-
throw new Error('Invalid EntryPayload: missing or invalid "entry" field');
|
|
282
|
-
}
|
|
283
|
-
const entry = decoded.entry;
|
|
284
|
-
if (typeof entry.seqNo !== "number") {
|
|
285
|
-
throw new Error('Invalid EntryPayload: "entry.seqNo" must be a number');
|
|
286
|
-
}
|
|
287
|
-
if (typeof entry.primaryTerm !== "number") {
|
|
288
|
-
throw new Error('Invalid EntryPayload: "entry.primaryTerm" must be a number');
|
|
289
|
-
}
|
|
290
|
-
if (entry.operation !== "INDEX" && entry.operation !== "DELETE") {
|
|
291
|
-
throw new Error('Invalid EntryPayload: "entry.operation" must be "INDEX" or "DELETE"');
|
|
292
|
-
}
|
|
293
|
-
if (typeof entry.partitionId !== "number") {
|
|
294
|
-
throw new Error('Invalid EntryPayload: "entry.partitionId" must be a number');
|
|
295
|
-
}
|
|
296
|
-
if (typeof entry.indexName !== "string") {
|
|
297
|
-
throw new Error('Invalid EntryPayload: "entry.indexName" must be a string');
|
|
298
|
-
}
|
|
299
|
-
if (typeof entry.documentId !== "string") {
|
|
300
|
-
throw new Error('Invalid EntryPayload: "entry.documentId" must be a string');
|
|
301
|
-
}
|
|
302
|
-
if (entry.document !== null && !(entry.document instanceof Uint8Array)) {
|
|
303
|
-
throw new Error('Invalid EntryPayload: "entry.document" must be Uint8Array or null');
|
|
304
|
-
}
|
|
305
|
-
if (typeof entry.checksum !== "number") {
|
|
306
|
-
throw new Error('Invalid EntryPayload: "entry.checksum" must be a number');
|
|
307
|
-
}
|
|
308
|
-
optionalIndexUuid(decoded.indexUuid, "EntryPayload");
|
|
309
|
-
optionalPreviousPrimaryTerm(decoded.previousPrimaryTerm, "EntryPayload");
|
|
310
|
-
return decoded;
|
|
311
|
-
}
|
|
312
|
-
function validateEntryBatchPayload(decoded) {
|
|
313
|
-
if (!isRecord(decoded) || !Array.isArray(decoded.entries)) {
|
|
314
|
-
throw new Error('Invalid EntryBatchPayload: missing or invalid "entries" field');
|
|
315
|
-
}
|
|
316
|
-
if (decoded.entries.length === 0) {
|
|
317
|
-
throw new Error('Invalid EntryBatchPayload: "entries" must not be empty');
|
|
318
|
-
}
|
|
319
|
-
const validated = decoded.entries.map((candidate) => validateEntryPayload({ entry: candidate }).entry);
|
|
320
|
-
const first = validated[0];
|
|
321
|
-
for (let index = 1; index < validated.length; index++) {
|
|
322
|
-
const entry = validated[index];
|
|
323
|
-
if (entry.indexName !== first.indexName || entry.partitionId !== first.partitionId) {
|
|
324
|
-
throw new Error("Invalid EntryBatchPayload: entries must belong to one partition of one index");
|
|
325
|
-
}
|
|
326
|
-
if (entry.primaryTerm !== first.primaryTerm) {
|
|
327
|
-
throw new Error("Invalid EntryBatchPayload: entries must share one primary term");
|
|
328
|
-
}
|
|
329
|
-
if (entry.seqNo !== validated[index - 1].seqNo + 1) {
|
|
330
|
-
throw new Error("Invalid EntryBatchPayload: entries must carry contiguous ascending sequence numbers");
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
const payload = { entries: validated };
|
|
334
|
-
const indexUuid = optionalIndexUuid(decoded.indexUuid, "EntryBatchPayload");
|
|
335
|
-
if (indexUuid !== void 0) payload.indexUuid = indexUuid;
|
|
336
|
-
const previousPrimaryTerm = optionalPreviousPrimaryTerm(decoded.previousPrimaryTerm, "EntryBatchPayload");
|
|
337
|
-
if (previousPrimaryTerm !== void 0) payload.previousPrimaryTerm = previousPrimaryTerm;
|
|
338
|
-
return payload;
|
|
339
|
-
}
|
|
340
|
-
function validateForwardBatchPayload(decoded) {
|
|
341
|
-
if (!isRecord(decoded)) {
|
|
342
|
-
throw new Error("Invalid ForwardBatchPayload: expected an object");
|
|
343
|
-
}
|
|
344
|
-
if (typeof decoded.indexName !== "string" || decoded.indexName.length === 0) {
|
|
345
|
-
throw new Error('Invalid ForwardBatchPayload: "indexName" must be a non-empty string');
|
|
346
|
-
}
|
|
347
|
-
if (!Array.isArray(decoded.operations)) {
|
|
348
|
-
throw new Error('Invalid ForwardBatchPayload: "operations" must be an array');
|
|
349
|
-
}
|
|
350
|
-
if (decoded.operations.length === 0) {
|
|
351
|
-
throw new Error('Invalid ForwardBatchPayload: "operations" must not be empty');
|
|
352
|
-
}
|
|
353
|
-
if (decoded.operations.length > MAX_FORWARD_BATCH_OPERATIONS) {
|
|
354
|
-
throw new Error(
|
|
355
|
-
`Invalid ForwardBatchPayload: "operations" exceeds maximum length of ${MAX_FORWARD_BATCH_OPERATIONS}`
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
for (let index = 0; index < decoded.operations.length; index++) {
|
|
359
|
-
const operation = decoded.operations[index];
|
|
360
|
-
if (!isRecord(operation)) {
|
|
361
|
-
throw new Error(`Invalid ForwardBatchPayload: "operations[${index}]" must be an object`);
|
|
362
|
-
}
|
|
363
|
-
if (typeof operation.documentId !== "string" || operation.documentId.length === 0) {
|
|
364
|
-
throw new Error(`Invalid ForwardBatchPayload: "operations[${index}].documentId" must be a non-empty string`);
|
|
365
|
-
}
|
|
366
|
-
if (operation.operation !== "insert" && operation.operation !== "remove" && operation.operation !== "update") {
|
|
367
|
-
throw new Error(
|
|
368
|
-
`Invalid ForwardBatchPayload: "operations[${index}].operation" must be "insert", "remove", or "update"`
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
|
-
if (operation.document !== null && !(operation.document instanceof Uint8Array)) {
|
|
372
|
-
throw new Error(`Invalid ForwardBatchPayload: "operations[${index}].document" must be Uint8Array or null`);
|
|
373
|
-
}
|
|
374
|
-
if (operation.operation === "insert" && operation.document === null) {
|
|
375
|
-
throw new Error(`Invalid ForwardBatchPayload: "operations[${index}]" requires a document`);
|
|
376
|
-
}
|
|
377
|
-
if (operation.operation === "update" && operation.document === null && !isRecord(operation.updateFields)) {
|
|
378
|
-
throw new Error(`Invalid ForwardBatchPayload: "operations[${index}]" requires a document or updateFields`);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
optionalIndexUuid(decoded.indexUuid, "ForwardBatchPayload");
|
|
382
|
-
return decoded;
|
|
383
|
-
}
|
|
384
|
-
function validateForwardBatchResultPayload(decoded) {
|
|
385
|
-
if (!isRecord(decoded)) {
|
|
386
|
-
throw new Error("Invalid ForwardBatchResultPayload: expected an object");
|
|
387
|
-
}
|
|
388
|
-
if (!Array.isArray(decoded.results)) {
|
|
389
|
-
throw new Error('Invalid ForwardBatchResultPayload: "results" must be an array');
|
|
390
|
-
}
|
|
391
|
-
for (let index = 0; index < decoded.results.length; index++) {
|
|
392
|
-
const result = decoded.results[index];
|
|
393
|
-
if (!isRecord(result)) {
|
|
394
|
-
throw new Error(`Invalid ForwardBatchResultPayload: "results[${index}]" must be an object`);
|
|
395
|
-
}
|
|
396
|
-
if (typeof result.documentId !== "string") {
|
|
397
|
-
throw new Error(`Invalid ForwardBatchResultPayload: "results[${index}].documentId" must be a string`);
|
|
398
|
-
}
|
|
399
|
-
if (typeof result.success !== "boolean") {
|
|
400
|
-
throw new Error(`Invalid ForwardBatchResultPayload: "results[${index}].success" must be a boolean`);
|
|
401
|
-
}
|
|
402
|
-
if (result.errorCode !== null && typeof result.errorCode !== "string") {
|
|
403
|
-
throw new Error(`Invalid ForwardBatchResultPayload: "results[${index}].errorCode" must be a string or null`);
|
|
404
|
-
}
|
|
405
|
-
if (result.errorMessage !== null && typeof result.errorMessage !== "string") {
|
|
406
|
-
throw new Error(`Invalid ForwardBatchResultPayload: "results[${index}].errorMessage" must be a string or null`);
|
|
407
|
-
}
|
|
408
|
-
if (result.errorDetails !== void 0 && result.errorDetails !== null && !isPlainObject(result.errorDetails)) {
|
|
409
|
-
throw new Error(`Invalid ForwardBatchResultPayload: "results[${index}].errorDetails" must be an object or absent`);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
return decoded;
|
|
413
|
-
}
|
|
414
|
-
function validateInsyncConfirmPayload(decoded) {
|
|
415
|
-
if (!isRecord(decoded)) {
|
|
416
|
-
throw new Error("Invalid InsyncConfirmPayload: expected an object");
|
|
417
|
-
}
|
|
418
|
-
if (typeof decoded.indexName !== "string") {
|
|
419
|
-
throw new Error('Invalid InsyncConfirmPayload: "indexName" must be a string');
|
|
420
|
-
}
|
|
421
|
-
if (typeof decoded.partitionId !== "number") {
|
|
422
|
-
throw new Error('Invalid InsyncConfirmPayload: "partitionId" must be a number');
|
|
423
|
-
}
|
|
424
|
-
if (typeof decoded.accepted !== "boolean") {
|
|
425
|
-
throw new Error('Invalid InsyncConfirmPayload: "accepted" must be a boolean');
|
|
426
|
-
}
|
|
427
|
-
return decoded;
|
|
428
|
-
}
|
|
429
|
-
function validateAckPayload(decoded) {
|
|
430
|
-
if (!isRecord(decoded)) {
|
|
431
|
-
throw new Error("Invalid AckPayload: expected an object");
|
|
432
|
-
}
|
|
433
|
-
if (typeof decoded.seqNo !== "number") {
|
|
434
|
-
throw new Error('Invalid AckPayload: "seqNo" must be a number');
|
|
435
|
-
}
|
|
436
|
-
if (typeof decoded.partitionId !== "number") {
|
|
437
|
-
throw new Error('Invalid AckPayload: "partitionId" must be a number');
|
|
438
|
-
}
|
|
439
|
-
if (typeof decoded.indexName !== "string") {
|
|
440
|
-
throw new Error('Invalid AckPayload: "indexName" must be a string');
|
|
441
|
-
}
|
|
442
|
-
return decoded;
|
|
443
|
-
}
|
|
444
|
-
function computeEntryChecksum(entry) {
|
|
445
|
-
const payload = encode([
|
|
446
|
-
entry.seqNo,
|
|
447
|
-
entry.primaryTerm,
|
|
448
|
-
entry.operation,
|
|
449
|
-
entry.partitionId,
|
|
450
|
-
entry.indexName,
|
|
451
|
-
entry.documentId,
|
|
452
|
-
entry.document
|
|
453
|
-
]);
|
|
454
|
-
return crc32(payload);
|
|
455
|
-
}
|
|
456
|
-
function buildEntry(fields) {
|
|
457
|
-
return { ...fields, checksum: computeEntryChecksum(fields) };
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
// src/persistence/durability/wal-framing.ts
|
|
461
|
-
var WAL_MAGIC = new Uint8Array([78, 82, 83, 87]);
|
|
462
|
-
var WAL_FORMAT_VERSION = 1;
|
|
463
|
-
var SEGMENT_HEADER_SIZE = 8;
|
|
464
|
-
var RECORD_LENGTH_SIZE = 4;
|
|
465
|
-
var FRAME_CRC_SIZE = 4;
|
|
466
|
-
var MAX_WAL_RECORD_BYTES = 268435456;
|
|
467
|
-
function writeSegmentHeader() {
|
|
468
|
-
const header = new Uint8Array(SEGMENT_HEADER_SIZE);
|
|
469
|
-
header.set(WAL_MAGIC, 0);
|
|
470
|
-
header[4] = WAL_FORMAT_VERSION & 255;
|
|
471
|
-
return header;
|
|
472
|
-
}
|
|
473
|
-
function frameRecord(entry) {
|
|
474
|
-
const payload = encode(entry);
|
|
475
|
-
const frame = new Uint8Array(RECORD_LENGTH_SIZE + payload.length + FRAME_CRC_SIZE);
|
|
476
|
-
const view = new DataView(frame.buffer);
|
|
477
|
-
view.setUint32(0, payload.length, false);
|
|
478
|
-
frame.set(payload, RECORD_LENGTH_SIZE);
|
|
479
|
-
view.setUint32(RECORD_LENGTH_SIZE + payload.length, crc32(payload), false);
|
|
480
|
-
return frame;
|
|
481
|
-
}
|
|
482
|
-
function checkSegmentHeader(data) {
|
|
483
|
-
if (data.length < SEGMENT_HEADER_SIZE) {
|
|
484
|
-
return { ok: false, reason: "segment shorter than the 8-byte header", code: ErrorCodes.PERSISTENCE_WAL_CORRUPT };
|
|
485
|
-
}
|
|
486
|
-
for (let i = 0; i < WAL_MAGIC.length; i += 1) {
|
|
487
|
-
if (data[i] !== WAL_MAGIC[i]) {
|
|
488
|
-
return { ok: false, reason: "missing NRSW magic", code: ErrorCodes.PERSISTENCE_WAL_CORRUPT };
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
const formatVersion = data[4];
|
|
492
|
-
if (formatVersion > WAL_FORMAT_VERSION) {
|
|
493
|
-
return {
|
|
494
|
-
ok: false,
|
|
495
|
-
reason: `WAL format version ${formatVersion} is newer than supported version ${WAL_FORMAT_VERSION}, so a newer release wrote this segment`,
|
|
496
|
-
code: ErrorCodes.ENVELOPE_VERSION_MISMATCH
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
return { ok: true };
|
|
500
|
-
}
|
|
501
|
-
function decodeWalEntry(payload) {
|
|
502
|
-
const decoded = decode(payload);
|
|
503
|
-
const { entry } = validateEntryPayload({ entry: decoded });
|
|
504
|
-
if (computeEntryChecksum(entry) !== entry.checksum) {
|
|
505
|
-
throw new Error("WAL record failed its logical entry checksum");
|
|
506
|
-
}
|
|
507
|
-
return entry;
|
|
508
|
-
}
|
|
509
|
-
function corrupt(message, details) {
|
|
510
|
-
throw new NarsilError(ErrorCodes.PERSISTENCE_WAL_CORRUPT, message, details);
|
|
511
|
-
}
|
|
512
|
-
function readDurableRegion(data, durableByteLength, maxRecordBytes = MAX_WAL_RECORD_BYTES) {
|
|
513
|
-
const header = checkSegmentHeader(data);
|
|
514
|
-
if (!header.ok) {
|
|
515
|
-
throw new NarsilError(header.code, `WAL segment header invalid in durable region: ${header.reason}`, {
|
|
516
|
-
reason: header.reason
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
if (durableByteLength < SEGMENT_HEADER_SIZE || durableByteLength > data.length) {
|
|
520
|
-
corrupt("Commit marker durable byte length is outside the segment", {
|
|
521
|
-
durableByteLength,
|
|
522
|
-
segmentLength: data.length
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
526
|
-
const entries = [];
|
|
527
|
-
let offset = SEGMENT_HEADER_SIZE;
|
|
528
|
-
while (offset < durableByteLength) {
|
|
529
|
-
if (offset + RECORD_LENGTH_SIZE > durableByteLength) {
|
|
530
|
-
corrupt("WAL record length field overruns the durable region", { offset, durableByteLength });
|
|
531
|
-
}
|
|
532
|
-
const recordLength = view.getUint32(offset, false);
|
|
533
|
-
if (recordLength === 0 || recordLength > maxRecordBytes) {
|
|
534
|
-
corrupt("WAL record length is zero or exceeds the maximum record size", { offset, recordLength });
|
|
535
|
-
}
|
|
536
|
-
const payloadStart = offset + RECORD_LENGTH_SIZE;
|
|
537
|
-
const crcStart = payloadStart + recordLength;
|
|
538
|
-
const frameEnd = crcStart + FRAME_CRC_SIZE;
|
|
539
|
-
if (frameEnd > durableByteLength) {
|
|
540
|
-
corrupt("WAL record overruns the durable region", { offset, frameEnd, durableByteLength });
|
|
541
|
-
}
|
|
542
|
-
const payload = data.subarray(payloadStart, crcStart);
|
|
543
|
-
const storedCrc = view.getUint32(crcStart, false);
|
|
544
|
-
if (crc32(payload) !== storedCrc) {
|
|
545
|
-
corrupt("WAL record failed its frame checksum inside the durable region", { offset });
|
|
546
|
-
}
|
|
547
|
-
let entry;
|
|
548
|
-
try {
|
|
549
|
-
entry = decodeWalEntry(payload);
|
|
550
|
-
} catch (err) {
|
|
551
|
-
corrupt("WAL record payload failed to decode inside the durable region", {
|
|
552
|
-
offset,
|
|
553
|
-
cause: err instanceof Error ? err.message : String(err)
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
if (entries.length > 0 && entry.seqNo <= entries[entries.length - 1].seqNo) {
|
|
557
|
-
corrupt("WAL sequence numbers are not strictly increasing", {
|
|
558
|
-
previousSeqNo: entries[entries.length - 1].seqNo,
|
|
559
|
-
seqNo: entry.seqNo
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
entries.push(entry);
|
|
563
|
-
offset = frameEnd;
|
|
564
|
-
}
|
|
565
|
-
return entries;
|
|
566
|
-
}
|
|
567
|
-
function readTailBeyondFrontier(data, durableByteLength, lastDurableSeqNo, maxRecordBytes = MAX_WAL_RECORD_BYTES) {
|
|
568
|
-
const start = Math.max(durableByteLength, SEGMENT_HEADER_SIZE);
|
|
569
|
-
const entries = [];
|
|
570
|
-
if (start >= data.length) {
|
|
571
|
-
return { entries, cleanEnd: start };
|
|
572
|
-
}
|
|
573
|
-
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
574
|
-
let offset = start;
|
|
575
|
-
let cleanEnd = start;
|
|
576
|
-
let previousSeqNo = lastDurableSeqNo;
|
|
577
|
-
while (offset < data.length) {
|
|
578
|
-
if (offset + RECORD_LENGTH_SIZE > data.length) {
|
|
579
|
-
break;
|
|
580
|
-
}
|
|
581
|
-
const recordLength = view.getUint32(offset, false);
|
|
582
|
-
if (recordLength === 0 || recordLength > maxRecordBytes) {
|
|
583
|
-
break;
|
|
584
|
-
}
|
|
585
|
-
const payloadStart = offset + RECORD_LENGTH_SIZE;
|
|
586
|
-
const crcStart = payloadStart + recordLength;
|
|
587
|
-
const frameEnd = crcStart + FRAME_CRC_SIZE;
|
|
588
|
-
if (frameEnd > data.length) {
|
|
589
|
-
break;
|
|
590
|
-
}
|
|
591
|
-
const payload = data.subarray(payloadStart, crcStart);
|
|
592
|
-
if (crc32(payload) !== view.getUint32(crcStart, false)) {
|
|
593
|
-
break;
|
|
594
|
-
}
|
|
595
|
-
let entry;
|
|
596
|
-
try {
|
|
597
|
-
entry = decodeWalEntry(payload);
|
|
598
|
-
} catch {
|
|
599
|
-
break;
|
|
600
|
-
}
|
|
601
|
-
if (entry.seqNo <= previousSeqNo) {
|
|
602
|
-
break;
|
|
603
|
-
}
|
|
604
|
-
entries.push(entry);
|
|
605
|
-
previousSeqNo = entry.seqNo;
|
|
606
|
-
offset = frameEnd;
|
|
607
|
-
cleanEnd = frameEnd;
|
|
608
|
-
}
|
|
609
|
-
return { entries, cleanEnd };
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
// src/persistence/durability/wal-segments.ts
|
|
613
|
-
function walPrefix(indexName, partitionId) {
|
|
614
|
-
return `${indexName}/wal/${partitionId}/`;
|
|
615
|
-
}
|
|
616
|
-
function nextSegmentKey(indexName, partitionId) {
|
|
617
|
-
return `${walPrefix(indexName, partitionId)}next`;
|
|
618
|
-
}
|
|
619
|
-
function segmentStartSeqNo(key, prefix) {
|
|
620
|
-
if (!key.startsWith(prefix)) {
|
|
621
|
-
return null;
|
|
622
|
-
}
|
|
623
|
-
const tail = key.slice(prefix.length);
|
|
624
|
-
if (!/^\d{16}$/.test(tail)) {
|
|
625
|
-
return null;
|
|
626
|
-
}
|
|
627
|
-
const value = Number.parseInt(tail, 10);
|
|
628
|
-
return Number.isSafeInteger(value) ? value : null;
|
|
629
|
-
}
|
|
630
|
-
async function collectSegments(directory, prefix) {
|
|
631
|
-
const keys = await directory.list(prefix);
|
|
632
|
-
const refs = [];
|
|
633
|
-
for (const key of keys) {
|
|
634
|
-
const startSeqNo = segmentStartSeqNo(key, prefix);
|
|
635
|
-
if (startSeqNo !== null) {
|
|
636
|
-
refs.push({ key, startSeqNo });
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
refs.sort((a, b) => a.startSeqNo - b.startSeqNo);
|
|
640
|
-
return refs;
|
|
641
|
-
}
|
|
642
|
-
async function openWal(directory, indexName, partitionId) {
|
|
643
|
-
const prefix = walPrefix(indexName, partitionId);
|
|
644
|
-
const markerBytes = await directory.read(`${prefix}commit`);
|
|
645
|
-
const marker = markerBytes === null ? null : readCommitMarker(markerBytes);
|
|
646
|
-
if (marker === null) {
|
|
647
|
-
return null;
|
|
648
|
-
}
|
|
649
|
-
return { marker, segments: await collectSegments(directory, prefix) };
|
|
650
|
-
}
|
|
651
|
-
async function* readSegmentsInOrder(directory, wal) {
|
|
652
|
-
const { marker, segments } = wal;
|
|
653
|
-
let highestRead = 0;
|
|
654
|
-
for (const { key, startSeqNo } of segments) {
|
|
655
|
-
if (startSeqNo > marker.state.activeSegmentSeqNo) {
|
|
656
|
-
continue;
|
|
657
|
-
}
|
|
658
|
-
const bytes = await directory.read(key);
|
|
659
|
-
if (bytes === null) {
|
|
660
|
-
continue;
|
|
661
|
-
}
|
|
662
|
-
if (startSeqNo < marker.state.activeSegmentSeqNo) {
|
|
663
|
-
const header = checkSegmentHeader(bytes);
|
|
664
|
-
if (!header.ok) {
|
|
665
|
-
throw new NarsilError(header.code, `Sealed WAL segment header invalid: ${header.reason}`, {
|
|
666
|
-
key,
|
|
667
|
-
reason: header.reason
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
const durableEntries2 = readDurableRegion(bytes, bytes.length);
|
|
671
|
-
for (const entry of durableEntries2) highestRead = Math.max(highestRead, entry.seqNo);
|
|
672
|
-
yield { durableEntries: durableEntries2, activeTail: null };
|
|
673
|
-
continue;
|
|
674
|
-
}
|
|
675
|
-
const durableEntries = readDurableRegion(bytes, marker.state.durableByteLength);
|
|
676
|
-
for (const entry of durableEntries) highestRead = Math.max(highestRead, entry.seqNo);
|
|
677
|
-
const tail = readTailBeyondFrontier(
|
|
678
|
-
bytes,
|
|
679
|
-
marker.state.durableByteLength,
|
|
680
|
-
Math.max(highestRead, marker.state.highestDurableSeqNo)
|
|
681
|
-
);
|
|
682
|
-
yield {
|
|
683
|
-
durableEntries,
|
|
684
|
-
activeTail: { key, entries: tail.entries, cleanEnd: tail.cleanEnd, segmentLength: bytes.length }
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
async function readWalSegments(directory, indexName, partitionId) {
|
|
689
|
-
const wal = await openWal(directory, indexName, partitionId);
|
|
690
|
-
if (wal === null) {
|
|
691
|
-
return null;
|
|
692
|
-
}
|
|
693
|
-
const durableEntries = [];
|
|
694
|
-
let highestReadFromWal = 0;
|
|
695
|
-
let activeTail = null;
|
|
696
|
-
for await (const segment of readSegmentsInOrder(directory, wal)) {
|
|
697
|
-
for (const entry of segment.durableEntries) {
|
|
698
|
-
durableEntries.push(entry);
|
|
699
|
-
highestReadFromWal = Math.max(highestReadFromWal, entry.seqNo);
|
|
700
|
-
}
|
|
701
|
-
activeTail = segment.activeTail ?? activeTail;
|
|
702
|
-
}
|
|
703
|
-
return { marker: wal.marker, segments: wal.segments, durableEntries, activeTail, highestReadFromWal };
|
|
704
|
-
}
|
|
705
|
-
function durableRecordMissing(indexName, partitionId, highestRead, marker) {
|
|
706
|
-
return new NarsilError(
|
|
707
|
-
ErrorCodes.PERSISTENCE_WAL_CORRUPT,
|
|
708
|
-
"A durable WAL record is missing: the highest recovered seqNo is below the commit marker",
|
|
709
|
-
{ indexName, partitionId, highestRead, highestDurable: marker.state.highestDurableSeqNo }
|
|
710
|
-
);
|
|
711
|
-
}
|
|
712
|
-
async function* walEntriesInRange(directory, indexName, partitionId, fromSeqNoExclusive, upToSeqNoInclusive) {
|
|
713
|
-
const wal = await openWal(directory, indexName, partitionId);
|
|
714
|
-
if (wal === null) {
|
|
715
|
-
return;
|
|
716
|
-
}
|
|
717
|
-
let highestRead = 0;
|
|
718
|
-
for await (const segment of readSegmentsInOrder(directory, wal)) {
|
|
719
|
-
for (const entry of segment.durableEntries) {
|
|
720
|
-
highestRead = Math.max(highestRead, entry.seqNo);
|
|
721
|
-
if (entry.seqNo > fromSeqNoExclusive && entry.seqNo <= upToSeqNoInclusive) {
|
|
722
|
-
yield entry;
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
if (Math.max(fromSeqNoExclusive, highestRead) < wal.marker.state.highestDurableSeqNo) {
|
|
727
|
-
throw durableRecordMissing(indexName, partitionId, highestRead, wal.marker);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
function writeRecordsOf(documents, written) {
|
|
731
|
-
const seqNos = new Float64Array(documents.length);
|
|
732
|
-
const primaryTerms = new Float64Array(documents.length);
|
|
733
|
-
for (let at = 0; at < documents.length; at++) {
|
|
734
|
-
const entry = written.get(documents[at].docId);
|
|
735
|
-
if (entry === void 0) continue;
|
|
736
|
-
seqNos[at] = entry.seqNo;
|
|
737
|
-
primaryTerms[at] = entry.primaryTerm;
|
|
738
|
-
}
|
|
739
|
-
return { seqNos, primaryTerms };
|
|
740
|
-
}
|
|
741
|
-
function everyVectorFieldIsTopLevel(vectorFieldPaths) {
|
|
742
|
-
for (const fieldPath of vectorFieldPaths) {
|
|
743
|
-
if (fieldPath.includes(".")) return false;
|
|
744
|
-
}
|
|
745
|
-
return vectorFieldPaths.size > 0;
|
|
746
|
-
}
|
|
747
|
-
function documentWithoutVectors(encoded, vectorFieldPaths, leavesVectorsUndecoded) {
|
|
748
|
-
const skipped = leavesVectorsUndecoded ? decodeMapWithoutFields(encoded, vectorFieldPaths) : null;
|
|
749
|
-
if (skipped !== null) return skipped;
|
|
750
|
-
const document = decode(encoded);
|
|
751
|
-
restoreVectorFields(document, vectorFieldPaths);
|
|
752
|
-
return prepareDocumentVectors(document, vectorFieldPaths).partitionDoc;
|
|
753
|
-
}
|
|
754
|
-
async function buildSegmentFromEntries(input) {
|
|
755
|
-
const leavesVectorsUndecoded = everyVectorFieldIsTopLevel(input.vectorFieldPaths);
|
|
756
|
-
const live = /* @__PURE__ */ new Map();
|
|
757
|
-
const deleted = /* @__PURE__ */ new Set();
|
|
758
|
-
const written = /* @__PURE__ */ new Map();
|
|
759
|
-
for await (const entry of input.entries) {
|
|
760
|
-
if (entry.operation === "DELETE") {
|
|
761
|
-
deleted.add(entry.documentId);
|
|
762
|
-
live.delete(entry.documentId);
|
|
763
|
-
written.delete(entry.documentId);
|
|
764
|
-
continue;
|
|
765
|
-
}
|
|
766
|
-
if (entry.document === null) continue;
|
|
767
|
-
live.delete(entry.documentId);
|
|
768
|
-
live.set(entry.documentId, documentWithoutVectors(entry.document, input.vectorFieldPaths, leavesVectorsUndecoded));
|
|
769
|
-
if (input.keepsWriteRecords) written.set(entry.documentId, entry);
|
|
770
|
-
}
|
|
771
|
-
const tombstones = [];
|
|
772
|
-
for (const docId of deleted) {
|
|
773
|
-
if (!live.has(docId)) tombstones.push(docId);
|
|
774
|
-
}
|
|
775
|
-
if (live.size === 0 && tombstones.length === 0) {
|
|
776
|
-
return null;
|
|
777
|
-
}
|
|
778
|
-
const documents = [];
|
|
779
|
-
for (const [docId, document] of live) documents.push({ docId, document });
|
|
780
|
-
const manager = createPartitionManager(input.indexName, input.config, input.language, createPartitionRouter(), 1);
|
|
781
|
-
const payload = buildSegmentPayload(
|
|
782
|
-
documents,
|
|
783
|
-
input.config.schema,
|
|
784
|
-
input.language,
|
|
785
|
-
resolvePartitionInsertOptions(input.config, manager.analysis),
|
|
786
|
-
input.config.trackPositions ?? true
|
|
787
|
-
);
|
|
788
|
-
const segment = createFrozenSegment(
|
|
789
|
-
payload,
|
|
790
|
-
documents.map((entry) => entry.document)
|
|
791
|
-
);
|
|
792
|
-
const built = { selections: [{ segment }], tombstones, docCount: live.size };
|
|
793
|
-
if (input.keepsWriteRecords) built.writeRecords = /* @__PURE__ */ new Map([[segment, writeRecordsOf(documents, written)]]);
|
|
794
|
-
return built;
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
// src/persistence/durability/segment/compaction.ts
|
|
798
|
-
function windowFits(segments, start, windowLength, paged) {
|
|
799
|
-
let documents = 0;
|
|
800
|
-
let bytes = SEGMENT_FILE_FRAMING_SLACK_BYTES;
|
|
801
|
-
for (let at = start; at < start + windowLength; at++) {
|
|
802
|
-
documents += segments[at].docCount;
|
|
803
|
-
bytes += segments[at].bytes;
|
|
804
|
-
}
|
|
805
|
-
if (paged) return bytes * MERGED_SEGMENT_GROWTH_ALLOWANCE <= MERGED_SEGMENT_TARGET_BYTES;
|
|
806
|
-
return documents <= COMPACTION_LARGEST_MERGED_DOCUMENT_COUNT && bytes <= MAX_FILE_BYTES;
|
|
807
|
-
}
|
|
808
|
-
function smallestFittingWindow(segments, windowLength, paged) {
|
|
809
|
-
let best = null;
|
|
810
|
-
let bestBytes = Number.POSITIVE_INFINITY;
|
|
811
|
-
for (let start = 0; start + windowLength <= segments.length; start++) {
|
|
812
|
-
if (!windowFits(segments, start, windowLength, paged)) continue;
|
|
813
|
-
let bytes = 0;
|
|
814
|
-
for (let at = start; at < start + windowLength; at++) bytes += segments[at].bytes;
|
|
815
|
-
if (bytes < bestBytes) {
|
|
816
|
-
bestBytes = bytes;
|
|
817
|
-
best = { start, windowLength };
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
return best;
|
|
821
|
-
}
|
|
822
|
-
function chooseWindow(segments, wantedLength, paged) {
|
|
823
|
-
for (let windowLength = Math.min(wantedLength, segments.length); windowLength >= 2; windowLength--) {
|
|
824
|
-
const window = smallestFittingWindow(segments, windowLength, paged);
|
|
825
|
-
if (window !== null) return window;
|
|
826
|
-
}
|
|
827
|
-
return null;
|
|
828
|
-
}
|
|
829
|
-
function frozenOf(contents) {
|
|
830
|
-
return createSharedFrozenSegment(shareSegmentArrays(contents.arrays, null));
|
|
831
|
-
}
|
|
832
|
-
function applyTimeOrder(frozen, contents) {
|
|
833
|
-
for (let newer = 1; newer < frozen.length; newer++) {
|
|
834
|
-
const replaced = new Set(contents[newer].tombstones);
|
|
835
|
-
const ids = frozen[newer].arrays.idTable;
|
|
836
|
-
for (let ordinal = 0; ordinal < ids.count; ordinal++) replaced.add(ids.idAt(ordinal));
|
|
837
|
-
for (let older = 0; older < newer; older++) {
|
|
838
|
-
for (const docId of replaced) frozen[older].tombstoneDocument(docId);
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
function writeRecordsOf2(frozen, contents) {
|
|
843
|
-
if (contents.every((segment) => segment.writeRecords === void 0)) return void 0;
|
|
844
|
-
const records = /* @__PURE__ */ new Map();
|
|
845
|
-
for (let at = 0; at < frozen.length; at++) {
|
|
846
|
-
const held = contents[at].writeRecords;
|
|
847
|
-
if (held !== void 0) records.set(frozen[at], held);
|
|
848
|
-
}
|
|
849
|
-
return records;
|
|
850
|
-
}
|
|
851
|
-
function retainedTombstones(frozen, contents) {
|
|
852
|
-
const retained = /* @__PURE__ */ new Set();
|
|
853
|
-
for (const segment of contents) {
|
|
854
|
-
for (const docId of segment.tombstones) {
|
|
855
|
-
if (!frozen.some((candidate) => candidate.hasDocument(docId))) retained.add(docId);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
return [...retained];
|
|
859
|
-
}
|
|
860
|
-
async function compactPartitionSegments(input) {
|
|
861
|
-
const { segments, compactionThreshold } = input;
|
|
862
|
-
if (segments.length <= compactionThreshold) {
|
|
863
|
-
return { segments, nextSegmentId: input.nextSegmentId };
|
|
864
|
-
}
|
|
865
|
-
const paged = input.paged === true;
|
|
866
|
-
const window = chooseWindow(segments, segments.length - compactionThreshold + 1, paged);
|
|
867
|
-
if (window === null) {
|
|
868
|
-
return { segments, nextSegmentId: input.nextSegmentId };
|
|
869
|
-
}
|
|
870
|
-
const windowRefs = segments.slice(window.start, window.start + window.windowLength);
|
|
871
|
-
const replacing = (written2) => ({
|
|
872
|
-
segments: [
|
|
873
|
-
...segments.slice(0, window.start),
|
|
874
|
-
...written2.segments,
|
|
875
|
-
...segments.slice(window.start + window.windowLength)
|
|
876
|
-
],
|
|
877
|
-
nextSegmentId: written2.nextSegmentId
|
|
878
|
-
});
|
|
879
|
-
if (paged) {
|
|
880
|
-
const { directory } = input.store;
|
|
881
|
-
if (directory === void 0) return { segments, nextSegmentId: input.nextSegmentId };
|
|
882
|
-
const { mergePagedWindow } = await import('./module-JYHFTVPS.mjs');
|
|
883
|
-
return replacing(
|
|
884
|
-
await mergePagedWindow({
|
|
885
|
-
store: input.store,
|
|
886
|
-
directory,
|
|
887
|
-
indexName: input.indexName,
|
|
888
|
-
partitionId: input.partitionId,
|
|
889
|
-
schema: input.schema,
|
|
890
|
-
partialWordAnalysis: input.partialWordAnalysis,
|
|
891
|
-
textAnalysis: input.textAnalysis,
|
|
892
|
-
nextSegmentId: input.nextSegmentId,
|
|
893
|
-
refs: windowRefs,
|
|
894
|
-
dropsEveryTombstone: window.start === 0
|
|
895
|
-
})
|
|
896
|
-
);
|
|
897
|
-
}
|
|
898
|
-
const contents = [];
|
|
899
|
-
for (const ref of windowRefs) contents.push(await readSegmentFile(input.store, ref));
|
|
900
|
-
const frozen = contents.map(frozenOf);
|
|
901
|
-
applyTimeOrder(frozen, contents);
|
|
902
|
-
const writeRecords = writeRecordsOf2(frozen, contents);
|
|
903
|
-
const written = await writeSegmentsOf({
|
|
904
|
-
store: input.store,
|
|
905
|
-
indexName: input.indexName,
|
|
906
|
-
partitionId: input.partitionId,
|
|
907
|
-
nextSegmentId: input.nextSegmentId,
|
|
908
|
-
schema: input.schema,
|
|
909
|
-
partialWordAnalysis: input.partialWordAnalysis,
|
|
910
|
-
textAnalysis: input.textAnalysis,
|
|
911
|
-
selections: frozen.map((segment) => ({ segment })),
|
|
912
|
-
tombstones: retainedTombstones(frozen, contents),
|
|
913
|
-
mergesIntoOneFile: true,
|
|
914
|
-
...writeRecords === void 0 ? {} : { writeRecords }
|
|
915
|
-
});
|
|
916
|
-
return replacing(written);
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
// src/persistence/durability/segment/write.ts
|
|
920
|
-
function textAnalysisOf(config) {
|
|
921
|
-
let resolved = null;
|
|
922
|
-
const resolve = () => {
|
|
923
|
-
resolved ??= {
|
|
924
|
-
language: getLanguage(config.language ?? "english"),
|
|
925
|
-
options: resolvePartitionInsertOptions(config, resolveIndexAnalysis(config))
|
|
926
|
-
};
|
|
927
|
-
return resolved;
|
|
928
|
-
};
|
|
929
|
-
return {
|
|
930
|
-
get language() {
|
|
931
|
-
return resolve().language;
|
|
932
|
-
},
|
|
933
|
-
get options() {
|
|
934
|
-
return resolve().options;
|
|
935
|
-
}
|
|
936
|
-
};
|
|
937
|
-
}
|
|
938
|
-
function partialWordAnalysisOf(config, text) {
|
|
939
|
-
const fields = partialFieldsOf(config.schema);
|
|
940
|
-
if (fields.length === 0) return null;
|
|
941
|
-
return {
|
|
942
|
-
fields,
|
|
943
|
-
get language() {
|
|
944
|
-
return text.language;
|
|
945
|
-
},
|
|
946
|
-
get options() {
|
|
947
|
-
return text.options;
|
|
948
|
-
}
|
|
949
|
-
};
|
|
950
|
-
}
|
|
951
|
-
function resolveCompactionThreshold(configured) {
|
|
952
|
-
if (!Number.isInteger(configured) || configured <= 0 || configured > MAX_SEGMENTS_PER_PARTITION) {
|
|
953
|
-
return DEFAULT_COMPACTION_THRESHOLD;
|
|
954
|
-
}
|
|
955
|
-
return configured;
|
|
956
|
-
}
|
|
957
|
-
function wholeContentsOf(input, partitionId) {
|
|
958
|
-
const whole = input.wholePartitions?.find((candidate) => candidate.partitionId === partitionId);
|
|
959
|
-
if (whole !== void 0) return whole;
|
|
960
|
-
const captured = input.capturedPartitions?.find((candidate) => candidate.partitionId === partitionId);
|
|
961
|
-
return captured === void 0 ? void 0 : contentsOfCaptured(captured);
|
|
962
|
-
}
|
|
963
|
-
function pagedSettingsOf(context) {
|
|
964
|
-
if (context.input.metadata.textStorage !== "disk") return {};
|
|
965
|
-
return { paged: true, keepsWriteRecords: context.input.keepsWriteRecords === true };
|
|
966
|
-
}
|
|
967
|
-
async function tombstonesOfDelta(context, older, selections, deleted) {
|
|
968
|
-
const { directory } = context.input.store;
|
|
969
|
-
if (context.input.metadata.textStorage !== "disk" || directory === void 0) return deleted;
|
|
970
|
-
const { pagedTombstonesFor } = await import('./module-JYHFTVPS.mjs');
|
|
971
|
-
return pagedTombstonesFor(
|
|
972
|
-
directory,
|
|
973
|
-
older,
|
|
974
|
-
selections.map((selection) => selection.segment),
|
|
975
|
-
deleted
|
|
976
|
-
);
|
|
977
|
-
}
|
|
978
|
-
async function writeWholePartition(context, partitionId, priorPartition, whole) {
|
|
979
|
-
const written = await writeSegmentsOf({
|
|
980
|
-
store: context.input.store,
|
|
981
|
-
indexName: context.indexName,
|
|
982
|
-
partitionId,
|
|
983
|
-
nextSegmentId: priorPartition?.nextSegmentId ?? 0,
|
|
984
|
-
schema: context.input.metadata.schema,
|
|
985
|
-
partialWordAnalysis: context.partialWordAnalysis,
|
|
986
|
-
textAnalysis: context.textAnalysis,
|
|
987
|
-
selections: whole.selections,
|
|
988
|
-
tombstones: [],
|
|
989
|
-
...whole.writeRecords === void 0 ? {} : { writeRecords: whole.writeRecords },
|
|
990
|
-
...pagedSettingsOf(context)
|
|
991
|
-
});
|
|
992
|
-
return { partitionId, nextSegmentId: written.nextSegmentId, segments: written.segments };
|
|
993
|
-
}
|
|
994
|
-
async function writeLoggedChanges(context, partitionId, priorPartition, entries) {
|
|
995
|
-
const built = await buildSegmentFromEntries({
|
|
996
|
-
indexName: context.indexName,
|
|
997
|
-
config: context.config,
|
|
998
|
-
language: getLanguage(context.config.language ?? "english"),
|
|
999
|
-
vectorFieldPaths: context.vectorFieldPaths,
|
|
1000
|
-
entries,
|
|
1001
|
-
keepsWriteRecords: context.input.keepsWriteRecords === true
|
|
1002
|
-
});
|
|
1003
|
-
let segments = priorPartition ? [...priorPartition.segments] : [];
|
|
1004
|
-
let nextSegmentId = priorPartition?.nextSegmentId ?? 0;
|
|
1005
|
-
if (built !== null) {
|
|
1006
|
-
const tombstones = await tombstonesOfDelta(context, segments, built.selections, built.tombstones);
|
|
1007
|
-
const written = await writeSegmentsOf({
|
|
1008
|
-
store: context.input.store,
|
|
1009
|
-
indexName: context.indexName,
|
|
1010
|
-
partitionId,
|
|
1011
|
-
nextSegmentId,
|
|
1012
|
-
schema: context.input.metadata.schema,
|
|
1013
|
-
partialWordAnalysis: context.partialWordAnalysis,
|
|
1014
|
-
textAnalysis: context.textAnalysis,
|
|
1015
|
-
selections: built.selections,
|
|
1016
|
-
tombstones,
|
|
1017
|
-
...built.writeRecords === void 0 ? {} : { writeRecords: built.writeRecords },
|
|
1018
|
-
...pagedSettingsOf(context)
|
|
1019
|
-
});
|
|
1020
|
-
segments.push(...written.segments);
|
|
1021
|
-
nextSegmentId = written.nextSegmentId;
|
|
1022
|
-
}
|
|
1023
|
-
if (segments.length > MAX_SEGMENTS_PER_PARTITION) {
|
|
1024
|
-
throw new NarsilError(
|
|
1025
|
-
ErrorCodes.PERSISTENCE_SAVE_FAILED,
|
|
1026
|
-
`Partition ${partitionId} would exceed the maximum of ${MAX_SEGMENTS_PER_PARTITION} segments`,
|
|
1027
|
-
{ partitionId, segmentCount: segments.length, maximum: MAX_SEGMENTS_PER_PARTITION }
|
|
1028
|
-
);
|
|
1029
|
-
}
|
|
1030
|
-
const compacted = await compactPartitionSegments({
|
|
1031
|
-
store: context.input.store,
|
|
1032
|
-
indexName: context.indexName,
|
|
1033
|
-
partitionId,
|
|
1034
|
-
schema: context.input.metadata.schema,
|
|
1035
|
-
partialWordAnalysis: context.partialWordAnalysis,
|
|
1036
|
-
textAnalysis: context.textAnalysis,
|
|
1037
|
-
segments,
|
|
1038
|
-
nextSegmentId,
|
|
1039
|
-
compactionThreshold: context.compactionThreshold,
|
|
1040
|
-
paged: context.input.metadata.textStorage === "disk"
|
|
1041
|
-
});
|
|
1042
|
-
segments = compacted.segments;
|
|
1043
|
-
nextSegmentId = compacted.nextSegmentId;
|
|
1044
|
-
return { partitionId, nextSegmentId, segments };
|
|
1045
|
-
}
|
|
1046
|
-
function carryForwardUncheckpointedPartitions(prior, targets, partitions, checkpointByPartition) {
|
|
1047
|
-
if (prior === null) return;
|
|
1048
|
-
const covered = new Set(targets.map((target) => target.partitionId));
|
|
1049
|
-
for (const priorPartition of prior.partitions) {
|
|
1050
|
-
if (covered.has(priorPartition.partitionId)) continue;
|
|
1051
|
-
partitions.push(priorPartition);
|
|
1052
|
-
const priorCheckpoint = prior.checkpoint.find((c) => c.partitionId === priorPartition.partitionId);
|
|
1053
|
-
if (priorCheckpoint !== void 0 && !checkpointByPartition.has(priorPartition.partitionId)) {
|
|
1054
|
-
checkpointByPartition.set(priorPartition.partitionId, priorCheckpoint);
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
async function writeCheckpointSegments(input) {
|
|
1059
|
-
const config = reconstructSchemaFromMetadata(input.metadata);
|
|
1060
|
-
const textAnalysis = textAnalysisOf(config);
|
|
1061
|
-
const context = {
|
|
1062
|
-
input,
|
|
1063
|
-
indexName: input.metadata.indexName,
|
|
1064
|
-
config,
|
|
1065
|
-
partialWordAnalysis: partialWordAnalysisOf(config, textAnalysis),
|
|
1066
|
-
textAnalysis,
|
|
1067
|
-
vectorFieldPaths: new Set(extractVectorFieldsFromSchema(config.schema).keys()),
|
|
1068
|
-
compactionThreshold: resolveCompactionThreshold(input.compactionThreshold)
|
|
1069
|
-
};
|
|
1070
|
-
const checkpointByPartition = /* @__PURE__ */ new Map();
|
|
1071
|
-
for (const target of input.targets) checkpointByPartition.set(target.partitionId, { ...target });
|
|
1072
|
-
const partitions = [];
|
|
1073
|
-
for (const target of input.targets) {
|
|
1074
|
-
const priorPartition = input.prior?.partitions.find((p) => p.partitionId === target.partitionId);
|
|
1075
|
-
const whole = wholeContentsOf(input, target.partitionId);
|
|
1076
|
-
if (whole !== void 0) {
|
|
1077
|
-
partitions.push(await writeWholePartition(context, target.partitionId, priorPartition, whole));
|
|
1078
|
-
continue;
|
|
1079
|
-
}
|
|
1080
|
-
if (input.directory === void 0) {
|
|
1081
|
-
throw new NarsilError(
|
|
1082
|
-
ErrorCodes.PERSISTENCE_SAVE_FAILED,
|
|
1083
|
-
`The checkpoint of partition ${target.partitionId} holds neither the partition's content nor a log to read it from`,
|
|
1084
|
-
{ partitionId: target.partitionId }
|
|
1085
|
-
);
|
|
1086
|
-
}
|
|
1087
|
-
const priorSeqNo = checkpointLastSeqNo(input.prior?.checkpoint ?? [], target.partitionId);
|
|
1088
|
-
const entries = walEntriesInRange(
|
|
1089
|
-
input.directory,
|
|
1090
|
-
context.indexName,
|
|
1091
|
-
target.partitionId,
|
|
1092
|
-
priorSeqNo,
|
|
1093
|
-
target.lastSeqNo
|
|
1094
|
-
);
|
|
1095
|
-
partitions.push(await writeLoggedChanges(context, target.partitionId, priorPartition, entries));
|
|
1096
|
-
}
|
|
1097
|
-
carryForwardUncheckpointedPartitions(input.prior, input.targets, partitions, checkpointByPartition);
|
|
1098
|
-
return { checkpoint: [...checkpointByPartition.values()], partitions };
|
|
1099
|
-
}
|
|
1100
|
-
async function commitCheckpointManifest(store, metadata, written, vectors) {
|
|
1101
|
-
const indexName = metadata.indexName;
|
|
1102
|
-
const manifest = {
|
|
1103
|
-
version: SEGMENT_MANIFEST_VERSION,
|
|
1104
|
-
schema: metadata.schema,
|
|
1105
|
-
language: metadata.language,
|
|
1106
|
-
...metadata.analysisGeneration ? { analysisGeneration: metadata.analysisGeneration } : {},
|
|
1107
|
-
checkpoint: written.checkpoint,
|
|
1108
|
-
partitions: written.partitions,
|
|
1109
|
-
vectors
|
|
1110
|
-
};
|
|
1111
|
-
const packed = await encodeSegmentManifest(manifest);
|
|
1112
|
-
await store.write(manifestKey(indexName), packed.chunks);
|
|
1113
|
-
return { garbage: await unreferencedKeys(store, indexName, manifest) };
|
|
1114
|
-
}
|
|
1115
|
-
async function unreferencedKeys(store, indexName, manifest) {
|
|
1116
|
-
const referenced = manifestReferencedKeys(manifest);
|
|
1117
|
-
const stored = await store.list(segmentsPrefix(indexName));
|
|
1118
|
-
return [...stored.filter((key) => !referenced.has(key)), snapshotBundleKey(indexName)];
|
|
1119
|
-
}
|
|
1120
|
-
async function removeCheckpointGarbage(store, garbage) {
|
|
1121
|
-
for (const key of garbage) {
|
|
1122
|
-
await store.remove(key);
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
|
-
export { FRAME_CRC_SIZE, MAX_WAL_RECORD_BYTES, RECORD_LENGTH_SIZE, SEGMENT_HEADER_SIZE, buildEntry, captureWholePartition, checkSegmentHeader, checkpointLastSeqNo, checkpointPrimaryTerm, commitCheckpointManifest, computeEntryChecksum, createAckMessage, createEntryBatchMessage, createEntryMessage, createForwardBatchMessage, createForwardBatchResultMessage, createForwardMessage, createInsyncAddMessage, createInsyncConfirmMessage, createInsyncRemoveMessage, createPrimaryResignMessage, decodeWalEntry, durableRecordMissing, encodeMarkerSlot, frameRecord, markerSlotOffset, nextMarkerSlot, nextSegmentKey, optionalIndexUuid, partitionContentsOf, readCommitMarker, readWalSegments, removeCheckpointGarbage, validateAckPayload, validateEntryBatchPayload, validateEntryPayload, validateForwardBatchPayload, validateForwardBatchResultPayload, validateInsyncConfirmPayload, writeCheckpointSegments, writeSegmentHeader };
|