func (db *MemDB) DiscardValues() {
	db.vlogInvalid = true
	db.vlog.reset()
}
DiscardValues releases the memory used by all values.
NOTE: any operation need value will panic after this function.
package unionstore
import (
	"bytes"
	"math"
	"reflect"
	"sync"
	"unsafe"
	tikverr "github.com/tikv/client-go/v2/error"
	"github.com/tikv/client-go/v2/kv"
)
var tombstone = []byte{}
func IsTombstone(val []byte) bool { return len(val) == 0 }
type MemKeyHandle struct {
	UserData uint16
	idx      uint16
	off      uint32
}
func (h MemKeyHandle) toAddr() memdbArenaAddr {
	return memdbArenaAddr{idx: uint32(h.idx), off: h.off}
}
type MemDB struct {
	sync.RWMutex
	root      memdbArenaAddr
	allocator nodeAllocator
	vlog      memdbVlog
	entrySizeLimit  uint64
	bufferSizeLimit uint64
	count           int
	size            int
	vlogInvalid bool
	dirty       bool
	stages      []memdbCheckpoint
}
func newMemDB() *MemDB {
	db := new(MemDB)
	db.allocator.init()
	db.root = nullAddr
	db.stages = make([]memdbCheckpoint, 0, 2)
	db.entrySizeLimit = math.MaxUint64
	db.bufferSizeLimit = math.MaxUint64
	return db
}
func (db *MemDB) Staging() int {
	db.Lock()
	defer db.Unlock()
	db.stages = append(db.stages, db.vlog.checkpoint())
	return len(db.stages)
}
func (db *MemDB) Release(h int) {
	if h != len(db.stages) {
		panic("cannot release staging buffer")
	}
	db.Lock()
	defer db.Unlock()
	if h == 1 {
		tail := db.vlog.checkpoint()
		if !db.stages[0].isSamePosition(&tail) {
			db.dirty = true
		}
	}
	db.stages = db.stages[:h-1]
}
func (db *MemDB) Cleanup(h int) {
	if h > len(db.stages) {
		return
	}
	if h < len(db.stages) {
		panic("cannot cleanup staging buffer")
	}
	db.Lock()
	defer db.Unlock()
	cp := &db.stages[h-1]
	if !db.vlogInvalid {
		curr := db.vlog.checkpoint()
		if !curr.isSamePosition(cp) {
			db.vlog.revertToCheckpoint(db, cp)
			db.vlog.truncate(cp)
		}
	}
	db.stages = db.stages[:h-1]
}
func (db *MemDB) Reset() {
	db.root = nullAddr
	db.stages = db.stages[:0]
	db.dirty = false
	db.vlogInvalid = false
	db.size = 0
	db.count = 0
	db.vlog.reset()
	db.allocator.reset()
}