From babf4e37e443ebafd448e9d9b0d2c06383cae482 Mon Sep 17 00:00:00 2001 From: Jiquan Long Date: Fri, 20 Oct 2023 16:30:09 +0800 Subject: [PATCH] Fix partition's gc (#27816) Signed-off-by: longjiquan --- internal/metastore/kv/rootcoord/kv_catalog.go | 5 +++++ .../metastore/kv/rootcoord/kv_catalog_test.go | 20 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/internal/metastore/kv/rootcoord/kv_catalog.go b/internal/metastore/kv/rootcoord/kv_catalog.go index 16b4fcacca..fdbd695228 100644 --- a/internal/metastore/kv/rootcoord/kv_catalog.go +++ b/internal/metastore/kv/rootcoord/kv_catalog.go @@ -523,6 +523,11 @@ func dropPartition(collMeta *pb.CollectionInfo, partitionID typeutil.UniqueID) { func (kc *Catalog) DropPartition(ctx context.Context, dbID int64, collectionID typeutil.UniqueID, partitionID typeutil.UniqueID, ts typeutil.Timestamp) error { collMeta, err := kc.loadCollection(ctx, dbID, collectionID, ts) + if errors.Is(err, merr.ErrCollectionNotFound) { + // collection's gc happened before partition's. + return nil + } + if err != nil { return err } diff --git a/internal/metastore/kv/rootcoord/kv_catalog_test.go b/internal/metastore/kv/rootcoord/kv_catalog_test.go index d1748a1399..54c22f9c08 100644 --- a/internal/metastore/kv/rootcoord/kv_catalog_test.go +++ b/internal/metastore/kv/rootcoord/kv_catalog_test.go @@ -666,10 +666,9 @@ func TestCatalog_DropPartitionV2(t *testing.T) { t.Run("failed to load collection", func(t *testing.T) { ctx := context.Background() - snapshot := kv.NewMockSnapshotKV() - snapshot.LoadFunc = func(key string, ts typeutil.Timestamp) (string, error) { - return "", errors.New("mock") - } + snapshot := mocks.NewSnapShotKV(t) + snapshot.On("Load", + mock.Anything, mock.Anything).Return("not in codec format", nil) kc := Catalog{Snapshot: snapshot} @@ -677,6 +676,19 @@ func TestCatalog_DropPartitionV2(t *testing.T) { assert.Error(t, err) }) + t.Run("failed to load collection, no key found", func(t *testing.T) { + ctx := context.Background() + + snapshot := mocks.NewSnapShotKV(t) + snapshot.On("Load", + mock.Anything, mock.Anything).Return("", merr.WrapErrIoKeyNotFound("partition")) + + kc := Catalog{Snapshot: snapshot} + + err := kc.DropPartition(ctx, 0, 100, 101, 0) + assert.NoError(t, err) + }) + t.Run("partition version after 210", func(t *testing.T) { ctx := context.Background()