diff options
author | EuAndreh <eu@euandre.org> | 2025-02-09 18:11:48 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2025-02-09 18:15:45 -0300 |
commit | 4cc8296024c7015b4e6e7dcd9b4efd3e247b16d4 (patch) | |
tree | 823e8c7056a4da3faa5cc7b1b82561246ff834eb /src/dedo.go | |
parent | src/dedo.go: Move transactionT to the beginning of the file (diff) | |
download | dedo-4cc8296024c7015b4e6e7dcd9b4efd3e247b16d4.tar.gz dedo-4cc8296024c7015b4e6e7dcd9b4efd3e247b16d4.tar.xz |
src/dedo.go: Introduce snapshotT type
Diffstat (limited to '')
-rw-r--r-- | src/dedo.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/dedo.go b/src/dedo.go index 2bb805e..580e6a6 100644 --- a/src/dedo.go +++ b/src/dedo.go @@ -91,6 +91,13 @@ type DatabaseI interface{ Path() string } +type snapshotT struct{ + db *DB + meta *meta + root roBucketT + pages map[pgid]*page +} + /// transactionT represents a read-only or read/write transaction on the /// database. Read-only transactions can be used for retrieving values for keys /// and creating cursors. Read/write transactions can create and remove buckets @@ -582,6 +589,16 @@ func newBucket(tx *transactionT) Bucket { return b } +/// newBucket() returns a new bucket associated with a transaction. +func newSnapshotBucket(snapshot *snapshotT) Bucket { + return Bucket{tx: &transactionT{ + db: snapshot.db, + meta: snapshot.meta, + root: snapshot.root, + pages: snapshot.pages, + }} +} + /// Bucket.Cursor() creates a cursor associated with the bucket. The cursor is /// only valid as long as the transaction is open. Do not use a cursor after /// the transaction is closed. @@ -3458,6 +3475,20 @@ func mergepgids(dst, a, b pgids) { _ = append(merged, follow...) } +func (snapshot *snapshotT) init(db *DB) { + snapshot.db = db + snapshot.pages = nil + + // Copy the meta page since it can be changed by the writer. + snapshot.meta = &meta{} + db.meta().copy(snapshot.meta) + + // Copy over the root bucket. + snapshot.root = newSnapshotBucket(snapshot) + snapshot.root.ref = &bucket{} + *snapshot.root.ref = snapshot.meta.root +} + /// transactionT.init() initializes the transaction. func (tx *transactionT) init(db *DB) { tx.db = db |