Skip to content

Commit

Permalink
feat: introduce a new method MemHookSet (tikv#1362)
Browse files Browse the repository at this point in the history
Signed-off-by: ekexium <[email protected]>
  • Loading branch information
ekexium authored Jun 14, 2024
1 parent 156cebc commit ac8fa1d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/unionstore/memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,3 +898,8 @@ func (db *MemDB) SetEntrySizeLimit(entryLimit, bufferLimit uint64) {
func (db *MemDB) setSkipMutex(skip bool) {
db.skipMutex = skip
}

// MemHookSet implements the MemBuffer interface.
func (db *MemDB) MemHookSet() bool {
return db.allocator.memChangeHook.Load() != nil
}
5 changes: 5 additions & 0 deletions internal/unionstore/pipelined_memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,8 @@ func (p *PipelinedMemDB) GetFlushMetrics() FlushMetrics {
WaitDuration: p.flushWaitDuration,
}
}

// MemHookSet implements the MemBuffer interface.
func (p *PipelinedMemDB) MemHookSet() bool {
return p.memChangeHook != nil
}
2 changes: 2 additions & 0 deletions internal/unionstore/union_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ type MemBuffer interface {
Dirty() bool
// SetMemoryFootprintChangeHook sets the hook for memory footprint change.
SetMemoryFootprintChangeHook(hook func(uint64))
// MemHookSet returns whether the memory footprint change hook is set.
MemHookSet() bool
// Mem returns the memory usage of MemBuffer.
Mem() uint64
// Len returns the count of entries in the MemBuffer.
Expand Down
5 changes: 5 additions & 0 deletions txnkv/transaction/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1703,3 +1703,8 @@ func (txn *KVTxn) SetRequestSourceType(tp string) {
func (txn *KVTxn) SetExplicitRequestSourceType(tp string) {
txn.RequestSource.SetExplicitRequestSourceType(tp)
}

// MemHookSet returns whether the mem buffer has a memory footprint change hook set.
func (txn *KVTxn) MemHookSet() bool {
return txn.us.GetMemBuffer().MemHookSet()
}

0 comments on commit ac8fa1d

Please sign in to comment.