diff --git a/api/handler/util.go b/api/handler/util.go index 3665488..48b5eae 100644 --- a/api/handler/util.go +++ b/api/handler/util.go @@ -12,6 +12,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data" s3errors "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer" + "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware" frosterrors "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/frostfs/errors" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/logs" @@ -67,7 +68,7 @@ func transformToS3Error(err error) error { } if errors.Is(err, layer.ErrAccessDenied) || - errors.Is(err, layer.ErrNodeAccessDenied) { + errors.Is(err, tree.ErrNodeAccessDenied) { return s3errors.GetAPIError(s3errors.ErrAccessDenied) } diff --git a/api/handler/util_test.go b/api/handler/util_test.go index 587f92c..6b18b42 100644 --- a/api/handler/util_test.go +++ b/api/handler/util_test.go @@ -7,6 +7,7 @@ import ( s3errors "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer" + "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree" "github.com/stretchr/testify/require" ) @@ -33,7 +34,7 @@ func TestTransformS3Errors(t *testing.T) { }, { name: "layer node access denied error to s3 access denied error", - err: layer.ErrNodeAccessDenied, + err: tree.ErrNodeAccessDenied, expected: s3errors.ErrAccessDenied, }, { diff --git a/api/layer/compound.go b/api/layer/compound.go index 7ff3e37..28fc61e 100644 --- a/api/layer/compound.go +++ b/api/layer/compound.go @@ -7,6 +7,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data" s3errors "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors" + "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree" ) func (n *Layer) GetObjectTaggingAndLock(ctx context.Context, objVersion *data.ObjectVersion, nodeVersion *data.NodeVersion) (map[string]string, data.LockInfo, error) { @@ -29,7 +30,7 @@ func (n *Layer) GetObjectTaggingAndLock(ctx context.Context, objVersion *data.Ob tags, lockInfo, err = n.treeService.GetObjectTaggingAndLock(ctx, objVersion.BktInfo, nodeVersion) if err != nil { - if errors.Is(err, ErrNodeNotFound) { + if errors.Is(err, tree.ErrNodeNotFound) { return nil, data.LockInfo{}, fmt.Errorf("%w: %s", s3errors.GetAPIError(s3errors.ErrNoSuchKey), err.Error()) } return nil, data.LockInfo{}, err diff --git a/api/layer/cors.go b/api/layer/cors.go index 43c0491..44549c3 100644 --- a/api/layer/cors.go +++ b/api/layer/cors.go @@ -9,6 +9,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors" + "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/logs" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -61,7 +62,7 @@ func (n *Layer) PutBucketCORS(ctx context.Context, p *PutCORSParams) error { } objsToDelete, err := n.treeService.PutBucketCORS(ctx, p.BktInfo, newAddress(corsBkt.CID, createdObj.ID)) - objToDeleteNotFound := errorsStd.Is(err, ErrNoNodeToRemove) + objToDeleteNotFound := errorsStd.Is(err, tree.ErrNoNodeToRemove) if err != nil && !objToDeleteNotFound { return err } @@ -104,7 +105,7 @@ func (n *Layer) GetBucketCORS(ctx context.Context, bktInfo *data.BucketInfo) (*d func (n *Layer) DeleteBucketCORS(ctx context.Context, bktInfo *data.BucketInfo) error { objs, err := n.treeService.DeleteBucketCORS(ctx, bktInfo) - objNotFound := errorsStd.Is(err, ErrNoNodeToRemove) + objNotFound := errorsStd.Is(err, tree.ErrNoNodeToRemove) if err != nil && !objNotFound { return err } diff --git a/api/layer/layer.go b/api/layer/layer.go index 6a46562..09ba4b5 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -20,6 +20,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors" s3errors "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/encryption" + "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/logs" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer" @@ -52,7 +53,7 @@ type ( anonKey AnonymousKey resolver BucketResolver cache *Cache - treeService TreeService + treeService tree.TreeService features FeatureSettings gateKey *keys.PrivateKey corsCnrInfo *data.BucketInfo @@ -65,7 +66,7 @@ type ( Cache *Cache AnonKey AnonymousKey Resolver BucketResolver - TreeService TreeService + TreeService tree.TreeService Features FeatureSettings GateKey *keys.PrivateKey CORSCnrInfo *data.BucketInfo @@ -663,7 +664,7 @@ func (n *Layer) getNodeVersionsToDelete(ctx context.Context, bkt *data.BucketInf var versionsToDelete []*data.NodeVersion versions, err := n.treeService.GetVersions(ctx, bkt, obj.Name) if err != nil { - if stderrors.Is(err, ErrNodeNotFound) { + if stderrors.Is(err, tree.ErrNodeNotFound) { return nil, fmt.Errorf("%w: %s", s3errors.GetAPIError(s3errors.ErrNoSuchKey), err.Error()) } return nil, err diff --git a/api/layer/lifecycle.go b/api/layer/lifecycle.go index ad052aa..2def9d1 100644 --- a/api/layer/lifecycle.go +++ b/api/layer/lifecycle.go @@ -11,6 +11,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data" apiErr "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors" + "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/logs" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "go.uber.org/zap" @@ -59,7 +60,7 @@ func (n *Layer) PutBucketLifecycleConfiguration(ctx context.Context, p *PutBucke } objsToDelete, err := n.treeService.PutBucketLifecycleConfiguration(ctx, p.BktInfo, newAddress(lifecycleBkt.CID, createdObj.ID)) - objsToDeleteNotFound := errors.Is(err, ErrNoNodeToRemove) + objsToDeleteNotFound := errors.Is(err, tree.ErrNoNodeToRemove) if err != nil && !objsToDeleteNotFound { return err } @@ -98,7 +99,7 @@ func (n *Layer) GetBucketLifecycleConfiguration(ctx context.Context, bktInfo *da } addr, err := n.treeService.GetBucketLifecycleConfiguration(ctx, bktInfo) - objNotFound := errors.Is(err, ErrNodeNotFound) + objNotFound := errors.Is(err, tree.ErrNodeNotFound) if err != nil && !objNotFound { return nil, err } @@ -132,7 +133,7 @@ func (n *Layer) GetBucketLifecycleConfiguration(ctx context.Context, bktInfo *da func (n *Layer) DeleteBucketLifecycleConfiguration(ctx context.Context, bktInfo *data.BucketInfo) error { objs, err := n.treeService.DeleteBucketLifecycleConfiguration(ctx, bktInfo) - objsNotFound := errors.Is(err, ErrNoNodeToRemove) + objsNotFound := errors.Is(err, tree.ErrNoNodeToRemove) if err != nil && !objsNotFound { return err } diff --git a/api/layer/multipart_upload.go b/api/layer/multipart_upload.go index 24ffa0e..212626f 100644 --- a/api/layer/multipart_upload.go +++ b/api/layer/multipart_upload.go @@ -19,6 +19,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data" s3errors "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/encryption" + "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/logs" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user" @@ -187,7 +188,7 @@ func (n *Layer) CreateMultipartUpload(ctx context.Context, p *CreateMultipartPar func (n *Layer) UploadPart(ctx context.Context, p *UploadPartParams) (string, error) { multipartInfo, err := n.treeService.GetMultipartUpload(ctx, p.Info.Bkt, p.Info.Key, p.Info.UploadID) if err != nil { - if errors.Is(err, ErrNodeNotFound) { + if errors.Is(err, tree.ErrNodeNotFound) { return "", fmt.Errorf("%w: %s", s3errors.GetAPIError(s3errors.ErrNoSuchUpload), err.Error()) } return "", err @@ -291,7 +292,7 @@ func (n *Layer) uploadPart(ctx context.Context, multipartInfo *data.MultipartInf } oldPartIDs, err := n.treeService.AddPart(ctx, bktInfo, multipartInfo.ID, partInfo) - oldPartIDNotFound := errors.Is(err, ErrNoNodeToRemove) + oldPartIDNotFound := errors.Is(err, tree.ErrNoNodeToRemove) if err != nil && !oldPartIDNotFound { return nil, err } @@ -323,7 +324,7 @@ func (n *Layer) uploadPart(ctx context.Context, multipartInfo *data.MultipartInf func (n *Layer) UploadPartCopy(ctx context.Context, p *UploadCopyParams) (*data.ObjectInfo, error) { multipartInfo, err := n.treeService.GetMultipartUpload(ctx, p.Info.Bkt, p.Info.Key, p.Info.UploadID) if err != nil { - if errors.Is(err, ErrNodeNotFound) { + if errors.Is(err, tree.ErrNodeNotFound) { return nil, fmt.Errorf("%w: %s", s3errors.GetAPIError(s3errors.ErrNoSuchUpload), err.Error()) } return nil, err @@ -646,7 +647,7 @@ func (p PartsInfo) Extract(part int, etag string, md5Enabled bool) *data.PartInf func (n *Layer) getUploadParts(ctx context.Context, p *UploadInfoParams) (*data.MultipartInfo, PartsInfo, error) { multipartInfo, err := n.treeService.GetMultipartUpload(ctx, p.Bkt, p.Key, p.UploadID) if err != nil { - if errors.Is(err, ErrNodeNotFound) { + if errors.Is(err, tree.ErrNodeNotFound) { return nil, nil, fmt.Errorf("%w: %s", s3errors.GetAPIError(s3errors.ErrNoSuchUpload), err.Error()) } return nil, nil, err diff --git a/api/layer/object.go b/api/layer/object.go index fa8b2a9..4780ee5 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -21,6 +21,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/auth" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data" apiErrors "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors" + "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/logs" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/pkg/detector" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" @@ -395,7 +396,7 @@ func (n *Layer) headLastVersionIfNotDeleted(ctx context.Context, bkt *data.Bucke node, err := n.treeService.GetLatestVersion(ctx, bkt, objectName) if err != nil { - if errors.Is(err, ErrNodeNotFound) { + if errors.Is(err, tree.ErrNodeNotFound) { return nil, fmt.Errorf("%w: %s", apiErrors.GetAPIError(apiErrors.ErrNoSuchKey), err.Error()) } return nil, err @@ -431,7 +432,7 @@ func (n *Layer) headVersion(ctx context.Context, bkt *data.BucketInfo, p *HeadOb if p.VersionID == data.UnversionedObjectVersionID { foundVersion, err = n.treeService.GetUnversioned(ctx, bkt, p.Object) if err != nil { - if errors.Is(err, ErrNodeNotFound) { + if errors.Is(err, tree.ErrNodeNotFound) { return nil, fmt.Errorf("%w: %s", apiErrors.GetAPIError(apiErrors.ErrNoSuchVersion), err.Error()) } return nil, err diff --git a/api/layer/system_object.go b/api/layer/system_object.go index 81f0b3f..02156c5 100644 --- a/api/layer/system_object.go +++ b/api/layer/system_object.go @@ -12,6 +12,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors" + "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" ) @@ -40,7 +41,7 @@ func (n *Layer) PutLockInfo(ctx context.Context, p *PutLockInfoParams) (err erro } lockInfo, err := n.treeService.GetLock(ctx, p.ObjVersion.BktInfo, versionNode.ID) - if err != nil && !errorsStd.Is(err, ErrNodeNotFound) { + if err != nil && !errorsStd.Is(err, tree.ErrNodeNotFound) { return err } @@ -146,7 +147,7 @@ func (n *Layer) GetLockInfo(ctx context.Context, objVersion *data.ObjectVersion) } lockInfo, err := n.treeService.GetLock(ctx, objVersion.BktInfo, versionNode.ID) - if err != nil && !errorsStd.Is(err, ErrNodeNotFound) { + if err != nil && !errorsStd.Is(err, tree.ErrNodeNotFound) { return nil, err } if lockInfo == nil { @@ -165,7 +166,7 @@ func (n *Layer) getCORS(ctx context.Context, bkt *data.BucketInfo) (*data.CORSCo } addr, err := n.treeService.GetBucketCORS(ctx, bkt) - objNotFound := errorsStd.Is(err, ErrNodeNotFound) + objNotFound := errorsStd.Is(err, tree.ErrNodeNotFound) if err != nil && !objNotFound { return nil, err } @@ -209,7 +210,7 @@ func (n *Layer) GetBucketSettings(ctx context.Context, bktInfo *data.BucketInfo) settings, err := n.treeService.GetSettingsNode(ctx, bktInfo) if err != nil { - if !errorsStd.Is(err, ErrNodeNotFound) { + if !errorsStd.Is(err, tree.ErrNodeNotFound) { return nil, err } settings = &data.BucketSettings{Versioning: data.VersioningUnversioned} diff --git a/api/layer/tagging.go b/api/layer/tagging.go index 293b6f6..2081096 100644 --- a/api/layer/tagging.go +++ b/api/layer/tagging.go @@ -7,6 +7,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data" s3errors "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors" + "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/logs" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -39,7 +40,7 @@ func (n *Layer) GetObjectTagging(ctx context.Context, p *data.GetObjectTaggingPa tags, err := n.treeService.GetObjectTagging(ctx, p.ObjectVersion.BktInfo, nodeVersion) if err != nil { - if errors.Is(err, ErrNodeNotFound) { + if errors.Is(err, tree.ErrNodeNotFound) { return "", nil, fmt.Errorf("%w: %s", s3errors.GetAPIError(s3errors.ErrNoSuchKey), err.Error()) } return "", nil, err @@ -62,7 +63,7 @@ func (n *Layer) PutObjectTagging(ctx context.Context, p *data.PutObjectTaggingPa err = n.treeService.PutObjectTagging(ctx, p.ObjectVersion.BktInfo, nodeVersion, p.TagSet) if err != nil { - if errors.Is(err, ErrNodeNotFound) { + if errors.Is(err, tree.ErrNodeNotFound) { return fmt.Errorf("%w: %s", s3errors.GetAPIError(s3errors.ErrNoSuchKey), err.Error()) } return err @@ -81,7 +82,7 @@ func (n *Layer) DeleteObjectTagging(ctx context.Context, p *data.ObjectVersion) err = n.treeService.DeleteObjectTagging(ctx, p.BktInfo, version) if err != nil { - if errors.Is(err, ErrNodeNotFound) { + if errors.Is(err, tree.ErrNodeNotFound) { return fmt.Errorf("%w: %s", s3errors.GetAPIError(s3errors.ErrNoSuchKey), err.Error()) } return err @@ -102,7 +103,7 @@ func (n *Layer) GetBucketTagging(ctx context.Context, bktInfo *data.BucketInfo) } tags, err := n.treeService.GetBucketTagging(ctx, bktInfo) - if err != nil && !errors.Is(err, ErrNodeNotFound) { + if err != nil && !errors.Is(err, tree.ErrNodeNotFound) { return nil, err } @@ -161,7 +162,7 @@ func (n *Layer) getNodeVersion(ctx context.Context, objVersion *data.ObjectVersi if err == nil && version.IsDeleteMarker && !objVersion.NoErrorOnDeleteMarker { return nil, fmt.Errorf("%w: found version is delete marker", s3errors.GetAPIError(s3errors.ErrNoSuchKey)) - } else if errors.Is(err, ErrNodeNotFound) { + } else if errors.Is(err, tree.ErrNodeNotFound) { return nil, fmt.Errorf("%w: %s", s3errors.GetAPIError(s3errors.ErrNoSuchKey), err.Error()) } diff --git a/api/layer/tree_service.go b/api/layer/tree/tree_service.go similarity index 99% rename from api/layer/tree_service.go rename to api/layer/tree/tree_service.go index 5a2047a..ab658d9 100644 --- a/api/layer/tree_service.go +++ b/api/layer/tree/tree_service.go @@ -1,4 +1,4 @@ -package layer +package tree import ( "context" diff --git a/api/layer/tree_mock.go b/api/layer/tree_mock.go index 8a85ffb..577f406 100644 --- a/api/layer/tree_mock.go +++ b/api/layer/tree_mock.go @@ -9,6 +9,7 @@ import ( "time" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data" + "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" ) @@ -105,7 +106,7 @@ func (t *TreeServiceMock) PutSettingsNode(_ context.Context, bktInfo *data.Bucke func (t *TreeServiceMock) GetSettingsNode(_ context.Context, bktInfo *data.BucketInfo) (*data.BucketSettings, error) { settings, ok := t.settings[bktInfo.CID.EncodeToString()] if !ok { - return nil, ErrNodeNotFound + return nil, tree.ErrNodeNotFound } return settings, nil @@ -140,7 +141,7 @@ func (t *TreeServiceMock) PutBucketCORS(_ context.Context, bktInfo *data.BucketI t.system[bktInfo.CID.EncodeToString()] = systemMap - return nil, ErrNoNodeToRemove + return nil, tree.ErrNoNodeToRemove } func (t *TreeServiceMock) DeleteBucketCORS(context.Context, *data.BucketInfo) ([]oid.Address, error) { @@ -150,12 +151,12 @@ func (t *TreeServiceMock) DeleteBucketCORS(context.Context, *data.BucketInfo) ([ func (t *TreeServiceMock) GetVersions(_ context.Context, bktInfo *data.BucketInfo, objectName string) ([]*data.NodeVersion, error) { cnrVersionsMap, ok := t.versions[bktInfo.CID.EncodeToString()] if !ok { - return nil, ErrNodeNotFound + return nil, tree.ErrNodeNotFound } versions, ok := cnrVersionsMap[objectName] if !ok { - return nil, ErrNodeNotFound + return nil, tree.ErrNodeNotFound } return versions, nil @@ -164,12 +165,12 @@ func (t *TreeServiceMock) GetVersions(_ context.Context, bktInfo *data.BucketInf func (t *TreeServiceMock) GetLatestVersion(_ context.Context, bktInfo *data.BucketInfo, objectName string) (*data.NodeVersion, error) { cnrVersionsMap, ok := t.versions[bktInfo.CID.EncodeToString()] if !ok { - return nil, ErrNodeNotFound + return nil, tree.ErrNodeNotFound } versions, ok := cnrVersionsMap[objectName] if !ok { - return nil, ErrNodeNotFound + return nil, tree.ErrNodeNotFound } sort.Slice(versions, func(i, j int) bool { @@ -180,13 +181,13 @@ func (t *TreeServiceMock) GetLatestVersion(_ context.Context, bktInfo *data.Buck return versions[len(versions)-1], nil } - return nil, ErrNodeNotFound + return nil, tree.ErrNodeNotFound } func (t *TreeServiceMock) InitVersionsByPrefixStream(_ context.Context, bktInfo *data.BucketInfo, prefix string, latestOnly bool) (data.VersionsStream, error) { cnrVersionsMap, ok := t.versions[bktInfo.CID.EncodeToString()] if !ok { - return nil, ErrNodeNotFound + return nil, tree.ErrNodeNotFound } var result []*data.NodeVersion @@ -218,12 +219,12 @@ func (t *TreeServiceMock) InitVersionsByPrefixStream(_ context.Context, bktInfo func (t *TreeServiceMock) GetUnversioned(_ context.Context, bktInfo *data.BucketInfo, objectName string) (*data.NodeVersion, error) { cnrVersionsMap, ok := t.versions[bktInfo.CID.EncodeToString()] if !ok { - return nil, ErrNodeNotFound + return nil, tree.ErrNodeNotFound } versions, ok := cnrVersionsMap[objectName] if !ok { - return nil, ErrNodeNotFound + return nil, tree.ErrNodeNotFound } for _, version := range versions { @@ -232,7 +233,7 @@ func (t *TreeServiceMock) GetUnversioned(_ context.Context, bktInfo *data.Bucket } } - return nil, ErrNodeNotFound + return nil, tree.ErrNodeNotFound } func (t *TreeServiceMock) AddVersion(_ context.Context, bktInfo *data.BucketInfo, newVersion *data.NodeVersion) (uint64, error) { @@ -278,7 +279,7 @@ func (t *TreeServiceMock) AddVersion(_ context.Context, bktInfo *data.BucketInfo func (t *TreeServiceMock) RemoveVersion(_ context.Context, bktInfo *data.BucketInfo, nodeID uint64) error { cnrVersionsMap, ok := t.versions[bktInfo.CID.EncodeToString()] if !ok { - return ErrNodeNotFound + return tree.ErrNodeNotFound } for key, versions := range cnrVersionsMap { @@ -290,7 +291,7 @@ func (t *TreeServiceMock) RemoveVersion(_ context.Context, bktInfo *data.BucketI } } - return ErrNodeNotFound + return tree.ErrNodeNotFound } func (t *TreeServiceMock) GetAllVersionsByPrefix(_ context.Context, bktInfo *data.BucketInfo, prefix string) ([]*data.NodeVersion, error) { @@ -334,7 +335,7 @@ func (t *TreeServiceMock) GetMultipartUploadsByPrefix(context.Context, *data.Buc func (t *TreeServiceMock) GetMultipartUpload(_ context.Context, bktInfo *data.BucketInfo, objectName, uploadID string) (*data.MultipartInfo, error) { cnrMultipartsMap, ok := t.multiparts[bktInfo.CID.EncodeToString()] if !ok { - return nil, ErrNodeNotFound + return nil, tree.ErrNodeNotFound } multiparts := cnrMultipartsMap[objectName] @@ -344,7 +345,7 @@ func (t *TreeServiceMock) GetMultipartUpload(_ context.Context, bktInfo *data.Bu } } - return nil, ErrNodeNotFound + return nil, tree.ErrNodeNotFound } func (t *TreeServiceMock) AddPart(ctx context.Context, bktInfo *data.BucketInfo, multipartNodeID uint64, info *data.PartInfo) (oldObjIDsToDelete []oid.ID, err error) { @@ -387,7 +388,7 @@ LOOP: } if foundMultipart == nil { - return nil, ErrNodeNotFound + return nil, tree.ErrNodeNotFound } partsMap := t.parts[foundMultipart.UploadID] @@ -411,18 +412,18 @@ func (t *TreeServiceMock) PutBucketLifecycleConfiguration(_ context.Context, bkt t.system[bktInfo.CID.EncodeToString()] = systemMap - return nil, ErrNoNodeToRemove + return nil, tree.ErrNoNodeToRemove } func (t *TreeServiceMock) GetBucketLifecycleConfiguration(_ context.Context, bktInfo *data.BucketInfo) (oid.Address, error) { systemMap, ok := t.system[bktInfo.CID.EncodeToString()] if !ok { - return oid.Address{}, ErrNodeNotFound + return oid.Address{}, tree.ErrNodeNotFound } node, ok := systemMap["lifecycle"] if !ok { - return oid.Address{}, ErrNodeNotFound + return oid.Address{}, tree.ErrNodeNotFound } return newAddress(bktInfo.CID, node.OID), nil @@ -431,12 +432,12 @@ func (t *TreeServiceMock) GetBucketLifecycleConfiguration(_ context.Context, bkt func (t *TreeServiceMock) DeleteBucketLifecycleConfiguration(_ context.Context, bktInfo *data.BucketInfo) ([]oid.Address, error) { systemMap, ok := t.system[bktInfo.CID.EncodeToString()] if !ok { - return nil, ErrNoNodeToRemove + return nil, tree.ErrNoNodeToRemove } node, ok := systemMap["lifecycle"] if !ok { - return nil, ErrNoNodeToRemove + return nil, tree.ErrNoNodeToRemove } delete(systemMap, "lifecycle") @@ -461,7 +462,7 @@ LOOP: } if uploadID == "" { - return ErrNodeNotFound + return tree.ErrNodeNotFound } delete(t.parts, uploadID) diff --git a/pkg/service/tree/tree.go b/pkg/service/tree/tree.go index c89d6af..bd2df22 100644 --- a/pkg/service/tree/tree.go +++ b/pkg/service/tree/tree.go @@ -13,6 +13,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer" + "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/logs" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" @@ -75,10 +76,10 @@ const ( var ( // ErrNodeNotFound is returned from ServiceClient in case of not found error. - ErrNodeNotFound = layer.ErrNodeNotFound + ErrNodeNotFound = tree.ErrNodeNotFound // ErrNodeAccessDenied is returned from ServiceClient service in case of access denied error. - ErrNodeAccessDenied = layer.ErrNodeAccessDenied + ErrNodeAccessDenied = tree.ErrNodeAccessDenied // ErrGatewayTimeout is returned from ServiceClient service in case of timeout error. ErrGatewayTimeout = layer.ErrGatewayTimeout @@ -523,7 +524,7 @@ func (c *Tree) GetSettingsNode(ctx context.Context, bktInfo *data.BucketInfo) (* func (c *Tree) PutSettingsNode(ctx context.Context, bktInfo *data.BucketInfo, settings *data.BucketSettings) error { multiNode, err := c.getSystemNode(ctx, bktInfo, settingsFileName) - isErrNotFound := errors.Is(err, layer.ErrNodeNotFound) + isErrNotFound := errors.Is(err, tree.ErrNodeNotFound) if err != nil && !isErrNotFound { return fmt.Errorf("couldn't get node: %w", err) } @@ -561,7 +562,7 @@ func (c *Tree) GetBucketCORS(ctx context.Context, bktInfo *data.BucketInfo) (oid func (c *Tree) PutBucketCORS(ctx context.Context, bktInfo *data.BucketInfo, addr oid.Address) ([]oid.Address, error) { multiNode, err := c.getSystemNode(ctx, bktInfo, corsFilename) - isErrNotFound := errors.Is(err, layer.ErrNodeNotFound) + isErrNotFound := errors.Is(err, tree.ErrNodeNotFound) if err != nil && !isErrNotFound { return nil, fmt.Errorf("couldn't get node: %w", err) } @@ -575,7 +576,7 @@ func (c *Tree) PutBucketCORS(ctx context.Context, bktInfo *data.BucketInfo, addr if _, err = c.service.AddNode(ctx, bktInfo, systemTree, 0, meta); err != nil { return nil, err } - return nil, layer.ErrNoNodeToRemove + return nil, tree.ErrNoNodeToRemove } latest := multiNode.Latest() @@ -601,13 +602,13 @@ func (c *Tree) PutBucketCORS(ctx context.Context, bktInfo *data.BucketInfo, addr func (c *Tree) DeleteBucketCORS(ctx context.Context, bktInfo *data.BucketInfo) ([]oid.Address, error) { multiNode, err := c.getSystemNode(ctx, bktInfo, corsFilename) - isErrNotFound := errors.Is(err, layer.ErrNodeNotFound) + isErrNotFound := errors.Is(err, tree.ErrNodeNotFound) if err != nil && !isErrNotFound { return nil, err } if isErrNotFound { - return nil, layer.ErrNoNodeToRemove + return nil, tree.ErrNoNodeToRemove } objToDelete := c.cleanOldNodes(ctx, multiNode.nodes, bktInfo) @@ -730,7 +731,7 @@ func (c *Tree) GetBucketTagging(ctx context.Context, bktInfo *data.BucketInfo) ( func (c *Tree) PutBucketTagging(ctx context.Context, bktInfo *data.BucketInfo, tagSet map[string]string) error { multiNode, err := c.getSystemNode(ctx, bktInfo, bucketTaggingFilename) - isErrNotFound := errors.Is(err, layer.ErrNodeNotFound) + isErrNotFound := errors.Is(err, tree.ErrNodeNotFound) if err != nil && !isErrNotFound { return fmt.Errorf("couldn't get node: %w", err) } @@ -852,7 +853,7 @@ func getLatestVersionNode(nodes []NodeResponse) (NodeResponse, error) { } if targetIndexNode == -1 { - return nil, layer.ErrNodeNotFound + return nil, tree.ErrNodeNotFound } return nodes[targetIndexNode], nil @@ -1104,7 +1105,7 @@ func (c *Tree) InitVersionsByPrefixStream(ctx context.Context, bktInfo *data.Buc func (c *Tree) getSubTreeByPrefixMainStream(ctx context.Context, bktInfo *data.BucketInfo, treeID, prefix string) (SubTreeStream, string, []uint64, error) { rootID, tailPrefix, err := c.determinePrefixNode(ctx, bktInfo, treeID, prefix) if err != nil { - if errors.Is(err, layer.ErrNodeNotFound) { + if errors.Is(err, tree.ErrNodeNotFound) { return nil, "", nil, io.EOF } return nil, "", nil, err @@ -1112,7 +1113,7 @@ func (c *Tree) getSubTreeByPrefixMainStream(ctx context.Context, bktInfo *data.B subTree, err := c.service.GetSubTreeStream(ctx, bktInfo, treeID, rootID, 2) if err != nil { - if errors.Is(err, layer.ErrNodeNotFound) { + if errors.Is(err, tree.ErrNodeNotFound) { return nil, "", nil, io.EOF } return nil, "", nil, err @@ -1158,7 +1159,7 @@ func (c *Tree) getPrefixNodeID(ctx context.Context, bktInfo *data.BucketInfo, tr } if len(intermediateNodes) == 0 { - return nil, layer.ErrNodeNotFound + return nil, tree.ErrNodeNotFound } return intermediateNodes, nil @@ -1167,7 +1168,7 @@ func (c *Tree) getPrefixNodeID(ctx context.Context, bktInfo *data.BucketInfo, tr func (c *Tree) getSubTreeByPrefix(ctx context.Context, bktInfo *data.BucketInfo, treeID, prefix string, latestOnly bool) ([]NodeResponse, string, error) { rootID, tailPrefix, err := c.determinePrefixNode(ctx, bktInfo, treeID, prefix) if err != nil { - if errors.Is(err, layer.ErrNodeNotFound) { + if errors.Is(err, tree.ErrNodeNotFound) { return nil, "", nil } return nil, "", err @@ -1175,7 +1176,7 @@ func (c *Tree) getSubTreeByPrefix(ctx context.Context, bktInfo *data.BucketInfo, subTree, err := c.service.GetSubTree(ctx, bktInfo, treeID, rootID, 2, false) if err != nil { - if errors.Is(err, layer.ErrNodeNotFound) { + if errors.Is(err, tree.ErrNodeNotFound) { return nil, "", nil } return nil, "", err @@ -1281,7 +1282,7 @@ func (c *Tree) getUnversioned(ctx context.Context, bktInfo *data.BucketInfo, tre } if len(nodes) == 0 { - return nil, layer.ErrNodeNotFound + return nil, tree.ErrNodeNotFound } if len(nodes) > 1 { @@ -1420,7 +1421,7 @@ func (c *Tree) GetMultipartUpload(ctx context.Context, bktInfo *data.BucketInfo, } } - return nil, layer.ErrNodeNotFound + return nil, tree.ErrNodeNotFound } func (c *Tree) AddPart(ctx context.Context, bktInfo *data.BucketInfo, multipartNodeID uint64, info *data.PartInfo) (oldObjIDsToDelete []oid.ID, err error) { @@ -1498,7 +1499,7 @@ func (c *Tree) AddPart(ctx context.Context, bktInfo *data.BucketInfo, multipartN return nil, err } - return nil, layer.ErrNoNodeToRemove + return nil, tree.ErrNoNodeToRemove } func (c *Tree) GetParts(ctx context.Context, bktInfo *data.BucketInfo, multipartNodeID uint64) ([]*data.PartInfoExtended, error) { @@ -1535,7 +1536,7 @@ func (c *Tree) GetParts(ctx context.Context, bktInfo *data.BucketInfo, multipart func (c *Tree) PutBucketLifecycleConfiguration(ctx context.Context, bktInfo *data.BucketInfo, addr oid.Address) ([]oid.Address, error) { multiNode, err := c.getSystemNode(ctx, bktInfo, bucketLifecycleFilename) - isErrNotFound := errors.Is(err, layer.ErrNodeNotFound) + isErrNotFound := errors.Is(err, tree.ErrNodeNotFound) if err != nil && !isErrNotFound { return nil, fmt.Errorf("couldn't get node: %w", err) } @@ -1549,7 +1550,7 @@ func (c *Tree) PutBucketLifecycleConfiguration(ctx context.Context, bktInfo *dat if _, err = c.service.AddNode(ctx, bktInfo, systemTree, 0, meta); err != nil { return nil, err } - return nil, layer.ErrNoNodeToRemove + return nil, tree.ErrNoNodeToRemove } latest := multiNode.Latest() @@ -1584,13 +1585,13 @@ func (c *Tree) GetBucketLifecycleConfiguration(ctx context.Context, bktInfo *dat func (c *Tree) DeleteBucketLifecycleConfiguration(ctx context.Context, bktInfo *data.BucketInfo) ([]oid.Address, error) { multiNode, err := c.getSystemNode(ctx, bktInfo, bucketLifecycleFilename) - isErrNotFound := errors.Is(err, layer.ErrNodeNotFound) + isErrNotFound := errors.Is(err, tree.ErrNodeNotFound) if err != nil && !isErrNotFound { return nil, err } if isErrNotFound { - return nil, layer.ErrNoNodeToRemove + return nil, tree.ErrNoNodeToRemove } objToDelete := c.cleanOldNodes(ctx, multiNode.nodes, bktInfo) @@ -1727,7 +1728,7 @@ func (c *Tree) addVersion(ctx context.Context, bktInfo *data.BucketInfo, treeID return node.ID, c.clearOutdatedVersionInfo(ctx, bktInfo, treeID, node.ID) } - if !errors.Is(err, layer.ErrNodeNotFound) { + if !errors.Is(err, tree.ErrNodeNotFound) { return 0, err } } @@ -1760,7 +1761,7 @@ func (c *Tree) getVersions(ctx context.Context, bktInfo *data.BucketInfo, treeID } nodes, err := c.service.GetNodes(ctx, p) if err != nil { - if errors.Is(err, layer.ErrNodeNotFound) { + if errors.Is(err, tree.ErrNodeNotFound) { return nil, nil } return nil, err @@ -1827,7 +1828,7 @@ func (c *Tree) getSystemNode(ctx context.Context, bktInfo *data.BucketInfo, name nodes = filterMultipartNodes(nodes) if len(nodes) == 0 { - return nil, layer.ErrNodeNotFound + return nil, tree.ErrNodeNotFound } if len(nodes) != 1 { c.reqLogger(ctx).Warn(logs.FoundSeveralSystemNodes, zap.String("name", name))