Skip to content

Commit

Permalink
fix: Correct varchar primarykey size calculation (milvus-io#37617)
Browse files Browse the repository at this point in the history
See also: milvus-io#37582

---------

Signed-off-by: yangxuan <[email protected]>
  • Loading branch information
XuanYang-cn authored Nov 14, 2024
1 parent cd181e4 commit 31a8d08
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions internal/flushcommon/writebuffer/delta_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func (s *DeltaBufferSuite) TestBuffer() {
})

memSize := deltaBuffer.Buffer(pks, tss, &msgpb.MsgPosition{Timestamp: 100}, &msgpb.MsgPosition{Timestamp: 200})
// 40 = (3*8+8)(string pk) + 8(ts)
s.EqualValues(100*40, memSize)
// 19 = (3+8)(string pk) + 8(ts)
s.EqualValues(100*19, memSize)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (s *DoubleCacheBufferSuite) TestPut() {
s.Equal(1, len(buffer.ListAfter(12)))
entryNum, memorySize := buffer.Size()
s.EqualValues(2, entryNum)
s.EqualValues(304, memorySize)
s.EqualValues(234, memorySize)

buffer.Put(&Item{
Ts: 13,
Expand All @@ -133,7 +133,7 @@ func (s *DoubleCacheBufferSuite) TestPut() {
s.Equal(1, len(buffer.ListAfter(13)))
entryNum, memorySize = buffer.Size()
s.EqualValues(2, entryNum)
s.EqualValues(304, memorySize)
s.EqualValues(234, memorySize)
}

func TestDoubleCacheDeleteBuffer(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions internal/storage/primary_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ func (ip *Int64PrimaryKey) GetValue() interface{} {
}

func (ip *Int64PrimaryKey) Size() int64 {
// 8 + reflect.ValueOf(Int64PrimaryKey).Type().Size()
return 16
}

Expand Down Expand Up @@ -256,7 +255,7 @@ func (vcp *VarCharPrimaryKey) Type() schemapb.DataType {
}

func (vcp *VarCharPrimaryKey) Size() int64 {
return int64(8*len(vcp.Value) + 8)
return int64(len(vcp.Value) + 8)
}

func GenPrimaryKeyByRawData(data interface{}, pkType schemapb.DataType) (PrimaryKey, error) {
Expand Down
10 changes: 9 additions & 1 deletion internal/storage/primary_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ import (
)

func TestVarCharPrimaryKey(t *testing.T) {
pk := NewVarCharPrimaryKey("milvus")
t.Run("size", func(t *testing.T) {
longString := "The High-Performance Vector Database Built for Scale"
pk := NewVarCharPrimaryKey(longString)
gotSize := pk.Size()
expectSize := len(longString) + 8

assert.EqualValues(t, expectSize, gotSize)
})

pk := NewVarCharPrimaryKey("milvus")
testPk := NewVarCharPrimaryKey("milvus")

// test GE
Expand Down

0 comments on commit 31a8d08

Please sign in to comment.