Skip to content

Commit

Permalink
Add an RemoveFromBuffer method for test (#387)
Browse files Browse the repository at this point in the history
* export DeleteKey

Signed-off-by: ekexium <ekexium@gmail.com>

* rename DeleteKey to UnsafeRemoveRecord

Signed-off-by: ekexium <ekexium@gmail.com>

* rename the old DeleteKey

Signed-off-by: ekexium <ekexium@gmail.com>
  • Loading branch information
ekexium authored Nov 30, 2021
1 parent b11da63 commit 350b6ce
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 10 additions & 0 deletions internal/unionstore/memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,3 +833,13 @@ func (n *memdbNode) getKeyFlags() kv.KeyFlags {
func (n *memdbNode) setKeyFlags(f kv.KeyFlags) {
n.flags = (^nodeFlagsMask & n.flags) | uint16(f)
}

// RemoveFromBuffer removes a record from the mem buffer. It should be only used for test.
func (db *MemDB) RemoveFromBuffer(key []byte) {
x := db.traverse(key, false)
if x.isNull() {
return
}
db.size -= len(db.vlog.getValue(x.vptr))
db.deleteNode(x)
}
2 changes: 1 addition & 1 deletion internal/unionstore/memdb_norace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestRandom(t *testing.T) {
for _, k := range keys {
op := rand.Float64()
if op < 0.35 {
p1.DeleteKey(k)
p1.RemoveFromBuffer(k)
p2.Delete(k)
} else {
newValue := make([]byte, rand.Intn(19)+1)
Expand Down
10 changes: 0 additions & 10 deletions internal/unionstore/memdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ func init() {
testMode = true
}

// DeleteKey is used in test to verify the `deleteNode` used in `vlog.revertToCheckpoint`.
func (db *MemDB) DeleteKey(key []byte) {
x := db.traverse(key, false)
if x.isNull() {
return
}
db.size -= len(db.vlog.getValue(x.vptr))
db.deleteNode(x)
}

func TestGetSet(t *testing.T) {
require := require.New(t)

Expand Down

0 comments on commit 350b6ce

Please sign in to comment.