[#682] Return added node id in AddVersion
Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
parent
a28d6b64b9
commit
9590b39333
5 changed files with 14 additions and 16 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue