Marina Biryukova
f215d200e8
All checks were successful
/ DCO (pull_request) Successful in 1m33s
/ Vulncheck (pull_request) Successful in 2m38s
/ Builds (pull_request) Successful in 2m48s
/ Lint (pull_request) Successful in 4m6s
/ Tests (pull_request) Successful in 2m48s
/ Vulncheck (push) Successful in 1m19s
/ Builds (push) Successful in 2m14s
/ Lint (push) Successful in 3m40s
/ Tests (push) Successful in 2m21s
Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
91 lines
3 KiB
Go
91 lines
3 KiB
Go
package layer
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"fmt"
|
|
"strconv"
|
|
"sync"
|
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/frostfs"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/logs"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/relations"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func (n *Layer) putTombstones(ctx context.Context, bkt *data.BucketInfo, networkInfo netmap.NetworkInfo, members []oid.ID) {
|
|
var wg sync.WaitGroup
|
|
tombstoneMembersSize := n.features.TombstoneMembersSize()
|
|
tombstoneLifetime := n.features.TombstoneLifetime()
|
|
|
|
for i := 0; i < len(members); i += tombstoneMembersSize {
|
|
end := tombstoneMembersSize * (i + 1)
|
|
if end > len(members) {
|
|
end = len(members)
|
|
}
|
|
n.submitPutTombstone(ctx, bkt, members[i:end], networkInfo.CurrentEpoch()+tombstoneLifetime, &wg)
|
|
}
|
|
|
|
wg.Wait()
|
|
}
|
|
|
|
func (n *Layer) submitPutTombstone(ctx context.Context, bkt *data.BucketInfo, members []oid.ID, expEpoch uint64, wg *sync.WaitGroup) {
|
|
tomb := object.NewTombstone()
|
|
tomb.SetExpirationEpoch(expEpoch)
|
|
tomb.SetMembers(members)
|
|
|
|
wg.Add(1)
|
|
err := n.workerPool.Submit(func() {
|
|
defer wg.Done()
|
|
|
|
if err := n.putTombstoneObject(ctx, tomb, bkt); err != nil {
|
|
n.reqLogger(ctx).Warn(logs.FailedToPutTombstoneObject, zap.String("cid", bkt.CID.EncodeToString()), zap.Error(err))
|
|
}
|
|
})
|
|
if err != nil {
|
|
wg.Done()
|
|
n.reqLogger(ctx).Warn(logs.FailedToSubmitTaskToPool, zap.Error(err))
|
|
}
|
|
}
|
|
|
|
func (n *Layer) putTombstoneObject(ctx context.Context, tomb *object.Tombstone, bktInfo *data.BucketInfo) error {
|
|
payload, err := tomb.Marshal()
|
|
if err != nil {
|
|
return fmt.Errorf("marshal tombstone: %w", err)
|
|
}
|
|
|
|
prm := frostfs.PrmObjectCreate{
|
|
Container: bktInfo.CID,
|
|
Attributes: [][2]string{{objectV2.SysAttributeExpEpoch, strconv.FormatUint(tomb.ExpirationEpoch(), 10)}},
|
|
Payload: bytes.NewReader(payload),
|
|
CreationTime: TimeNow(ctx),
|
|
ClientCut: n.features.ClientCut(),
|
|
WithoutHomomorphicHash: bktInfo.HomomorphicHashDisabled,
|
|
BufferMaxSize: n.features.BufferMaxSizeForPut(),
|
|
Type: object.TypeTombstone,
|
|
}
|
|
n.prepareAuthParameters(ctx, &prm.PrmAuth, bktInfo.Owner)
|
|
|
|
_, err = n.frostFS.CreateObject(ctx, prm)
|
|
return err
|
|
}
|
|
|
|
func prepareTokensParameter(ctx context.Context, bktOwner user.ID) relations.Tokens {
|
|
tokens := relations.Tokens{}
|
|
|
|
if bd, err := middleware.GetBoxData(ctx); err == nil && bd.Gate.BearerToken != nil {
|
|
if bd.Gate.BearerToken.Impersonate() || bktOwner.Equals(bearer.ResolveIssuer(*bd.Gate.BearerToken)) {
|
|
tokens.Bearer = bd.Gate.BearerToken
|
|
}
|
|
}
|
|
|
|
return tokens
|
|
}
|