Open
Description
Context
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 = function ttl (db) {
// Imagine a sublevel to which we write expiry metadata
const sublevel = ...
db.hooks.prewrite.add(function (op, batch) {
if (op.type === 'put') {
const exp = Date.now() + op.ttl
batch.add({ type: 'put', sublevel, key: op.key, value: exp })
} else {
batch.add({ type: 'del', sublevel, key: op.key })
}
})
// Background job
setInterval(function sweep () {
// Imagine we're deleting an expired key
db.del('foo').catch(..)
}, 60e3)
}
Solution
db.del('foo', { prewrite: false })
As well as:
db.put('foo', 'bar', { prewrite: false })
db.batch([], { prewrite: false })
db.batch().put('foo', 'bar', { prewrite: false })
db.batch().del('foo', { prewrite: false })
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Todo