[#25] Client: Implement Patch and Range methods

Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
Pavel Gross 2024-11-08 10:38:50 +03:00
parent bff8d67867
commit 003b7fdfdd
51 changed files with 1338 additions and 137 deletions

View file

@ -285,6 +285,25 @@ public class FrostFSClient : IFrostFSClient
return service.GetObjectAsync(args);
}
public Task<RangeReader> GetRangeAsync(PrmRangeGet args)
{
if (args is null)
throw new ArgumentNullException(nameof(args));
var service = GetObjectService(args);
return service.GetRangeAsync(args);
}
public Task<IEnumerable<ReadOnlyMemory<byte>>> GetRangeHashAsync(PrmRangeHashGet args)
{
if (args is null)
throw new ArgumentNullException(nameof(args));
var service = GetObjectService(args);
return service.GetRangeHashAsync(args);
}
public Task<FrostFsObjectId> PutObjectAsync(PrmObjectPut args)
{
if (args is null)
@ -303,6 +322,17 @@ public class FrostFSClient : IFrostFSClient
return service.PutSingleObjectAsync(args);
}
public Task<FrostFsObjectId> PatchObjectAsync(PrmObjectPatch args)
{
if (args is null)
{
throw new ArgumentNullException(nameof(args));
}
var service = GetObjectService(args);
return service.PatchObjectAsync(args);
}
public Task DeleteObjectAsync(PrmObjectDelete args)
{
if (args is null)

View file

@ -42,10 +42,16 @@ public interface IFrostFSClient : IDisposable
Task<FrostFsObject> GetObjectAsync(PrmObjectGet args);
Task<RangeReader> GetRangeAsync(PrmRangeGet args);
Task<IEnumerable<ReadOnlyMemory<byte>>> GetRangeHashAsync(PrmRangeHashGet args);
Task<FrostFsObjectId> PutObjectAsync(PrmObjectPut args);
Task<FrostFsObjectId> PutSingleObjectAsync(PrmSingleObjectPut args);
Task<FrostFsObjectId> PatchObjectAsync(PrmObjectPatch args);
Task DeleteObjectAsync(PrmObjectDelete args);
IAsyncEnumerable<FrostFsObjectId> SearchObjectsAsync(PrmObjectSearch args);

View file

@ -33,7 +33,16 @@ public static class ContainerIdMapper
Caches.Containers.Set(containerId, message, _oneHourExpiration);
}
return message!;
}
public static FrostFsContainerId ToModel(this ContainerID message)
{
if (message is null)
{
throw new ArgumentNullException(nameof(message));
}
return new FrostFsContainerId(Base58.Encode(message.Value.ToByteArray()));
}
}

View file

@ -0,0 +1,48 @@
using FrostFS.Refs;
using FrostFS.SDK.ClientV2.Mappers.GRPC;
namespace FrostFS.SDK;
public class FrostFsAddress
{
private FrostFsObjectId? frostFsObjectId;
private FrostFsContainerId? frostFsContainerId;
private ObjectID? objectId;
private ContainerID? containerId;
public FrostFsAddress(FrostFsContainerId frostFsContainerId, FrostFsObjectId frostFsObjectId)
{
FrostFsObjectId = frostFsObjectId ?? throw new System.ArgumentNullException(nameof(frostFsObjectId));
FrostFsContainerId = frostFsContainerId ?? throw new System.ArgumentNullException(nameof(frostFsContainerId));
}
internal FrostFsAddress(ObjectID objectId, ContainerID containerId)
{
ObjectId = objectId ?? throw new System.ArgumentNullException(nameof(objectId));
ContainerId = containerId ?? throw new System.ArgumentNullException(nameof(containerId));
}
public FrostFsObjectId FrostFsObjectId
{
get => frostFsObjectId ??= objectId!.ToModel();
set => frostFsObjectId = value;
}
public FrostFsContainerId FrostFsContainerId
{
get => frostFsContainerId ??= containerId!.ToModel();
set => frostFsContainerId = value;
}
public ObjectID ObjectId
{
get => objectId ??= frostFsObjectId!.ToMessage();
set => objectId = value;
}
public ContainerID ContainerId
{
get => containerId ??= frostFsContainerId!.ToMessage();
set => containerId = value;
}
}

View file

@ -0,0 +1,27 @@
namespace FrostFS.SDK;
public readonly struct FrostFsRange(ulong offset, ulong length) : System.IEquatable<FrostFsRange>
{
public ulong Offset { get; } = offset;
public ulong Length { get; } = length;
public override readonly bool Equals(object obj) => this == (FrostFsRange)obj;
public override readonly int GetHashCode() => $"{Offset}{Length}".GetHashCode();
public static bool operator ==(FrostFsRange left, FrostFsRange right)
{
return left.Equals(right);
}
public static bool operator !=(FrostFsRange left, FrostFsRange right)
{
return !(left == right);
}
public readonly bool Equals(FrostFsRange other)
{
return this == other;
}
}

View file

@ -6,5 +6,5 @@ namespace FrostFS.SDK;
public interface IObjectReader : IDisposable
{
Task<ReadOnlyMemory<byte>?> ReadChunk(CancellationToken cancellationToken = default);
ValueTask<ReadOnlyMemory<byte>?> ReadChunk(CancellationToken cancellationToken = default);
}

View file

@ -0,0 +1,24 @@
using System.IO;
namespace FrostFS.SDK.ClientV2;
public sealed class PrmObjectPatch(FrostFsAddress address, CallContext? ctx = null) : PrmBase(ctx), ISessionToken
{
public FrostFsAddress Address { get; } = address;
public FrostFsRange Range { get; set; }
/// <summary>
/// A stream with source data
/// </summary>
public Stream? Payload { get; set; }
public FrostFsAttributePair[]? NewAttributes { get; set; }
public bool ReplaceAttributes { get; set; }
public int MaxPayloadPatchChunkLength { get; set; }
/// <inheritdoc />
public FrostFsSessionToken? SessionToken { get; set; }
}

View file

@ -0,0 +1,20 @@
namespace FrostFS.SDK.ClientV2;
public sealed class PrmRangeGet(
FrostFsContainerId containerId,
FrostFsObjectId objectId,
FrostFsRange range,
bool raw = false,
CallContext? ctx = null) : PrmBase(ctx), ISessionToken
{
public FrostFsContainerId ContainerId { get; } = containerId;
public FrostFsObjectId ObjectId { get; } = objectId;
public FrostFsRange Range { get; } = range;
public bool Raw { get; } = raw;
/// <inheritdoc />
public FrostFsSessionToken? SessionToken { get; set; }
}

View file

@ -0,0 +1,20 @@
namespace FrostFS.SDK.ClientV2;
public sealed class PrmRangeHashGet(
FrostFsContainerId containerId,
FrostFsObjectId objectId,
FrostFsRange[] ranges,
byte[] salt,
CallContext? ctx = null) : PrmBase(ctx), ISessionToken
{
public FrostFsContainerId ContainerId { get; } = containerId;
public FrostFsObjectId ObjectId { get; } = objectId;
public FrostFsRange[] Ranges { get; } = ranges;
public byte[] Salt { get; } = salt;
/// <inheritdoc />
public FrostFsSessionToken? SessionToken { get; set; }
}

View file

@ -101,9 +101,9 @@ public class ClientWrapper : ClientStatusMonitor
await ScheduleGracefulClose().ConfigureAwait(false);
}
#pragma warning disable CA2000 // Dispose objects before losing scope: will be disposed manually
//#pragma warning disable CA2000 // Dispose objects before losing scope: will be disposed manually
FrostFSClient client = new(WrapperPrm, sessionCache);
#pragma warning restore CA2000
//#pragma warning restore CA2000
//TODO: set additioanl params
var error = await client.Dial(ctx).ConfigureAwait(false);

