From 4b077e1bd2e1dca763c3005dff36155e54c0d673 Mon Sep 17 00:00:00 2001 From: "cai.zhang" Date: Fri, 20 Sep 2024 14:33:11 +0800 Subject: [PATCH] fix: Fix the compatibility bug between stats task and segment (#36359) issue: #33744 Signed-off-by: Cai Zhang --- internal/metastore/kv/datacoord/kv_catalog.go | 2 +- .../metastore/kv/datacoord/kv_catalog_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/metastore/kv/datacoord/kv_catalog.go b/internal/metastore/kv/datacoord/kv_catalog.go index a0aae7c2bf..a512cf67be 100644 --- a/internal/metastore/kv/datacoord/kv_catalog.go +++ b/internal/metastore/kv/datacoord/kv_catalog.go @@ -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 } diff --git a/internal/metastore/kv/datacoord/kv_catalog_test.go b/internal/metastore/kv/datacoord/kv_catalog_test.go index 567b82f23c..9d3df05270 100644 --- a/internal/metastore/kv/datacoord/kv_catalog_test.go +++ b/internal/metastore/kv/datacoord/kv_catalog_test.go @@ -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