fix: incorrect memory size and delta count in SegmentInfo (#35369)

issue: #35368

Signed-off-by: jaime <yun.zhang@zilliz.com>
pull/35377/head
jaime 2024-08-13 17:20:19 +08:00 committed by GitHub
parent 196b343a94
commit 1b0ea49d25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 2 deletions

View File

@ -473,8 +473,9 @@ func SetLevel(level datapb.SegmentLevel) SegmentInfoOption {
} }
} }
// getSegmentSize use cached value when segment is immutable
func (s *SegmentInfo) getSegmentSize() int64 { func (s *SegmentInfo) getSegmentSize() int64 {
if s.size.Load() <= 0 || s.GetState() == commonpb.SegmentState_Growing { if s.size.Load() <= 0 || s.GetState() != commonpb.SegmentState_Flushed {
var size int64 var size int64
for _, binlogs := range s.GetBinlogs() { for _, binlogs := range s.GetBinlogs() {
for _, l := range binlogs.GetBinlogs() { for _, l := range binlogs.GetBinlogs() {
@ -500,8 +501,9 @@ func (s *SegmentInfo) getSegmentSize() int64 {
return s.size.Load() return s.size.Load()
} }
// getDeltaCount use cached value when segment is immutable
func (s *SegmentInfo) getDeltaCount() int64 { func (s *SegmentInfo) getDeltaCount() int64 {
if s.deltaRowcount.Load() < 0 { if s.deltaRowcount.Load() < 0 || s.State != commonpb.SegmentState_Flushed {
var rc int64 var rc int64
for _, deltaLogs := range s.GetDeltalogs() { for _, deltaLogs := range s.GetDeltalogs() {
for _, l := range deltaLogs.GetBinlogs() { for _, l := range deltaLogs.GetBinlogs() {

View File

@ -97,6 +97,46 @@ func TestCompactionTo(t *testing.T) {
assert.Nil(t, s) assert.Nil(t, s)
} }
func TestGetSegmentSize(t *testing.T) {
segment := &SegmentInfo{
SegmentInfo: &datapb.SegmentInfo{
Binlogs: []*datapb.FieldBinlog{
{
Binlogs: []*datapb.Binlog{
{
LogID: 1,
MemorySize: 1,
},
},
},
},
Statslogs: []*datapb.FieldBinlog{
{
Binlogs: []*datapb.Binlog{
{
LogID: 1,
MemorySize: 1,
},
},
},
},
Deltalogs: []*datapb.FieldBinlog{
{
Binlogs: []*datapb.Binlog{
{
LogID: 1,
MemorySize: 1,
},
},
},
},
},
}
assert.Equal(t, int64(3), segment.getSegmentSize())
assert.Equal(t, int64(3), segment.getSegmentSize())
}
func TestIsDeltaLogExists(t *testing.T) { func TestIsDeltaLogExists(t *testing.T) {
segment := &SegmentInfo{ segment := &SegmentInfo{
SegmentInfo: &datapb.SegmentInfo{ SegmentInfo: &datapb.SegmentInfo{