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"
|
2023-10-09 06:57:33 +00:00
|
|
|
"io"
|
2022-05-20 08:26:35 +00:00
|
|
|
"sort"
|
2022-05-20 15:02:00 +00:00
|
|
|
"strings"
|
2024-07-18 13:40:55 +00:00
|
|
|
"time"
|
2022-05-20 08:26:35 +00:00
|
|
|
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
2024-09-27 08:13:13 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree"
|
2023-03-07 14:38:08 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2022-05-20 08:26:35 +00:00
|
|
|
)
|
|
|
|
|
2024-01-20 22:13:35 +00:00
|
|
|
type VersionsByPrefixStreamMock struct {
|
2023-10-09 06:57:33 +00:00
|
|
|
result []*data.NodeVersion
|
|
|
|
offset int
|
|
|
|
}
|
|
|
|
|
2024-01-20 22:13:35 +00:00
|
|
|
func (s *VersionsByPrefixStreamMock) Next(context.Context) (*data.NodeVersion, error) {
|
2023-10-09 06:57:33 +00:00
|
|
|
if s.offset > len(s.result)-1 {
|
|
|
|
return nil, io.EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
res := s.result[s.offset]
|
|
|
|
s.offset++
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
2022-05-20 08:26:35 +00:00
|
|
|
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
|
2024-07-18 13:40:55 +00:00
|
|
|
parts map[string]map[int]*data.PartInfoExtended
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-09-13 09:44:18 +00:00
|
|
|
func (t *TreeServiceMock) GetObjectTaggingAndLock(ctx context.Context, bktInfo *data.BucketInfo, objVersion *data.NodeVersion) (map[string]string, *data.LockInfo, error) {
|
2022-06-02 15:26:26 +00:00
|
|
|
// TODO implement object tagging
|
2022-09-13 09:44:18 +00:00
|
|
|
lock, err := t.GetLock(ctx, bktInfo, objVersion.ID)
|
2022-06-02 15:26:26 +00:00
|
|
|
return nil, lock, err
|
2022-05-31 14:25:47 +00:00
|
|
|
}
|
|
|
|
|
2022-09-13 09:44:18 +00:00
|
|
|
func (t *TreeServiceMock) GetObjectTagging(_ context.Context, bktInfo *data.BucketInfo, nodeVersion *data.NodeVersion) (map[string]string, error) {
|
|
|
|
cnrTagsMap, ok := t.tags[bktInfo.CID.EncodeToString()]
|
2022-08-23 14:13:59 +00:00
|
|
|
if !ok {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return cnrTagsMap[nodeVersion.ID], nil
|
2022-05-24 06:58:33 +00:00
|
|
|
}
|
|
|
|
|
2022-09-13 09:44:18 +00:00
|
|
|
func (t *TreeServiceMock) PutObjectTagging(_ context.Context, bktInfo *data.BucketInfo, nodeVersion *data.NodeVersion, tagSet map[string]string) error {
|
|
|
|
cnrTagsMap, ok := t.tags[bktInfo.CID.EncodeToString()]
|
2022-08-23 14:13:59 +00:00
|
|
|
if !ok {
|
2022-09-13 09:44:18 +00:00
|
|
|
t.tags[bktInfo.CID.EncodeToString()] = map[uint64]map[string]string{
|
2022-08-23 14:13:59 +00:00
|
|
|
nodeVersion.ID: tagSet,
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cnrTagsMap[nodeVersion.ID] = tagSet
|
|
|
|
|
|
|
|
return nil
|
2022-05-24 06:58:33 +00:00
|
|
|
}
|
|
|
|
|
2023-10-18 06:52:37 +00:00
|
|
|
func (t *TreeServiceMock) DeleteObjectTagging(ctx context.Context, bktInfo *data.BucketInfo, objVersion *data.NodeVersion) error {
|
|
|
|
return t.PutObjectTagging(ctx, bktInfo, objVersion, nil)
|
2022-05-24 06:58:33 +00:00
|
|
|
}
|
|
|
|
|
2023-05-31 16:39:35 +00:00
|
|
|
func (t *TreeServiceMock) GetBucketTagging(context.Context, *data.BucketInfo) (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")
|
|
|
|
}
|
|
|
|
|
2023-05-31 16:39:35 +00:00
|
|
|
func (t *TreeServiceMock) PutBucketTagging(context.Context, *data.BucketInfo, 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")
|
|
|
|
}
|
|
|
|
|
2023-05-31 16:39:35 +00:00
|
|
|
func (t *TreeServiceMock) DeleteBucketTagging(context.Context, *data.BucketInfo) 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),
|
2024-07-18 13:40:55 +00:00
|
|
|
parts: make(map[string]map[int]*data.PartInfoExtended),
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-13 09:44:18 +00:00
|
|
|
func (t *TreeServiceMock) PutSettingsNode(_ context.Context, bktInfo *data.BucketInfo, settings *data.BucketSettings) error {
|
|
|
|
t.settings[bktInfo.CID.EncodeToString()] = settings
|
2022-05-20 08:26:35 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-13 09:44:18 +00:00
|
|
|
func (t *TreeServiceMock) GetSettingsNode(_ context.Context, bktInfo *data.BucketInfo) (*data.BucketSettings, error) {
|
|
|
|
settings, ok := t.settings[bktInfo.CID.EncodeToString()]
|
2022-05-20 08:26:35 +00:00
|
|
|
if !ok {
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return settings, nil
|
|
|
|
}
|
|
|
|
|
2024-07-15 15:35:54 +00:00
|
|
|
func (t *TreeServiceMock) GetBucketCORS(_ context.Context, bktInfo *data.BucketInfo) (oid.Address, error) {
|
2023-02-20 09:18:29 +00:00
|
|
|
systemMap, ok := t.system[bktInfo.CID.EncodeToString()]
|
|
|
|
if !ok {
|
2024-07-15 15:35:54 +00:00
|
|
|
return oid.Address{}, nil
|
2023-02-20 09:18:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
node, ok := systemMap["cors"]
|
|
|
|
if !ok {
|
2024-07-15 15:35:54 +00:00
|
|
|
return oid.Address{}, nil
|
2023-02-20 09:18:29 +00:00
|
|
|
}
|
|
|
|
|
2024-07-15 15:35:54 +00:00
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(bktInfo.CID)
|
|
|
|
addr.SetObject(node.OID)
|
|
|
|
return addr, nil
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2024-07-17 09:44:38 +00:00
|
|
|
func (t *TreeServiceMock) PutBucketCORS(_ context.Context, bktInfo *data.BucketInfo, addr oid.Address) ([]oid.Address, error) {
|
2023-02-20 09:18:29 +00:00
|
|
|
systemMap, ok := t.system[bktInfo.CID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
systemMap = make(map[string]*data.BaseNodeVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
systemMap["cors"] = &data.BaseNodeVersion{
|
2024-07-15 15:35:54 +00:00
|
|
|
OID: addr.Object(),
|
2023-02-20 09:18:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t.system[bktInfo.CID.EncodeToString()] = systemMap
|
|
|
|
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNoNodeToRemove
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2024-07-17 09:44:38 +00:00
|
|
|
func (t *TreeServiceMock) DeleteBucketCORS(context.Context, *data.BucketInfo) ([]oid.Address, error) {
|
2022-05-20 08:26:35 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-09-13 09:44:18 +00:00
|
|
|
func (t *TreeServiceMock) GetVersions(_ context.Context, bktInfo *data.BucketInfo, objectName string) ([]*data.NodeVersion, error) {
|
|
|
|
cnrVersionsMap, ok := t.versions[bktInfo.CID.EncodeToString()]
|
2022-05-20 15:02:00 +00:00
|
|
|
if !ok {
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNodeNotFound
|
2022-05-20 15:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
versions, ok := cnrVersionsMap[objectName]
|
|
|
|
if !ok {
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNodeNotFound
|
2022-05-20 15:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return versions, nil
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-09-13 09:44:18 +00:00
|
|
|
func (t *TreeServiceMock) GetLatestVersion(_ context.Context, bktInfo *data.BucketInfo, objectName string) (*data.NodeVersion, error) {
|
|
|
|
cnrVersionsMap, ok := t.versions[bktInfo.CID.EncodeToString()]
|
2022-05-20 08:26:35 +00:00
|
|
|
if !ok {
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
versions, ok := cnrVersionsMap[objectName]
|
|
|
|
if !ok {
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.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
|
|
|
|
}
|
|
|
|
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2024-01-20 22:13:35 +00:00
|
|
|
func (t *TreeServiceMock) InitVersionsByPrefixStream(_ context.Context, bktInfo *data.BucketInfo, prefix string, latestOnly bool) (data.VersionsStream, error) {
|
2022-09-13 09:44:18 +00:00
|
|
|
cnrVersionsMap, ok := t.versions[bktInfo.CID.EncodeToString()]
|
2022-05-20 15:02:00 +00:00
|
|
|
if !ok {
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNodeNotFound
|
2022-05-20 15:02:00 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-01-20 22:13:35 +00:00
|
|
|
if !latestOnly {
|
|
|
|
result = append(result, versions...)
|
2023-10-09 06:57:33 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(versions, func(i, j int) bool {
|
|
|
|
return versions[i].ID < versions[j].ID
|
|
|
|
})
|
|
|
|
|
|
|
|
if len(versions) != 0 {
|
|
|
|
result = append(result, versions[len(versions)-1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-20 22:13:35 +00:00
|
|
|
return &VersionsByPrefixStreamMock{
|
2024-01-19 06:26:58 +00:00
|
|
|
result: result,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-09-13 09:44:18 +00:00
|
|
|
func (t *TreeServiceMock) GetUnversioned(_ context.Context, bktInfo *data.BucketInfo, objectName string) (*data.NodeVersion, error) {
|
|
|
|
cnrVersionsMap, ok := t.versions[bktInfo.CID.EncodeToString()]
|
2022-05-31 08:12:53 +00:00
|
|
|
if !ok {
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNodeNotFound
|
2022-05-31 08:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
versions, ok := cnrVersionsMap[objectName]
|
|
|
|
if !ok {
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNodeNotFound
|
2022-05-31 08:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, version := range versions {
|
|
|
|
if version.IsUnversioned {
|
|
|
|
return version, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-09-13 09:44:18 +00:00
|
|
|
func (t *TreeServiceMock) AddVersion(_ context.Context, bktInfo *data.BucketInfo, newVersion *data.NodeVersion) (uint64, error) {
|
|
|
|
cnrVersionsMap, ok := t.versions[bktInfo.CID.EncodeToString()]
|
2022-05-20 08:26:35 +00:00
|
|
|
if !ok {
|
2022-09-13 09:44:18 +00:00
|
|
|
t.versions[bktInfo.CID.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-09-13 09:44:18 +00:00
|
|
|
func (t *TreeServiceMock) RemoveVersion(_ context.Context, bktInfo *data.BucketInfo, nodeID uint64) error {
|
|
|
|
cnrVersionsMap, ok := t.versions[bktInfo.CID.EncodeToString()]
|
2022-05-31 08:12:53 +00:00
|
|
|
if !ok {
|
2024-09-27 08:13:13 +00:00
|
|
|
return tree.ErrNodeNotFound
|
2022-05-31 08:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for key, versions := range cnrVersionsMap {
|
|
|
|
for i, node := range versions {
|
|
|
|
if node.ID == nodeID {
|
|
|
|
cnrVersionsMap[key] = append(versions[:i], versions[i+1:]...)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 08:13:13 +00:00
|
|
|
return tree.ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-09-13 09:44:18 +00:00
|
|
|
func (t *TreeServiceMock) GetAllVersionsByPrefix(_ context.Context, bktInfo *data.BucketInfo, prefix string) ([]*data.NodeVersion, error) {
|
|
|
|
cnrVersionsMap, ok := t.versions[bktInfo.CID.EncodeToString()]
|
2022-05-31 08:12:53 +00:00
|
|
|
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-09-13 09:44:18 +00:00
|
|
|
func (t *TreeServiceMock) CreateMultipartUpload(_ context.Context, bktInfo *data.BucketInfo, info *data.MultipartInfo) error {
|
|
|
|
cnrMultipartsMap, ok := t.multiparts[bktInfo.CID.EncodeToString()]
|
2022-06-01 09:54:27 +00:00
|
|
|
if !ok {
|
2022-09-13 09:44:18 +00:00
|
|
|
t.multiparts[bktInfo.CID.EncodeToString()] = map[string][]*data.MultipartInfo{
|
2022-06-01 09:54:27 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-05-31 16:39:35 +00:00
|
|
|
func (t *TreeServiceMock) GetMultipartUploadsByPrefix(context.Context, *data.BucketInfo, string) ([]*data.MultipartInfo, error) {
|
2022-05-24 08:41:10 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
2022-05-24 11:30:37 +00:00
|
|
|
|
2022-09-13 09:44:18 +00:00
|
|
|
func (t *TreeServiceMock) GetMultipartUpload(_ context.Context, bktInfo *data.BucketInfo, objectName, uploadID string) (*data.MultipartInfo, error) {
|
|
|
|
cnrMultipartsMap, ok := t.multiparts[bktInfo.CID.EncodeToString()]
|
2022-06-01 09:54:27 +00:00
|
|
|
if !ok {
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNodeNotFound
|
2022-06-01 09:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
multiparts := cnrMultipartsMap[objectName]
|
|
|
|
for _, multipart := range multiparts {
|
|
|
|
if multipart.UploadID == uploadID {
|
|
|
|
return multipart, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNodeNotFound
|
2022-05-24 11:30:37 +00:00
|
|
|
}
|
|
|
|
|
2024-07-18 13:40:55 +00:00
|
|
|
func (t *TreeServiceMock) AddPart(ctx context.Context, bktInfo *data.BucketInfo, multipartNodeID uint64, info *data.PartInfo) (oldObjIDsToDelete []oid.ID, err error) {
|
2022-09-13 09:44:18 +00:00
|
|
|
multipartInfo, err := t.GetMultipartUpload(ctx, bktInfo, info.Key, info.UploadID)
|
2022-06-01 09:54:27 +00:00
|
|
|
if err != nil {
|
2024-07-18 13:40:55 +00:00
|
|
|
return nil, err
|
2022-06-01 09:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if multipartInfo.ID != multipartNodeID {
|
2024-07-18 13:40:55 +00:00
|
|
|
return nil, fmt.Errorf("invalid multipart info id")
|
2022-06-01 09:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
partsMap, ok := t.parts[info.UploadID]
|
|
|
|
if !ok {
|
2024-07-18 13:40:55 +00:00
|
|
|
partsMap = make(map[int]*data.PartInfoExtended)
|
2022-06-01 09:54:27 +00:00
|
|
|
}
|
|
|
|
|
2024-07-18 13:40:55 +00:00
|
|
|
partsMap[info.Number] = &data.PartInfoExtended{
|
|
|
|
PartInfo: *info,
|
|
|
|
Timestamp: uint64(time.Now().UnixMicro()),
|
|
|
|
}
|
2022-06-01 09:54:27 +00:00
|
|
|
|
|
|
|
t.parts[info.UploadID] = partsMap
|
2024-07-18 13:40:55 +00:00
|
|
|
return nil, nil
|
2022-05-24 11:30:37 +00:00
|
|
|
}
|
2022-05-24 13:07:47 +00:00
|
|
|
|
2024-07-18 13:40:55 +00:00
|
|
|
func (t *TreeServiceMock) GetParts(_ context.Context, bktInfo *data.BucketInfo, multipartNodeID uint64) ([]*data.PartInfoExtended, error) {
|
2022-09-13 09:44:18 +00:00
|
|
|
cnrMultipartsMap := t.multiparts[bktInfo.CID.EncodeToString()]
|
2022-06-01 09:54:27 +00:00
|
|
|
|
|
|
|
var foundMultipart *data.MultipartInfo
|
|
|
|
|
|
|
|
LOOP:
|
|
|
|
for _, multiparts := range cnrMultipartsMap {
|
|
|
|
for _, multipart := range multiparts {
|
|
|
|
if multipart.ID == multipartNodeID {
|
|
|
|
foundMultipart = multipart
|
|
|
|
break LOOP
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if foundMultipart == nil {
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNodeNotFound
|
2022-06-01 09:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
partsMap := t.parts[foundMultipart.UploadID]
|
2024-07-18 13:40:55 +00:00
|
|
|
result := make([]*data.PartInfoExtended, 0, len(partsMap))
|
2022-06-01 09:54:27 +00:00
|
|
|
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
|
|
|
|
2024-08-12 11:22:56 +00:00
|
|
|
func (t *TreeServiceMock) PutBucketLifecycleConfiguration(_ context.Context, bktInfo *data.BucketInfo, addr oid.Address) ([]oid.Address, error) {
|
|
|
|
systemMap, ok := t.system[bktInfo.CID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
systemMap = make(map[string]*data.BaseNodeVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
systemMap["lifecycle"] = &data.BaseNodeVersion{
|
|
|
|
OID: addr.Object(),
|
|
|
|
}
|
|
|
|
|
|
|
|
t.system[bktInfo.CID.EncodeToString()] = systemMap
|
|
|
|
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNoNodeToRemove
|
2024-08-12 11:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) GetBucketLifecycleConfiguration(_ context.Context, bktInfo *data.BucketInfo) (oid.Address, error) {
|
|
|
|
systemMap, ok := t.system[bktInfo.CID.EncodeToString()]
|
|
|
|
if !ok {
|
2024-09-27 08:13:13 +00:00
|
|
|
return oid.Address{}, tree.ErrNodeNotFound
|
2024-08-12 11:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
node, ok := systemMap["lifecycle"]
|
|
|
|
if !ok {
|
2024-09-27 08:13:13 +00:00
|
|
|
return oid.Address{}, tree.ErrNodeNotFound
|
2024-08-12 11:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return newAddress(bktInfo.CID, node.OID), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) DeleteBucketLifecycleConfiguration(_ context.Context, bktInfo *data.BucketInfo) ([]oid.Address, error) {
|
|
|
|
systemMap, ok := t.system[bktInfo.CID.EncodeToString()]
|
|
|
|
if !ok {
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNoNodeToRemove
|
2024-08-12 11:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
node, ok := systemMap["lifecycle"]
|
|
|
|
if !ok {
|
2024-09-27 08:13:13 +00:00
|
|
|
return nil, tree.ErrNoNodeToRemove
|
2024-08-12 11:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete(systemMap, "lifecycle")
|
|
|
|
|
|
|
|
return []oid.Address{newAddress(bktInfo.CID, node.OID)}, nil
|
|
|
|
}
|
|
|
|
|
2023-12-04 06:42:25 +00:00
|
|
|
func (t *TreeServiceMock) DeleteMultipartUpload(_ context.Context, bktInfo *data.BucketInfo, multipartInfo *data.MultipartInfo) error {
|
2022-09-13 09:44:18 +00:00
|
|
|
cnrMultipartsMap := t.multiparts[bktInfo.CID.EncodeToString()]
|
2022-06-01 09:54:27 +00:00
|
|
|
|
|
|
|
var uploadID string
|
|
|
|
|
|
|
|
LOOP:
|
|
|
|
for key, multiparts := range cnrMultipartsMap {
|
|
|
|
for i, multipart := range multiparts {
|
2023-12-04 06:42:25 +00:00
|
|
|
if multipart.ID == multipartInfo.ID {
|
2022-06-01 09:54:27 +00:00
|
|
|
uploadID = multipart.UploadID
|
|
|
|
cnrMultipartsMap[key] = append(multiparts[:i], multiparts[i+1:]...)
|
|
|
|
break LOOP
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if uploadID == "" {
|
2024-09-27 08:13:13 +00:00
|
|
|
return tree.ErrNodeNotFound
|
2022-06-01 09:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete(t.parts, uploadID)
|
|
|
|
return nil
|
2022-05-24 13:27:15 +00:00
|
|
|
}
|
2022-05-26 13:11:14 +00:00
|
|
|
|
2023-05-31 16:39:35 +00:00
|
|
|
func (t *TreeServiceMock) PutLock(_ context.Context, bktInfo *data.BucketInfo, nodeID uint64, lock *data.LockInfo) error {
|
2022-09-13 09:44:18 +00:00
|
|
|
cnrLockMap, ok := t.locks[bktInfo.CID.EncodeToString()]
|
2022-05-26 13:11:14 +00:00
|
|
|
if !ok {
|
2022-09-13 09:44:18 +00:00
|
|
|
t.locks[bktInfo.CID.EncodeToString()] = map[uint64]*data.LockInfo{
|
2022-05-26 13:11:14 +00:00
|
|
|
nodeID: lock,
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cnrLockMap[nodeID] = lock
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-05-31 16:39:35 +00:00
|
|
|
func (t *TreeServiceMock) GetLock(_ context.Context, bktInfo *data.BucketInfo, nodeID uint64) (*data.LockInfo, error) {
|
2022-09-13 09:44:18 +00:00
|
|
|
cnrLockMap, ok := t.locks[bktInfo.CID.EncodeToString()]
|
2022-05-26 13:11:14 +00:00
|
|
|
if !ok {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return cnrLockMap[nodeID], nil
|
|
|
|
}
|