From 31a8d08bdd523c0e0c02e43e6c2d324bca928bae Mon Sep 17 00:00:00 2001 From: XuanYang-cn Date: Thu, 14 Nov 2024 14:16:38 +0800 Subject: [PATCH] fix: Correct varchar primarykey size calculation (#37617) See also: #37582 --------- Signed-off-by: yangxuan --- internal/flushcommon/writebuffer/delta_buffer_test.go | 4 ++-- .../delegator/deletebuffer/delete_buffer_test.go | 4 ++-- internal/storage/primary_key.go | 3 +-- internal/storage/primary_key_test.go | 10 +++++++++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/internal/flushcommon/writebuffer/delta_buffer_test.go b/internal/flushcommon/writebuffer/delta_buffer_test.go index c7900c14e57d0..7fdbb7f41c025 100644 --- a/internal/flushcommon/writebuffer/delta_buffer_test.go +++ b/internal/flushcommon/writebuffer/delta_buffer_test.go @@ -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) }) } diff --git a/internal/querynodev2/delegator/deletebuffer/delete_buffer_test.go b/internal/querynodev2/delegator/deletebuffer/delete_buffer_test.go index cef7a4a8461d2..44e8c26c1f1e3 100644 --- a/internal/querynodev2/delegator/deletebuffer/delete_buffer_test.go +++ b/internal/querynodev2/delegator/deletebuffer/delete_buffer_test.go @@ -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, @@ -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) { diff --git a/internal/storage/primary_key.go b/internal/storage/primary_key.go index 6e82ec1537598..ed39825c54087 100644 --- a/internal/storage/primary_key.go +++ b/internal/storage/primary_key.go @@ -155,7 +155,6 @@ func (ip *Int64PrimaryKey) GetValue() interface{} { } func (ip *Int64PrimaryKey) Size() int64 { - // 8 + reflect.ValueOf(Int64PrimaryKey).Type().Size() return 16 } @@ -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) { diff --git a/internal/storage/primary_key_test.go b/internal/storage/primary_key_test.go index 8d7edef75daea..12b1f666d424e 100644 --- a/internal/storage/primary_key_test.go +++ b/internal/storage/primary_key_test.go @@ -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