From f58a0d04ff431206d00a9add8ac98e1b94aae12b Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 18 Oct 2023 09:52:37 +0300 Subject: [PATCH] [#233] Clean tag node in the tree service instead of removal With new retry policy of tree service pool, gateway should avoid deletion of system nodes from tree. Absence of node in the tree will trigger retry. Other storage in the network may return already deleted node while tree is not completely synced, and client will get unexpected result. Signed-off-by: Alex Vanin --- api/layer/tree_mock.go | 10 ++-------- pkg/service/tree/tree.go | 22 ++-------------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/api/layer/tree_mock.go b/api/layer/tree_mock.go index ffdedc2a..abe7a0db 100644 --- a/api/layer/tree_mock.go +++ b/api/layer/tree_mock.go @@ -49,14 +49,8 @@ func (t *TreeServiceMock) PutObjectTagging(_ context.Context, bktInfo *data.Buck return nil } -func (t *TreeServiceMock) DeleteObjectTagging(_ context.Context, bktInfo *data.BucketInfo, objVersion *data.NodeVersion) error { - cnrTagsMap, ok := t.tags[bktInfo.CID.EncodeToString()] - if !ok { - return nil - } - - delete(cnrTagsMap, objVersion.ID) - return nil +func (t *TreeServiceMock) DeleteObjectTagging(ctx context.Context, bktInfo *data.BucketInfo, objVersion *data.NodeVersion) error { + return t.PutObjectTagging(ctx, bktInfo, objVersion, nil) } func (t *TreeServiceMock) GetBucketTagging(context.Context, *data.BucketInfo) (map[string]string, error) { diff --git a/pkg/service/tree/tree.go b/pkg/service/tree/tree.go index edc58ee7..fbab21a9 100644 --- a/pkg/service/tree/tree.go +++ b/pkg/service/tree/tree.go @@ -476,16 +476,7 @@ func (c *Tree) PutObjectTagging(ctx context.Context, bktInfo *data.BucketInfo, o } func (c *Tree) DeleteObjectTagging(ctx context.Context, bktInfo *data.BucketInfo, objVersion *data.NodeVersion) error { - tagNode, err := c.getTreeNode(ctx, bktInfo, objVersion.ID, isTagKV) - if err != nil { - return err - } - - if tagNode == nil { - return nil - } - - return c.service.RemoveNode(ctx, bktInfo, versionTree, tagNode.ID) + return c.PutObjectTagging(ctx, bktInfo, objVersion, nil) } func (c *Tree) GetBucketTagging(ctx context.Context, bktInfo *data.BucketInfo) (map[string]string, error) { @@ -529,16 +520,7 @@ func (c *Tree) PutBucketTagging(ctx context.Context, bktInfo *data.BucketInfo, t } func (c *Tree) DeleteBucketTagging(ctx context.Context, bktInfo *data.BucketInfo) error { - node, err := c.getSystemNode(ctx, bktInfo, []string{bucketTaggingFilename}, nil) - if err != nil && !errors.Is(err, layer.ErrNodeNotFound) { - return err - } - - if node != nil { - return c.service.RemoveNode(ctx, bktInfo, systemTree, node.ID) - } - - return nil + return c.PutBucketTagging(ctx, bktInfo, nil) } func (c *Tree) getTreeNode(ctx context.Context, bktInfo *data.BucketInfo, nodeID uint64, key string) (*treeNode, error) {