/// <summary> /// LeaseGrant creates a lease in async which expires if the server does not receive a keepAlive /// within a given time to live period. All keys attached to the lease will be expired and /// deleted if the lease expires. Each expired key generates a delete event in the event history. /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <LeaseGrantResponse> LeaseGrantAsync(LeaseGrantRequest request, Metadata headers = null) { LeaseGrantResponse response = new LeaseGrantResponse(); bool success = false; int retryCount = 0; while (!success) { try { response = await _balancer.GetConnection().leaseClient.LeaseGrantAsync(request, headers); success = true; } catch (RpcException ex) when(ex.StatusCode == StatusCode.Unavailable) { retryCount++; if (retryCount >= _balancer._numNodes) { throw ex; } } } return(response); }
/// <summary> /// LeaseGrant creates a lease which expires if the server does not receive a keepAlive /// within a given time to live period. All keys attached to the lease will be expired and /// deleted if the lease expires. Each expired key generates a delete event in the event history. /// </summary> /// <param name="request">The request to send to the server.</param> /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param> /// <param name="cancellationToken">An optional token for canceling the call.</param> /// <returns>The response received from the server.</returns> public LeaseGrantResponse LeaseGrant(LeaseGrantRequest request, Grpc.Core.Metadata headers = null, DateTime?deadline = null, CancellationToken cancellationToken = default) { return(CallEtcd((connection) => connection.leaseClient .LeaseGrant(request, headers, deadline, cancellationToken))); }
/// <summary> /// LeaseGrant creates a lease in async which expires if the server does not receive a keepAlive /// within a given time to live period. All keys attached to the lease will be expired and /// deleted if the lease expires. Each expired key generates a delete event in the event history. /// </summary> /// <param name="request">The request to send to the server.</param> /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param> /// <param name="cancellationToken">An optional token for canceling the call.</param> /// <returns>The response received from the server.</returns> public async Task <LeaseGrantResponse> LeaseGrantAsync(LeaseGrantRequest request, Grpc.Core.Metadata headers = null, DateTime?deadline = null, CancellationToken cancellationToken = default) { return(await CallEtcdAsync(async (connection) => await connection.leaseClient .LeaseGrantAsync(request, headers, deadline, cancellationToken))); }
public LeaseGrantResponse LeaseGrant(LeaseGrantRequest request) { var req = request.ToProto(); var rsp = client.LeaseGrant(req); return(rsp.FromProto()); }
/// <summary> /// LeaseGrant creates a lease in async which expires if the server does not receive a keepAlive /// within a given time to live period. All keys attached to the lease will be expired and /// deleted if the lease expires. Each expired key generates a delete event in the event history. /// </summary> /// <param name="request">The request to send to the server.</param> /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param> /// <param name="cancellationToken">An optional token for canceling the call.</param> /// <returns>The response received from the server.</returns> public async Task <LeaseGrantResponse> LeaseGrantAsync(LeaseGrantRequest request, Grpc.Core.Metadata headers = null, DateTime?deadline = null, CancellationToken cancellationToken = default) { LeaseGrantResponse response = new LeaseGrantResponse(); bool success = false; int retryCount = 0; while (!success) { try { response = await _balancer.GetConnection().leaseClient .LeaseGrantAsync(request, headers, deadline, cancellationToken); success = true; } catch (RpcException ex) when(ex.StatusCode == StatusCode.Unavailable) { retryCount++; if (retryCount >= _balancer._numNodes) { throw; } } } return(response); }
/// <summary> /// LeaseGrant creates a lease in async which expires if the server does not receive a keepAlive /// within a given time to live period. All keys attached to the lease will be expired and /// deleted if the lease expires. Each expired key generates a delete event in the event history. /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <LeaseGrantResponse> LeaseGrantAsync(LeaseGrantRequest request) { try { return(await _leaseClient.LeaseGrantAsync(request, _headers)); } catch (RpcException) { ResetConnection(); throw; } catch { throw; } }
/// <summary> /// LeaseGrant creates a lease which expires if the server does not receive a keepAlive /// within a given time to live period. All keys attached to the lease will be expired and /// deleted if the lease expires. Each expired key generates a delete event in the event history. /// </summary> /// <param name="request"></param> /// <returns></returns> public LeaseGrantResponse LeaseGrant(LeaseGrantRequest request) { try { return(_leaseClient.LeaseGrant(request, _headers)); } catch (RpcException) { ResetConnection(); throw; } catch { throw; } }
static async Task TestMemLeakAsync() { var channel = new Channel("192.168.2.13", 2379, ChannelCredentials.Insecure); var leaseClient = new Lease.LeaseClient(channel); Console.WriteLine("Start"); Console.ReadLine(); for (int i = 0; i < 100; i++) { var leaseGrantReq = new LeaseGrantRequest() { TTL = 100, }; var leaseGrantRes = await leaseClient.LeaseGrantAsync(leaseGrantReq, cancellationToken : channel.ShutdownToken); using (var leaser = leaseClient.LeaseKeepAlive(cancellationToken: channel.ShutdownToken)) { var leaseKeepAliveReq = new LeaseKeepAliveRequest() { ID = leaseGrantRes.ID }; await leaser.RequestStream.WriteAsync(leaseKeepAliveReq); await leaser.RequestStream.CompleteAsync(); while (await leaser.ResponseStream.MoveNext(channel.ShutdownToken)) { var leaseKeepAliveRes = leaser.ResponseStream.Current; if (leaseKeepAliveRes.ID == leaseKeepAliveReq.ID) { break; } } } } Console.WriteLine("Done"); Console.ReadLine(); GC.Collect(); Console.WriteLine("GC"); Console.ReadLine(); await channel.ShutdownAsync(); }
public async Task ImHere() { var leaseGrantRequest = new LeaseGrantRequest { TTL = LeaseTtl }; var leaseGrantResponse = await _client.LeaseGrantAsync(leaseGrantRequest); _leaseId = leaseGrantResponse.ID; await _client.PutAsync(new PutRequest { Lease = leaseGrantResponse.ID, Key = _key, Value = _broker }); _timer = new Timer(LeaseKeepAlive, null, TimeSpan.Zero, TimeSpan.FromSeconds(5)); }
public void LeaseGrant() { Mock <IEtcdClient> etcdClientMock = new Mock <IEtcdClient>(); Mock <IDisposable> disposableMock = new Mock <IDisposable>(); EtcdCompoundClient client = new EtcdCompoundClient(etcdClientMock.Object, disposableMock.Object); Fixture fixture = new Fixture(); LeaseGrantRequest request = fixture.Create <LeaseGrantRequest>(); LeaseGrantResponse response = fixture.Create <LeaseGrantResponse>(); etcdClientMock.Setup(p => p.LeaseGrant(request, null, null, CancellationToken.None)).Returns(response); LeaseGrantResponse actualResponse = client.LeaseGrant(request); etcdClientMock.Verify(p => p.LeaseGrant(request, null, null, CancellationToken.None), Times.Once); Assert.AreSame(response, actualResponse); }
internal LeaseGrantRequest LeaseGrant(LeaseGrantRequest leaseGrantRequest) { throw new NotImplementedException(); }
/// <summary> /// LeaseGrant creates a lease in async which expires if the server does not receive a keepAlive /// within a given time to live period. All keys attached to the lease will be expired and /// deleted if the lease expires. Each expired key generates a delete event in the event history. /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <LeaseGrantResponse> LeaseGrantAsync(LeaseGrantRequest request, Metadata headers = null) { return(await _balancer.GetConnection().leaseClient.LeaseGrantAsync(request, headers)); }
/// <summary> /// LeaseGrant creates a lease which expires if the server does not receive a keepAlive /// within a given time to live period. All keys attached to the lease will be expired and /// deleted if the lease expires. Each expired key generates a delete event in the event history. /// </summary> /// <param name="request"></param> /// <returns></returns> public LeaseGrantResponse LeaseGrant(LeaseGrantRequest request, Metadata headers = null) { return(_balancer.GetConnection().leaseClient.LeaseGrant(request, headers)); }
public LeaseGrantResponse LeaseGrant(LeaseGrantRequest request) { return(_etcdClient.LeaseGrant(request)); }