[#28] Client: Apply code optimizations
Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
766f61a5f7
commit
749000a090
57 changed files with 845 additions and 1116 deletions
|
@ -35,18 +35,17 @@ public partial class Pool : IFrostFSClient
|
|||
|
||||
private InnerPool[]? InnerPools { get; set; }
|
||||
|
||||
private ECDsa Key { get; set; }
|
||||
|
||||
private string PublicKey { get; }
|
||||
private ClientKey Key { get; set; }
|
||||
|
||||
private OwnerID? _ownerId;
|
||||
|
||||
private FrostFsOwner? _owner;
|
||||
|
||||
private FrostFsOwner Owner
|
||||
{
|
||||
get
|
||||
{
|
||||
_owner ??= new FrostFsOwner(Key.PublicKey().PublicKeyToAddress());
|
||||
_owner ??= new FrostFsOwner(Key.ECDsaKey.PublicKey().PublicKeyToAddress());
|
||||
return _owner;
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +56,7 @@ public partial class Pool : IFrostFSClient
|
|||
{
|
||||
if (_ownerId == null)
|
||||
{
|
||||
_owner = new FrostFsOwner(Key.PublicKey().PublicKeyToAddress());
|
||||
_owner = Key.Owner;
|
||||
_ownerId = _owner.ToMessage();
|
||||
}
|
||||
return _ownerId;
|
||||
|
@ -101,8 +100,7 @@ public partial class Pool : IFrostFSClient
|
|||
|
||||
FillDefaultInitParams(options, this);
|
||||
|
||||
Key = options.Key;
|
||||
PublicKey = $"{Key.PublicKey()}";
|
||||
Key = new ClientKey(options.Key);
|
||||
|
||||
SessionCache = cache;
|
||||
logger = options.Logger;
|
||||
|
@ -115,16 +113,9 @@ public partial class Pool : IFrostFSClient
|
|||
options.SessionExpirationDuration);
|
||||
|
||||
ClientBuilder = options.ClientBuilder!;
|
||||
}
|
||||
|
||||
private void SetupContext(CallContext ctx)
|
||||
{
|
||||
if (ctx == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(ctx));
|
||||
}
|
||||
// ClientContext.PoolErrorHandler = client.HandleError;
|
||||
|
||||
ctx.Key ??= Key;
|
||||
}
|
||||
|
||||
// Dial establishes a connection to the servers from the FrostFS network.
|
||||
|
@ -137,8 +128,6 @@ public partial class Pool : IFrostFSClient
|
|||
// See also InitParameters.SetClientRebalanceInterval.
|
||||
public async Task<string?> Dial(CallContext ctx)
|
||||
{
|
||||
SetupContext(ctx);
|
||||
|
||||
var inner = new InnerPool[RebalanceParams.NodesParams.Length];
|
||||
|
||||
bool atLeastOneHealthy = false;
|
||||
|
@ -158,11 +147,11 @@ public partial class Pool : IFrostFSClient
|
|||
await client.Dial(ctx).ConfigureAwait(false);
|
||||
dialed = true;
|
||||
|
||||
var token = await InitSessionForDuration(ctx, client, RebalanceParams.SessionExpirationDuration, Key, false)
|
||||
var token = await InitSessionForDuration(ctx, client, RebalanceParams.SessionExpirationDuration, Key.ECDsaKey, false)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var key = FormCacheKey(nodeParams.Addresses[j], Key.PrivateKey().ToString());
|
||||
_ = SessionCache.Cache[key] = token;
|
||||
var key = FormCacheKey(nodeParams.Addresses[j], Key.PublicKey);
|
||||
SessionCache.SetValue(key, token);
|
||||
|
||||
atLeastOneHealthy = true;
|
||||
}
|
||||
|
@ -291,12 +280,14 @@ public partial class Pool : IFrostFSClient
|
|||
var wrapperPrm = new WrapperPrm
|
||||
{
|
||||
Address = address,
|
||||
Key = parameters.Key,
|
||||
Key = parameters.Key!,
|
||||
Logger = parameters.Logger,
|
||||
DialTimeout = parameters.NodeDialTimeout,
|
||||
StreamTimeout = parameters.NodeStreamTimeout,
|
||||
ErrorThreshold = parameters.ErrorThreshold,
|
||||
GracefulCloseOnSwitchTimeout = parameters.GracefulCloseOnSwitchTimeout
|
||||
GracefulCloseOnSwitchTimeout = parameters.GracefulCloseOnSwitchTimeout,
|
||||
Callback = parameters.Callback,
|
||||
Interceptors = parameters.Interceptors
|
||||
};
|
||||
|
||||
return new ClientWrapper(wrapperPrm, pool);
|
||||
|
@ -318,7 +309,7 @@ public partial class Pool : IFrostFSClient
|
|||
throw new FrostFsException("Cannot find alive client");
|
||||
}
|
||||
|
||||
private static async Task<FrostFsSessionToken?> InitSessionForDuration(CallContext ctx, ClientWrapper cw, ulong duration, ECDsa key, bool clientCut)
|
||||
private static async Task<FrostFsSessionToken> InitSessionForDuration(CallContext ctx, ClientWrapper cw, ulong duration, ECDsa key, bool clientCut)
|
||||
{
|
||||
var client = cw.Client;
|
||||
var networkInfo = await client!.GetNetworkSettingsAsync(new PrmNetworkSettings(ctx)).ConfigureAwait(false);
|
||||
|
@ -521,7 +512,6 @@ public partial class Pool : IFrostFSClient
|
|||
var client = Connection();
|
||||
|
||||
args ??= new();
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
return await client.Client!.GetNetmapSnapshotAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
@ -529,278 +519,126 @@ public partial class Pool : IFrostFSClient
|
|||
public async Task<FrostFsNodeInfo> GetNodeInfoAsync(PrmNodeInfo? args = null)
|
||||
{
|
||||
var client = Connection();
|
||||
|
||||
args ??= new();
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
return await client.Client!.GetNodeInfoAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<NetworkSettings> GetNetworkSettingsAsync(PrmNetworkSettings? args = null)
|
||||
{
|
||||
var client = Connection();
|
||||
|
||||
args ??= new();
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
return await client.Client!.GetNetworkSettingsAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<FrostFsSessionToken> CreateSessionAsync(PrmSessionCreate args)
|
||||
{
|
||||
if (args is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
var client = Connection();
|
||||
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
return await client.Client!.CreateSessionAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<byte[]> AddChainAsync(PrmApeChainAdd args)
|
||||
public async Task<ReadOnlyMemory<byte>> AddChainAsync(PrmApeChainAdd args)
|
||||
{
|
||||
if (args is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
var client = Connection();
|
||||
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
return await client.Client!.AddChainAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task RemoveChainAsync(PrmApeChainRemove args)
|
||||
{
|
||||
if (args is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
var client = Connection();
|
||||
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
await client.Client!.RemoveChainAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<Chain[]> ListChainAsync(PrmApeChainList args)
|
||||
{
|
||||
if (args is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
var client = Connection();
|
||||
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
return await client.Client!.ListChainAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<FrostFsContainerInfo> GetContainerAsync(PrmContainerGet args)
|
||||
{
|
||||
if (args is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
var client = Connection();
|
||||
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
return await client.Client!.GetContainerAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<FrostFsContainerId> ListContainersAsync(PrmContainerGetAll? args = null)
|
||||
{
|
||||
var client = Connection();
|
||||
|
||||
args ??= new();
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
return client.Client!.ListContainersAsync(args);
|
||||
}
|
||||
|
||||
public async Task<FrostFsContainerId> CreateContainerAsync(PrmContainerCreate args)
|
||||
{
|
||||
if (args is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
var client = Connection();
|
||||
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
return await client.Client!.CreateContainerAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task DeleteContainerAsync(PrmContainerDelete args)
|
||||
{
|
||||
if (args is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
var client = Connection();
|
||||
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
await client.Client!.DeleteContainerAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<FrostFsObjectHeader> GetObjectHeadAsync(PrmObjectHeadGet args)
|
||||
{
|
||||
if (args is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
var client = Connection();
|
||||
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
return await client.Client!.GetObjectHeadAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<FrostFsObject> GetObjectAsync(PrmObjectGet args)
|
||||
{
|
||||
if (args is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
var client = Connection();
|
||||
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
return await client.Client!.GetObjectAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<FrostFsObjectId> PutObjectAsync(PrmObjectPut args)
|
||||
{
|
||||
if (args is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
var client = Connection();
|
||||
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
return await client.Client!.PutObjectAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<FrostFsObjectId> PutSingleObjectAsync(PrmSingleObjectPut args)
|
||||
{
|
||||
if (args is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
var client = Connection();
|
||||
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
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<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)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
var client = Connection();
|
||||
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
await client.Client!.DeleteObjectAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<FrostFsObjectId> SearchObjectsAsync(PrmObjectSearch args)
|
||||
{
|
||||
if (args is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
var client = Connection();
|
||||
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
return client.Client!.SearchObjectsAsync(args);
|
||||
}
|
||||
|
||||
public async Task<Accounting.Decimal> GetBalanceAsync(PrmBalance? args)
|
||||
{
|
||||
var client = Connection();
|
||||
|
||||
args ??= new();
|
||||
args.Context.PoolErrorHandler = client.HandleError;
|
||||
|
||||
return await client.Client!.GetBalanceAsync(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
@ -824,7 +662,7 @@ public partial class Pool : IFrostFSClient
|
|||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public FrostFsObjectId CalculateObjectId(FrostFsObjectHeader header, CallContext ctx)
|
||||
public FrostFsObjectId CalculateObjectId(FrostFsObjectHeader header)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue