Skip to content

Commit

Permalink
Disallow write transactions on core snapshots (#60)
Browse files Browse the repository at this point in the history
* Disallow write transactions on snapshots

* Throw when creating tx (simplify)
  • Loading branch information
HDegroote authored Jan 15, 2025
1 parent e26f7cc commit 24a91e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const CORE_HINTS = schema.getEncoding('@core/hints')

class CoreTX {
constructor (core, db, view, changes) {
if (db.snapshotted) throw new Error('Cannot open core tx on snapshot')
this.core = core
this.db = db
this.view = view
Expand Down
20 changes: 20 additions & 0 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,23 @@ test('delete bitfield page range', async (t) => {
t.is(b4a.toString(data4), 'bitfield-data-4')
}
})

test('cannot open tx on snapshot', async (t) => {
const core = await createCore(t)

const snap = core.snapshot()
t.exception(
() => snap.write(),
/Cannot open core tx on snapshot/
)
})

test('cannot create sessions on snapshot', async (t) => {
const core = await createCore(t)
const snap = core.snapshot()

await t.exception(
async () => await snap.createSession(),
/Cannot open core tx on snapshot/
)
})

0 comments on commit 24a91e1

Please sign in to comment.