[#28] Client: Use external GRPC Channnel
Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
9bb7b5eff8
commit
c9418a1894
27 changed files with 520 additions and 438 deletions
|
@ -134,20 +134,20 @@ public partial class Pool : IFrostFSClient
|
|||
int i = 0;
|
||||
foreach (var nodeParams in RebalanceParams.NodesParams)
|
||||
{
|
||||
var clients = new ClientWrapper[nodeParams.Weights.Count];
|
||||
var wrappers = new ClientWrapper[nodeParams.Weights.Count];
|
||||
|
||||
for (int j = 0; j < nodeParams.Addresses.Count; j++)
|
||||
{
|
||||
ClientWrapper? client = null;
|
||||
ClientWrapper? wrapper = null;
|
||||
bool dialed = false;
|
||||
try
|
||||
{
|
||||
client = clients[j] = ClientBuilder(nodeParams.Addresses[j]);
|
||||
wrapper = wrappers[j] = ClientBuilder(nodeParams.Addresses[j]);
|
||||
|
||||
await client.Dial(ctx).ConfigureAwait(false);
|
||||
await wrapper.Dial(ctx).ConfigureAwait(false);
|
||||
dialed = true;
|
||||
|
||||
var token = await InitSessionForDuration(ctx, client, RebalanceParams.SessionExpirationDuration, Key.ECDsaKey, false)
|
||||
var token = await InitSessionForDuration(ctx, wrapper, RebalanceParams.SessionExpirationDuration, Key.ECDsaKey, false)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var key = FormCacheKey(nodeParams.Addresses[j], Key.PublicKey);
|
||||
|
@ -158,13 +158,13 @@ public partial class Pool : IFrostFSClient
|
|||
catch (RpcException ex)
|
||||
{
|
||||
if (!dialed)
|
||||
client!.SetUnhealthyOnDial();
|
||||
wrapper!.SetUnhealthyOnDial();
|
||||
else
|
||||
client!.SetUnhealthy();
|
||||
wrapper!.SetUnhealthy();
|
||||
|
||||
if (logger != null)
|
||||
{
|
||||
FrostFsMessages.SessionCreationError(logger, client!.WrapperPrm.Address, ex.Message);
|
||||
FrostFsMessages.SessionCreationError(logger, wrapper!.WrapperPrm.Address, ex.Message);
|
||||
}
|
||||
}
|
||||
catch (FrostFsInvalidObjectException)
|
||||
|
@ -175,7 +175,7 @@ public partial class Pool : IFrostFSClient
|
|||
|
||||
var sampler = new Sampler(nodeParams.Weights.ToArray());
|
||||
|
||||
inner[i] = new InnerPool(sampler, clients);
|
||||
inner[i] = new InnerPool(sampler, wrappers);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ public partial class Pool : IFrostFSClient
|
|||
|
||||
parameters.ClientBuilder ??= new Func<string, ClientWrapper>((address) =>
|
||||
{
|
||||
var wrapperPrm = new WrapperPrm
|
||||
var wrapperPrm = new WrapperPrm()
|
||||
{
|
||||
Address = address,
|
||||
Key = parameters.Key!,
|
||||
|
@ -287,7 +287,9 @@ public partial class Pool : IFrostFSClient
|
|||
ErrorThreshold = parameters.ErrorThreshold,
|
||||
GracefulCloseOnSwitchTimeout = parameters.GracefulCloseOnSwitchTimeout,
|
||||
Callback = parameters.Callback,
|
||||
Interceptors = parameters.Interceptors
|
||||
Interceptors = parameters.Interceptors,
|
||||
GrpcChannelFactory = parameters.GrpcChannelFactory
|
||||
|
||||
};
|
||||
|
||||
return new ClientWrapper(wrapperPrm, pool);
|
||||
|
@ -334,14 +336,14 @@ public partial class Pool : IFrostFSClient
|
|||
{
|
||||
CancellationTokenSource.Cancel();
|
||||
|
||||
if (InnerPools != null)
|
||||
{
|
||||
// close all clients
|
||||
foreach (var innerPool in InnerPools)
|
||||
foreach (var client in innerPool.Clients)
|
||||
if (client.IsDialed())
|
||||
client.Client?.Close();
|
||||
}
|
||||
//if (InnerPools != null)
|
||||
//{
|
||||
// // close all clients
|
||||
// foreach (var innerPool in InnerPools)
|
||||
// foreach (var client in innerPool.Clients)
|
||||
// if (client.IsDialed())
|
||||
// client.Client?.Close();
|
||||
//}
|
||||
}
|
||||
|
||||
// startRebalance runs loop to monitor connection healthy status.
|
||||
|
@ -586,12 +588,18 @@ public partial class Pool : IFrostFSClient
|
|||
return await client.Client!.GetObjectAsync(args, ctx).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<FrostFsObjectId> PutObjectAsync(PrmObjectPut args, CallContext ctx)
|
||||
public async Task<IObjectWriter> PutObjectAsync(PrmObjectPut args, CallContext ctx)
|
||||
{
|
||||
var client = Connection();
|
||||
return await client.Client!.PutObjectAsync(args, ctx).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<FrostFsObjectId> PutClientCutObjectAsync(PrmObjectClientCutPut args, CallContext ctx)
|
||||
{
|
||||
var client = Connection();
|
||||
return await client.Client!.PutClientCutObjectAsync(args, ctx).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<FrostFsObjectId> PutSingleObjectAsync(PrmSingleObjectPut args, CallContext ctx)
|
||||
{
|
||||
var client = Connection();
|
||||
|
@ -655,8 +663,6 @@ public partial class Pool : IFrostFSClient
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue