From 6381d5d416cf623a9d2e03427fd9ce46a35247fc Mon Sep 17 00:00:00 2001 From: ekexium Date: Fri, 24 Jun 2022 15:09:47 +0800 Subject: [PATCH] simplify the signature Signed-off-by: ekexium --- internal/unionstore/memdb.go | 7 ++----- internal/unionstore/memdb_arena.go | 4 ++-- tikv/kv.go | 11 +---------- txnkv/transaction/txn.go | 2 +- 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/internal/unionstore/memdb.go b/internal/unionstore/memdb.go index 71f494b14..5bd8d7fc7 100644 --- a/internal/unionstore/memdb.go +++ b/internal/unionstore/memdb.go @@ -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 @@ -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 diff --git a/internal/unionstore/memdb_arena.go b/internal/unionstore/memdb_arena.go index 67386ac82..f19279023 100644 --- a/internal/unionstore/memdb_arena.go +++ b/internal/unionstore/memdb_arena.go @@ -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) { @@ -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() } } diff --git a/tikv/kv.go b/tikv/kv.go index 643a2f878..140073d6f 100644 --- a/tikv/kv.go +++ b/tikv/kv.go @@ -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" @@ -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 @@ -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. diff --git a/txnkv/transaction/txn.go b/txnkv/transaction/txn.go index e4f553d97..57b1dcb23 100644 --- a/txnkv/transaction/txn.go +++ b/txnkv/transaction/txn.go @@ -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) }