Skip to content

Commit

Permalink
pre allocate cache key for the block cache and the bloom filter cache (
Browse files Browse the repository at this point in the history
…#1371)

Signed-off-by: Tiger <rbalajis25@gmail.com>
  • Loading branch information
poonai authored and Ibrahim Jarif committed Oct 2, 2020
1 parent 2892a1f commit df41006
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,13 @@ func (t *Table) block(idx int) (*block, error) {
// bfCacheKey returns the cache key for bloom filter.
func (t *Table) bfCacheKey() []byte {
y.AssertTrue(t.id < math.MaxUint32)
buf := make([]byte, 4)
binary.BigEndian.PutUint32(buf, uint32(t.id))

buf := make([]byte, 6)
// Without the "bf" prefix, we will have conflict with the blockCacheKey.
return append([]byte("bf"), buf...)
buf[0] = 'b'
buf[1] = 'f'

binary.BigEndian.PutUint32(buf[2:], uint32(t.id))
return buf
}

func (t *Table) blockCacheKey(idx int) []byte {
Expand All @@ -617,10 +619,12 @@ func (t *Table) blockCacheKey(idx int) []byte {
// blockOffsetsCacheKey returns the cache key for block offsets.
func (t *Table) blockOffsetsCacheKey() []byte {
y.AssertTrue(t.id < math.MaxUint32)
buf := make([]byte, 4, 6)
binary.BigEndian.PutUint32(buf, uint32(t.id))
buf := make([]byte, 6)
buf[0] = 'b'
buf[1] = 'o'

return append([]byte("bo"), buf...)
binary.BigEndian.PutUint32(buf[2:], uint32(t.id))
return buf
}

// EstimatedSize returns the total size of key-values stored in this table (including the
Expand Down

0 comments on commit df41006

Please sign in to comment.