diff --git a/src/FrostFS.SDK.ClientV2/FrostFSClient.cs b/src/FrostFS.SDK.ClientV2/FrostFSClient.cs index e13b6b6..1a34a53 100644 --- a/src/FrostFS.SDK.ClientV2/FrostFSClient.cs +++ b/src/FrostFS.SDK.ClientV2/FrostFSClient.cs @@ -285,6 +285,15 @@ public class FrostFSClient : IFrostFSClient return service.GetObjectAsync(args); } + public Task GetRangeAsync(PrmRangeGet args) + { + if (args is null) + throw new ArgumentNullException(nameof(args)); + + var service = GetObjectService(args); + return service.GetRangeAsync(args); + } + public Task PutObjectAsync(PrmObjectPut args) { if (args is null) @@ -302,6 +311,17 @@ public class FrostFSClient : IFrostFSClient var service = GetObjectService(args); return service.PutSingleObjectAsync(args); } + + public Task 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) { diff --git a/src/FrostFS.SDK.ClientV2/Interfaces/IFrostFSClient.cs b/src/FrostFS.SDK.ClientV2/Interfaces/IFrostFSClient.cs index e81343b..ac862b8 100644 --- a/src/FrostFS.SDK.ClientV2/Interfaces/IFrostFSClient.cs +++ b/src/FrostFS.SDK.ClientV2/Interfaces/IFrostFSClient.cs @@ -42,10 +42,14 @@ public interface IFrostFSClient : IDisposable Task GetObjectAsync(PrmObjectGet args); + Task GetRangeAsync(PrmRangeGet args); + Task PutObjectAsync(PrmObjectPut args); Task PutSingleObjectAsync(PrmSingleObjectPut args); + Task PatchObjectAsync(PrmObjectPatch args); + Task DeleteObjectAsync(PrmObjectDelete args); IAsyncEnumerable SearchObjectsAsync(PrmObjectSearch args); diff --git a/src/FrostFS.SDK.ClientV2/Mappers/ContainerId.cs b/src/FrostFS.SDK.ClientV2/Mappers/ContainerId.cs index 7a5359d..bc691cb 100644 --- a/src/FrostFS.SDK.ClientV2/Mappers/ContainerId.cs +++ b/src/FrostFS.SDK.ClientV2/Mappers/ContainerId.cs @@ -1,4 +1,5 @@ using System; +using System.Security.Cryptography; using FrostFS.Refs; using FrostFS.SDK.Cryptography; @@ -33,7 +34,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())); + } } \ No newline at end of file diff --git a/src/FrostFS.SDK.ClientV2/Models/Object/FrostFsAddress.cs b/src/FrostFS.SDK.ClientV2/Models/Object/FrostFsAddress.cs new file mode 100644 index 0000000..598ecda --- /dev/null +++ b/src/FrostFS.SDK.ClientV2/Models/Object/FrostFsAddress.cs @@ -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(FrostFsObjectId frostFsObjectId, FrostFsContainerId frostFsContainerId) + { + 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; + } +} diff --git a/src/FrostFS.SDK.ClientV2/Models/Object/FrostFsRange.cs b/src/FrostFS.SDK.ClientV2/Models/Object/FrostFsRange.cs new file mode 100644 index 0000000..22f5d40 --- /dev/null +++ b/src/FrostFS.SDK.ClientV2/Models/Object/FrostFsRange.cs @@ -0,0 +1,27 @@ +namespace FrostFS.SDK; + +public struct FrostFsRange : System.IEquatable +{ + public ulong Offset {get; set;} + + public ulong Length { get; set; } + + 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; + } +} diff --git a/src/FrostFS.SDK.ClientV2/Models/Object/IObjectReader.cs b/src/FrostFS.SDK.ClientV2/Models/Object/IObjectReader.cs index 51211fd..8b08e6b 100644 --- a/src/FrostFS.SDK.ClientV2/Models/Object/IObjectReader.cs +++ b/src/FrostFS.SDK.ClientV2/Models/Object/IObjectReader.cs @@ -6,5 +6,5 @@ namespace FrostFS.SDK; public interface IObjectReader : IDisposable { - Task?> ReadChunk(CancellationToken cancellationToken = default); + ValueTask?> ReadChunk(CancellationToken cancellationToken = default); } diff --git a/src/FrostFS.SDK.ClientV2/Parameters/PrmObjectPatch.cs b/src/FrostFS.SDK.ClientV2/Parameters/PrmObjectPatch.cs new file mode 100644 index 0000000..180c634 --- /dev/null +++ b/src/FrostFS.SDK.ClientV2/Parameters/PrmObjectPatch.cs @@ -0,0 +1,25 @@ +using System.IO; +using System.Security.Cryptography; + +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; } + + /// + /// A stream with source data + /// + public Stream? Payload { get; set; } + + public FrostFsAttributePair[]? NewAttributes { get; set; } + + public bool ReplaceAttributes { get; set; } + + public int MaxPayloadPatchChunkLength { get; set; } + + /// + public FrostFsSessionToken? SessionToken { get; set; } +} diff --git a/src/FrostFS.SDK.ClientV2/Parameters/PrmRangeGet.cs b/src/FrostFS.SDK.ClientV2/Parameters/PrmRangeGet.cs new file mode 100644 index 0000000..5f03770 --- /dev/null +++ b/src/FrostFS.SDK.ClientV2/Parameters/PrmRangeGet.cs @@ -0,0 +1,17 @@ +namespace FrostFS.SDK.ClientV2; + +public sealed class PrmRangeGet( + FrostFsContainerId containerId, + FrostFsObjectId objectId, + FrostFsRange range, + CallContext? ctx = null) : PrmBase(ctx), ISessionToken +{ + public FrostFsContainerId ContainerId { get; } = containerId; + + public FrostFsObjectId ObjectId { get; } = objectId; + + public FrostFsRange Range { get; } = range; + + /// + public FrostFsSessionToken? SessionToken { get; set; } +} diff --git a/src/FrostFS.SDK.ClientV2/Poll/ClientWrapper.cs b/src/FrostFS.SDK.ClientV2/Poll/ClientWrapper.cs index ddde002..777c311 100644 --- a/src/FrostFS.SDK.ClientV2/Poll/ClientWrapper.cs +++ b/src/FrostFS.SDK.ClientV2/Poll/ClientWrapper.cs @@ -101,10 +101,10 @@ 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); if (!string.IsNullOrEmpty(error)) diff --git a/src/FrostFS.SDK.ClientV2/Poll/Pool.cs b/src/FrostFS.SDK.ClientV2/Poll/Pool.cs index 3e20634..8bb44f2 100644 --- a/src/FrostFS.SDK.ClientV2/Poll/Pool.cs +++ b/src/FrostFS.SDK.ClientV2/Poll/Pool.cs @@ -711,6 +711,20 @@ public partial class Pool : IFrostFSClient return await client.Client!.PutSingleObjectAsync(args).ConfigureAwait(false); } + public async Task PatchAsync(PrmObjectPatch args) + { + if (args is null) + { + throw new ArgumentNullException(nameof(args)); + } + + var client = Connection(); + + args.Context.PoolErrorHandler = client.HandleError; + + await client.Client!.PatchObjectAsync(args).ConfigureAwait(false); + } + public async Task DeleteObjectAsync(PrmObjectDelete args) { if (args is null) @@ -773,4 +787,14 @@ public partial class Pool : IFrostFSClient { throw new NotImplementedException(); } + + public Task PatchObjectAsync(PrmObjectPatch args) + { + throw new NotImplementedException(); + } + + public Task GetRangeAsync(PrmRangeGet args) + { + throw new NotImplementedException(); + } } diff --git a/src/FrostFS.SDK.ClientV2/Services/ObjectServiceProvider.cs b/src/FrostFS.SDK.ClientV2/Services/ObjectServiceProvider.cs index bcea7c7..9af8fb7 100644 --- a/src/FrostFS.SDK.ClientV2/Services/ObjectServiceProvider.cs +++ b/src/FrostFS.SDK.ClientV2/Services/ObjectServiceProvider.cs @@ -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,47 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl return await GetObject(request, ctx).ConfigureAwait(false); } + internal async Task 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 + } + } + }; + + 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 DeleteObjectAsync(PrmObjectDelete args) { var ctx = args.Context!; @@ -191,7 +233,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 +243,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 +281,89 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl return FrostFsObjectId.FromHash(grpcObject.ObjectId.Value.ToByteArray()); } + internal async Task 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; + + while (true) + { + var bytesCount = await payload.ReadAsync(chunkBuffer, 0, chunkSize, ctx.CancellationToken).ConfigureAwait(false); + + if (bytesCount == 0) + { + break; + } + + if (isFirstChunk) + { + foreach (var attr in args.NewAttributes) + { + request.Body.NewAttributes.Add(attr.ToMessage()); + } + } + + request.Sign(ctx.Key); + + request.Body.Patch = new PatchRequest.Types.Body.Types.Patch + { + Chunk = ByteString.CopyFrom(chunkBuffer, 0, bytesCount), + SourceRange = new Object.Range { Offset = 0, Length = (ulong)bytesCount } + }; + + await call.RequestStream.WriteAsync(request).ConfigureAwait(false); + + isFirstChunk = false; + } + } + finally + { + await call.RequestStream.CompleteAsync().ConfigureAwait(false); + + if (chunkBuffer != null) + { + ArrayPool.Shared.Return(chunkBuffer); + } + } + } + private async Task PutClientCutObject(PrmObjectPut args) { var ctx = args.Context!; @@ -405,8 +534,8 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl } } } - - private async Task GetUploadStream(PrmObjectPut args, CallContext ctx) + + private async Task> GetUploadStream(PrmObjectPut args, CallContext ctx) { var header = args.Header!; @@ -424,7 +553,7 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl } var oid = new ObjectID { Value = grpcHeader.Sha256() }; - + var initRequest = new PutRequest { Body = new PutRequest.Types.Body @@ -451,6 +580,20 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl return await PutObjectInit(initRequest, ctx).ConfigureAwait(false); } + private async Task> 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 Task GetObject(GetRequest request, CallContext ctx) { var reader = GetObjectInit(request, ctx); @@ -473,20 +616,6 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl return new ObjectReader(call); } - private async Task 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 SearchObjects(SearchRequest request, CallContext ctx) { using var stream = GetSearchReader(request, ctx); diff --git a/src/FrostFS.SDK.ClientV2/Tools/ObjectReader.cs b/src/FrostFS.SDK.ClientV2/Tools/ObjectReader.cs index 7df2343..c6af0c8 100644 --- a/src/FrostFS.SDK.ClientV2/Tools/ObjectReader.cs +++ b/src/FrostFS.SDK.ClientV2/Tools/ObjectReader.cs @@ -32,7 +32,7 @@ public sealed class ObjectReader(AsyncServerStreamingCall call) : I }; } - public async Task?> ReadChunk(CancellationToken cancellationToken = default) + public async ValueTask?> ReadChunk(CancellationToken cancellationToken = default) { if (!await Call.ResponseStream.MoveNext(cancellationToken).ConfigureAwait(false)) return null; diff --git a/src/FrostFS.SDK.ClientV2/Tools/ObjectStreamer.cs b/src/FrostFS.SDK.ClientV2/Tools/ObjectStreamer.cs index acd0d28..3389b8e 100644 --- a/src/FrostFS.SDK.ClientV2/Tools/ObjectStreamer.cs +++ b/src/FrostFS.SDK.ClientV2/Tools/ObjectStreamer.cs @@ -7,11 +7,11 @@ using Grpc.Core; namespace FrostFS.SDK.ClientV2; -internal sealed class ObjectStreamer(AsyncClientStreamingCall call) : IDisposable +internal sealed class ObjectStreamer(AsyncClientStreamingCall call) : IDisposable { - public AsyncClientStreamingCall Call { get; private set; } = call; + public AsyncClientStreamingCall Call { get; private set; } = call; - public async Task Write(PutRequest request) + public async Task Write(TRequest request) { if (request is null) { @@ -21,7 +21,7 @@ internal sealed class ObjectStreamer(AsyncClientStreamingCall Close() + public async Task Close() { await Call.RequestStream.CompleteAsync().ConfigureAwait(false); diff --git a/src/FrostFS.SDK.ClientV2/Tools/RangeReader.cs b/src/FrostFS.SDK.ClientV2/Tools/RangeReader.cs new file mode 100644 index 0000000..d1128c8 --- /dev/null +++ b/src/FrostFS.SDK.ClientV2/Tools/RangeReader.cs @@ -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 call) : IObjectReader +{ + private bool disposed; + + public AsyncServerStreamingCall Call { get; private set; } = call; + + public async ValueTask?> 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; + } + } +} diff --git a/src/FrostFS.SDK.ProtosV2/accounting/service.proto b/src/FrostFS.SDK.ProtosV2/accounting/service.proto index 715ef63..6049e0f 100644 --- a/src/FrostFS.SDK.ProtosV2/accounting/service.proto +++ b/src/FrostFS.SDK.ProtosV2/accounting/service.proto @@ -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. diff --git a/src/FrostFS.SDK.ProtosV2/acl/types.proto b/src/FrostFS.SDK.ProtosV2/acl/types.proto index 186f08f..a1d9ae2 100644 --- a/src/FrostFS.SDK.ProtosV2/acl/types.proto +++ b/src/FrostFS.SDK.ProtosV2/acl/types.proto @@ -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" ]; diff --git a/src/FrostFS.SDK.ProtosV2/netmap/service.proto b/src/FrostFS.SDK.ProtosV2/netmap/service.proto index 8611d9a..11f8f96 100644 --- a/src/FrostFS.SDK.ProtosV2/netmap/service.proto +++ b/src/FrostFS.SDK.ProtosV2/netmap/service.proto @@ -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 diff --git a/src/FrostFS.SDK.ProtosV2/netmap/types.proto b/src/FrostFS.SDK.ProtosV2/netmap/types.proto index baaca04..5f0e93e 100644 --- a/src/FrostFS.SDK.ProtosV2/netmap/types.proto +++ b/src/FrostFS.SDK.ProtosV2/netmap/types.proto @@ -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" ]; } diff --git a/src/FrostFS.SDK.ProtosV2/object/Extension.Message.cs b/src/FrostFS.SDK.ProtosV2/object/Extension.Message.cs index 7c0c87d..6691400 100644 --- a/src/FrostFS.SDK.ProtosV2/object/Extension.Message.cs +++ b/src/FrostFS.SDK.ProtosV2/object/Extension.Message.cs @@ -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; + } + } } \ No newline at end of file diff --git a/src/FrostFS.SDK.ProtosV2/object/service.proto b/src/FrostFS.SDK.ProtosV2/object/service.proto index 383e83b..2b8042b 100644 --- a/src/FrostFS.SDK.ProtosV2/object/service.proto +++ b/src/FrostFS.SDK.ProtosV2/object/service.proto @@ -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: @@ -813,4 +865,75 @@ message PutSingleResponse { // authenticate the nodes of the message route and check the correctness of // transmission. neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} \ No newline at end of file +} + +// 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; +} diff --git a/src/FrostFS.SDK.ProtosV2/object/types.proto b/src/FrostFS.SDK.ProtosV2/object/types.proto index 6e62b86..b838c8e 100644 --- a/src/FrostFS.SDK.ProtosV2/object/types.proto +++ b/src/FrostFS.SDK.ProtosV2/object/types.proto @@ -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" ]; diff --git a/src/FrostFS.SDK.ProtosV2/refs/types.proto b/src/FrostFS.SDK.ProtosV2/refs/types.proto index 15d32c1..014c736 100644 --- a/src/FrostFS.SDK.ProtosV2/refs/types.proto +++ b/src/FrostFS.SDK.ProtosV2/refs/types.proto @@ -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" ]; diff --git a/src/FrostFS.SDK.ProtosV2/session/service.proto b/src/FrostFS.SDK.ProtosV2/session/service.proto index 6f48e3a..6511f3b 100644 --- a/src/FrostFS.SDK.ProtosV2/session/service.proto +++ b/src/FrostFS.SDK.ProtosV2/session/service.proto @@ -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. // diff --git a/src/FrostFS.SDK.ProtosV2/session/types.proto b/src/FrostFS.SDK.ProtosV2/session/types.proto index d1a9ef1..bc0d7f1 100644 --- a/src/FrostFS.SDK.ProtosV2/session/types.proto +++ b/src/FrostFS.SDK.ProtosV2/session/types.proto @@ -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" ]; } diff --git a/src/FrostFS.SDK.ProtosV2/status/types.proto b/src/FrostFS.SDK.ProtosV2/status/types.proto index 8ab2f40..694f969 100644 --- a/src/FrostFS.SDK.ProtosV2/status/types.proto +++ b/src/FrostFS.SDK.ProtosV2/status/types.proto @@ -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. diff --git a/src/FrostFS.SDK.ProtosV2/tombstone/types.proto b/src/FrostFS.SDK.ProtosV2/tombstone/types.proto index 739bef4..8780317 100644 --- a/src/FrostFS.SDK.ProtosV2/tombstone/types.proto +++ b/src/FrostFS.SDK.ProtosV2/tombstone/types.proto @@ -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. diff --git a/src/FrostFS.SDK.Tests/SmokeClientTests.cs b/src/FrostFS.SDK.Tests/SmokeClientTests.cs index 426aa9b..470e0e4 100644 --- a/src/FrostFS.SDK.Tests/SmokeClientTests.cs +++ b/src/FrostFS.SDK.Tests/SmokeClientTests.cs @@ -1,6 +1,7 @@ using System.Diagnostics.CodeAnalysis; using System.Security.Cryptography; +using FrostFS.Refs; using FrostFS.SDK.ClientV2; using FrostFS.SDK.ClientV2.Interfaces; using FrostFS.SDK.Cryptography; @@ -247,37 +248,193 @@ public class SmokeClientTests : SmokeTestsBase [InlineData(3 * 1024 * 1024)] // exactly one chunk size - 3MB [InlineData(6 * 1024 * 1024 + 100)] public async void SimpleScenarioTest(int objectSize) + { + try + { + using var client = FrostFSClient.GetSingleOwnerInstance(GetSingleOwnerOptions(this.keyString, this.url)); + + await Cleanup(client); + + bool callbackInvoked = false; + var ctx = new CallContext + { + // Timeout = TimeSpan.FromSeconds(20), + Callback = new((CallStatistics cs) => + { + callbackInvoked = true; + Assert.True(cs.ElapsedMicroSeconds > 0); + }) + }; + + var createContainerParam = new PrmContainerCreate( + new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1)), [new("testKey", "testValue")]), ctx); + + var createdContainer = await client.CreateContainerAsync(createContainerParam); + + var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer, ctx)); + Assert.NotNull(container); + Assert.True(callbackInvoked); + + var bytes = GetRandomBytes(objectSize); + + var param = new PrmObjectPut(new CallContext + { + Callback = new((CallStatistics cs) => Assert.True(cs.ElapsedMicroSeconds > 0)) + }) + { + 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 filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test"); + + bool hasObject = false; + await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(createdContainer) { Filters = [filter] })) + { + hasObject = true; + + var objHeader = await client.GetObjectHeadAsync(new PrmObjectHeadGet(createdContainer, objectId)); + Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength); + Assert.NotNull(objHeader.Attributes); + Assert.Single(objHeader.Attributes); + Assert.Equal("fileName", objHeader.Attributes.First().Key); + Assert.Equal("test", objHeader.Attributes.First().Value); + } + + Assert.True(hasObject); + + var @object = await client.GetObjectAsync(new PrmObjectGet(createdContainer, objectId)); + + var downloadedBytes = new byte[@object.Header.PayloadLength]; + MemoryStream ms = new(downloadedBytes); + + ReadOnlyMemory? chunk = null; + while ((chunk = await @object.ObjectReader!.ReadChunk()) != null) + { + ms.Write(chunk.Value.Span); + } + + Assert.Equal(SHA256.HashData(bytes), SHA256.HashData(downloadedBytes)); + + await Cleanup(client); + + await foreach (var _ in client.ListContainersAsync()) + { + Assert.Fail("Containers exist"); + } + } + catch (Exception ex) + { + + } + } + + [Fact] + public async void PatchTest() + { + try + { + 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[4 * 1024]; + for (int i = 0; i < 4 * 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[1024]; + for (int i = 0; i < 1024; i++) + { + bytes[i] = (byte)32; + } + + var patchParams = new PrmObjectPatch(new FrostFsAddress(objectId, createdContainer)) + { + Payload = new MemoryStream(patch), + MaxPayloadPatchChunkLength = 1024, + NewAttributes = [new FrostFsAttributePair("testKey", "testValue")], + Range = new FrostFsRange() { Length = 1024, Offset = 10 }, + ReplaceAttributes = false + }; + + await client.PatchObjectAsync(patchParams); + + var @object = await client.GetObjectAsync(new PrmObjectGet(createdContainer, objectId)); + + var downloadedBytes = new byte[@object.Header.PayloadLength]; + MemoryStream ms = new(downloadedBytes); + + ReadOnlyMemory? chunk = null; + while ((chunk = await @object.ObjectReader!.ReadChunk()) != null) + { + ms.Write(chunk.Value.Span); + } + + Assert.Equal(SHA256.HashData(bytes), SHA256.HashData(downloadedBytes)); + + await Cleanup(client); + + await foreach (var _ in client.ListContainersAsync()) + { + Assert.Fail("Containers exist"); + } + } + catch (Exception ex) + { + + } + } + + [Fact] + public async void RangeTest() { using var client = FrostFSClient.GetSingleOwnerInstance(GetSingleOwnerOptions(this.keyString, this.url)); await Cleanup(client); - bool callbackInvoked = false; - var ctx = new CallContext - { - // Timeout = TimeSpan.FromSeconds(20), - Callback = new((CallStatistics cs) => - { - callbackInvoked = true; - Assert.True(cs.ElapsedMicroSeconds > 0); - }) - }; - var createContainerParam = new PrmContainerCreate( - new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1)), [new("testKey", "testValue")]), ctx); + 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, ctx)); + var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer)); Assert.NotNull(container); - Assert.True(callbackInvoked); - var bytes = GetRandomBytes(objectSize); - - var param = new PrmObjectPut(new CallContext + var bytes = new byte[256]; + for (int i = 0; i < 256; i++) { - Callback = new((CallStatistics cs) => Assert.True(cs.ElapsedMicroSeconds > 0)) - }) + bytes[i] = (byte)i; + } + + var param = new PrmObjectPut { Header = new FrostFsObjectHeader( containerId: createdContainer, @@ -289,35 +446,20 @@ public class SmokeClientTests : SmokeTestsBase var objectId = await client.PutObjectAsync(param); - var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test"); + var rangeParam = new PrmRangeGet(createdContainer, objectId, new FrostFsRange { Offset = 100, Length = 64 }); - bool hasObject = false; - await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(createdContainer) { Filters = [filter] })) - { - hasObject = true; + var rangeReader = await client.GetRangeAsync(rangeParam); - var objHeader = await client.GetObjectHeadAsync(new PrmObjectHeadGet(createdContainer, objectId)); - Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength); - Assert.NotNull(objHeader.Attributes); - Assert.Single(objHeader.Attributes); - Assert.Equal("fileName", objHeader.Attributes.First().Key); - Assert.Equal("test", objHeader.Attributes.First().Value); - } - - Assert.True(hasObject); - - var @object = await client.GetObjectAsync(new PrmObjectGet(createdContainer, objectId)); - - var downloadedBytes = new byte[@object.Header.PayloadLength]; + var downloadedBytes = new byte[rangeParam.Range.Length]; MemoryStream ms = new(downloadedBytes); ReadOnlyMemory? chunk = null; - while ((chunk = await @object.ObjectReader!.ReadChunk()) != null) + while ((chunk = await rangeReader!.ReadChunk()) != null) { ms.Write(chunk.Value.Span); } - Assert.Equal(SHA256.HashData(bytes), SHA256.HashData(downloadedBytes)); + Assert.Equal(SHA256.HashData(bytes.AsSpan().Slice(100, 64)), SHA256.HashData(downloadedBytes)); await Cleanup(client); diff --git a/src/FrostFS.SDK.Tests/SmokeTestsBase.cs b/src/FrostFS.SDK.Tests/SmokeTestsBase.cs index 6b42144..e0d53d7 100644 --- a/src/FrostFS.SDK.Tests/SmokeTestsBase.cs +++ b/src/FrostFS.SDK.Tests/SmokeTestsBase.cs @@ -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";