Skip to content

Commit

Permalink
fix memdb snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
absolutelightning committed Jul 20, 2024
1 parent 7b2c2af commit d728330
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func TestWatchUpdate(t *testing.T) {
watchSetPrefix.Add(watch)

// Write to a snapshot.
snap := db.Snapshot(true)
snap := db.Snapshot()
txn2 := snap.Txn(true) // write
noErr(t, txn2.Delete("people", raw))
txn2.Commit()
Expand Down
10 changes: 5 additions & 5 deletions memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ func (db *MemDB) DBSchema() *DBSchema {
}

// getRoot is used to do an atomic load of the root pointer
func (db *MemDB) getRoot(clone bool) *iradix.Tree {
func (db *MemDB) getRoot(snap bool) *iradix.Tree {
root := (*iradix.Tree)(atomic.LoadPointer(&db.root))
if clone {
root = root.Clone()
if snap {
root = root.Snapshot()

Check failure on line 69 in memdb.go

View workflow job for this annotation

GitHub Actions / go-test (oldstable)

root.Snapshot undefined (type *iradix.Tree has no field or method Snapshot)

Check failure on line 69 in memdb.go

View workflow job for this annotation

GitHub Actions / go-test (oldstable)

root.Snapshot undefined (type *iradix.Tree has no field or method Snapshot)

Check failure on line 69 in memdb.go

View workflow job for this annotation

GitHub Actions / go-test (stable)

root.Snapshot undefined (type *iradix.Tree has no field or method Snapshot)

Check failure on line 69 in memdb.go

View workflow job for this annotation

GitHub Actions / go-test (stable)

root.Snapshot undefined (type *iradix.Tree has no field or method Snapshot)
}
return root
}
Expand All @@ -91,10 +91,10 @@ func (db *MemDB) Txn(write bool) *Txn {
// If MemDB is storing reference-based values (pointers, maps, slices, etc.),
// the Snapshot will not deep copy those values. Therefore, it is still unsafe
// to modify any inserted values in either DB.
func (db *MemDB) Snapshot(write bool) *MemDB {
func (db *MemDB) Snapshot() *MemDB {
clone := &MemDB{
schema: db.schema,
root: unsafe.Pointer(db.getRoot(write)),
root: unsafe.Pointer(db.getRoot(true)),
primary: false,
}
return clone
Expand Down
4 changes: 2 additions & 2 deletions memdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestMemDB_Snapshot(t *testing.T) {
txn.Commit()

// Clone the db
db2 := db.Snapshot(true)
db2 := db.Snapshot()

// Remove the object
txn = db.Txn(true)
Expand Down Expand Up @@ -101,7 +101,7 @@ func BenchmarkMemDB_Snapshot(b *testing.B) {
txn.Commit()
}
// Clone the db
snap := db.Snapshot(false)
snap := db.Snapshot()
fmt.Println(snap.getRoot(false).Len())
fmt.Println(counter)
}
8 changes: 6 additions & 2 deletions txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func (txn *Txn) readableIndex(table, index string) *iradix.Txn {
// Create a read transaction
path := indexPath(table, index)
raw, _ := txn.rootTxn.Get(path)
indexTxn := raw.(*iradix.Tree).Txn()
tree := raw.(*iradix.Tree)
tree.Root().SetSnapShotNode(txn.rootTxn.Root().GetSnapshotNode())

Check failure on line 75 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (oldstable)

tree.Root().SetSnapShotNode undefined (type *iradix.Node has no field or method SetSnapShotNode)

Check failure on line 75 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (oldstable)

txn.rootTxn.Root().GetSnapshotNode undefined (type *iradix.Node has no field or method GetSnapshotNode)

Check failure on line 75 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (oldstable)

tree.Root().SetSnapShotNode undefined (type *iradix.Node has no field or method SetSnapShotNode)

Check failure on line 75 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (oldstable)

txn.rootTxn.Root().GetSnapshotNode undefined (type *iradix.Node has no field or method GetSnapshotNode)

Check failure on line 75 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (stable)

tree.Root().SetSnapShotNode undefined (type *iradix.Node has no field or method SetSnapShotNode)

Check failure on line 75 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (stable)

txn.rootTxn.Root().GetSnapshotNode undefined (type *iradix.Node has no field or method GetSnapshotNode)

Check failure on line 75 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (stable)

tree.Root().SetSnapShotNode undefined (type *iradix.Node has no field or method SetSnapShotNode)

Check failure on line 75 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (stable)

txn.rootTxn.Root().GetSnapshotNode undefined (type *iradix.Node has no field or method GetSnapshotNode)
indexTxn := tree.Txn()
return indexTxn
}

Expand All @@ -92,7 +94,9 @@ func (txn *Txn) writableIndex(table, index string) *iradix.Txn {
// Start a new transaction
path := indexPath(table, index)
raw, _ := txn.rootTxn.Get(path)
indexTxn := raw.(*iradix.Tree).Txn()
tree := raw.(*iradix.Tree)
tree.Root().SetSnapShotNode(txn.rootTxn.Root().GetSnapshotNode())

Check failure on line 98 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (oldstable)

tree.Root().SetSnapShotNode undefined (type *iradix.Node has no field or method SetSnapShotNode)

Check failure on line 98 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (oldstable)

txn.rootTxn.Root().GetSnapshotNode undefined (type *iradix.Node has no field or method GetSnapshotNode)

Check failure on line 98 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (oldstable)

tree.Root().SetSnapShotNode undefined (type *iradix.Node has no field or method SetSnapShotNode)

Check failure on line 98 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (oldstable)

txn.rootTxn.Root().GetSnapshotNode undefined (type *iradix.Node has no field or method GetSnapshotNode)

Check failure on line 98 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (stable)

tree.Root().SetSnapShotNode undefined (type *iradix.Node has no field or method SetSnapShotNode)

Check failure on line 98 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (stable)

txn.rootTxn.Root().GetSnapshotNode undefined (type *iradix.Node has no field or method GetSnapshotNode)

Check failure on line 98 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (stable)

tree.Root().SetSnapShotNode undefined (type *iradix.Node has no field or method SetSnapShotNode)

Check failure on line 98 in txn.go

View workflow job for this annotation

GitHub Actions / go-test (stable)

txn.rootTxn.Root().GetSnapshotNode undefined (type *iradix.Node has no field or method GetSnapshotNode)
indexTxn := tree.Txn()

// If we are the primary DB, enable mutation tracking. Snapshots should
// not notify, otherwise we will trigger watches on the primary DB when
Expand Down

0 comments on commit d728330

Please sign in to comment.