You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A write after ensureLoaded() evicts an expired record corrupts the secondary index #2937
Writing a record right after ensureLoaded() evicted it for expiry corrupts the table's secondary index on both storage engines. It needs a table with no source, a TTL expiration, and a resource method that calls this.ensureLoaded() before writing. On an expired record, ensureLoaded() takes the no-source expiry branch of ensureLoadedFromSource (resources/Table.ts), which evicts the record by nulling entry.value on the loaded entry object in place. The write that follows then diffs its index entries against that mutated entry instead of the stored record.
Reproduce
Observed on main at 2d81ebc (Node 24.21). Target.evict is stubbed so the eviction does not land, which leaves the stored record as the only correct base:
constTarget=table({database: 'repro',table: 'Target',attributes: [{name: 'id',isPrimaryKey: true},{name: 'value',indexed: true}],});Target.setTTLExpiration({expiration: 0.005});Target.evict=()=>Promise.resolve();awaitTarget.put('expired',{value: 1});awaitnewPromise((resolve)=>setTimeout(resolve,20));classLoadsFirstextendsTarget{asyncput(data,target){awaitthis.ensureLoaded();returnsuper.put(data,target);}}awaitLoadsFirst.put('expired',{value: 2});// search value = 1 / value = 2:// RocksDB: value 1 still returns 'expired' (orphaned index entry)// LMDB: value 2 returns nothing (missing index entry)
Expected
The record is { value: 2 } and only the value = 2 index entry exists. The in-place entry.value = null in the expiry branch is the likely root: an entry object the resource (and, on LMDB, the write's ifVersion base) still holds should not be mutated. Evicting through a fresh entry, or reloading the write base after an eviction, would avoid it.
Found while testing a write-path change that reuses the pre-load as the commit base (which is correct on RocksDB for this case); this reproduces on main without it.
Activity