fix: update() field asymmetry causing index corruption
CRITICAL: Fixed metadata index corruption on update() operations where removalMetadata only contained custom metadata + type, while entityForIndexing contained ALL indexed fields. This caused 7 fields to accumulate on every update, eventually making queries return 0 results. - Fix removalMetadata to include all indexed fields (src/brainy.ts) - Add validateIndexConsistency() and getIndexStats() public APIs - Add auto-corruption detection and repair on startup - Add getOrAssignSync() for EntityIdMapper persistence - Add comprehensive regression tests
This commit is contained in:
parent
478c6e6342
commit
a94219e720
5 changed files with 470 additions and 4 deletions
|
|
@ -86,6 +86,26 @@ export class EntityIdMapper {
|
|||
return newId
|
||||
}
|
||||
|
||||
/**
|
||||
* v7.5.0: Get integer ID for UUID with immediate persistence guarantee
|
||||
* Unlike getOrAssign(), this method flushes to storage immediately after assigning
|
||||
* a new ID. This prevents UUID→int mapping divergence if the process crashes
|
||||
* before a normal flush() occurs.
|
||||
*
|
||||
* Use this for critical operations where data integrity is paramount.
|
||||
* Normal operations can use getOrAssign() with batched flushing for better performance.
|
||||
*/
|
||||
async getOrAssignSync(uuid: string): Promise<number> {
|
||||
const id = this.getOrAssign(uuid)
|
||||
|
||||
// If a new ID was assigned, immediately persist to storage
|
||||
if (this.dirty) {
|
||||
await this.flush()
|
||||
}
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
/**
|
||||
* Get UUID for integer ID
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue