2020-11-17 12:26:03 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
2020-11-17 12:26:03 +00:00
|
|
|
"errors"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
2023-09-27 08:02:06 +00:00
|
|
|
tracingPkg "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
2023-05-31 09:24:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2023-11-21 12:06:54 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2023-03-07 13:38:26 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2023-04-12 14:01:29 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
2020-11-17 12:26:03 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PutPrm groups the parameters of Put operation.
|
|
|
|
type PutPrm struct {
|
2024-10-01 12:27:06 +00:00
|
|
|
Object *objectSDK.Object
|
|
|
|
IsIndexedContainer bool
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var errPutShard = errors.New("could not put object to any shard")
|
|
|
|
|
2023-11-21 12:06:54 +00:00
|
|
|
type putToShardStatus byte
|
|
|
|
|
|
|
|
const (
|
|
|
|
putToShardUnknown putToShardStatus = iota
|
|
|
|
putToShardSuccess
|
|
|
|
putToShardExists
|
|
|
|
putToShardRemoved
|
|
|
|
)
|
|
|
|
|
|
|
|
type putToShardRes struct {
|
|
|
|
status putToShardStatus
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
2020-11-17 12:26:03 +00:00
|
|
|
// Put saves the object to local storage.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that
|
|
|
|
// did not allow to completely save the object.
|
2021-11-09 15:46:12 +00:00
|
|
|
//
|
|
|
|
// Returns an error if executions are blocked (see BlockExecution).
|
2022-03-17 08:03:58 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns an error of type apistatus.ObjectAlreadyRemoved if the object has been marked as removed.
|
2023-04-12 14:01:29 +00:00
|
|
|
func (e *StorageEngine) Put(ctx context.Context, prm PutPrm) (err error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.Put",
|
|
|
|
trace.WithAttributes(
|
2024-10-01 10:28:46 +00:00
|
|
|
attribute.String("address", object.AddressOf(prm.Object).EncodeToString()),
|
2023-04-12 14:01:29 +00:00
|
|
|
))
|
|
|
|
defer span.End()
|
2024-11-11 09:46:55 +00:00
|
|
|
defer elapsed("Put", e.metrics.AddMethodDuration)()
|
2023-04-12 14:01:29 +00:00
|
|
|
|
2021-11-10 15:00:30 +00:00
|
|
|
err = e.execIfNotBlocked(func() error {
|
2023-04-12 14:01:29 +00:00
|
|
|
err = e.put(ctx, prm)
|
2021-11-09 15:46:12 +00:00
|
|
|
return err
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
func (e *StorageEngine) put(ctx context.Context, prm PutPrm) error {
|
2024-10-01 10:28:46 +00:00
|
|
|
addr := object.AddressOf(prm.Object)
|
2022-03-03 14:19:05 +00:00
|
|
|
|
2024-04-01 06:54:42 +00:00
|
|
|
// In #1146 this check was parallelized, however, it became
|
|
|
|
// much slower on fast machines for 4 shards.
|
2024-12-10 09:52:26 +00:00
|
|
|
var ecParent oid.Address
|
2024-10-01 10:28:46 +00:00
|
|
|
if prm.Object.ECHeader() != nil {
|
2024-12-10 09:52:26 +00:00
|
|
|
ecParent.SetObject(prm.Object.ECHeader().Parent())
|
|
|
|
ecParent.SetContainer(addr.Container())
|
2024-05-27 19:07:43 +00:00
|
|
|
}
|
2024-05-30 06:26:06 +00:00
|
|
|
var shPrm shard.ExistsPrm
|
|
|
|
shPrm.Address = addr
|
2024-12-10 09:52:26 +00:00
|
|
|
shPrm.ECParentAddress = ecParent
|
2024-05-30 06:26:06 +00:00
|
|
|
existed, locked, err := e.exists(ctx, shPrm)
|
2020-12-01 11:06:14 +00:00
|
|
|
if err != nil {
|
2023-04-12 14:01:29 +00:00
|
|
|
return err
|
2020-12-01 11:06:14 +00:00
|
|
|
}
|
2020-11-17 12:26:03 +00:00
|
|
|
|
2024-05-27 19:07:43 +00:00
|
|
|
if !existed && locked {
|
2024-12-10 09:52:26 +00:00
|
|
|
lockers, err := e.GetLocked(ctx, ecParent)
|
2024-05-27 19:07:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, locker := range lockers {
|
|
|
|
err = e.lock(ctx, addr.Container(), locker, []oid.ID{addr.Object()})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-21 12:06:54 +00:00
|
|
|
var shRes putToShardRes
|
2024-02-20 12:55:18 +00:00
|
|
|
e.iterateOverSortedShards(addr, func(_ int, sh hashedShard) (stop bool) {
|
2021-10-08 12:25:45 +00:00
|
|
|
e.mtx.RLock()
|
[#2188] engine: Fix panic during setting shard mode
Under load changing shard mode can lead to it being removed from the
list during some other PUT.
```
Dec 28 07:01:26 az neofs-node[364505]: panic: runtime error: invalid memory address or nil pointer dereference
Dec 28 07:01:26 az neofs-node[364505]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xc9fbb1]
Dec 28 07:01:26 az neofs-node[364505]: goroutine 11791912 [running]:
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.(*StorageEngine).putToShard(0xc000435490, {0xc0003f7a28?, 0xc0001192c0?}, 0x2, {0x0, 0x>
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/put.go:91 +0x1b1
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.(*StorageEngine).put.func1(0xc000435490?, {0xc0003f7a28?, 0xc0001192c0?})
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/put.go:71 +0x19c
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.(*StorageEngine).iterateOverSortedShards(0x1?, {{0x62, 0x23, 0xfe, 0x60, 0x67, 0xd5, 0x>
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/shards.go:225 +0xc8
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.(*StorageEngine).put(0xc000435490, {0x1?})
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/put.go:66 +0x2a9
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.(*StorageEngine).Put.func1()
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/put.go:43 +0x2a
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.(*StorageEngine).execIfNotBlocked(0x8?, 0x38?)
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/control.go:147 +0xcf
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.(*StorageEngine).Put(0xc4df775a80?, {0x0?})
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/put.go:42 +0x65
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.Put(0xc06d928b80?, 0xc06b1b8dc8?)
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/put.go:158 +0x19
Dec 28 07:01:26 az neofs-node[364505]: main.engineWithoutNotifications.Put({0x20301b?}, 0x20301b?)
```
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2022-12-29 08:12:01 +00:00
|
|
|
pool, ok := e.shardPools[sh.ID().String()]
|
2021-10-08 12:25:45 +00:00
|
|
|
e.mtx.RUnlock()
|
[#2188] engine: Fix panic during setting shard mode
Under load changing shard mode can lead to it being removed from the
list during some other PUT.
```
Dec 28 07:01:26 az neofs-node[364505]: panic: runtime error: invalid memory address or nil pointer dereference
Dec 28 07:01:26 az neofs-node[364505]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xc9fbb1]
Dec 28 07:01:26 az neofs-node[364505]: goroutine 11791912 [running]:
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.(*StorageEngine).putToShard(0xc000435490, {0xc0003f7a28?, 0xc0001192c0?}, 0x2, {0x0, 0x>
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/put.go:91 +0x1b1
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.(*StorageEngine).put.func1(0xc000435490?, {0xc0003f7a28?, 0xc0001192c0?})
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/put.go:71 +0x19c
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.(*StorageEngine).iterateOverSortedShards(0x1?, {{0x62, 0x23, 0xfe, 0x60, 0x67, 0xd5, 0x>
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/shards.go:225 +0xc8
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.(*StorageEngine).put(0xc000435490, {0x1?})
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/put.go:66 +0x2a9
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.(*StorageEngine).Put.func1()
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/put.go:43 +0x2a
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.(*StorageEngine).execIfNotBlocked(0x8?, 0x38?)
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/control.go:147 +0xcf
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.(*StorageEngine).Put(0xc4df775a80?, {0x0?})
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/put.go:42 +0x65
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine.Put(0xc06d928b80?, 0xc06b1b8dc8?)
Dec 28 07:01:26 az neofs-node[364505]: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine/put.go:158 +0x19
Dec 28 07:01:26 az neofs-node[364505]: main.engineWithoutNotifications.Put({0x20301b?}, 0x20301b?)
```
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2022-12-29 08:12:01 +00:00
|
|
|
if !ok {
|
|
|
|
// Shard was concurrently removed, skip.
|
|
|
|
return false
|
|
|
|
}
|
2024-10-01 15:19:12 +00:00
|
|
|
shRes = e.putToShard(ctx, sh, pool, addr, prm.Object, prm.IsIndexedContainer)
|
2023-11-21 12:06:54 +00:00
|
|
|
return shRes.status != putToShardUnknown
|
2022-09-12 11:48:06 +00:00
|
|
|
})
|
2023-11-21 12:06:54 +00:00
|
|
|
switch shRes.status {
|
|
|
|
case putToShardUnknown:
|
|
|
|
return errPutShard
|
|
|
|
case putToShardRemoved:
|
|
|
|
return shRes.err
|
|
|
|
case putToShardExists, putToShardSuccess:
|
|
|
|
return nil
|
|
|
|
default:
|
|
|
|
return errPutShard
|
2022-09-12 11:48:06 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-27 18:38:28 +00:00
|
|
|
|
2022-09-13 11:18:00 +00:00
|
|
|
// putToShard puts object to sh.
|
2023-11-21 12:06:54 +00:00
|
|
|
// Return putToShardStatus and error if it is necessary to propagate an error upper.
|
2024-02-20 12:55:18 +00:00
|
|
|
func (e *StorageEngine) putToShard(ctx context.Context, sh hashedShard, pool util.WorkerPool,
|
2024-10-01 15:19:12 +00:00
|
|
|
addr oid.Address, obj *objectSDK.Object, isIndexedContainer bool,
|
2023-11-21 12:06:54 +00:00
|
|
|
) (res putToShardRes) {
|
2022-09-12 11:48:06 +00:00
|
|
|
exitCh := make(chan struct{})
|
2020-11-17 12:26:03 +00:00
|
|
|
|
2022-09-12 11:48:06 +00:00
|
|
|
if err := pool.Submit(func() {
|
|
|
|
defer close(exitCh)
|
2020-11-17 12:26:03 +00:00
|
|
|
|
2022-09-12 11:48:06 +00:00
|
|
|
var existPrm shard.ExistsPrm
|
2024-05-30 06:26:06 +00:00
|
|
|
existPrm.Address = addr
|
2021-10-08 12:25:45 +00:00
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
exists, err := sh.Exists(ctx, existPrm)
|
2022-09-12 11:48:06 +00:00
|
|
|
if err != nil {
|
|
|
|
if shard.IsErrObjectExpired(err) {
|
|
|
|
// object is already found but
|
|
|
|
// expired => do nothing with it
|
2023-11-21 12:06:54 +00:00
|
|
|
res.status = putToShardExists
|
2024-07-03 14:14:47 +00:00
|
|
|
} else {
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Warn(ctx, logs.EngineCouldNotCheckObjectExistence,
|
2024-07-03 14:14:47 +00:00
|
|
|
zap.Stringer("shard_id", sh.ID()),
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2022-09-12 11:48:06 +00:00
|
|
|
}
|
2020-11-17 12:26:03 +00:00
|
|
|
|
2022-09-12 11:48:06 +00:00
|
|
|
return // this is not ErrAlreadyRemoved error so we can go to the next shard
|
|
|
|
}
|
2020-11-17 12:26:03 +00:00
|
|
|
|
2023-11-21 12:06:54 +00:00
|
|
|
if exists.Exists() {
|
|
|
|
res.status = putToShardExists
|
2022-09-12 11:48:06 +00:00
|
|
|
return
|
2021-10-08 14:33:51 +00:00
|
|
|
}
|
2020-11-17 12:26:03 +00:00
|
|
|
|
2022-09-12 11:48:06 +00:00
|
|
|
var putPrm shard.PutPrm
|
|
|
|
putPrm.SetObject(obj)
|
2024-10-01 15:19:12 +00:00
|
|
|
putPrm.SetIndexAttributes(isIndexedContainer)
|
2020-12-01 11:06:14 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = sh.Put(ctx, putPrm)
|
2022-09-12 11:48:06 +00:00
|
|
|
if err != nil {
|
2022-09-28 08:10:46 +00:00
|
|
|
if errors.Is(err, shard.ErrReadOnlyMode) || errors.Is(err, blobstor.ErrNoPlaceFound) ||
|
|
|
|
errors.Is(err, common.ErrReadOnly) || errors.Is(err, common.ErrNoSpace) {
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Warn(ctx, logs.EngineCouldNotPutObjectToShard,
|
2022-09-28 08:10:46 +00:00
|
|
|
zap.Stringer("shard_id", sh.ID()),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("error", err.Error()),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2022-09-28 08:10:46 +00:00
|
|
|
return
|
|
|
|
}
|
2023-11-21 12:06:54 +00:00
|
|
|
if client.IsErrObjectAlreadyRemoved(err) {
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Warn(ctx, logs.EngineCouldNotPutObjectToShard,
|
2023-11-21 12:06:54 +00:00
|
|
|
zap.Stringer("shard_id", sh.ID()),
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
|
|
|
res.status = putToShardRemoved
|
|
|
|
res.err = err
|
|
|
|
return
|
|
|
|
}
|
2020-12-01 10:18:25 +00:00
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
e.reportShardError(ctx, sh, "could not put object to shard", err, zap.Stringer("address", addr))
|
2022-09-12 11:48:06 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-11-21 12:06:54 +00:00
|
|
|
res.status = putToShardSuccess
|
2022-09-12 11:48:06 +00:00
|
|
|
}); err != nil {
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Warn(ctx, logs.EngineCouldNotPutObjectToShard, zap.Error(err))
|
2022-09-12 11:48:06 +00:00
|
|
|
close(exitCh)
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2022-09-12 11:48:06 +00:00
|
|
|
<-exitCh
|
|
|
|
|
2023-11-21 12:06:54 +00:00
|
|
|
return
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
2020-11-19 08:15:49 +00:00
|
|
|
|
|
|
|
// Put writes provided object to local storage.
|
2024-10-01 12:27:06 +00:00
|
|
|
func Put(ctx context.Context, storage *StorageEngine, obj *objectSDK.Object, indexedContainer bool) error {
|
|
|
|
return storage.Put(ctx, PutPrm{Object: obj, IsIndexedContainer: indexedContainer})
|
2020-11-19 08:15:49 +00:00
|
|
|
}
|