Exemple #1
0
        private void Initialize(string address, IChannelFormatter channelFormatter)
        {
            TraceProvider traceProvider = EnableTracing ? new TraceProvider() : null;

            //    ManagementHost.RegisterCompactTypes();
            if (string.IsNullOrEmpty(address))
            {
                address = NetworkUtil.GetLocalIPAddress().ToString();
            }
            //binding IP is null for ConfigClient
            _channel = new DualChannel(address, _port, null, _sessionType, traceProvider, channelFormatter);
            //_channel.RegisterRequestHandler(this);


            //RTD: whats the purpose of this?
            try
            {
                if (_channel.Connect(true))
                {
                    //string _sessionType = ((int)sessionType).ToString();
                    //_channel.SendMessage(_sessionType, true);
                }
            }
            catch (ChannelException ex)
            {
                //if (LoggerManager.Instance.CONDBLogger != null && LoggerManager.Instance.CONDBLogger.IsErrorEnabled)
                //    LoggerManager.Instance.CONDBLogger.Error("Error: OutprocConfigClient.Init()", ex.ToString());
                throw;
            }
        }
Exemple #2
0
 public RemoteShard(IChannelFactory factory, IChannelFormatter channelFormatter, NodeContext context, IConnectionRestoration connectionRestoration)
 {
     this.factory                = factory;
     this._channelFormatter      = channelFormatter;
     this.context                = context;
     this._connectionRestoration = connectionRestoration;
     this._threadPool            = new ClrThreadPool();
     this._threadPool.Initialize();
 }
 public ClientSessionManager(IDatabaseEngineFactory databaseEngineFactory)
 {
     _databaseEngineFactory = databaseEngineFactory;
     _clientSessions        = new HashVector <string, ClientSession>();
     SetLocalAddress();
     _traceProvider    = new TraceProvider();
     _channelFormatter = new DbEngineFormatter();
     _threadPool       = new ClrThreadPool();
     _threadPool.Initialize();
 }
Exemple #4
0
        public void Connect(string serviceURI, int port, SessionTypes sessionType, IChannelFormatter channelFormatter)
        {
            //_bindIp = NetworkUtil.GetLocalIPAddress().ToString(); ;
            _port             = port;
            _channelFormatter = channelFormatter;
            SetURI(serviceURI);
            _sessionType             = sessionType;
            _firstConfiguratioServer = serviceURI;

            try
            {
                Initialize(_firstConfiguratioServer, channelFormatter);
            }
            catch (Exception)
            {
                if (_secondConfiguratioServer != null)
                {
                    Initialize(_secondConfiguratioServer, channelFormatter);
                }
            }
        }
        public RemoteShardConnections(IChannelFactory factory, IChannelFormatter channelFormatter, ShardInfo shardInfo,
                                      TraceProvider traceProvider, SessionTypes sessionType)
        {
            _clientContexts    = new Dictionary <string, ClientContext>();
            _clientCredentials = new Dictionary <string, ClientCredential>();

            _factory          = factory;
            _channelFormatter = channelFormatter;
            _shardInfo        = shardInfo;
            _traceProvider    = traceProvider;
            if (shardInfo.Primary != null)
            {
                _primary =
                    new Server(
                        new Address(shardInfo.Primary.Address.IpAddress.ToString(), _shardInfo.Primary.Address.Port),
                        Status.Running); // If its primary it must be running
            }
            else
            {
                // TODO: Write exception to log
                //throw new Exception("At Query Distributor: No primary exists for " + shardInfo.Name);
            }
            _sessionType = sessionType;
        }
Exemple #6
0
 IRequestResponseChannel IChannelFactory.GetChannel(IConnection connection, string peerIP, int peerPort, string bindingIP, SessionTypes sessionType, ITraceProvider traceProvider, IChannelFormatter channelFormatter)
 {
     return(new DualChannel(connection, peerIP, peerPort, bindingIP, sessionType, traceProvider, channelFormatter, _requestTimeout));
 }
