From 00b2b77b261b195df583916660161d45df4a30ae Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 2 May 2024 14:29:59 +0300 Subject: [PATCH] [#1112] node: Implement `Range\RangeHash` requests for EC object Signed-off-by: Anton Nikiforov --- go.mod | 4 +- go.sum | Bin 43435 -> 43435 bytes pkg/local_object_storage/engine/range.go | 13 ++++ pkg/services/object/get/assemblerec.go | 62 +++++++++++++++--- .../object/get/v2/get_range_forwarder.go | 3 + pkg/services/object/get/v2/service.go | 3 + pkg/services/object/get/v2/util.go | 11 ++++ 7 files changed, 84 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 1be2526f..08a59581 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,10 @@ go 1.21 require ( code.gitea.io/sdk/gitea v0.17.1 - git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240422151450-df9b65324a4c + git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240427200446-67c6f305b21f git.frostfs.info/TrueCloudLab/frostfs-contract v0.19.0 git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20231101111734-b3ad3335ff65 - git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20240424080726-20ab57bf7ec3 + git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20240507063414-99e02858af12 git.frostfs.info/TrueCloudLab/hrw v1.2.1 git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20240412130734-0e69e485115a git.frostfs.info/TrueCloudLab/tzhash v1.8.0 diff --git a/go.sum b/go.sum index 0795c955b7dfee7e8350931d360f390790f252ca..6200022c7134e6ceb478cf0db641b73a6d6bd15b 100644 GIT binary patch delta 269 zcmZ2|nQ8T9rU@^c&5aBUOiavl&CHX{(u@sElZ*`06fz90A}h0s1N};h^3nsVJiYxx zOB@R#@-t0~Obb%W6H9!xlOxg!A`LCeqQdhhe`L~_cve~jn^Bva7`2#PO%2Qq%#2M8 zO>`|SQw@wPOf3@A42?k6l)5_RX@@vPRHPS1L{z31MTQ$iSfse+x>u&SS9+B>C7V_j z=cReLWkmW;E@ZLx!ETa%dcIz6ehSFIRC5o@JU_RB3d4{r;~*o0sQijbgRp$F;G&!) dv#KytAM>cdh{ANsqCAty7g@D7FJk3f0s#L{RMG$d delta 269 zcmZ2|nQ8T9rU@^cjSNi+lMM|fe`L~_cve~jn^Bva7`2#PO^i$oEDX$z z%yf+m5|d2LlhVvnlZ`>vmH;-vIL*1A~YZ)3B(pDmNqF(u_(k=e+!q d%8axMkI1~TB3D;;{Zy057g@D7FJk3f0sz)FQ=9+* diff --git a/pkg/local_object_storage/engine/range.go b/pkg/local_object_storage/engine/range.go index e45845d6..f5b33a25 100644 --- a/pkg/local_object_storage/engine/range.go +++ b/pkg/local_object_storage/engine/range.go @@ -102,6 +102,9 @@ func (e *StorageEngine) getRange(ctx context.Context, prm RngPrm) (RngRes, error if it.SplitInfo != nil { return RngRes{}, logicerr.Wrap(objectSDK.NewSplitInfoError(it.SplitInfo)) } + if it.ECInfo != nil { + return RngRes{}, logicerr.Wrap(objectSDK.NewECInfoError(it.ECInfo)) + } if it.Object == nil { // If any shard is in a degraded mode, we should assume that metabase could store @@ -147,6 +150,8 @@ type getRangeShardIterator struct { Object *objectSDK.Object SplitInfoError *objectSDK.SplitInfoError SplitInfo *objectSDK.SplitInfo + ECInfoError *objectSDK.ECInfoError + ECInfo *objectSDK.ECInfo OutError error ShardWithMeta hashedShard MetaError error @@ -188,6 +193,14 @@ func (i *getRangeShardIterator) tryGetWithMeta(ctx context.Context) { // stop iterating over shards if SplitInfo structure is complete return withLink && withLast + case errors.As(err, &i.ECInfoError): + if i.ECInfo == nil { + i.ECInfo = objectSDK.NewECInfo() + } + + util.MergeECInfo(i.ECInfoError.ECInfo(), i.ECInfo) + // stop iterating over shards if ECInfo structure is complete + return len(i.ECInfo.Chunks) == int(i.ECInfo.Chunks[0].Total) case client.IsErrObjectAlreadyRemoved(err), shard.IsErrOutOfRange(err): diff --git a/pkg/services/object/get/assemblerec.go b/pkg/services/object/get/assemblerec.go index d73d771c..4a624e46 100644 --- a/pkg/services/object/get/assemblerec.go +++ b/pkg/services/object/get/assemblerec.go @@ -8,6 +8,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/policy" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" + apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/erasurecode" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -45,23 +46,64 @@ func newAssemblerEC( // Assemble assembles erasure-coded object and writes it's content to ObjectWriter. // It returns parent object. func (a *assemblerec) Assemble(ctx context.Context, writer ObjectWriter, headOnly bool) (*objectSDK.Object, error) { - parts := a.retrieveParts(ctx, headOnly) + if headOnly { + return a.reconstructHeader(ctx, writer) + } else if a.rng != nil { + return a.reconstructRange(ctx, writer) + } + return a.reconstructObject(ctx, writer) +} + +func (a *assemblerec) getConstructor() (*erasurecode.Constructor, error) { cnt, err := a.cs.Get(a.addr.Container()) if err != nil { return nil, err } - c, err := erasurecode.NewConstructor( - policy.ECDataCount(cnt.Value.PlacementPolicy()), - policy.ECParityCount(cnt.Value.PlacementPolicy()), - ) + dataCount := policy.ECDataCount(cnt.Value.PlacementPolicy()) + parityCount := policy.ECParityCount(cnt.Value.PlacementPolicy()) + return erasurecode.NewConstructor(dataCount, parityCount) +} + +func (a *assemblerec) reconstructHeader(ctx context.Context, writer ObjectWriter) (*objectSDK.Object, error) { + parts := a.retrieveParts(ctx, true) + c, err := a.getConstructor() if err != nil { return nil, err } - if headOnly { - obj, err := c.ReconstructHeader(parts) - if err == nil { - return obj, writer.WriteHeader(ctx, obj) - } + obj, err := c.ReconstructHeader(parts) + if err == nil { + return obj, writer.WriteHeader(ctx, obj) + } + return nil, err +} + +func (a *assemblerec) reconstructRange(ctx context.Context, writer ObjectWriter) (*objectSDK.Object, error) { + parts := a.retrieveParts(ctx, false) + c, err := a.getConstructor() + if err != nil { + return nil, err + } + obj, err := c.Reconstruct(parts) + if err != nil { + return nil, err + } + + from := a.rng.GetOffset() + to := from + a.rng.GetLength() + if pLen := uint64(len(obj.Payload())); to < from || pLen < from || pLen < to { + return nil, &apistatus.ObjectOutOfRange{} + } + err = writer.WriteChunk(ctx, obj.Payload()[from:to]) + if err != nil { + return nil, err + } + return obj, err +} + +func (a *assemblerec) reconstructObject(ctx context.Context, writer ObjectWriter) (*objectSDK.Object, error) { + parts := a.retrieveParts(ctx, false) + c, err := a.getConstructor() + if err != nil { return nil, err } obj, err := c.Reconstruct(parts) diff --git a/pkg/services/object/get/v2/get_range_forwarder.go b/pkg/services/object/get/v2/get_range_forwarder.go index 8a56c59a..5b05ec37 100644 --- a/pkg/services/object/get/v2/get_range_forwarder.go +++ b/pkg/services/object/get/v2/get_range_forwarder.go @@ -132,6 +132,9 @@ func (f *getRangeRequestForwarder) readStream(ctx context.Context, rangeStream * case *objectV2.SplitInfo: si := objectSDK.NewSplitInfoFromV2(v) return objectSDK.NewSplitInfoError(si) + case *objectV2.ECInfo: + ei := objectSDK.NewECInfoFromV2(v) + return objectSDK.NewECInfoError(ei) } } return nil diff --git a/pkg/services/object/get/v2/service.go b/pkg/services/object/get/v2/service.go index 682128df..edd19b44 100644 --- a/pkg/services/object/get/v2/service.go +++ b/pkg/services/object/get/v2/service.go @@ -104,10 +104,13 @@ func (s *Service) GetRange(req *objectV2.GetRangeRequest, stream objectSvc.GetOb err = s.svc.GetRange(stream.Context(), *p) var splitErr *objectSDK.SplitInfoError + var ecErr *objectSDK.ECInfoError switch { case errors.As(err, &splitErr): return stream.Send(splitInfoRangeResponse(splitErr.SplitInfo())) + case errors.As(err, &ecErr): + return stream.Send(ecInfoRangeResponse(ecErr.ECInfo())) default: return err } diff --git a/pkg/services/object/get/v2/util.go b/pkg/services/object/get/v2/util.go index da642898..610076c7 100644 --- a/pkg/services/object/get/v2/util.go +++ b/pkg/services/object/get/v2/util.go @@ -292,6 +292,17 @@ func splitInfoRangeResponse(info *objectSDK.SplitInfo) *objectV2.GetRangeRespons return resp } +func ecInfoRangeResponse(info *objectSDK.ECInfo) *objectV2.GetRangeResponse { + resp := new(objectV2.GetRangeResponse) + + body := new(objectV2.GetRangeResponseBody) + resp.SetBody(body) + + body.SetRangePart(info.ToV2()) + + return resp +} + func setSplitInfoHeadResponse(info *objectSDK.SplitInfo, resp *objectV2.HeadResponse) { resp.GetBody().SetHeaderPart(info.ToV2()) }