示例#1
0
            public override async Task <Stream> ConnectToPeer(string url, X509Certificate2 certificate)
            {
                TimeSpan time;

                using (ContextPoolForReadOnlyOperations.AllocateOperationContext(out TransactionOperationContext ctx))
                    using (ctx.OpenReadTransaction())
                    {
                        time = _parent.ElectionTimeout * (_parent.GetTopology(ctx).AllNodes.Count - 2);
                    }
                var tcpClient = await TcpUtils.ConnectAsync(url, time);

                return(tcpClient.GetStream());
            }
示例#2
0
        private async Task <PingResult> PingOnce(string url)
        {
            var sp     = Stopwatch.StartNew();
            var result = new PingResult
            {
                Url = url
            };

            try
            {
                using (var cts = new CancellationTokenSource(ServerStore.Engine.TcpConnectionTimeout))
                {
                    var info = await ReplicationUtils.GetTcpInfoAsync(url, null, "PingTest", ServerStore.Engine.ClusterCertificate, cts.Token);

                    result.TcpInfoTime = sp.ElapsedMilliseconds;
                    using (var tcpClient = await TcpUtils.ConnectAsync(info.Url, ServerStore.Engine.TcpConnectionTimeout).ConfigureAwait(false))
                        using (var stream = await TcpUtils
                                            .WrapStreamWithSslAsync(tcpClient, info, ServerStore.Engine.ClusterCertificate, ServerStore.Engine.TcpConnectionTimeout).ConfigureAwait(false))
                            using (ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context))
                            {
                                var msg = new DynamicJsonValue
                                {
                                    [nameof(TcpConnectionHeaderMessage.DatabaseName)]     = null,
                                    [nameof(TcpConnectionHeaderMessage.Operation)]        = TcpConnectionHeaderMessage.OperationTypes.Ping,
                                    [nameof(TcpConnectionHeaderMessage.OperationVersion)] = -1
                                };

                                using (var writer = new BlittableJsonTextWriter(context, stream))
                                    using (var msgJson = context.ReadObject(msg, "message"))
                                    {
                                        result.SendTime = sp.ElapsedMilliseconds;
                                        context.Write(writer, msgJson);
                                    }
                                using (var response = context.ReadForMemory(stream, "cluster-ConnectToPeer-header-response"))
                                {
                                    JsonDeserializationServer.TcpConnectionHeaderResponse(response);
                                    result.RecieveTime = sp.ElapsedMilliseconds;
                                }
                            }
                }
            }
            catch (Exception e)
            {
                result.Error = e.ToString();
            }
            return(result);
        }
示例#3
0
            public override async Task <RachisConnection> ConnectToPeer(string url, X509Certificate2 certificate)
            {
                TimeSpan time;

                using (ContextPoolForReadOnlyOperations.AllocateOperationContext(out TransactionOperationContext ctx))
                    using (ctx.OpenReadTransaction())
                    {
                        time = _parent.ElectionTimeout * (_parent.GetTopology(ctx).AllNodes.Count - 2);
                    }
                var tcpClient = await TcpUtils.ConnectAsync(url, time);

                return(new RachisConnection
                {
                    Stream = tcpClient.GetStream(),

                    SupportedFeatures = new TcpConnectionHeaderMessage.SupportedFeatures(TcpConnectionHeaderMessage.NoneBaseLine40000),
                    Disconnect = () => tcpClient.Client.Disconnect(false)
                });
            }
示例#4
0
            public override async Task <RachisConnection> ConnectToPeer(string url, string tag, X509Certificate2 certificate, CancellationToken token)
            {
                TimeSpan time;

                using (ContextPoolForReadOnlyOperations.AllocateOperationContext(out ClusterOperationContext ctx))
                    using (ctx.OpenReadTransaction())
                    {
                        time = _parent.ElectionTimeout * (_parent.GetTopology(ctx).AllNodes.Count - 2);
                    }
                var tcpClient = await TcpUtils.ConnectAsync(url, time, token : token);

                try
                {
                    var stream = tcpClient.GetStream();
                    var conn   = new RachisConnection
                    {
                        Stream            = stream,
                        SupportedFeatures = TcpConnectionHeaderMessage.GetSupportedFeaturesFor(
                            TcpConnectionHeaderMessage.OperationTypes.Cluster, TcpConnectionHeaderMessage.ClusterWithMultiTree),
                        Disconnect = () =>
                        {
                            using (tcpClient)
                            {
                                tcpClient.Client.Disconnect(false);
                            }
                        }
                    };
                    return(conn);
                }
                catch
                {
                    using (tcpClient)
                    {
                        tcpClient.Client.Disconnect(false);
                    }
                    throw;
                }
            }
            public override async Task <Stream> ConnectToPeer(string url, X509Certificate2 certificate)
            {
                var tcpClient = await TcpUtils.ConnectAsync(url, _parent.TcpConnectionTimeout);

                return(tcpClient.GetStream());
            }