fix: Correct varchar primarykey size calculation (#37617)

See also: #37582

---------

Signed-off-by: yangxuan <xuan.yang@zilliz.com>
This commit is contained in:
XuanYang-cn 2024-11-14 14:16:38 +08:00 committed by GitHub
parent cd181e4c6d
commit 31a8d08bdd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 7 deletions

View File

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

View File

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

View File

@ -155,7 +155,6 @@ func (ip *Int64PrimaryKey) GetValue() interface{} {
} }
func (ip *Int64PrimaryKey) Size() int64 { func (ip *Int64PrimaryKey) Size() int64 {
// 8 + reflect.ValueOf(Int64PrimaryKey).Type().Size()
return 16 return 16
} }
@ -256,7 +255,7 @@ func (vcp *VarCharPrimaryKey) Type() schemapb.DataType {
} }
func (vcp *VarCharPrimaryKey) Size() int64 { 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) { func GenPrimaryKeyByRawData(data interface{}, pkType schemapb.DataType) (PrimaryKey, error) {

View File

@ -10,8 +10,16 @@ import (
) )
func TestVarCharPrimaryKey(t *testing.T) { 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") testPk := NewVarCharPrimaryKey("milvus")
// test GE // test GE