[42] Client: add splitId patch

Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
Pavel Gross 2025-03-26 16:51:42 +03:00
parent 5e86f53b0e
commit 7c66b4cbe2
5 changed files with 56 additions and 15 deletions

View file

@ -24,25 +24,14 @@ public static class ObjectHeaderMapper
_ => throw new ArgumentException($"Unknown ObjectType. Value: '{header.ObjectType}'.") _ => throw new ArgumentException($"Unknown ObjectType. Value: '{header.ObjectType}'.")
}; };
FrostFsSplit? split = null; FrostFsSplit? split = header!.Split != null
? header.Split.ToModel()
if (header.Split != null) : null;
{
var children = header.Split.Children.Count != 0 ? new ReadOnlyCollection<FrostFsObjectId>(
header.Split.Children.Select(x => x.ToModel()).ToList()) : null;
split = new FrostFsSplit(new SplitId(header.Split.SplitId.ToUuid()),
header.Split.Previous?.ToModel(),
header.Split.Parent?.ToModel(),
header.Split.ParentHeader?.ToModel(),
null,
children);
}
var model = new FrostFsObjectHeader( var model = new FrostFsObjectHeader(
new FrostFsContainerId(Base58.Encode(header.ContainerId.Value.Span)), new FrostFsContainerId(Base58.Encode(header.ContainerId.Value.Span)),
objTypeName, objTypeName,
header.Attributes.Select(attribute => attribute.ToModel()).ToArray(), [.. header.Attributes.Select(attribute => attribute.ToModel())],
split, split,
header.OwnerId.ToModel(), header.OwnerId.ToModel(),
header.Version.ToModel()) header.Version.ToModel())
@ -52,4 +41,18 @@ public static class ObjectHeaderMapper
return model; return model;
} }
public static FrostFsSplit ToModel(this Header.Types.Split split)
{
var children = split!.Children.Count != 0
? new ReadOnlyCollection<FrostFsObjectId>([.. split.Children.Select(x => x.ToModel())])
: null;
return new FrostFsSplit(new SplitId(split.SplitId.ToUuid()),
split.Previous?.ToModel(),
split.Parent?.ToModel(),
split.ParentHeader?.ToModel(),
null,
children);
}
} }

View file

@ -1,4 +1,7 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq;
using FrostFS.Object;
using FrostFS.SDK.Client.Mappers.GRPC;
namespace FrostFS.SDK; namespace FrostFS.SDK;
@ -9,6 +12,8 @@ public class FrostFsSplit(SplitId splitId,
FrostFsSignature? parentSignature = null, FrostFsSignature? parentSignature = null,
ReadOnlyCollection<FrostFsObjectId>? children = null) ReadOnlyCollection<FrostFsObjectId>? children = null)
{ {
private Header.Types.Split? _split;
public FrostFsSplit() : this(new SplitId()) public FrostFsSplit() : this(new SplitId())
{ {
} }
@ -24,4 +29,25 @@ public class FrostFsSplit(SplitId splitId,
public FrostFsObjectHeader? ParentHeader { get; set; } = parentHeader; public FrostFsObjectHeader? ParentHeader { get; set; } = parentHeader;
public ReadOnlyCollection<FrostFsObjectId>? Children { get; } = children; public ReadOnlyCollection<FrostFsObjectId>? Children { get; } = children;
public Header.Types.Split GetSplit()
{
if (_split == null)
{
_split = new Header.Types.Split
{
SplitId = SplitId?.GetSplitId(),
Parent = Parent?.ToMessage(),
ParentHeader = ParentHeader?.GetHeader(),
ParentSignature = ParentSignature?.ToMessage()
};
if (Children != null)
{
_split.Children.AddRange(Children.Select(x => x.ToMessage()));
}
}
return _split;
}
} }

View file

@ -10,6 +10,7 @@ public readonly struct PrmObjectPatch(
FrostFsSessionToken? sessionToken = null, FrostFsSessionToken? sessionToken = null,
bool replaceAttributes = false, bool replaceAttributes = false,
FrostFsAttributePair[]? newAttributes = null, FrostFsAttributePair[]? newAttributes = null,
FrostFsSplit? newSplitHeader = null,
string[]? xheaders = null) : ISessionToken, System.IEquatable<PrmObjectPatch> string[]? xheaders = null) : ISessionToken, System.IEquatable<PrmObjectPatch>
{ {
public FrostFsAddress Address { get; } = address; public FrostFsAddress Address { get; } = address;
@ -23,6 +24,8 @@ public readonly struct PrmObjectPatch(
public FrostFsAttributePair[]? NewAttributes { get; } = newAttributes; public FrostFsAttributePair[]? NewAttributes { get; } = newAttributes;
public FrostFsSplit? NewSplitHeader { get; } = newSplitHeader;
public bool ReplaceAttributes { get; } = replaceAttributes; public bool ReplaceAttributes { get; } = replaceAttributes;
public int MaxChunkLength { get; } = maxChunkLength; public int MaxChunkLength { get; } = maxChunkLength;

View file

@ -356,6 +356,11 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
} }
} }
if (args.NewSplitHeader != null)
{
request.Body.NewSplitHeader = args.NewSplitHeader.GetSplit();
}
isFirstChunk = false; isFirstChunk = false;
} }
else else

View file

@ -887,6 +887,10 @@ message PatchRequest {
// key, then it just replaces it while merging the lists. // key, then it just replaces it while merging the lists.
bool replace_attributes = 3; bool replace_attributes = 3;
// New split header for the object. This defines how the object will relate
// to other objects in a split operation.
neo.fs.v2.object.Header.Split new_split_header = 5;
// The patch for the object's payload. // The patch for the object's payload.
message Patch { message Patch {
// The range of the source object for which the payload is replaced by the // The range of the source object for which the payload is replaced by the