diff --git a/api/layer/layer.go b/api/layer/layer.go index c69d47a53..185dba8db 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -594,7 +594,7 @@ func (n *layer) deleteObject(ctx context.Context, bkt *data.BucketInfo, settings IsUnversioned: settings.VersioningSuspended(), } - if obj.Error = n.treeService.AddVersion(ctx, bkt.CID, newVersion); obj.Error != nil { + if _, obj.Error = n.treeService.AddVersion(ctx, bkt.CID, newVersion); obj.Error != nil { return obj } diff --git a/api/layer/object.go b/api/layer/object.go index 1949eec10..a96e07eb3 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -250,7 +250,7 @@ func (n *layer) PutObject(ctx context.Context, p *PutObjectParams) (*data.Object newVersion.OID = id newVersion.ETag = hex.EncodeToString(hash) - if err = n.treeService.AddVersion(ctx, p.BktInfo.CID, newVersion); err != nil { + if newVersion.ID, err = n.treeService.AddVersion(ctx, p.BktInfo.CID, newVersion); err != nil { return nil, fmt.Errorf("couldn't add new verion to tree service: %w", err) } diff --git a/api/layer/tree_mock.go b/api/layer/tree_mock.go index 3392c443b..07f2bb6c0 100644 --- a/api/layer/tree_mock.go +++ b/api/layer/tree_mock.go @@ -202,19 +202,19 @@ func (t *TreeServiceMock) GetUnversioned(_ context.Context, cnrID cid.ID, object return nil, ErrNodeNotFound } -func (t *TreeServiceMock) AddVersion(_ context.Context, cnrID cid.ID, newVersion *data.NodeVersion) error { +func (t *TreeServiceMock) AddVersion(_ context.Context, cnrID cid.ID, newVersion *data.NodeVersion) (uint64, error) { cnrVersionsMap, ok := t.versions[cnrID.EncodeToString()] if !ok { t.versions[cnrID.EncodeToString()] = map[string][]*data.NodeVersion{ newVersion.FilePath: {newVersion}, } - return nil + return newVersion.ID, nil } versions, ok := cnrVersionsMap[newVersion.FilePath] if !ok { cnrVersionsMap[newVersion.FilePath] = []*data.NodeVersion{newVersion} - return nil + return newVersion.ID, nil } sort.Slice(versions, func(i, j int) bool { @@ -239,7 +239,7 @@ func (t *TreeServiceMock) AddVersion(_ context.Context, cnrID cid.ID, newVersion cnrVersionsMap[newVersion.FilePath] = append(result, newVersion) - return nil + return newVersion.ID, nil } func (t *TreeServiceMock) RemoveVersion(_ context.Context, cnrID cid.ID, nodeID uint64) error { diff --git a/api/layer/tree_service.go b/api/layer/tree_service.go index 8e87dce97..ef1005703 100644 --- a/api/layer/tree_service.go +++ b/api/layer/tree_service.go @@ -58,7 +58,7 @@ type TreeService interface { GetLatestVersionsByPrefix(ctx context.Context, cnrID cid.ID, prefix string) ([]*data.NodeVersion, error) GetAllVersionsByPrefix(ctx context.Context, cnrID cid.ID, prefix string) ([]*data.NodeVersion, error) GetUnversioned(ctx context.Context, cnrID cid.ID, objectName string) (*data.NodeVersion, error) - AddVersion(ctx context.Context, cnrID cid.ID, newVersion *data.NodeVersion) error + AddVersion(ctx context.Context, cnrID cid.ID, newVersion *data.NodeVersion) (uint64, error) RemoveVersion(ctx context.Context, cnrID cid.ID, nodeID uint64) error PutLock(ctx context.Context, cnrID cid.ID, nodeID uint64, lock *data.LockInfo) error diff --git a/internal/neofs/tree.go b/internal/neofs/tree.go index 3e2ed8b7a..1f60bf730 100644 --- a/internal/neofs/tree.go +++ b/internal/neofs/tree.go @@ -829,7 +829,7 @@ func (c *TreeClient) getUnversioned(ctx context.Context, cnrID cid.ID, treeID, f return nodes[0], nil } -func (c *TreeClient) AddVersion(ctx context.Context, cnrID cid.ID, version *data.NodeVersion) error { +func (c *TreeClient) AddVersion(ctx context.Context, cnrID cid.ID, version *data.NodeVersion) (uint64, error) { return c.addVersion(ctx, cnrID, versionTree, version) } @@ -1053,7 +1053,7 @@ func (c *TreeClient) Close() error { return nil } -func (c *TreeClient) addVersion(ctx context.Context, cnrID cid.ID, treeID string, version *data.NodeVersion) error { +func (c *TreeClient) addVersion(ctx context.Context, cnrID cid.ID, treeID string, version *data.NodeVersion) (uint64, error) { path := pathFromName(version.FilePath) meta := map[string]string{ oidKV: version.OID.EncodeToString(), @@ -1080,24 +1080,22 @@ func (c *TreeClient) addVersion(ctx context.Context, cnrID cid.ID, treeID string if err == nil { parentID, err := c.getParent(ctx, cnrID, treeID, node.ID) if err != nil { - return err + return 0, err } if err = c.moveNode(ctx, cnrID, treeID, node.ID, parentID, meta); err != nil { - return err + return 0, err } - return c.clearOutdatedVersionInfo(ctx, cnrID, treeID, node.ID) + return node.ID, c.clearOutdatedVersionInfo(ctx, cnrID, treeID, node.ID) } if !errors.Is(err, layer.ErrNodeNotFound) { - return err + return 0, err } } - _, err := c.addNodeByPath(ctx, cnrID, treeID, path[:len(path)-1], meta) - - return err + return c.addNodeByPath(ctx, cnrID, treeID, path[:len(path)-1], meta) } func (c *TreeClient) clearOutdatedVersionInfo(ctx context.Context, cnrID cid.ID, treeID string, nodeID uint64) error {