Exemple #7
0
        public DualChannel(IConnection connection, string peerIP, int peerPort, string bindingIP, SessionTypes sessionType, ITraceProvider traceProvider, IChannelFormatter channelFormatter, int requestTimeout = 90)
        {
            //==================================

            tcpChannel           = new TcpChannel(connection, peerIP, peerPort, bindingIP, traceProvider);
            tcpChannel.Formatter = channelFormatter;
            requestManager       = new RequestManager(tcpChannel, false, requestTimeout);
            _peerAddress         = new Address(peerIP, peerPort);
            DualChannelListener _lisetner = new DualChannelListener(tcpChannel.UsesAsynchronousIO ? null : new ClrThreadPool());

            _lisetner.RegisterRequestListener(this);
            _lisetner.RegisterResponseListener(requestManager);
            tcpChannel.RegisterEventListener(_lisetner);

            //=================================
        }
Exemple #8
0
        public virtual IConfigurationServer GetConfigurationServer(TimeSpan timeout, SessionTypes sessionType, IChannelFormatter channelFormatter)
        {
            IConfigurationServer cs = null;

            try
            {
                cs = ConnectConfigurationService();
            }
            catch (SocketException exception)
            {
                if (exception.SocketErrorCode == SocketError.TimedOut)
                {
                    throw exception;
                }
                try
                {
                    Start(timeout);
                    cs = ConnectConfigurationService();
                }
                catch (Exception ex)
                {
                    throw  exception;
                }
            }

            return(cs);
        }
 public IShardConfigurationSession OpenShardConfigurationSession(string cluster, string shard, ServerNode node, UserCredentials credentials, IChannelFormatter channelFormatter)
 {
     return(new InProcShardConfigurationSession(_server.OpenShardConfigurationSession(cluster, shard, node, credentials, channelFormatter)));
 }
Exemple #10
0
 IRequestResponseChannel IChannelFactory.GetChannel(IConnection connection, string peerIP, int peerPort, string bindingIP, SessionTypes sessionType, ITraceProvider traceProvider, IChannelFormatter channelFormatter)
 {
     throw new NotImplementedException("client channel factory does not implement this method");
 }
Exemple #11
0
        public override IConfigurationServer GetConfigurationServer(TimeSpan timeout, SessionTypes sessionType, IChannelFormatter channelFormatter)
        {
            OutProcConfigurationClient client = new OutProcConfigurationClient();

            TryIntializeService(client, timeout, sessionType, channelFormatter);
            return(client);
        }
Exemple #12
0
 private void TryIntializeService(OutProcConfigurationClient client, TimeSpan timeout, SessionTypes sessionType, IChannelFormatter channelFormatter)
 {
     try
     {
         TraceProvider traceProvider = EnableTracing ? new TraceProvider() : null;
         if (_port > 0 && _port < 65535)
         {
             client.Connect(_addressURI, _port, sessionType, channelFormatter);
         }
         else
         {
             client.Connect(_addressURI, sessionType);
         }
     }
     catch (Exception e)
     {
         if (retries-- > 0)
         {
             Start(timeout);
             System.Threading.Thread.Sleep(3000);
             TryIntializeService(client, timeout, sessionType, channelFormatter);
         }
         else
         {
             throw e;
         }
     }
     finally
     {
         retries = 3;
     }
 }
