Skip to content

Commit

Permalink
cherry pick pingcap#12470 to release-3.1
Browse files Browse the repository at this point in the history
Signed-off-by: sre-bot <sre-bot@pingcap.com>
  • Loading branch information
H-ZeX authored and sre-bot committed Apr 8, 2020
1 parent f2ebfa2 commit 3f7ad51
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions util/chunk/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func newFixedLenColumn(elemLen, cap int) *column {
return &column{
elemBuf: make([]byte, elemLen),
data: make([]byte, 0, cap*elemLen),
nullBitmap: make([]byte, 0, cap>>3),
nullBitmap: make([]byte, 0, (cap+7)>>3),
}
}

Expand All @@ -147,7 +147,7 @@ func newVarLenColumn(cap int, old *column) *column {
return &column{
offsets: make([]int64, 1, cap+1),
data: make([]byte, 0, cap*estimatedElemLen),
nullBitmap: make([]byte, 0, cap>>3),
nullBitmap: make([]byte, 0, (cap+7)>>3),
}
}

Expand Down
10 changes: 9 additions & 1 deletion util/chunk/chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,19 @@ func (s *testChunkSuite) TestChunkMemoryUsage(c *check.C) {

//cap(c.nullBitmap) + cap(c.offsets)*4 + cap(c.data) + cap(c.elemBuf)
colUsage := make([]int, len(fieldTypes))
<<<<<<< HEAD
colUsage[0] = initCap>>3 + 0 + initCap*4 + 4
colUsage[1] = initCap>>3 + (initCap+1)*4 + initCap*8 + 0
colUsage[2] = initCap>>3 + (initCap+1)*4 + initCap*8 + 0
colUsage[3] = initCap>>3 + 0 + initCap*16 + 16
colUsage[4] = initCap>>3 + 0 + initCap*8 + 8
=======
colUsage[0] = (initCap+7)>>3 + 0 + initCap*4 + 4
colUsage[1] = (initCap+7)>>3 + (initCap+1)*4 + initCap*8 + 0
colUsage[2] = (initCap+7)>>3 + (initCap+1)*4 + initCap*8 + 0
colUsage[3] = (initCap+7)>>3 + 0 + initCap*sizeTime + sizeTime
colUsage[4] = (initCap+7)>>3 + 0 + initCap*8 + 8
>>>>>>> b3ad90e... util: increase column's nullBitmap's capacity (#12470)

expectedUsage := 0
for i := range colUsage {
Expand Down Expand Up @@ -572,7 +580,7 @@ func (s *testChunkSuite) TestChunkMemoryUsage(c *check.C) {
chk.AppendDuration(4, durationObj)

memUsage = chk.MemoryUsage()
colUsage[1] = initCap>>3 + (initCap+1)*4 + cap(chk.columns[1].data) + 0
colUsage[1] = (initCap+7)>>3 + (initCap+1)*4 + cap(chk.columns[1].data) + 0
expectedUsage = 0
for i := range colUsage {
expectedUsage += colUsage[i] + int(unsafe.Sizeof(*chk.columns[i]))
Expand Down

0 comments on commit 3f7ad51

Please sign in to comment.