package control import ( "context" "git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/server/ctrlmessage" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) func (s *Server) GetShardByObjectID(ctx context.Context, req *control.GetShardByObjectIDRequest) (*control.GetShardByObjectIDResponse, error) { // verify request err := s.isValidRequest(req) if err != nil { return nil, status.Error(codes.PermissionDenied, err.Error()) } var oid oid.ID err = oid.DecodeString(req.GetBody().GetOid()) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } var cid cid.ID err = cid.DecodeString(req.GetBody().GetCid()) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } // create and fill response resp := new(control.GetShardByObjectIDResponse) body := new(control.GetShardByObjectIDResponse_Body) resp.SetBody(body) // fill shard info prm := shard.SearchPrm{ ObjectID: oid, ContainerID: cid, } info, err := s.s.GetShardByObjectID(ctx, prm) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } if info.ID == nil { return nil, status.Error(codes.Internal, logs.ShardCouldNotFindObject) } res := ShardInfo(info) body.SetShards(&res) // Sign the response if err := ctrlmessage.Sign(s.key, resp); err != nil { return nil, status.Error(codes.Internal, err.Error()) } return resp, nil } func ShardInfo(info shard.Info) control.ShardInfo { var shardInfo control.ShardInfo shardInfo.SetShard_ID(*info.ID) shardInfo.SetMetabasePath(info.MetaBaseInfo.Path) shardInfo.Blobstor = blobstorInfoToProto(info.BlobStorInfo) shardInfo.SetWritecachePath(info.WriteCacheInfo.Path) shardInfo.SetPiloramaPath(info.PiloramaInfo.Path) var m control.ShardMode switch info.Mode { case mode.ReadWrite: m = control.ShardMode_READ_WRITE case mode.ReadOnly: m = control.ShardMode_READ_ONLY case mode.Degraded: m = control.ShardMode_DEGRADED case mode.DegradedReadOnly: m = control.ShardMode_DEGRADED_READ_ONLY default: m = control.ShardMode_SHARD_MODE_UNDEFINED } shardInfo.SetMode(m) shardInfo.SetErrorCount(info.ErrorCount) shardInfo.SetEvacuationInProgress(info.EvacuationInProgress) return shardInfo }