Ejemplo n.º 1
0
        private TcpConnectionInfo GetConnectionInfo(ReplicationNode node, bool external)
        {
            var shutdownInfo = new ConnectionShutdownInfo
            {
                Node     = node,
                External = external
            };

            _outgoingFailureInfo.TryAdd(node, shutdownInfo);
            try
            {
                if (node is ExternalReplication exNode)
                {
                    using (var requestExecutor = RequestExecutor.Create(exNode.ConnectionString.TopologyDiscoveryUrls, exNode.Database,
                                                                        _server.Server.ClusterCertificateHolder.Certificate,
                                                                        DocumentConventions.Default))
                        using (_server.ContextPool.AllocateOperationContext(out TransactionOperationContext ctx))
                        {
                            var cmd = new GetTcpInfoCommand("extrenal-replication");
                            requestExecutor.Execute(cmd, ctx);
                            node.Url = requestExecutor.Url;
                            return(cmd.Result);
                        }
                }
                if (node is InternalReplication internalNode)
                {
                    return(ReplicationUtils.GetTcpInfo(internalNode.Url, internalNode.NodeTag, "Replication", _server.Server.ClusterCertificateHolder.Certificate));
                }
                throw new InvalidOperationException(
                          $"Unexpected replication node type, Expected to be '{typeof(ExternalReplication)}' or '{typeof(InternalReplication)}', but got '{node.GetType()}'");
            }
            catch (Exception e)
            {
                // will try to fetch it again later
                if (_log.IsInfoEnabled)
                {
                    _log.Info($"Failed to fetch tcp connection information for the destination '{node.FromString()}' , the connection will be retried later.", e);
                }

                _reconnectQueue.TryAdd(shutdownInfo);
            }
            return(null);
        }