Skip to content

Commit

Permalink
fix: do not call onMemChange in alloc, since it will make the latest …
Browse files Browse the repository at this point in the history
…block empty, which breaks a precondition for some operations (e.g. revertToCheckpoint) (#632)

Signed-off-by: ekexium <[email protected]>
  • Loading branch information
ekexium authored Dec 5, 2022
1 parent 50651d6 commit ad59ca8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/unionstore/memdb_arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ func (a *memdbArena) enlarge(allocSize, blockSize int) {
buf: make([]byte, a.blockSize),
})
a.capacity += uint64(a.blockSize)
a.onMemChange()
// We shall not call a.onMemChange() here, since it will make the latest block empty, which breaks a precondition
// for some operations (e.g. revertToCheckpoint)
}

func (a *memdbArena) onMemChange() {
Expand Down Expand Up @@ -250,11 +251,15 @@ func (a *nodeAllocator) getNode(addr memdbArenaAddr) *memdbNode {

func (a *nodeAllocator) allocNode(key []byte) (memdbArenaAddr, *memdbNode) {
nodeSize := 8*4 + 2 + kv.FlagBytes + len(key)
prevBlocks := len(a.blocks)
addr, mem := a.alloc(nodeSize, true)
n := (*memdbNode)(unsafe.Pointer(&mem[0]))
n.vptr = nullAddr
n.klen = uint16(len(key))
copy(n.getKey(), key)
if prevBlocks != len(a.blocks) {
a.onMemChange()
}
return addr, n
}

Expand Down Expand Up @@ -313,13 +318,17 @@ func (hdr *memdbVlogHdr) load(src []byte) {

func (l *memdbVlog) appendValue(nodeAddr memdbArenaAddr, oldValue memdbArenaAddr, value []byte) memdbArenaAddr {
size := memdbVlogHdrSize + len(value)
prevBlocks := len(l.blocks)
addr, mem := l.alloc(size, false)

copy(mem, value)
hdr := memdbVlogHdr{nodeAddr, oldValue, uint32(len(value))}
hdr.store(mem[len(value):])

addr.off += uint32(size)
if prevBlocks != len(l.blocks) {
l.onMemChange()
}
return addr
}

Expand Down

0 comments on commit ad59ca8

Please sign in to comment.