fix: Fix the compatibility bug between stats task and segment (#36359)

issue: #33744

Signed-off-by: Cai Zhang <cai.zhang@zilliz.com>
This commit is contained in:
cai.zhang 2024-09-20 14:33:11 +08:00 committed by GitHub
parent d2c774fb6d
commit 4b077e1bd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View File

@ -115,7 +115,7 @@ func (kc *Catalog) listSegments() ([]*datapb.SegmentInfo, error) {
// due to StatsTaskPrefix has the same prefix with SegmentPrefix, so skip it.
// when the WalkWithPrefix is refactored, this patch can be removed.
if strings.Contains(string(value), StatsTaskPrefix) {
if strings.Contains(string(key), StatsTaskPrefix) {
return nil
}

View File

@ -22,6 +22,7 @@ import (
"log"
"math/rand"
"os"
"path"
"strings"
"testing"
"time"
@ -64,6 +65,7 @@ var (
k6 = buildFieldBinlogPath(collectionID, partitionID, segmentID2, fieldID)
k7 = buildFieldDeltalogPath(collectionID, partitionID, segmentID2, fieldID)
k8 = buildFieldStatslogPath(collectionID, partitionID, segmentID2, fieldID)
k9 = buildStatsTaskKey(10000)
keys = map[string]struct{}{
k1: {},
@ -74,6 +76,7 @@ var (
k6: {},
k7: {},
k8: {},
k9: {},
}
invalidSegment = &datapb.SegmentInfo{
@ -202,6 +205,22 @@ func Test_ListSegments(t *testing.T) {
verifySegments(t, logID, ret)
})
t.Run("test compatibility with stats task", func(t *testing.T) {
metakv := mocks.NewMetaKv(t)
metakv.EXPECT().WalkWithPrefix(mock.Anything, mock.Anything, mock.Anything).RunAndReturn(func(s string, i int, f func([]byte, []byte) error) error {
if strings.HasPrefix(k9, path.Join(s)) {
return f([]byte(k9), nil)
}
return nil
})
catalog := NewCatalog(metakv, rootPath, "")
ret, err := catalog.ListSegments(context.TODO())
assert.NotNil(t, ret)
assert.NoError(t, err)
assert.Zero(t, len(ret))
})
t.Run("list successfully", func(t *testing.T) {
var savedKvs map[string]string