[#24] Client: Implement pool part2
Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
c9a75ea025
commit
ee20798379
63 changed files with 801 additions and 526 deletions
|
@ -15,30 +15,32 @@ using Google.Protobuf;
|
|||
|
||||
namespace FrostFS.SDK.ClientV2;
|
||||
|
||||
internal sealed class ObjectServiceProvider : ContextAccessor, ISessionProvider
|
||||
internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient client, ClientContext clientCtx)
|
||||
: ContextAccessor(clientCtx), ISessionProvider
|
||||
{
|
||||
private readonly SessionProvider sessions;
|
||||
private ObjectService.ObjectServiceClient client;
|
||||
|
||||
internal ObjectServiceProvider(ObjectService.ObjectServiceClient client, EnvironmentContext env)
|
||||
: base(env)
|
||||
{
|
||||
this.sessions = new(EnvironmentContext);
|
||||
this.client = client;
|
||||
}
|
||||
private SessionProvider? sessions;
|
||||
private readonly ObjectService.ObjectServiceClient client = client;
|
||||
|
||||
public async ValueTask<SessionToken> GetOrCreateSession(ISessionToken args, CallContext ctx)
|
||||
{
|
||||
sessions ??= new(ClientContext);
|
||||
|
||||
if (ClientContext.SessionCache.Cache != null &&
|
||||
ClientContext.SessionCache.Cache.ContainsKey(ClientContext.SessionCacheKey))
|
||||
{
|
||||
return (SessionToken)ClientContext.SessionCache.Cache[ClientContext.SessionCacheKey];
|
||||
}
|
||||
|
||||
return await sessions.GetOrCreateSession(args, ctx).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal async Task<FrostFsObjectHeader> GetObjectHeadAsync(PrmObjectHeadGet args)
|
||||
{
|
||||
var ctx = args.Context!;
|
||||
ctx.Key ??= EnvironmentContext.Key?.ECDsaKey;
|
||||
ctx.Key ??= ClientContext.Key?.ECDsaKey;
|
||||
|
||||
if (ctx.Key == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Key));
|
||||
throw new ArgumentNullException(nameof(args), "Key is null");
|
||||
|
||||
var request = new HeadRequest
|
||||
{
|
||||
|
@ -74,10 +76,10 @@ internal sealed class ObjectServiceProvider : ContextAccessor, ISessionProvider
|
|||
{
|
||||
var ctx = args.Context!;
|
||||
|
||||
ctx.Key ??= EnvironmentContext.Key?.ECDsaKey;
|
||||
ctx.Key ??= ClientContext.Key?.ECDsaKey;
|
||||
|
||||
if (ctx.Key == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Key));
|
||||
throw new ArgumentNullException(nameof(args), "Key is null");
|
||||
|
||||
var request = new GetRequest
|
||||
{
|
||||
|
@ -108,10 +110,10 @@ internal sealed class ObjectServiceProvider : ContextAccessor, ISessionProvider
|
|||
internal async Task DeleteObjectAsync(PrmObjectDelete args)
|
||||
{
|
||||
var ctx = args.Context!;
|
||||
ctx.Key ??= EnvironmentContext.Key?.ECDsaKey;
|
||||
ctx.Key ??= ClientContext.Key?.ECDsaKey;
|
||||
|
||||
if (ctx.Key == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Key));
|
||||
throw new ArgumentNullException(nameof(args), "Key is null");
|
||||
|
||||
var request = new DeleteRequest
|
||||
{
|
||||
|
@ -145,7 +147,7 @@ internal sealed class ObjectServiceProvider : ContextAccessor, ISessionProvider
|
|||
var ctx = args.Context!;
|
||||
|
||||
if (ctx.Key == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Key));
|
||||
throw new ArgumentNullException(nameof(args), "Key is null");
|
||||
|
||||
var request = new SearchRequest
|
||||
{
|
||||
|
@ -183,10 +185,10 @@ internal sealed class ObjectServiceProvider : ContextAccessor, ISessionProvider
|
|||
throw new ArgumentNullException(nameof(args));
|
||||
|
||||
if (args.Header == null)
|
||||
throw new ArgumentException(nameof(args.Header));
|
||||
throw new ArgumentNullException(nameof(args), "Header is null");
|
||||
|
||||
if (args.Payload == null)
|
||||
throw new ArgumentException(nameof(args.Payload));
|
||||
throw new ArgumentNullException(nameof(args), "Payload is null");
|
||||
|
||||
if (args.ClientCut)
|
||||
return await PutClientCutObject(args).ConfigureAwait(false);
|
||||
|
@ -206,7 +208,7 @@ internal sealed class ObjectServiceProvider : ContextAccessor, ISessionProvider
|
|||
var ctx = args.Context!;
|
||||
|
||||
if (ctx.Key == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Key));
|
||||
throw new ArgumentNullException(nameof(args), "Key is null");
|
||||
|
||||
var grpcObject = ObjectTools.CreateObject(args.FrostFsObject, ctx);
|
||||
|
||||
|
@ -254,7 +256,7 @@ internal sealed class ObjectServiceProvider : ContextAccessor, ISessionProvider
|
|||
|
||||
if (args.MaxObjectSizeCache == 0)
|
||||
{
|
||||
var networkSettings = await EnvironmentContext.Client.GetNetworkSettingsAsync(new PrmNetworkSettings() { Context = ctx })
|
||||
var networkSettings = await ClientContext.Client.GetNetworkSettingsAsync(new PrmNetworkSettings(ctx))
|
||||
.ConfigureAwait(false);
|
||||
|
||||
args.MaxObjectSizeCache = (int)networkSettings.MaxObjectSize;
|
||||
|
@ -306,7 +308,7 @@ internal sealed class ObjectServiceProvider : ContextAccessor, ISessionProvider
|
|||
|
||||
var linkObject = new FrostFsLinkObject(header.ContainerId, split!.SplitId, largeObjectHeader, sentObjectIds);
|
||||
|
||||
_ = await PutSingleObjectAsync(new PrmSingleObjectPut(linkObject) { Context = args.Context }).ConfigureAwait(false);
|
||||
_ = await PutSingleObjectAsync(new PrmSingleObjectPut(linkObject, args.Context)).ConfigureAwait(false);
|
||||
|
||||
var parentHeader = args.Header.GetHeader();
|
||||
|
||||
|
@ -331,7 +333,7 @@ internal sealed class ObjectServiceProvider : ContextAccessor, ISessionProvider
|
|||
{
|
||||
var ctx = args.Context!;
|
||||
if (ctx.Key == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Key));
|
||||
throw new ArgumentNullException(nameof(args), "Key is null");
|
||||
|
||||
var payload = args.Payload!;
|
||||
|
||||
|
@ -352,7 +354,7 @@ internal sealed class ObjectServiceProvider : ContextAccessor, ISessionProvider
|
|||
}
|
||||
else
|
||||
{
|
||||
chunkBuffer = EnvironmentContext.GetArrayPool(Constants.ObjectChunkSize).Rent(chunkSize);
|
||||
chunkBuffer = ClientContext.GetArrayPool(Constants.ObjectChunkSize).Rent(chunkSize);
|
||||
isRentBuffer = true;
|
||||
}
|
||||
|
||||
|
@ -409,7 +411,7 @@ internal sealed class ObjectServiceProvider : ContextAccessor, ISessionProvider
|
|||
var header = args.Header!;
|
||||
|
||||
if (ctx.Key == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Key));
|
||||
throw new ArgumentNullException(nameof(args), "Key is null");
|
||||
|
||||
header.OwnerId ??= ctx.OwnerId;
|
||||
header.Version ??= ctx.Version;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue