Skip to content

Commit

Permalink
s/GetMemoryDelta/GetAndCleanMemoryDelta
Browse files Browse the repository at this point in the history
  • Loading branch information
wshwsh12 committed Apr 19, 2022
1 parent 33551d5 commit 7d358db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions executor/hash_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (c *hashRowContainer) PutChunkSelected(chk *chunk.Chunk, selected, ignoreNu
rowPtr := chunk.RowPtr{ChkIdx: chkIdx, RowIdx: uint32(i)}
c.hashTable.Put(key, rowPtr)
}
c.GetMemTracker().Consume(c.hashTable.GetMemoryDelta())
c.GetMemTracker().Consume(c.hashTable.GetAndCleanMemoryDelta())
return nil
}

Expand Down Expand Up @@ -280,9 +280,9 @@ type baseHashTable interface {
Put(hashKey uint64, rowPtr chunk.RowPtr)
Get(hashKey uint64) (rowPtrs []chunk.RowPtr)
Len() uint64
// GetMemoryDelta gets the memDelta of the baseHashTable. Memory delta will be cleared after each fetch.
// It indicates the memory delta of the baseHashTable since the last calling GetMemoryDelta().
GetMemoryDelta() int64
// GetAndCleanMemoryDelta gets and cleans the memDelta of the baseHashTable. Memory delta will be cleared after each fetch.
// It indicates the memory delta of the baseHashTable since the last calling GetAndCleanMemoryDelta().
GetAndCleanMemoryDelta() int64
}

// TODO (fangzhuhe) remove unsafeHashTable later if it not used anymore
Expand All @@ -295,7 +295,7 @@ type unsafeHashTable struct {
length uint64

bInMap int64 // indicate there are 2^bInMap buckets in hashMap
memDelta int64 // the memory delta of the unsafeHashTable since the last calling GetMemoryDelta()
memDelta int64 // the memory delta of the unsafeHashTable since the last calling GetAndCleanMemoryDelta()
}

// newUnsafeHashTable creates a new unsafeHashTable. estCount means the estimated size of the hashMap.
Expand Down Expand Up @@ -336,8 +336,8 @@ func (ht *unsafeHashTable) Get(hashKey uint64) (rowPtrs []chunk.RowPtr) {
// if the same key is put more than once.
func (ht *unsafeHashTable) Len() uint64 { return ht.length }

// GetMemoryDelta gets the memDelta of the unsafeHashTable.
func (ht *unsafeHashTable) GetMemoryDelta() int64 {
// GetAndCleanMemoryDelta gets and cleans the memDelta of the unsafeHashTable.
func (ht *unsafeHashTable) GetAndCleanMemoryDelta() int64 {
memDelta := ht.memDelta
ht.memDelta = 0
return memDelta
Expand All @@ -348,7 +348,7 @@ type concurrentMapHashTable struct {
hashMap concurrentMap
entryStore *entryStore
length uint64
memDelta int64 // the memory delta of the concurrentMapHashTable since the last calling GetMemoryDelta()
memDelta int64 // the memory delta of the concurrentMapHashTable since the last calling GetAndCleanMemoryDelta()
}

// newConcurrentMapHashTable creates a concurrentMapHashTable
Expand Down Expand Up @@ -388,8 +388,8 @@ func (ht *concurrentMapHashTable) Get(hashKey uint64) (rowPtrs []chunk.RowPtr) {
return
}

// GetMemoryDelta gets the memDelta of the concurrentMapHashTable. Memory delta will be cleared after each fetch.
func (ht *concurrentMapHashTable) GetMemoryDelta() int64 {
// GetAndCleanMemoryDelta gets and cleans the memDelta of the concurrentMapHashTable. Memory delta will be cleared after each fetch.
func (ht *concurrentMapHashTable) GetAndCleanMemoryDelta() int64 {
var memDelta int64
for {
memDelta = atomic.LoadInt64(&ht.memDelta)
Expand Down
4 changes: 2 additions & 2 deletions executor/hash_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,6 @@ func TestConcurrentMapHashTableMemoryUsage(t *testing.T) {
}
mapMemoryExpected := int64(1024) * hack.DefBucketMemoryUsageForMapIntToPtr
entryMemoryExpected := 16 * int64(64+128+256+512+1024+2048+4096)
require.Equal(t, mapMemoryExpected+entryMemoryExpected, m.GetMemoryDelta())
require.Equal(t, int64(0), m.GetMemoryDelta())
require.Equal(t, mapMemoryExpected+entryMemoryExpected, m.GetAndCleanMemoryDelta())
require.Equal(t, int64(0), m.GetAndCleanMemoryDelta())
}

0 comments on commit 7d358db

Please sign in to comment.