View file

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@ -711,6 +710,62 @@ public partial class Pool : IFrostFSClient
return await client.Client!.PutSingleObjectAsync(args).ConfigureAwait(false);
}
public async Task<FrostFsObjectId> PatchObjectAsync(PrmObjectPatch args)
{
if (args is null)
{
throw new ArgumentNullException(nameof(args));
}
var client = Connection();
args.Context.PoolErrorHandler = client.HandleError;
return await client.Client!.PatchObjectAsync(args).ConfigureAwait(false);
}
public async Task<RangeReader> GetRangeAsync(PrmRangeGet args)
{
if (args is null)
{
throw new ArgumentNullException(nameof(args));
}
var client = Connection();
args.Context.PoolErrorHandler = client.HandleError;
return await client.Client!.GetRangeAsync(args).ConfigureAwait(false);
}
public async Task<IEnumerable<ReadOnlyMemory<byte>>> GetRangeHashAsync(PrmRangeHashGet args)
{
if (args is null)
{
throw new ArgumentNullException(nameof(args));
}
var client = Connection();
args.Context.PoolErrorHandler = client.HandleError;
return await client.Client!.GetRangeHashAsync(args).ConfigureAwait(false);
}
public async Task<FrostFsObjectId> PatchAsync(PrmObjectPatch args)
{
if (args is null)
{
throw new ArgumentNullException(nameof(args));
}
var client = Connection();
args.Context.PoolErrorHandler = client.HandleError;
return await client.Client!.PatchObjectAsync(args).ConfigureAwait(false);
}
public async Task DeleteObjectAsync(PrmObjectDelete args)
{
if (args is null)

View file

@ -1,6 +1,7 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@ -107,6 +108,101 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
return await GetObject(request, ctx).ConfigureAwait(false);
}
internal async Task<RangeReader> GetRangeAsync(PrmRangeGet args)
{
var ctx = args.Context!;
ctx.Key ??= ClientContext.Key?.ECDsaKey;
if (ctx.Key == null)
throw new ArgumentNullException(nameof(args), "Key is null");
var request = new GetRangeRequest
{
Body = new GetRangeRequest.Types.Body
{
Address = new Address
{
ContainerId = args.ContainerId.ToMessage(),
ObjectId = args.ObjectId.ToMessage()
},
Range = new Object.Range
{
Offset = args.Range.Offset,
Length = args.Range.Length
},
Raw = args.Raw
}
};
var sessionToken = await GetOrCreateSession(args, ctx).ConfigureAwait(false);
sessionToken.CreateObjectTokenContext(
request.Body.Address,
ObjectSessionContext.Types.Verb.Range,
ctx.Key);
request.AddMetaHeader(args.XHeaders, sessionToken);
request.Sign(ctx.Key);
var call = client.GetRange(request, null, ctx.Deadline, ctx.CancellationToken);
return new RangeReader(call);
}
internal async Task<IEnumerable<ReadOnlyMemory<byte>>> GetRangeHashAsync(PrmRangeHashGet args)
{
var ctx = args.Context!;
ctx.Key ??= ClientContext.Key?.ECDsaKey;
if (ctx.Key == null)
throw new ArgumentNullException(nameof(args), "Key is null");
var request = new GetRangeHashRequest
{
Body = new GetRangeHashRequest.Types.Body
{
Address = new Address
{
ContainerId = args.ContainerId.ToMessage(),
ObjectId = args.ObjectId.ToMessage()
},
Type = ChecksumType.Sha256,
Salt = ByteString.CopyFrom(args.Salt) // TODO: create a type with calculated cashed ByteString inside
}
};
foreach (var range in args.Ranges)
{
request.Body.Ranges.Add(new Object.Range
{
Length = range.Length,
Offset = range.Offset
});
}
var sessionToken = await GetOrCreateSession(args, ctx).ConfigureAwait(false);
sessionToken.CreateObjectTokenContext(
request.Body.Address,
ObjectSessionContext.Types.Verb.Rangehash,
ctx.Key);
request.AddMetaHeader(args.XHeaders, sessionToken);
request.Sign(ctx.Key);
var response = await client.GetRangeHashAsync(request, null, ctx.Deadline, ctx.CancellationToken);
Verifier.CheckResponse(response);
var hashCollection = response.Body.HashList.ToArray().Select(h => h.Memory);
return hashCollection;
}
internal async Task DeleteObjectAsync(PrmObjectDelete args)
{
var ctx = args.Context!;
@ -191,7 +287,9 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
throw new ArgumentNullException(nameof(args), "Payload is null");
if (args.ClientCut)
{
return await PutClientCutObject(args).ConfigureAwait(false);
}
else
{
if (args.Header.PayloadLength > 0)
@ -199,7 +297,9 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
else if (args.Payload.CanSeek)
args.FullLength = (ulong)args.Payload.Length;
return (await PutStreamObject(args).ConfigureAwait(false)).ObjectId;
var response = await PutStreamObject(args).ConfigureAwait(false);
return response.ObjectId;
}
}
@ -235,6 +335,100 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
return FrostFsObjectId.FromHash(grpcObject.ObjectId.Value.ToByteArray());
}
internal async Task<FrostFsObjectId> PatchObjectAsync(PrmObjectPatch args)
{
var ctx = args.Context!;
if (ctx.Key == null)
throw new ArgumentNullException(nameof(args), "Key is null");
var chunkSize = args.MaxPayloadPatchChunkLength;
Stream payload = args.Payload ?? throw new ArgumentNullException(nameof(args), "Stream parameter is null");
var call = client.Patch(null, ctx.Deadline, ctx.CancellationToken);
byte[]? chunkBuffer = null;
try
{
// common
chunkBuffer = ClientContext.GetArrayPool(Constants.ObjectChunkSize).Rent(chunkSize);
var address = new Address
{
ObjectId = args.Address.ObjectId,
ContainerId = args.Address.ContainerId
};
var sessionToken = await GetOrCreateSession(args, ctx).ConfigureAwait(false);
sessionToken.CreateObjectTokenContext(
address,
ObjectSessionContext.Types.Verb.Patch,
ctx.Key
);
var request = new PatchRequest()
{
Body = new()
{
Address = address,
ReplaceAttributes = args.ReplaceAttributes,
}
};
bool isFirstChunk = true;
ulong currentPos = args.Range.Offset;
while (true)
{
var bytesCount = await payload.ReadAsync(chunkBuffer, 0, chunkSize, ctx.CancellationToken).ConfigureAwait(false);
if (bytesCount == 0)
{
break;
}
if (isFirstChunk && args.NewAttributes != null && args.NewAttributes.Length > 0)
{
foreach (var attr in args.NewAttributes)
{
request.Body.NewAttributes.Add(attr.ToMessage());
}
}
request.Body.Patch = new PatchRequest.Types.Body.Types.Patch
{
Chunk = ByteString.CopyFrom(chunkBuffer, 0, bytesCount),
SourceRange = new Object.Range { Offset = currentPos, Length = (ulong)bytesCount }
};
currentPos += (ulong)bytesCount;
request.AddMetaHeader(args.XHeaders, sessionToken);
request.Sign(ctx.Key);
await call.RequestStream.WriteAsync(request).ConfigureAwait(false);
isFirstChunk = false;
}
}
finally
{
await call.RequestStream.CompleteAsync().ConfigureAwait(false);
if (chunkBuffer != null)
{
ArrayPool<byte>.Shared.Return(chunkBuffer);
}
}
var response = await call.ResponseAsync.ConfigureAwait(false);
Verifier.CheckResponse(response);
return response.Body.ObjectId.ToModel();
}
private async Task<FrostFsObjectId> PutClientCutObject(PrmObjectPut args)
{
var ctx = args.Context!;
@ -406,7 +600,7 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
}
}
private async Task<ObjectStreamer> GetUploadStream(PrmObjectPut args, CallContext ctx)
private async Task<ObjectStreamer<PutRequest, PutResponse>> GetUploadStream(PrmObjectPut args, CallContext ctx)
{
var header = args.Header!;
@ -451,6 +645,20 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
return await PutObjectInit(initRequest, ctx).ConfigureAwait(false);
}
private async Task<ObjectStreamer<PutRequest, PutResponse>> PutObjectInit(PutRequest initRequest, CallContext ctx)
{
if (initRequest is null)
{
throw new ArgumentNullException(nameof(initRequest));
}
var call = client.Put(null, ctx.Deadline, ctx.CancellationToken);
await call.RequestStream.WriteAsync(initRequest).ConfigureAwait(false);
return new ObjectStreamer<PutRequest, PutResponse>(call);
}
private async Task<FrostFsObject> GetObject(GetRequest request, CallContext ctx)
{
var reader = GetObjectInit(request, ctx);
@ -473,20 +681,6 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
return new ObjectReader(call);
}
private async Task<ObjectStreamer> PutObjectInit(PutRequest initRequest, CallContext ctx)
{
if (initRequest is null)
{
throw new ArgumentNullException(nameof(initRequest));
}
var call = client.Put(null, ctx.Deadline, ctx.CancellationToken);
await call.RequestStream.WriteAsync(initRequest).ConfigureAwait(false);
return new ObjectStreamer(call);
}
private async IAsyncEnumerable<ObjectID> SearchObjects(SearchRequest request, CallContext ctx)
{
using var stream = GetSearchReader(request, ctx);

View file

@ -32,7 +32,7 @@ public sealed class ObjectReader(AsyncServerStreamingCall<GetResponse> call) : I
};
}
public async Task<ReadOnlyMemory<byte>?> ReadChunk(CancellationToken cancellationToken = default)
public async ValueTask<ReadOnlyMemory<byte>?> ReadChunk(CancellationToken cancellationToken = default)
{
if (!await Call.ResponseStream.MoveNext(cancellationToken).ConfigureAwait(false))
return null;

View file

@ -1,17 +1,15 @@
using System;
using System.Threading.Tasks;
using FrostFS.Object;
using Grpc.Core;
namespace FrostFS.SDK.ClientV2;
internal sealed class ObjectStreamer(AsyncClientStreamingCall<PutRequest, PutResponse> call) : IDisposable
internal sealed class ObjectStreamer<TRequest, TResponse>(AsyncClientStreamingCall<TRequest, TResponse> call) : IDisposable
{
public AsyncClientStreamingCall<PutRequest, PutResponse> Call { get; private set; } = call;
public AsyncClientStreamingCall<TRequest, TResponse> Call { get; private set; } = call;
public async Task Write(PutRequest request)
public async Task Write(TRequest request)
{
if (request is null)
{
@ -21,7 +19,7 @@ internal sealed class ObjectStreamer(AsyncClientStreamingCall<PutRequest, PutRes
await Call.RequestStream.WriteAsync(request).ConfigureAwait(false);
}
public async Task<PutResponse> Close()
public async Task<TResponse> Close()
{
await Call.RequestStream.CompleteAsync().ConfigureAwait(false);

View file

@ -0,0 +1,38 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using FrostFS.Object;
using Grpc.Core;
namespace FrostFS.SDK.ClientV2;
public sealed class RangeReader(AsyncServerStreamingCall<GetRangeResponse> call) : IObjectReader
{
private bool disposed;
public AsyncServerStreamingCall<GetRangeResponse> Call { get; private set; } = call;
public async ValueTask<ReadOnlyMemory<byte>?> ReadChunk(CancellationToken cancellationToken = default)
{
if (!await Call.ResponseStream.MoveNext(cancellationToken).ConfigureAwait(false))
return null;
var response = Call.ResponseStream.Current;
Verifier.CheckResponse(response);
return response.Body.Chunk.Memory;
}
public void Dispose()
{
if (!disposed)
{
Call?.Dispose();
GC.SuppressFinalize(this);
disposed = true;
}
}
}

View file

@ -9,13 +9,13 @@ import "accounting/types.proto";
import "refs/types.proto";
import "session/types.proto";
// Accounting service provides methods for interaction with NeoFS sidechain via
// other NeoFS nodes to get information about the account balance. Deposit and
// Withdraw operations can't be implemented here, as they require Mainnet NeoFS
// smart contract invocation. Transfer operations between internal NeoFS
// accounts are possible if both use the same token type.
// Accounting service provides methods for interaction with FrostFS sidechain
// via other FrostFS nodes to get information about the account balance. Deposit
// and Withdraw operations can't be implemented here, as they require Mainnet
// FrostFS smart contract invocation. Transfer operations between internal
// FrostFS accounts are possible if both use the same token type.
service AccountingService {
// Returns the amount of funds in GAS token for the requested NeoFS account.
// Returns the amount of funds in GAS token for the requested FrostFS account.
//
// Statuses:
// - **OK** (0, SECTION_SUCCESS):
@ -27,9 +27,9 @@ service AccountingService {
// BalanceRequest message
message BalanceRequest {
// To indicate the account for which the balance is requested, its identifier
// is used. It can be any existing account in NeoFS sidechain `Balance` smart
// contract. If omitted, client implementation MUST set it to the request's
// signer `OwnerID`.
// is used. It can be any existing account in FrostFS sidechain `Balance`
// smart contract. If omitted, client implementation MUST set it to the
// request's signer `OwnerID`.
message Body {
// Valid user identifier in `OwnerID` format for which the balance is
// requested. Required field.

View file

@ -6,6 +6,7 @@ option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc;ac
option csharp_namespace = "FrostFS.Acl";
import "refs/types.proto";
import "ape/types.proto";
// Target role of the access control rule in access control list.
enum Role {
@ -88,14 +89,14 @@ enum HeaderType {
// Filter object headers
OBJECT = 2;
// Filter service headers. These are not processed by NeoFS nodes and
// Filter service headers. These are not processed by FrostFS nodes and
// exist for service use only.
SERVICE = 3;
}
// Describes a single eACL rule.
message EACLRecord {
// NeoFS request Verb to match
// FrostFS request Verb to match
Operation operation = 1 [ json_name = "operation" ];
// Rule execution result. Either allows or denies access if filters match.
@ -164,7 +165,7 @@ message EACLRecord {
// Extended ACL rules table. A list of ACL rules defined additionally to Basic
// ACL. Extended ACL rules can be attached to a container and can be updated
// or may be defined in `BearerToken` structure. Please see the corresponding
// NeoFS Technical Specification section for detailed description.
// FrostFS Technical Specification section for detailed description.
message EACLTable {
// eACL format version. Effectively, the version of API library used to create
// eACL Table.
@ -194,6 +195,9 @@ message BearerToken {
// container. If it contains `container_id` field, bearer token is only
// valid for this specific container. Otherwise, any container of the same
// owner is allowed.
//
// Deprecated: eACL tables are no longer relevant - `APEOverrides` should be
// used instead.
EACLTable eacl_table = 1 [ json_name = "eaclTable" ];
// `OwnerID` defines to whom the token was issued. It must match the request
@ -218,6 +222,24 @@ message BearerToken {
// AllowImpersonate flag to consider token signer as request owner.
// If this field is true extended ACL table in token body isn't processed.
bool allow_impersonate = 4 [ json_name = "allowImpersonate" ];
// APEOverride is the list of APE chains defined for a target.
// These chains are meant to serve as overrides to the already defined (or
// even undefined) APE chains for the target (see contract `Policy`).
//
// The server-side processing of the bearer token with set APE overrides
// must verify if a client is permitted to override chains for the target,
// preventing unauthorized access through the APE mechanism.
message APEOverride {
// Target for which chains are applied.
frostfs.v2.ape.ChainTarget target = 1 [ json_name = "target" ];
// The list of APE chains.
repeated frostfs.v2.ape.Chain chains = 2 [ json_name = "chains" ];
}
// APE override for the target.
APEOverride ape_override = 5 [ json_name = "apeOverride" ];
}
// Bearer Token body
Body body = 1 [ json_name = "body" ];

View file

@ -12,7 +12,7 @@ import "session/types.proto";
// `NetmapService` provides methods to work with `Network Map` and the
// information required to build it. The resulting `Network Map` is stored in
// sidechain `Netmap` smart contract, while related information can be obtained
// from other NeoFS nodes.
// from other FrostFS nodes.
service NetmapService {
// Get NodeInfo structure from the particular node directly.
// Node information can be taken from `Netmap` smart contract. In some cases,
@ -27,7 +27,7 @@ service NetmapService {
// - Common failures (SECTION_FAILURE_COMMON).
rpc LocalNodeInfo(LocalNodeInfoRequest) returns (LocalNodeInfoResponse);
// Read recent information about the NeoFS network.
// Read recent information about the FrostFS network.
//
// Statuses:
// - **OK** (0, SECTION_SUCCESS):
@ -35,7 +35,7 @@ service NetmapService {
// - Common failures (SECTION_FAILURE_COMMON).
rpc NetworkInfo(NetworkInfoRequest) returns (NetworkInfoResponse);
// Returns network map snapshot of the current NeoFS epoch.
// Returns network map snapshot of the current FrostFS epoch.
//
// Statuses:
// - **OK** (0, SECTION_SUCCESS):
@ -65,7 +65,7 @@ message LocalNodeInfoRequest {
message LocalNodeInfoResponse {
// Local Node Info, including API Version in use.
message Body {
// Latest NeoFS API version in use
// Latest FrostFS API version in use
neo.fs.v2.refs.Version version = 1;
// NodeInfo structure with recent information from node itself

View file

@ -36,6 +36,9 @@ enum Operation {
// Logical negation
NOT = 9;
// Matches pattern
LIKE = 10;
}
// Selector modifier shows how the node set will be formed. By default selector
@ -119,7 +122,7 @@ message PlacementPolicy {
// bucket
repeated Replica replicas = 1 [ json_name = "replicas" ];
// Container backup factor controls how deep NeoFS will search for nodes
// Container backup factor controls how deep FrostFS will search for nodes
// alternatives to include into container's nodes subset
uint32 container_backup_factor = 2 [ json_name = "containerBackupFactor" ];
@ -133,25 +136,25 @@ message PlacementPolicy {
bool unique = 5 [ json_name = "unique" ];
}
// NeoFS node description
// FrostFS node description
message NodeInfo {
// Public key of the NeoFS node in a binary format
// Public key of the FrostFS node in a binary format
bytes public_key = 1 [ json_name = "publicKey" ];
// Ways to connect to a node
repeated string addresses = 2 [ json_name = "addresses" ];
// Administrator-defined Attributes of the NeoFS Storage Node.
// Administrator-defined Attributes of the FrostFS Storage Node.
//
// `Attribute` is a Key-Value metadata pair. Key name must be a valid UTF-8
// string. Value can't be empty.
//
// Attributes can be constructed into a chain of attributes: any attribute can
// have a parent attribute and a child attribute (except the first and the
// last one). A string representation of the chain of attributes in NeoFS
// last one). A string representation of the chain of attributes in FrostFS
// Storage Node configuration uses ":" and "/" symbols, e.g.:
//
// `NEOFS_NODE_ATTRIBUTE_1=key1:val1/key2:val2`
// `FrostFS_NODE_ATTRIBUTE_1=key1:val1/key2:val2`
//
// Therefore the string attribute representation in the Node configuration
// must use "\:", "\/" and "\\" escaped symbols if any of them appears in an
@ -198,8 +201,8 @@ message NodeInfo {
// [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2). Calculated
// automatically from `UN-LOCODE` attribute.
// * Continent \
// Node's continent name according to the [Seven-Continent model]
// (https://en.wikipedia.org/wiki/Continent#Number). Calculated
// Node's continent name according to the [Seven-Continent
// model](https://en.wikipedia.org/wiki/Continent#Number). Calculated
// automatically from `UN-LOCODE` attribute.
// * ExternalAddr
// Node's preferred way for communications with external clients.
@ -207,7 +210,7 @@ message NodeInfo {
// Must contain a comma-separated list of multi-addresses.
//
// For detailed description of each well-known attribute please see the
// corresponding section in NeoFS Technical Specification.
// corresponding section in FrostFS Technical Specification.
message Attribute {
// Key of the node attribute
string key = 1 [ json_name = "key" ];
@ -219,13 +222,13 @@ message NodeInfo {
// `Country`.
repeated string parents = 3 [ json_name = "parents" ];
}
// Carries list of the NeoFS node attributes in a key-value form. Key name
// Carries list of the FrostFS node attributes in a key-value form. Key name
// must be a node-unique valid UTF-8 string. Value can't be empty. NodeInfo
// structures with duplicated attribute names or attributes with empty values
// will be considered invalid.
repeated Attribute attributes = 3 [ json_name = "attributes" ];
// Represents the enumeration of various states of the NeoFS node.
// Represents the enumeration of various states of the FrostFS node.
enum State {
// Unknown state
UNSPECIFIED = 0;
@ -240,7 +243,7 @@ message NodeInfo {
MAINTENANCE = 3;
}
// Carries state of the NeoFS node
// Carries state of the FrostFS node
State state = 4 [ json_name = "state" ];
}
@ -253,7 +256,7 @@ message Netmap {
repeated NodeInfo nodes = 2 [ json_name = "nodes" ];
}
// NeoFS network configuration
// FrostFS network configuration
message NetworkConfig {
// Single configuration parameter. Key MUST be network-unique.
//
@ -272,7 +275,7 @@ message NetworkConfig {
// Fee paid for container creation by the container owner.
// Value: little-endian integer. Default: 0.
// - **EpochDuration** \
// NeoFS epoch duration measured in Sidechain blocks.
// FrostFS epoch duration measured in Sidechain blocks.
// Value: little-endian integer. Default: 0.
// - **HomomorphicHashingDisabled** \
// Flag of disabling the homomorphic hashing of objects' payload.
@ -284,8 +287,39 @@ message NetworkConfig {
// Flag allowing setting the MAINTENANCE state to storage nodes.
// Value: true if any byte != 0. Default: false.
// - **MaxObjectSize** \
// Maximum size of physically stored NeoFS object measured in bytes.
// Maximum size of physically stored FrostFS object measured in bytes.
// Value: little-endian integer. Default: 0.
//
// This value refers to the maximum size of a **physically** stored object
// in FrostFS. However, from a user's perspective, the **logical** size of a
// stored object can be significantly larger. The relationship between the
// physical and logical object sizes is governed by the following formula
//
// ```math
// \mathrm{Stored\ Object\ Size} \le
// \frac{
// \left(\mathrm{Max\ Object\ Size}\right)^2
// }{
// \mathrm{Object\ ID\ Size}
// }
// ```
//
// This arises from the fact that a tombstone, also being an object, stores
// the IDs of inhumed objects and cannot be divided into smaller objects,
// thus having an upper limit for its size.
//
// For example, if:
// * Max Object Size Size = 64 MiB;
// * Object ID Size = 32 B;
//
// then:
// ```math
// \mathrm{Stored\ Object\ Size} \le
// \frac{\left(64\ \mathrm{MiB}\right)^2}{32\ \mathrm{B}} =
// \frac{2^{52}}{2^5}\ \mathrm{B} =
// 2^{47}\ \mathrm{B} =
// 128\ \mathrm{TiB}
// ```
// - **WithdrawFee** \
// Fee paid for withdrawal of funds paid by the account owner.
// Value: little-endian integer. Default: 0.
@ -306,18 +340,18 @@ message NetworkConfig {
repeated Parameter parameters = 1 [ json_name = "parameters" ];
}
// Information about NeoFS network
// Information about FrostFS network
message NetworkInfo {
// Number of the current epoch in the NeoFS network
// Number of the current epoch in the FrostFS network
uint64 current_epoch = 1 [ json_name = "currentEpoch" ];
// Magic number of the sidechain of the NeoFS network
// Magic number of the sidechain of the FrostFS network
uint64 magic_number = 2 [ json_name = "magicNumber" ];
// MillisecondsPerBlock network parameter of the sidechain of the NeoFS
// MillisecondsPerBlock network parameter of the sidechain of the FrostFS
// network
int64 ms_per_block = 3 [ json_name = "msPerBlock" ];
// NeoFS network configuration
// FrostFS network configuration
NetworkConfig network_config = 4 [ json_name = "networkConfig" ];
}

View file

@ -458,4 +458,60 @@ namespace FrostFS.Object
return Body;
}
}
public partial class PatchRequest : IRequest
{
IMetaHeader IVerifiableMessage.GetMetaHeader()
{
return MetaHeader;
}
IVerificationHeader IVerifiableMessage.GetVerificationHeader()
{
return VerifyHeader;
}
void IVerifiableMessage.SetMetaHeader(IMetaHeader metaHeader)
{
MetaHeader = (RequestMetaHeader)metaHeader;
}
void IVerifiableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
{
VerifyHeader = (RequestVerificationHeader)verificationHeader;
}
public IMessage GetBody()
{
return Body;
}
}
public partial class PatchResponse : IResponse
{
IMetaHeader IVerifiableMessage.GetMetaHeader()
{
return MetaHeader;
}
IVerificationHeader IVerifiableMessage.GetVerificationHeader()
{
return VerifyHeader;
}
void IVerifiableMessage.SetMetaHeader(IMetaHeader metaHeader)
{
MetaHeader = (ResponseMetaHeader)metaHeader;
}
void IVerifiableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
{
VerifyHeader = (ResponseVerificationHeader)verificationHeader;
}
public IMessage GetBody()
{
return Body;
}
}
}

View file

@ -151,7 +151,7 @@ service ObjectService {
rpc Head(HeadRequest) returns (HeadResponse);
// Search objects in container. Search query allows to match by Object
// Header's filed values. Please see the corresponding NeoFS Technical
// Header's filed values. Please see the corresponding FrostFS Technical
// Specification section for more details.
//
// Extended headers can change `Search` behaviour:
@ -283,6 +283,55 @@ service ObjectService {
// - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \
// provided session token has expired.
rpc PutSingle(PutSingleRequest) returns (PutSingleResponse);
// Patch the object. Request uses gRPC stream. First message must set
// the address of the object that is going to get patched. If the object's
// attributes are patched, then these attrubutes must be set only within the
// first stream message.
//
// If the patch request is performed by NOT the object's owner but if the
// actor has the permission to perform the patch, then `OwnerID` of the object
// is changed. In this case the object's owner loses the object's ownership
// after the patch request is successfully done.
//
// As objects are content-addressable the patching causes new object ID
// generation for the patched object. This object id is set witihn
// `PatchResponse`. But the object id may remain unchanged in such cases:
// 1. The chunk of the applying patch contains the same value as the object's
// payload within the same range;
// 2. The patch that reverts the changes applied by preceding patch;
// 3. The application of the same patches for the object a few times.
//
// Extended headers can change `Patch` behaviour:
// * [ __SYSTEM__NETMAP_EPOCH \
// (`__NEOFS__NETMAP_EPOCH` is deprecated) \
// Will use the requsted version of Network Map for object placement
// calculation.
//
// Please refer to detailed `XHeader` description.
//
// Statuses:
// - **OK** (0, SECTION_SUCCESS): \
// object has been successfully patched and saved in the container;
// - Common failures (SECTION_FAILURE_COMMON);
// - **ACCESS_DENIED** (2048, SECTION_OBJECT): \
// write access to the container is denied;
// - **OBJECT_NOT_FOUND** (2049, SECTION_OBJECT): \
// object not found in container;
// - **OBJECT_ALREADY_REMOVED** (2052, SECTION_OBJECT): \
// the requested object has been marked as deleted.
// - **OUT_OF_RANGE** (2053, SECTION_OBJECT): \
// the requested range is out of bounds;
// - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \
// object storage container not found;
// - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \
// access to container is denied;
// - **TOKEN_NOT_FOUND** (4096, SECTION_SESSION): \
// (for trusted object preparation) session private key does not exist or
// has been deleted;
// - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \
// provided session token has expired.
rpc Patch(stream PatchRequest) returns (PatchResponse);
}
// GET object request
@ -583,6 +632,9 @@ message SearchRequest {
// object_id of parent
// * $Object:split.splitID \
// 16 byte UUIDv4 used to identify the split object hierarchy parts
// * $Object:ec.parent \
// If the object is stored according to EC policy, then ec_parent
// attribute is set to return an id list of all related EC chunks.
//
// There are some well-known filter aliases to match objects by certain
// properties:
@ -814,3 +866,74 @@ message PutSingleResponse {
// transmission.
neo.fs.v2.session.ResponseVerificationHeader verify_header = 3;
}
// Object PATCH request
message PatchRequest {
// PATCH request body
message Body {
// The address of the object that is requested to get patched.
neo.fs.v2.refs.Address address = 1;
// New attributes for the object. See `replace_attributes` flag usage to
// define how new attributes should be set.
repeated neo.fs.v2.object.Header.Attribute new_attributes = 2;
// If this flag is set, then the object's attributes will be entirely
// replaced by `new_attributes` list. The empty `new_attributes` list with
// `replace_attributes = true` just resets attributes list for the object.
//
// Default `false` value for this flag means the attributes will be just
// merged. If the incoming `new_attributes` list contains already existing
// key, then it just replaces it while merging the lists.
bool replace_attributes = 3;
// The patch for the object's payload.
message Patch {
// The range of the source object for which the payload is replaced by the
// patch's chunk. If the range's `length = 0`, then the patch's chunk is
// just appended to the original payload starting from the `offest`
// without any replace.
Range source_range = 1;
// The chunk that is being appended to or that replaces the original
// payload on the given range.
bytes chunk = 2;
}
// The patch that is applied for the object.
Patch patch = 4;
}
// Body for patch request message.
Body body = 1;
// Carries request meta information. Header data is used only to regulate
// message transport and does not affect request execution.
neo.fs.v2.session.RequestMetaHeader meta_header = 2;
// Carries request verification information. This header is used to
// authenticate the nodes of the message route and check the correctness of
// transmission.
neo.fs.v2.session.RequestVerificationHeader verify_header = 3;
}
// Object PATCH response
message PatchResponse {
// PATCH response body
message Body {
// The object ID of the saved patched object.
neo.fs.v2.refs.ObjectID object_id = 1;
}
// Body for patch response message.
Body body = 1;
// Carries response meta information. Header data is used only to regulate
// message transport and does not affect request execution.
neo.fs.v2.session.ResponseMetaHeader meta_header = 2;
// Carries response verification information. This header is used to
// authenticate the nodes of the message route and check the correctness of
// transmission.
neo.fs.v2.session.ResponseVerificationHeader verify_header = 3;
}

View file

@ -155,7 +155,7 @@ message Header {
// MIME Content Type of object's payload
//
// For detailed description of each well-known attribute please see the
// corresponding section in NeoFS Technical Specification.
// corresponding section in FrostFS Technical Specification.
message Attribute {
// string key to the object attribute
string key = 1 [ json_name = "key" ];
@ -208,6 +208,18 @@ message Header {
uint32 header_length = 4 [ json_name = "headerLength" ];
// Chunk of a parent header.
bytes header = 5 [ json_name = "header" ];
// As the origin object is EC-splitted its identifier is known to all
// chunks as parent. But parent itself can be a part of Split (does not
// relate to EC-split). In this case parent_split_id should be set.
bytes parent_split_id = 6 [ json_name = "parentSplitID" ];
// EC-parent's parent ID. parent_split_parent_id is set if EC-parent,
// itself, is a part of Split and if an object ID of its parent is
// presented. The field allows to determine how EC-chunk is placed in Split
// hierarchy.
neo.fs.v2.refs.ObjectID parent_split_parent_id = 7
[ json_name = "parentSplitParentID" ];
// EC parent's attributes.
repeated Attribute parent_attributes = 8 [ json_name = "parentAttributes" ];
}
// Erasure code chunk information.
EC ec = 12 [ json_name = "ec" ];

View file

@ -5,7 +5,7 @@ package neo.fs.v2.refs;
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc;refs";
option csharp_namespace = "FrostFS.Refs";
// Objects in NeoFS are addressed by their ContainerID and ObjectID.
// Objects in FrostFS are addressed by their ContainerID and ObjectID.
//
// String presentation of `Address` is a concatenation of string encoded
// `ContainerID` and `ObjectID` delimited by '/' character.
@ -16,8 +16,9 @@ message Address {
ObjectID object_id = 2 [ json_name = "objectID" ];
}
// NeoFS Object unique identifier. Objects are immutable and content-addressed.
// It means `ObjectID` will change if the `header` or the `payload` changes.
// FrostFS Object unique identifier. Objects are immutable and
// content-addressed. It means `ObjectID` will change if the `header` or the
// `payload` changes.
//
// `ObjectID` is a 32 byte long
// [SHA256](https://csrc.nist.gov/publications/detail/fips/180/4/final) hash of
@ -37,7 +38,7 @@ message ObjectID {
bytes value = 1 [ json_name = "value" ];
}
// NeoFS container identifier. Container structures are immutable and
// FrostFS container identifier. Container structures are immutable and
// content-addressed.
//
// `ContainerID` is a 32 byte long
@ -90,7 +91,7 @@ message Version {
uint32 minor = 2 [ json_name = "minor" ];
}
// Signature of something in NeoFS.
// Signature of something in FrostFS.
message Signature {
// Public key used for signing
bytes key = 1 [ json_name = "key" ];

View file

@ -11,7 +11,7 @@ import "session/types.proto";
// `SessionService` allows to establish a temporary trust relationship between
// two peer nodes and generate a `SessionToken` as the proof of trust to be
// attached in requests for further verification. Please see corresponding
// section of NeoFS Technical Specification for details.
// section of FrostFS Technical Specification for details.
service SessionService {
// Open a new session between two peers.
//

View file

@ -36,6 +36,9 @@ message ObjectSessionContext {
// Refers to object.GetRangeHash RPC call
RANGEHASH = 7;
// Refers to object.Patch RPC call
PATCH = 8;
}
// Type of request for which the token is issued
Verb verb = 1 [ json_name = "verb" ];
@ -47,7 +50,7 @@ message ObjectSessionContext {
refs.ContainerID container = 1 [ json_name = "container" ];
// Indicates which objects the session is spread to. Objects are expected
// to be stored in the NeoFS container referenced by `container` field.
// to be stored in the FrostFS container referenced by `container` field.
// Each element MUST have correct format.
repeated refs.ObjectID objects = 2 [ json_name = "objects" ];
}
@ -85,7 +88,7 @@ message ContainerSessionContext {
refs.ContainerID container_id = 3 [ json_name = "containerID" ];
}
// NeoFS Session Token.
// FrostFS Session Token.
message SessionToken {
// Session Token body
message Body {
@ -123,7 +126,7 @@ message SessionToken {
}
// Session Token contains the proof of trust between peers to be attached in
// requests for further verification. Please see corresponding section of
// NeoFS Technical Specification for details.
// FrostFS Technical Specification for details.
Body body = 1 [ json_name = "body" ];
// Signature of `SessionToken` information
@ -183,7 +186,7 @@ message RequestMetaHeader {
// `RequestMetaHeader` of the origin request
RequestMetaHeader origin = 7 [ json_name = "origin" ];
// NeoFS network magic. Must match the value for the network
// FrostFS network magic. Must match the value for the network
// that the server belongs to.
uint64 magic_number = 8 [ json_name = "magicNumber" ];
}

View file

@ -5,12 +5,12 @@ package neo.fs.v2.status;
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc;status";
option csharp_namespace = "FrostFS.Status";
// Declares the general format of the status returns of the NeoFS RPC protocol.
// Status is present in all response messages. Each RPC of NeoFS protocol
// describes the possible outcomes and details of the operation.
// Declares the general format of the status returns of the FrostFS RPC
// protocol. Status is present in all response messages. Each RPC of FrostFS
// protocol describes the possible outcomes and details of the operation.
//
// Each status is assigned a one-to-one numeric code. Any unique result of an
// operation in NeoFS is unambiguously associated with the code value.
// operation in FrostFS is unambiguously associated with the code value.
//
// Numerical set of codes is split into 1024-element sections. An enumeration
// is defined for each section. Values can be referred to in the following ways:
@ -78,7 +78,7 @@ enum Section {
SECTION_APE_MANAGER = 5;
}
// Section of NeoFS successful return codes.
// Section of FrostFS successful return codes.
enum Success {
// [**0**] Default success. Not detailed.
// If the server cannot match successful outcome to the code, it should
@ -93,9 +93,9 @@ enum CommonFail {
// use this code.
INTERNAL = 0;
// [**1025**] Wrong magic of the NeoFS network.
// [**1025**] Wrong magic of the FrostFS network.
// Details:
// - [**0**] Magic number of the served NeoFS network (big-endian 64-bit
// - [**0**] Magic number of the served FrostFS network (big-endian 64-bit
// unsigned integer).
WRONG_MAGIC_NUMBER = 1;
@ -104,6 +104,11 @@ enum CommonFail {
// [**1027**] Node is under maintenance.
NODE_UNDER_MAINTENANCE = 3;
// [**1028**] Invalid argument error. If the server fails on validation of a
// request parameter as the client sent it incorrectly, then this code should
// be used.
INVALID_ARGUMENT = 4;
}
// Section of statuses for object-related operations.

View file

@ -8,10 +8,10 @@ option csharp_namespace = "FrostFS.Tombstone";
import "refs/types.proto";
// Tombstone keeps record of deleted objects for a few epochs until they are
// purged from the NeoFS network.
// purged from the FrostFS network.
message Tombstone {
// Last NeoFS epoch number of the tombstone lifetime. It's set by the
// tombstone creator depending on the current NeoFS network settings. A
// Last FrostFS epoch number of the tombstone lifetime. It's set by the
// tombstone creator depending on the current FrostFS network settings. A
// tombstone object must have the same expiration epoch value in
// `__SYSTEM__EXPIRATION_EPOCH` (`__NEOFS__EXPIRATION_EPOCH` is deprecated)
// attribute. Otherwise, the tombstone will be rejected by a storage node.

View file

@ -0,0 +1,43 @@
using System.Security.Cryptography;
using FrostFS.Object;
using FrostFS.SDK.ClientV2;
using FrostFS.SDK.ClientV2.Mappers.GRPC;
using FrostFS.SDK.Cryptography;
using FrostFS.Session;
using Google.Protobuf;
using Grpc.Core;
namespace FrostFS.SDK.Tests;
public class AsyncStreamRangeReaderMock(string key, byte[] response) : ServiceBase(key), IAsyncStreamReader<GetRangeResponse>
{
private readonly byte[] _response = response;
public GetRangeResponse Current
{
get
{
var response = new GetRangeResponse
{
Body = new GetRangeResponse.Types.Body
{
Chunk = ByteString.CopyFrom(_response)
},
MetaHeader = new ResponseMetaHeader()
};
response.VerifyHeader = GetResponseVerificationHeader(response);
return response;
}
}
public Task<bool> MoveNext(CancellationToken cancellationToken)
{
return Task.FromResult(true);
}
}

View file

@ -5,6 +5,7 @@ using FrostFS.Object;
using FrostFS.SDK.ClientV2;
using FrostFS.SDK.ClientV2.Mappers.GRPC;
using FrostFS.SDK.Cryptography;
using FrostFS.Session;
using Google.Protobuf;
@ -16,6 +17,32 @@ namespace FrostFS.SDK.Tests;
public class ObjectMocker(string key) : ObjectServiceBase(key)
{
public FrostFsObjectId? ObjectId { get; set; }
public FrostFsObjectHeader? ObjectHeader { get; set; }
public Header? HeadResponse { get; set; }
public Collection<byte[]>? ResultObjectIds { get; } = [];
public ClientStreamWriter? ClientStreamWriter { get; } = new();
public PatchStreamWriter? PatchStreamWriter { get; } = new();
public Collection<PutSingleRequest> PutSingleRequests { get; } = [];
public Collection<DeleteRequest> DeleteRequests { get; } = [];
public Collection<HeadRequest> HeadRequests { get; } = [];
public byte[] RangeResponse { get; set; } = [];
public GetRangeRequest? GetRangeRequest { get; set; }
public GetRangeHashRequest? GetRangeHashRequest { get; set; }
public Collection<ByteString> RangeHashResponses { get; } = [];
public override Mock<ObjectService.ObjectServiceClient> GetMock()
{
var mock = new Mock<ObjectService.ObjectServiceClient>();
@ -189,23 +216,88 @@ public class ObjectMocker(string key) : ObjectServiceBase(key)
});
}
return mock;
mock.Setup(x => x.GetRange(
It.IsAny<GetRangeRequest>(),
It.IsAny<Metadata>(),
It.IsAny<DateTime?>(),
It.IsAny<CancellationToken>()))
.Returns((GetRangeRequest r, Metadata m, DateTime? dt, CancellationToken ct) =>
{
Verifier.CheckRequest(r);
GetRangeRequest = r;
return new AsyncServerStreamingCall<GetRangeResponse>(
new AsyncStreamRangeReaderMock(StringKey, RangeResponse),
Task.FromResult(ResponseMetaData),
() => new Grpc.Core.Status(StatusCode.OK, string.Empty),
() => ResponseMetaData,
() => { });
});
mock.Setup(x => x.GetRangeHashAsync(
It.IsAny<GetRangeHashRequest>(),
It.IsAny<Metadata>(),
It.IsAny<DateTime?>(),
It.IsAny<CancellationToken>()))
.Returns((GetRangeHashRequest r, Metadata m, DateTime? dt, CancellationToken ct) =>
{
Verifier.CheckRequest(r);
GetRangeHashRequest = r;
var response = new GetRangeHashResponse
{
Body = new GetRangeHashResponse.Types.Body(),
MetaHeader = ResponseMetaHeader
};
if (RangeHashResponses != null)
{
foreach (var hash in RangeHashResponses)
{
response.Body.HashList.Add(hash);
}
}
public FrostFsObjectId? ObjectId { get; set; }
response.VerifyHeader = GetResponseVerificationHeader(response);
public FrostFsObjectHeader? ObjectHeader { get; set; }
return new AsyncUnaryCall<GetRangeHashResponse>(
Task.FromResult(response),
Task.FromResult(ResponseMetaData),
() => new Grpc.Core.Status(StatusCode.OK, string.Empty),
() => ResponseMetaData,
() => { });
});
public Header? HeadResponse { get; set; }
public Collection<byte[]>? ResultObjectIds { get; } = [];
mock.Setup(x => x.Patch(
It.IsAny<Metadata>(),
It.IsAny<DateTime?>(),
It.IsAny<CancellationToken>()))
.Returns((Metadata m, DateTime? dt, CancellationToken ct) =>
{
var patchResponse = new PatchResponse
{
Body = new PatchResponse.Types.Body
{
ObjectId = new Refs.ObjectID { Value = ByteString.CopyFrom(SHA256.HashData([1,2,3])) },
},
MetaHeader = ResponseMetaHeader
};
public ClientStreamWriter? ClientStreamWriter { get; private set; } = new();
patchResponse.VerifyHeader = GetResponseVerificationHeader(patchResponse);
public Collection<PutSingleRequest> PutSingleRequests { get; private set; } = [];
return new AsyncClientStreamingCall<PatchRequest, PatchResponse>(
PatchStreamWriter!,
Task.FromResult(patchResponse),
Task.FromResult(ResponseMetaData),
() => new Grpc.Core.Status(StatusCode.OK, string.Empty),
() => ResponseMetaData,
() => { });
});
public Collection<DeleteRequest> DeleteRequests { get; private set; } = [];
public Collection<HeadRequest> HeadRequests { get; private set; } = [];
return mock;
}
}

View file

@ -0,0 +1,36 @@
using System.Collections.ObjectModel;
using FrostFS.SDK.ProtosV2.Interfaces;
using Grpc.Core;
namespace FrostFS.SDK.Tests;
public class PatchStreamWriter : IClientStreamWriter<IRequest>
{
private WriteOptions? _options;
public Collection<IRequest> Messages { get; } = [];
public bool CompletedTask { get; private set; }
public WriteOptions? WriteOptions
{
get => _options;
set => _options = value;
}
public Task CompleteAsync()
{
CompletedTask = true;
return Task.CompletedTask;
}
public Task WriteAsync(IRequest message)
{
Object.PatchRequest pr = new((Object.PatchRequest)message);
Messages.Add(pr);
return Task.CompletedTask;
}
}

View file

@ -10,6 +10,8 @@ using FrostFS.SDK.Cryptography;
using Google.Protobuf;
using static FrostFS.Object.ECInfo.Types;
namespace FrostFS.SDK.Tests;
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Default Value is correct for tests")]
@ -223,4 +225,121 @@ public class ObjectTest : ObjectTestsBase
Assert.Null(response.Split);
}
[Fact]
public async void GetRangeTest()
{
Mocker.ResultObjectIds!.Add(SHA256.HashData([]));
Random rnd = new();
var bytes = new byte[1024];
rnd.NextBytes(bytes);
Mocker.RangeResponse = bytes;
Mocker.ObjectId = new ObjectID { Value = ByteString.CopyFrom(SHA256.HashData(Encoding.UTF8.GetBytes("test"))) }.ToModel();
var param = new PrmRangeGet(ContainerId, Mocker.ObjectId, new FrostFsRange(100, (ulong)Mocker.RangeResponse.Length));
var result = await GetClient().GetRangeAsync(param);
Assert.NotNull(Mocker.GetRangeRequest);
Assert.Equal(param.Range.Offset, Mocker.GetRangeRequest.Body.Range.Offset);
Assert.Equal(param.Range.Length, Mocker.GetRangeRequest.Body.Range.Length);
Assert.NotNull(result);
var chunk = await result.ReadChunk();
var chunkBytes = chunk.Value.Span.ToArray();
Assert.Equal(chunkBytes.Length, Mocker.RangeResponse.Length);
Assert.Equal(SHA256.HashData(bytes), SHA256.HashData(Mocker.RangeResponse));
}
[Fact]
public async void GetRangeHashTest()
{
Mocker.ResultObjectIds!.Add(SHA256.HashData([]));
Random rnd = new();
var bytes = new byte[1024];
rnd.NextBytes(bytes);
var salt = new byte[32];
rnd.NextBytes(salt);
var hash = new byte[32];
rnd.NextBytes(hash);
Mocker.RangeResponse = bytes;
var len = (ulong)bytes.Length;
Mocker.RangeHashResponses.Add(ByteString.CopyFrom(hash));
Mocker.ObjectId = new ObjectID { Value = ByteString.CopyFrom(SHA256.HashData(Encoding.UTF8.GetBytes("test"))) }.ToModel();
var param = new PrmRangeHashGet(ContainerId, Mocker.ObjectId, [new FrostFsRange(100, len)], salt);
var result = await GetClient().GetRangeHashAsync(param);
Assert.NotNull(Mocker.GetRangeHashRequest);
Assert.Equal(param.Ranges[0].Offset, Mocker.GetRangeHashRequest.Body.Ranges[0].Offset);
Assert.Equal(param.Ranges[0].Length, Mocker.GetRangeHashRequest.Body.Ranges[0].Length);
Assert.NotNull(result);
Assert.Single(result);
Assert.Equal(SHA256.HashData(hash), SHA256.HashData(result.First().ToArray()));
}
[Fact]
public async void PatchTest()
{
Mocker.ObjectId = new ObjectID { Value = ByteString.CopyFrom(SHA256.HashData(Encoding.UTF8.GetBytes("test"))) }.ToModel();
var address = new FrostFsAddress(ContainerId, Mocker.ObjectId);
Mocker.ResultObjectIds!.Add(SHA256.HashData([]));
Random rnd = new();
var patch = new byte[32];
rnd.NextBytes(patch);
var range = new FrostFsRange(8, (ulong)patch.Length);
var param = new PrmObjectPatch(address)
{
Payload = new MemoryStream(patch),
MaxPayloadPatchChunkLength = 32,
Range = range
};
var result = await GetClient().PatchObjectAsync(param);
Assert.NotNull(result);
Assert.NotNull(result.Value);
Assert.NotNull(Mocker.PatchStreamWriter);
Assert.Single(Mocker.PatchStreamWriter.Messages);
var sentMessages = Mocker.PatchStreamWriter!.Messages;
var body = sentMessages.First().GetBody() as Object.PatchRequest.Types.Body;
Assert.NotNull(body);
Assert.True(Mocker.PatchStreamWriter.CompletedTask);
Assert.Equal(address.ContainerId, body.Address.ContainerId);
Assert.Equal(address.ObjectId, body.Address.ObjectId);
Assert.Equal(32, body.Patch.Chunk.Length);
Assert.Equal(SHA256.HashData(patch), SHA256.HashData(body.Patch.Chunk.ToArray()));
}
}

View file

@ -327,6 +327,190 @@ public class SmokeClientTests : SmokeTestsBase
}
}
[Fact]
public async void PatchTest()
{
using var client = FrostFSClient.GetSingleOwnerInstance(GetSingleOwnerOptions(this.keyString, this.url));
await Cleanup(client);
var createContainerParam = new PrmContainerCreate(
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1)), [new("testKey", "testValue")]));
var createdContainer = await client.CreateContainerAsync(createContainerParam);
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer));
Assert.NotNull(container);
var bytes = new byte[1024];
for (int i = 0; i < 1024; i++)
{
bytes[i] = (byte)31;
}
var param = new PrmObjectPut
{
Header = new FrostFsObjectHeader(
containerId: createdContainer,
type: FrostFsObjectType.Regular,
[new FrostFsAttributePair("fileName", "test")]),
Payload = new MemoryStream(bytes),
ClientCut = false
};
var objectId = await client.PutObjectAsync(param);
var patch = new byte[16];
for (int i = 0; i < 16; i++)
{
patch[i] = (byte)32;
}
var range = new FrostFsRange(8, (ulong)patch.Length);
var patchParams = new PrmObjectPatch(new FrostFsAddress(createdContainer, objectId))
{
Payload = new MemoryStream(patch),
MaxPayloadPatchChunkLength = 32,
Range = range
};
var newIbjId = await client.PatchObjectAsync(patchParams);
var @object = await client.GetObjectAsync(new PrmObjectGet(createdContainer, newIbjId));
var downloadedBytes = new byte[@object.Header.PayloadLength];
MemoryStream ms = new(downloadedBytes);
ReadOnlyMemory<byte>? chunk = null;
while ((chunk = await @object.ObjectReader!.ReadChunk()) != null)
{
ms.Write(chunk.Value.Span);
}
for(int i = 0; i < (int)range.Offset; i++)
Assert.Equal(downloadedBytes[i], bytes[i]);
var rangeEnd = range.Offset + range.Length;
for (int i = (int)range.Offset; i < (int)rangeEnd; i++)
Assert.Equal(downloadedBytes[i], patch[i - (int)range.Offset]);
for (int i = (int)rangeEnd; i < bytes.Length; i++)
Assert.Equal(downloadedBytes[i], bytes[i]);
await Cleanup(client);
await foreach (var _ in client.ListContainersAsync())
{
Assert.Fail("Containers exist");
}
}
[Fact]
public async void RangeTest()
{
using var client = FrostFSClient.GetSingleOwnerInstance(GetSingleOwnerOptions(this.keyString, this.url));
await Cleanup(client);
var createContainerParam = new PrmContainerCreate(
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1)), [new("testKey", "testValue")]));
var createdContainer = await client.CreateContainerAsync(createContainerParam);
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer));
Assert.NotNull(container);
var bytes = new byte[256];
for (int i = 0; i < 256; i++)
{
bytes[i] = (byte)i;
}
var param = new PrmObjectPut
{
Header = new FrostFsObjectHeader(
containerId: createdContainer,
type: FrostFsObjectType.Regular),
Payload = new MemoryStream(bytes),
ClientCut = false
};
var objectId = await client.PutObjectAsync(param);
var rangeParam = new PrmRangeGet(createdContainer, objectId, new FrostFsRange(100, 64));
var rangeReader = await client.GetRangeAsync(rangeParam);
var downloadedBytes = new byte[rangeParam.Range.Length];
MemoryStream ms = new(downloadedBytes);
ReadOnlyMemory<byte>? chunk = null;
while ((chunk = await rangeReader!.ReadChunk()) != null)
{
ms.Write(chunk.Value.Span);
}
Assert.Equal(SHA256.HashData(bytes.AsSpan().Slice(100, 64)), SHA256.HashData(downloadedBytes));
await Cleanup(client);
await foreach (var _ in client.ListContainersAsync())
{
Assert.Fail("Containers exist");
}
}
[Fact]
public async void RangeHashTest()
{
using var client = FrostFSClient.GetSingleOwnerInstance(GetSingleOwnerOptions(this.keyString, this.url));
await Cleanup(client);
var createContainerParam = new PrmContainerCreate(
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1)), [new("testKey", "testValue")]));
var createdContainer = await client.CreateContainerAsync(createContainerParam);
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer));
Assert.NotNull(container);
var bytes = new byte[256];
for (int i = 0; i < 256; i++)
{
bytes[i] = (byte)i;
}
var param = new PrmObjectPut
{
Header = new FrostFsObjectHeader(
containerId: createdContainer,
type: FrostFsObjectType.Regular),
Payload = new MemoryStream(bytes),
ClientCut = false
};
var objectId = await client.PutObjectAsync(param);
var rangeParam = new PrmRangeHashGet(createdContainer, objectId, [ new FrostFsRange(100, 64)], bytes);
var hashes = await client.GetRangeHashAsync(rangeParam);
foreach (var hash in hashes)
{
var x = hash.Slice(0, 32).ToArray();
}
await Cleanup(client);
await foreach (var _ in client.ListContainersAsync())
{
Assert.Fail("Containers exist");
}
}
[Theory]
[InlineData(1)]
[InlineData(3 * 1024 * 1024)] // exactly one chunk size - 3MB

View file

@ -7,6 +7,8 @@ namespace FrostFS.SDK.SmokeTests;
public abstract class SmokeTestsBase
{
// internal readonly string keyString = "KzPXA6669m2pf18XmUdoR8MnP1pi1PMmefiFujStVFnv7WR5SRmK";
internal readonly string keyString = "KzPXA6669m2pf18XmUdoR8MnP1pi1PMmefiFujStVFnv7WR5SRmK";
internal readonly string url = "http://172.23.32.4:8080";