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
I'm working on a rewrite of level-ttl, not because I need it, but to make it use hooks and find out what gaps we in that API.
Problem
If a plugin like level-ttl uses the prewrite hook but also has a background job that writes to the same db, it will trigger its own hook function (as well as other hook functions). E.g.:
module.exports=functionttl(db){// Imagine a sublevel to which we write expiry metadataconstsublevel= ...
db.hooks.prewrite.add(function(op,batch){if(op.type==='put'){constexp=Date.now()+op.ttlbatch.add({type: 'put', sublevel,key: op.key,value: exp})}else{batch.add({type: 'del', sublevel,key: op.key})}})// Background jobsetInterval(functionsweep(){// Imagine we're deleting an expired keydb.del('foo').catch(..)},60e3)}
Activity
vweevers commentedon Nov 20, 2022
Only question is, if
dbis a sublevel, should it forward{ prewrite: false }to its parent database?I think no, to keep it isolated.vweevers commentedon Nov 20, 2022
The
prewritehook is fast, so technically this could also be solved in userland. Like so:And adding a
prewriteoption wouldn't be a breaking change, so I'm removing this from the v2 milestone. Not a blocker.