aboutsummaryrefslogtreecommitdiff
path: root/src/dedo.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/dedo.go31
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