2022-05-31 08:12:53 +00:00
|
|
|
package layer
|
2022-05-20 08:26:35 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-06-01 09:54:27 +00:00
|
|
|
"fmt"
|
2022-05-20 08:26:35 +00:00
|
|
|
"sort"
|
2022-05-20 15:02:00 +00:00
|
|
|
"strings"
|
2022-05-20 08:26:35 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TreeServiceMock struct {
|
2022-06-01 09:54:27 +00:00
|
|
|
settings map[string]*data.BucketSettings
|
|
|
|
versions map[string]map[string][]*data.NodeVersion
|
|
|
|
system map[string]map[string]*data.BaseNodeVersion
|
|
|
|
locks map[string]map[uint64]*data.LockInfo
|
2022-08-23 14:13:59 +00:00
|
|
|
tags map[string]map[uint64]map[string]string
|
2022-06-01 09:54:27 +00:00
|
|
|
multiparts map[string]map[string][]*data.MultipartInfo
|
|
|
|
parts map[string]map[int]*data.PartInfo
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) GetObjectTaggingAndLock(ctx context.Context, cnrID cid.ID, objVersion *data.NodeVersion) (map[string]string, *data.LockInfo, error) {
|
2022-06-02 15:26:26 +00:00
|
|
|
// TODO implement object tagging
|
|
|
|
lock, err := t.GetLock(ctx, cnrID, objVersion.ID)
|
|
|
|
return nil, lock, err
|
2022-05-31 14:25:47 +00:00
|
|
|
}
|
|
|
|
|
2022-08-23 14:13:59 +00:00
|
|
|
func (t *TreeServiceMock) GetObjectTagging(_ context.Context, cnrID cid.ID, nodeVersion *data.NodeVersion) (map[string]string, error) {
|
|
|
|
cnrTagsMap, ok := t.tags[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return cnrTagsMap[nodeVersion.ID], nil
|
2022-05-24 06:58:33 +00:00
|
|
|
}
|
|
|
|
|
2022-08-23 14:13:59 +00:00
|
|
|
func (t *TreeServiceMock) PutObjectTagging(_ context.Context, cnrID cid.ID, nodeVersion *data.NodeVersion, tagSet map[string]string) error {
|
|
|
|
cnrTagsMap, ok := t.tags[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
t.tags[cnrID.EncodeToString()] = map[uint64]map[string]string{
|
|
|
|
nodeVersion.ID: tagSet,
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cnrTagsMap[nodeVersion.ID] = tagSet
|
|
|
|
|
|
|
|
return nil
|
2022-05-24 06:58:33 +00:00
|
|
|
}
|
|
|
|
|
2022-08-23 14:13:59 +00:00
|
|
|
func (t *TreeServiceMock) DeleteObjectTagging(_ context.Context, cnrID cid.ID, objVersion *data.NodeVersion) error {
|
|
|
|
cnrTagsMap, ok := t.tags[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(cnrTagsMap, objVersion.ID)
|
|
|
|
return nil
|
2022-05-24 06:58:33 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) GetBucketTagging(ctx context.Context, cnrID cid.ID) (map[string]string, error) {
|
2022-05-31 14:25:47 +00:00
|
|
|
// TODO implement me
|
2022-05-25 01:58:25 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) PutBucketTagging(ctx context.Context, cnrID cid.ID, tagSet map[string]string) error {
|
2022-05-31 14:25:47 +00:00
|
|
|
// TODO implement me
|
2022-05-25 01:58:25 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) DeleteBucketTagging(ctx context.Context, cnrID cid.ID) error {
|
2022-05-31 14:25:47 +00:00
|
|
|
// TODO implement me
|
2022-05-25 01:58:25 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-05-20 08:26:35 +00:00
|
|
|
func NewTreeService() *TreeServiceMock {
|
|
|
|
return &TreeServiceMock{
|
2022-06-01 09:54:27 +00:00
|
|
|
settings: make(map[string]*data.BucketSettings),
|
|
|
|
versions: make(map[string]map[string][]*data.NodeVersion),
|
|
|
|
system: make(map[string]map[string]*data.BaseNodeVersion),
|
|
|
|
locks: make(map[string]map[uint64]*data.LockInfo),
|
2022-08-23 14:13:59 +00:00
|
|
|
tags: make(map[string]map[uint64]map[string]string),
|
2022-06-01 09:54:27 +00:00
|
|
|
multiparts: make(map[string]map[string][]*data.MultipartInfo),
|
|
|
|
parts: make(map[string]map[int]*data.PartInfo),
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) PutSettingsNode(_ context.Context, id cid.ID, settings *data.BucketSettings) error {
|
2022-05-20 08:26:35 +00:00
|
|
|
t.settings[id.EncodeToString()] = settings
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) GetSettingsNode(_ context.Context, id cid.ID) (*data.BucketSettings, error) {
|
2022-05-20 08:26:35 +00:00
|
|
|
settings, ok := t.settings[id.EncodeToString()]
|
|
|
|
if !ok {
|
2022-05-20 15:02:00 +00:00
|
|
|
return nil, ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return settings, nil
|
|
|
|
}
|
|
|
|
|
2022-06-27 09:33:36 +00:00
|
|
|
func (t *TreeServiceMock) GetNotificationConfigurationNode(ctx context.Context, cnrID cid.ID) (oid.ID, error) {
|
2022-05-20 08:26:35 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-06-27 09:33:36 +00:00
|
|
|
func (t *TreeServiceMock) PutNotificationConfigurationNode(ctx context.Context, cnrID cid.ID, objID oid.ID) (oid.ID, error) {
|
2022-05-20 08:26:35 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-06-27 09:33:36 +00:00
|
|
|
func (t *TreeServiceMock) GetBucketCORS(ctx context.Context, cnrID cid.ID) (oid.ID, error) {
|
2022-05-20 08:26:35 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-06-27 09:33:36 +00:00
|
|
|
func (t *TreeServiceMock) PutBucketCORS(ctx context.Context, cnrID cid.ID, objID oid.ID) (oid.ID, error) {
|
2022-05-20 08:26:35 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-06-27 09:33:36 +00:00
|
|
|
func (t *TreeServiceMock) DeleteBucketCORS(ctx context.Context, cnrID cid.ID) (oid.ID, error) {
|
2022-05-20 08:26:35 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) GetVersions(_ context.Context, cnrID cid.ID, objectName string) ([]*data.NodeVersion, error) {
|
2022-05-20 15:02:00 +00:00
|
|
|
cnrVersionsMap, ok := t.versions[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
return nil, ErrNodeNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
versions, ok := cnrVersionsMap[objectName]
|
|
|
|
if !ok {
|
|
|
|
return nil, ErrNodeNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
return versions, nil
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) GetLatestVersion(_ context.Context, cnrID cid.ID, objectName string) (*data.NodeVersion, error) {
|
2022-05-20 08:26:35 +00:00
|
|
|
cnrVersionsMap, ok := t.versions[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
2022-05-20 15:02:00 +00:00
|
|
|
return nil, ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
versions, ok := cnrVersionsMap[objectName]
|
|
|
|
if !ok {
|
2022-05-20 15:02:00 +00:00
|
|
|
return nil, ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(versions, func(i, j int) bool {
|
|
|
|
return versions[i].ID < versions[j].ID
|
|
|
|
})
|
|
|
|
|
|
|
|
if len(versions) != 0 {
|
|
|
|
return versions[len(versions)-1], nil
|
|
|
|
}
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
return nil, ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) GetLatestVersionsByPrefix(_ context.Context, cnrID cid.ID, prefix string) ([]*data.NodeVersion, error) {
|
2022-05-20 15:02:00 +00:00
|
|
|
cnrVersionsMap, ok := t.versions[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
return nil, ErrNodeNotFound
|
|
|
|
}
|
|
|
|
|
2022-06-10 11:57:41 +00:00
|
|
|
var result []*data.NodeVersion
|
2022-05-20 15:02:00 +00:00
|
|
|
|
|
|
|
for key, versions := range cnrVersionsMap {
|
|
|
|
if !strings.HasPrefix(key, prefix) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(versions, func(i, j int) bool {
|
|
|
|
return versions[i].ID < versions[j].ID
|
|
|
|
})
|
|
|
|
|
|
|
|
if len(versions) != 0 {
|
2022-06-10 11:57:41 +00:00
|
|
|
result = append(result, versions[len(versions)-1])
|
2022-05-20 15:02:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) GetUnversioned(_ context.Context, cnrID cid.ID, objectName string) (*data.NodeVersion, error) {
|
2022-05-31 08:12:53 +00:00
|
|
|
cnrVersionsMap, ok := t.versions[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
return nil, ErrNodeNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
versions, ok := cnrVersionsMap[objectName]
|
|
|
|
if !ok {
|
|
|
|
return nil, ErrNodeNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, version := range versions {
|
|
|
|
if version.IsUnversioned {
|
|
|
|
return version, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-08-29 10:57:11 +00:00
|
|
|
func (t *TreeServiceMock) AddVersion(_ context.Context, cnrID cid.ID, newVersion *data.NodeVersion) (uint64, error) {
|
2022-05-20 08:26:35 +00:00
|
|
|
cnrVersionsMap, ok := t.versions[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
2022-05-20 15:02:00 +00:00
|
|
|
t.versions[cnrID.EncodeToString()] = map[string][]*data.NodeVersion{
|
2022-06-10 11:57:41 +00:00
|
|
|
newVersion.FilePath: {newVersion},
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
2022-08-29 10:57:11 +00:00
|
|
|
return newVersion.ID, nil
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-06-10 11:57:41 +00:00
|
|
|
versions, ok := cnrVersionsMap[newVersion.FilePath]
|
2022-05-20 08:26:35 +00:00
|
|
|
if !ok {
|
2022-06-10 11:57:41 +00:00
|
|
|
cnrVersionsMap[newVersion.FilePath] = []*data.NodeVersion{newVersion}
|
2022-08-29 10:57:11 +00:00
|
|
|
return newVersion.ID, nil
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(versions, func(i, j int) bool {
|
|
|
|
return versions[i].ID < versions[j].ID
|
|
|
|
})
|
|
|
|
|
|
|
|
if len(versions) != 0 {
|
|
|
|
newVersion.ID = versions[len(versions)-1].ID + 1
|
2022-05-31 08:12:53 +00:00
|
|
|
newVersion.Timestamp = versions[len(versions)-1].Timestamp + 1
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
result := versions
|
|
|
|
|
|
|
|
if newVersion.IsUnversioned {
|
|
|
|
result = make([]*data.NodeVersion, 0, len(versions))
|
|
|
|
for _, node := range versions {
|
|
|
|
if !node.IsUnversioned {
|
|
|
|
result = append(result, node)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-10 11:57:41 +00:00
|
|
|
cnrVersionsMap[newVersion.FilePath] = append(result, newVersion)
|
2022-05-20 08:26:35 +00:00
|
|
|
|
2022-08-29 10:57:11 +00:00
|
|
|
return newVersion.ID, nil
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) RemoveVersion(_ context.Context, cnrID cid.ID, nodeID uint64) error {
|
2022-05-31 08:12:53 +00:00
|
|
|
cnrVersionsMap, ok := t.versions[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
return ErrNodeNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
for key, versions := range cnrVersionsMap {
|
|
|
|
for i, node := range versions {
|
|
|
|
if node.ID == nodeID {
|
|
|
|
cnrVersionsMap[key] = append(versions[:i], versions[i+1:]...)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) GetAllVersionsByPrefix(_ context.Context, cnrID cid.ID, prefix string) ([]*data.NodeVersion, error) {
|
2022-05-31 08:12:53 +00:00
|
|
|
cnrVersionsMap, ok := t.versions[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var result []*data.NodeVersion
|
|
|
|
for objName, versions := range cnrVersionsMap {
|
|
|
|
if strings.HasPrefix(objName, prefix) {
|
|
|
|
result = append(result, versions...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
2022-05-20 15:02:00 +00:00
|
|
|
}
|
2022-05-24 08:41:10 +00:00
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) CreateMultipartUpload(_ context.Context, cnrID cid.ID, info *data.MultipartInfo) error {
|
2022-06-01 09:54:27 +00:00
|
|
|
cnrMultipartsMap, ok := t.multiparts[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
t.multiparts[cnrID.EncodeToString()] = map[string][]*data.MultipartInfo{
|
|
|
|
info.Key: {info},
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
multiparts := cnrMultipartsMap[info.Key]
|
|
|
|
if len(multiparts) != 0 {
|
|
|
|
info.ID = multiparts[len(multiparts)-1].ID + 1
|
|
|
|
}
|
|
|
|
cnrMultipartsMap[info.Key] = append(multiparts, info)
|
|
|
|
|
|
|
|
return nil
|
2022-05-24 08:41:10 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) GetMultipartUploadsByPrefix(ctx context.Context, cnrID cid.ID, prefix string) ([]*data.MultipartInfo, error) {
|
2022-05-24 08:41:10 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
2022-05-24 11:30:37 +00:00
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) GetMultipartUpload(_ context.Context, cnrID cid.ID, objectName, uploadID string) (*data.MultipartInfo, error) {
|
2022-06-01 09:54:27 +00:00
|
|
|
cnrMultipartsMap, ok := t.multiparts[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
return nil, ErrNodeNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
multiparts := cnrMultipartsMap[objectName]
|
|
|
|
for _, multipart := range multiparts {
|
|
|
|
if multipart.UploadID == uploadID {
|
|
|
|
return multipart, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, ErrNodeNotFound
|
2022-05-24 11:30:37 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 09:33:36 +00:00
|
|
|
func (t *TreeServiceMock) AddPart(ctx context.Context, cnrID cid.ID, multipartNodeID uint64, info *data.PartInfo) (oldObjIDToDelete oid.ID, err error) {
|
2022-06-01 09:54:27 +00:00
|
|
|
multipartInfo, err := t.GetMultipartUpload(ctx, cnrID, info.Key, info.UploadID)
|
|
|
|
if err != nil {
|
2022-06-27 09:33:36 +00:00
|
|
|
return oid.ID{}, err
|
2022-06-01 09:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if multipartInfo.ID != multipartNodeID {
|
2022-06-27 09:33:36 +00:00
|
|
|
return oid.ID{}, fmt.Errorf("invalid multipart info id")
|
2022-06-01 09:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
partsMap, ok := t.parts[info.UploadID]
|
|
|
|
if !ok {
|
|
|
|
partsMap = make(map[int]*data.PartInfo)
|
|
|
|
}
|
|
|
|
|
|
|
|
partsMap[info.Number] = info
|
|
|
|
|
|
|
|
t.parts[info.UploadID] = partsMap
|
2022-06-27 09:33:36 +00:00
|
|
|
return oid.ID{}, nil
|
2022-05-24 11:30:37 +00:00
|
|
|
}
|
2022-05-24 13:07:47 +00:00
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) GetParts(_ context.Context, cnrID cid.ID, multipartNodeID uint64) ([]*data.PartInfo, error) {
|
2022-06-01 09:54:27 +00:00
|
|
|
cnrMultipartsMap := t.multiparts[cnrID.EncodeToString()]
|
|
|
|
|
|
|
|
var foundMultipart *data.MultipartInfo
|
|
|
|
|
|
|
|
LOOP:
|
|
|
|
for _, multiparts := range cnrMultipartsMap {
|
|
|
|
for _, multipart := range multiparts {
|
|
|
|
if multipart.ID == multipartNodeID {
|
|
|
|
foundMultipart = multipart
|
|
|
|
break LOOP
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if foundMultipart == nil {
|
|
|
|
return nil, ErrNodeNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
partsMap := t.parts[foundMultipart.UploadID]
|
|
|
|
result := make([]*data.PartInfo, 0, len(partsMap))
|
|
|
|
for _, part := range partsMap {
|
|
|
|
result = append(result, part)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
2022-05-24 13:07:47 +00:00
|
|
|
}
|
2022-05-24 13:27:15 +00:00
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) DeleteMultipartUpload(_ context.Context, cnrID cid.ID, multipartNodeID uint64) error {
|
2022-06-01 09:54:27 +00:00
|
|
|
cnrMultipartsMap := t.multiparts[cnrID.EncodeToString()]
|
|
|
|
|
|
|
|
var uploadID string
|
|
|
|
|
|
|
|
LOOP:
|
|
|
|
for key, multiparts := range cnrMultipartsMap {
|
|
|
|
for i, multipart := range multiparts {
|
|
|
|
if multipart.ID == multipartNodeID {
|
|
|
|
uploadID = multipart.UploadID
|
|
|
|
cnrMultipartsMap[key] = append(multiparts[:i], multiparts[i+1:]...)
|
|
|
|
break LOOP
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if uploadID == "" {
|
|
|
|
return ErrNodeNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(t.parts, uploadID)
|
|
|
|
return nil
|
2022-05-24 13:27:15 +00:00
|
|
|
}
|
2022-05-26 13:11:14 +00:00
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) PutLock(ctx context.Context, cnrID cid.ID, nodeID uint64, lock *data.LockInfo) error {
|
2022-05-26 13:11:14 +00:00
|
|
|
cnrLockMap, ok := t.locks[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
t.locks[cnrID.EncodeToString()] = map[uint64]*data.LockInfo{
|
|
|
|
nodeID: lock,
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cnrLockMap[nodeID] = lock
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
func (t *TreeServiceMock) GetLock(ctx context.Context, cnrID cid.ID, nodeID uint64) (*data.LockInfo, error) {
|
2022-05-26 13:11:14 +00:00
|
|
|
cnrLockMap, ok := t.locks[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return cnrLockMap[nodeID], nil
|
|
|
|
}
|