Skip to content

Commit

Permalink
simplify the signature
Browse files Browse the repository at this point in the history
Signed-off-by: ekexium <ekexium@fastmail.com>
  • Loading branch information
ekexium committed Jun 24, 2022
1 parent ddfca0d commit 6381d5d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
7 changes: 2 additions & 5 deletions internal/unionstore/memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ var tombstone = []byte{}
// IsTombstone returns whether the value is a tombstone.
func IsTombstone(val []byte) bool { return len(val) == 0 }

// MemoryFootprintChangeHook is a callback that accepts a component's memory footprint in bytes
type MemoryFootprintChangeHook func(footprint uint64)

// MemKeyHandle represents a pointer for key in MemBuffer.
type MemKeyHandle struct {
// Opaque user data
Expand Down Expand Up @@ -862,8 +859,8 @@ func (db *MemDB) RemoveFromBuffer(key []byte) {
}

// SetMemoryFootprintChangeHook sets the hook function that is triggered when memdb grows.
func (db *MemDB) SetMemoryFootprintChangeHook(hook MemoryFootprintChangeHook) {
innerHook := func(capacity uint64) {
func (db *MemDB) SetMemoryFootprintChangeHook(hook func(uint64)) {
innerHook := func() {
hook(db.allocator.capacity + db.vlog.capacity)
}
db.allocator.enlargeHook = innerHook
Expand Down
4 changes: 2 additions & 2 deletions internal/unionstore/memdb_arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type memdbArena struct {
// the total size of all blocks, also the approximate memory footprint of the arena.
capacity uint64
// when it enlarges or shrinks, call this function with the current memory footprint (in bytes)
enlargeHook MemoryFootprintChangeHook
enlargeHook func()
}

func (a *memdbArena) alloc(size int, align bool) (memdbArenaAddr, []byte) {
Expand Down Expand Up @@ -129,7 +129,7 @@ func (a *memdbArena) enlarge(allocSize, blockSize int) {
})
a.capacity += uint64(a.blockSize)
if a.enlargeHook != nil {
a.enlargeHook(a.capacity)
a.enlargeHook()
}
}

Expand Down
11 changes: 1 addition & 10 deletions tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import (
"github.com/tikv/client-go/v2/internal/locate"
"github.com/tikv/client-go/v2/internal/logutil"
"github.com/tikv/client-go/v2/internal/retry"
"github.com/tikv/client-go/v2/internal/unionstore"
"github.com/tikv/client-go/v2/kv"
"github.com/tikv/client-go/v2/metrics"
"github.com/tikv/client-go/v2/oracle"
Expand Down Expand Up @@ -613,7 +612,7 @@ func NewLockResolver(etcdAddrs []string, security config.Security, opts ...pd.Cl
type txnOptions struct {
TxnScope string
StartTS *uint64
MemoryFootprintChangeHook unionstore.MemoryFootprintChangeHook
MemoryFootprintChangeHook func(uint64)
}

// TxnOption configures Transaction
Expand All @@ -633,14 +632,6 @@ func WithStartTS(startTS uint64) TxnOption {
}
}

// WithMemoryFootprintChangeHook sets the MemoryFootprintChangeHook to hook, which is triggered when the memory
// footprint of the mem buffer changes.
func WithMemoryFootprintChangeHook(hook unionstore.MemoryFootprintChangeHook) TxnOption {
return func(st *txnOptions) {
st.MemoryFootprintChangeHook = hook
}
}

// TODO: remove once tidb and br are ready

// KVTxn contains methods to interact with a TiKV transaction.
Expand Down
2 changes: 1 addition & 1 deletion txnkv/transaction/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ func (txn *KVTxn) GetClusterID() uint64 {
}

// SetMemoryFootprintChangeHook sets the hook function that is triggered when memdb grows
func (txn *KVTxn) SetMemoryFootprintChangeHook(hook unionstore.MemoryFootprintChangeHook) {
func (txn *KVTxn) SetMemoryFootprintChangeHook(hook func(uint64)) {
txn.us.GetMemBuffer().SetMemoryFootprintChangeHook(hook)
}

Expand Down

0 comments on commit 6381d5d

Please sign in to comment.