fix: flush all native providers on shutdown to prevent data loss

Shutdown/close/flush now properly flushes all 4 components in parallel:
metadataIndex, graphIndex, HNSW dirty nodes, and storage counts. Previously
only counts were flushed, causing native provider data loss on restart.

Also:
- Wire roaring, msgpack, entityIdMapper provider consumption from plugins
- Fix allOf filter O(n²) intersection → O(n) Set-based
- Fix ne/exists negation filter to use Set-based exclusion
- Add setMsgpackImplementation() swap in SSTable for native msgpack
- Add setRoaringImplementation() swap for native CRoaring bitmaps
- Add getAllIntIds() to EntityIdMapper for bitmap operations
- Remove TypeAwareHNSWIndex from default index creation path
- Export memory detection utilities from internals
- Clean up 26 permanently-skipped dead tests
This commit is contained in:
David Snelling 2026-02-01 16:23:49 -08:00
parent b87426409d
commit 773c5171c3
24 changed files with 297 additions and 1268 deletions

View file

@ -14,9 +14,23 @@
* - Footer: checksum, stats
*/
import { encode, decode } from '@msgpack/msgpack'
import { encode as defaultEncode, decode as defaultDecode } from '@msgpack/msgpack'
import { BloomFilter, SerializedBloomFilter } from './BloomFilter.js'
// Swappable msgpack implementation — defaults to @msgpack/msgpack JS,
// can be replaced with native msgpack (e.g., cortex's Rust-backed encoder)
let _encode: (data: unknown) => Uint8Array = defaultEncode as (data: unknown) => Uint8Array
let _decode: (data: Uint8Array) => unknown = defaultDecode as (data: Uint8Array) => unknown
/**
* Replace the msgpack encode/decode implementation at runtime.
* Called by brainy.ts when a cortex 'msgpack' provider is registered.
*/
export function setMsgpackImplementation(impl: { encode: (data: unknown) => Uint8Array, decode: (data: Uint8Array) => unknown }) {
_encode = impl.encode
_decode = impl.decode
}
/**
* Entry in the SSTable
* Maps a source node to its target nodes
@ -299,7 +313,7 @@ export class SSTable {
checksum: this.calculateChecksum(this.entries)
}
const serialized = encode(data)
const serialized = _encode(data)
// Update size in metadata
this.metadata.sizeBytes = serialized.length
@ -331,7 +345,7 @@ export class SSTable {
* @returns SSTable instance
*/
static deserialize(data: Uint8Array): SSTable {
const decoded = decode(data) as SerializedSSTable
const decoded = _decode(data) as SerializedSSTable
// Verify checksum
const sstable = new SSTable(