2020-12-01 08:40:32 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
2023-09-27 08:02:06 +00:00
|
|
|
tracingPkg "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
|
2023-05-31 09:24:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2023-03-07 13:38:26 +00:00
|
|
|
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-12-01 08:40:32 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ToMoveItPrm encapsulates parameters for ToMoveIt operation.
|
|
|
|
type ToMoveItPrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr oid.Address
|
2020-12-01 08:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToMoveItRes encapsulates results of ToMoveIt operation.
|
|
|
|
type ToMoveItRes struct{}
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
// SetAddress sets object address that should be marked to move into another
|
2020-12-01 08:40:32 +00:00
|
|
|
// shard.
|
2022-07-13 12:43:04 +00:00
|
|
|
func (p *ToMoveItPrm) SetAddress(addr oid.Address) {
|
|
|
|
p.addr = addr
|
2020-12-01 08:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToMoveIt calls metabase.ToMoveIt method to mark object as relocatable to
|
|
|
|
// another shard.
|
2023-04-12 14:01:29 +00:00
|
|
|
func (s *Shard) ToMoveIt(ctx context.Context, prm ToMoveItPrm) (ToMoveItRes, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.ToMoveIt",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
attribute.String("address", prm.addr.EncodeToString()),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
m := s.info.Mode
|
2022-06-29 11:27:36 +00:00
|
|
|
if m.ReadOnly() {
|
2022-05-31 11:50:39 +00:00
|
|
|
return ToMoveItRes{}, ErrReadOnlyMode
|
2022-06-29 11:27:36 +00:00
|
|
|
} else if m.NoMetabase() {
|
|
|
|
return ToMoveItRes{}, ErrDegradedMode
|
2021-12-27 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
var toMovePrm meta.ToMoveItPrm
|
2022-07-12 14:59:37 +00:00
|
|
|
toMovePrm.SetAddress(prm.addr)
|
2022-07-12 14:42:55 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err := s.metaBase.ToMoveIt(ctx, toMovePrm)
|
2020-12-01 08:40:32 +00:00
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
s.log.Debug(logs.ShardCouldNotMarkObjectForShardRelocationInMetabase,
|
2020-12-01 08:40:32 +00:00
|
|
|
zap.String("error", err.Error()),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)),
|
2020-12-01 08:40:32 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
return ToMoveItRes{}, nil
|
2020-12-01 08:40:32 +00:00
|
|
|
}
|