forked from TrueCloudLab/frostfs-s3-gw
[#477] Aggregate fetching tags and lock in layer.TreeService
New method aggregates GetObjectTagging and GetLock methods in single RPC to the tree service. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
5304e68b9a
commit
f8496973b8
3 changed files with 42 additions and 10 deletions
|
@ -20,6 +20,11 @@ type TreeServiceMock struct {
|
|||
parts map[string]map[int]*data.PartInfo
|
||||
}
|
||||
|
||||
func (t *TreeServiceMock) GetObjectTaggingAndLock(ctx context.Context, cnrID *cid.ID, objVersion *data.NodeVersion) (map[string]string, *data.LockInfo, error) {
|
||||
// TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t *TreeServiceMock) GetObjectTagging(ctx context.Context, cnrID *cid.ID, objVersion *data.NodeVersion) (map[string]string, error) {
|
||||
// TODO implement me
|
||||
panic("implement me")
|
||||
|
|
|
@ -59,6 +59,11 @@ type TreeService interface {
|
|||
// If a part is being added for the first time, the previous part ID will be nil.
|
||||
AddPart(ctx context.Context, cnrID *cid.ID, multipartNodeID uint64, info *data.PartInfo) (oldObjIDToDelete *oid.ID, err error)
|
||||
GetParts(ctx context.Context, cnrID *cid.ID, multipartNodeID uint64) ([]*data.PartInfo, error)
|
||||
|
||||
// Compound methods for optimizations
|
||||
|
||||
// GetObjectTaggingAndLock unifies GetObjectTagging and GetLock methods in single tree service invocation.
|
||||
GetObjectTaggingAndLock(ctx context.Context, cnrID *cid.ID, objVersion *data.NodeVersion) (map[string]string, *data.LockInfo, error)
|
||||
}
|
||||
|
||||
// ErrNodeNotFound is returned from Tree service in case of not found error.
|
||||
|
|
|
@ -369,8 +369,12 @@ func (c *TreeClient) GetObjectTagging(ctx context.Context, cnrID *cid.ID, objVer
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return getObjectTagging(tagNode), nil
|
||||
}
|
||||
|
||||
func getObjectTagging(tagNode *TreeNode) map[string]string {
|
||||
if tagNode == nil {
|
||||
return nil, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
meta := make(map[string]string)
|
||||
|
@ -381,7 +385,7 @@ func (c *TreeClient) GetObjectTagging(ctx context.Context, cnrID *cid.ID, objVer
|
|||
}
|
||||
}
|
||||
|
||||
return meta, nil
|
||||
return meta
|
||||
}
|
||||
|
||||
func (c *TreeClient) PutObjectTagging(ctx context.Context, cnrID *cid.ID, objVersion *data.NodeVersion, tagSet map[string]string) error {
|
||||
|
@ -916,6 +920,10 @@ func (c *TreeClient) GetLock(ctx context.Context, cnrID *cid.ID, nodeID uint64)
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return getLock(lockNode)
|
||||
}
|
||||
|
||||
func getLock(lockNode *TreeNode) (*data.LockInfo, error) {
|
||||
lockInfo := &data.LockInfo{}
|
||||
if lockNode == nil {
|
||||
return lockInfo, nil
|
||||
|
@ -924,7 +932,7 @@ func (c *TreeClient) GetLock(ctx context.Context, cnrID *cid.ID, nodeID uint64)
|
|||
|
||||
if legalHold, ok := lockNode.Get(legalHoldOIDKV); ok {
|
||||
var legalHoldOID oid.ID
|
||||
if err = legalHoldOID.DecodeString(legalHold); err != nil {
|
||||
if err := legalHoldOID.DecodeString(legalHold); err != nil {
|
||||
return nil, fmt.Errorf("invalid legal hold object id: %w", err)
|
||||
}
|
||||
lockInfo.LegalHoldOID = &legalHoldOID
|
||||
|
@ -932,7 +940,7 @@ func (c *TreeClient) GetLock(ctx context.Context, cnrID *cid.ID, nodeID uint64)
|
|||
|
||||
if retention, ok := lockNode.Get(retentionOIDKV); ok {
|
||||
var retentionOID oid.ID
|
||||
if err = retentionOID.DecodeString(retention); err != nil {
|
||||
if err := retentionOID.DecodeString(retention); err != nil {
|
||||
return nil, fmt.Errorf("invalid retention object id: %w", err)
|
||||
}
|
||||
lockInfo.RetentionOID = &retentionOID
|
||||
|
@ -944,6 +952,20 @@ func (c *TreeClient) GetLock(ctx context.Context, cnrID *cid.ID, nodeID uint64)
|
|||
return lockInfo, nil
|
||||
}
|
||||
|
||||
func (c *TreeClient) GetObjectTaggingAndLock(ctx context.Context, cnrID *cid.ID, objVersion *data.NodeVersion) (map[string]string, *data.LockInfo, error) {
|
||||
nodes, err := c.getTreeNodes(ctx, cnrID, objVersion.ID, isTagKV, isLockKV)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
lockInfo, err := getLock(nodes[isLockKV])
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return getObjectTagging(nodes[isTagKV]), lockInfo, nil
|
||||
}
|
||||
|
||||
func (c *TreeClient) Close() error {
|
||||
if c.conn != nil {
|
||||
return c.conn.Close()
|
||||
|
|
Loading…
Reference in a new issue