Exemple #13
0
        public static IConfigurationSession Connect(string[] configServers, int configServerPort, string cluster, out IConfigurationServer remote, IChannelFormatter channelFormatter, IClientAuthenticationCredential clientAuthenticationCredential, bool remoteRouter = false)
        {
            Exception          exception = null;
            DatabaseRPCService rpc       = null;

            remote = null;
            IConfigurationSession configurationSession = null;
            int     csPort = configServerPort;
            Boolean found  = false;

            foreach (String current in configServers)
            {
                if (found)
                {
                    break;
                }

                int retries = 3;
                while (retries > 0)
                {
                    try
                    {
                        if (configurationSession != null)
                        {
                            configurationSession.Close();
                            configurationSession = null;
                        }
                        rpc = new DatabaseRPCService(current, csPort);

                        //if (remote == null)
                        {
                            remote = rpc.GetConfigurationServer(new TimeSpan(0, 0, 90), SessionTypes.Client, channelFormatter);
                        }

                        if (remoteRouter)
                        {
                            remote.MarkDistributorSession();
                        }

                        configurationSession = remote.OpenConfigurationSession(clientAuthenticationCredential);

                        if (configurationSession != null)
                        {
                            List <Alachisoft.NosDB.Common.Net.Address> csServers = configurationSession.GetConfServers(cluster);

                            if (csServers == null || csServers.Count < 1)
                            {
                                throw new DatabaseException(Common.ErrorHandling.ErrorCodes.Distributor.CLUSTER_INFO_UNAVAILABLE, new[] { cluster });
                            }

                            foreach (Alachisoft.NosDB.Common.Net.Address add in csServers)
                            {
                                if (add.ip.Equals(current))
                                {
                                    found = true;
                                }
                            }

                            if (!found)
                            {
                                configurationSession.Close();
                                configurationSession = null;

                                foreach (Alachisoft.NosDB.Common.Net.Address cur in csServers)
                                {
                                    try
                                    {
                                        rpc    = new DatabaseRPCService(cur.ip, csPort);
                                        remote = rpc.GetConfigurationServer(new TimeSpan(0, 0, 90), SessionTypes.Client, channelFormatter);

                                        if (remoteRouter)
                                        {
                                            remote.MarkDistributorSession();
                                        }
                                        configurationSession = remote.OpenConfigurationSession(clientAuthenticationCredential);
                                        found = true;
                                    }
                                    catch (Exception ex)
                                    {
                                        exception = ex;
                                    }
                                }
                            }
                        }

                        if (found)
                        {
                            break;
                        }
                    }
                    catch (Alachisoft.NosDB.Common.Exceptions.TimeoutException)
                    {
                        if (configurationSession != null)
                        {
                            configurationSession.Close();
                            configurationSession = null;
                        }

                        exception = new DistributorException(ErrorCodes.Distributor.CONFIGURATION_SERVER_NOTRESPONDING);
                        retries--;
                        if (retries == 0)
                        {
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        if (configurationSession != null)
                        {
                            configurationSession.Close();
                            configurationSession = null;
                        }

                        exception = e;
                        retries--;
                        if (retries == 0)
                        {
                            break;
                        }
                    }
                }
            }

            if (configurationSession != null)
            {
                return(configurationSession);
            }
            else if (exception != null)
            {
                throw exception;
            }
            return(null);
        }
Exemple #14
0
 public ClientChannel(string peerIP, int peerPort, string bindingIP, SessionTypes sessionType, ITraceProvider traceProvider, IChannelFormatter channelFormatter, int requestTimeout)
 {
     _peerAddress         = new Address(peerIP, peerPort);
     tcpChannel           = new TcpChannel(_peerAddress.IpAddress.ToString(), _peerAddress.Port, bindingIP, sessionType, traceProvider);
     tcpChannel.Formatter = channelFormatter;
     requestManager       = new RequestManager(tcpChannel, true, requestTimeout);
 }
Exemple #15
0
 public IShardConfigurationSession OpenShardConfigurationSession(string cluster, string shard, ServerNode node, UserCredentials credentials, IChannelFormatter channelFormatter)
 {
     Initialize(_serviceURI, channelFormatter);
     _shardSession = new OutProcShardConfigurationSession(cluster, shard, node, credentials, _channel);
     return(_shardSession);
 }
Exemple #16
0
        public ServerChannel(IConnection connection, string peerIP, int peerPort, string bindingIP, SessionTypes sessionType, ITraceProvider traceProvider, IChannelFormatter channelFormatter)
        {
            tcpChannel           = new TcpChannel(connection, peerIP, peerPort, bindingIP, traceProvider);
            tcpChannel.Formatter = channelFormatter;
            peerAddress          = new Address(peerIP, peerPort);
            tcpChannel.RegisterEventListener(this);

            _threadPool = new ClrThreadPool();
            _threadPool.Initialize();
        }