//When a new shard is added, do the following public void OnShardAdded(ShardInfo shard) { if (shard != null) { if (shard.Name != context.LocalShardName && _remoteShards != null && !_remoteShards.ContainsKey(shard.Name)) { if (_clusterConfigMgr != null) { _clusterConfigMgr.UpdateClusterConfiguration(); ShardConfiguration sConfig = _clusterConfigMgr.GetShardConfiguration(context.LocalShardName); if (sConfig == null) { if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsWarnEnabled) { LoggerManager.Instance.ShardLogger.Warn("ClusterManager.OnShardAdded() ", "The shard " + shard.Name + " does not exist in the configuration."); } return; } IShard remoteShard = new RemoteShard(new DualChannelFactory(), new ShardChannelFormatter(), context, _connectionRestoration); remoteShard.Initialize(sConfig); remoteShard.RegisterShardListener(Common.MiscUtil.CLUSTER_MANAGER, this); lock (_remoteShards) { _remoteShards.Add(shard.Name, remoteShard); } } } } }
public bool OnSessionEstablished(Session session) { if (session == null || session.SessionType != SessionTypes.Shard || session.Connection == null) { return(false); } SessionInfo info = GetSessionInfo(session); //SessionInfo info = new SessionInfo(); //info.Cluster = "cluster1"; //info.Shard = "shard1"; if (info == null || String.IsNullOrEmpty(info.Cluster) || String.IsNullOrEmpty(info.Shard)) { session.Connection.Disconnect(); return(false); } if (info.Cluster.Equals(context.ClusterName) && info.Shard.Equals(_localShard.Name)) { return(_localShard.OnSessionEstablished(session)); } else if (_localShard != null && ((LocalShard)_localShard).NodeRole == NodeRole.Primary) { if (_remoteShards != null) { if (this._remoteShards.ContainsKey(info.Shard)) { RemoteShard shard = this._remoteShards[info.Shard] as RemoteShard; return(shard.OnSessionEstablished(session)); } else { session.Connection.Disconnect(); } } } else { session.Connection.Disconnect(); } return(false); }
////RTD: Needs to be moved. //public ShardInfo ThisShard //{ // get { return _localShardInfo; } //} //public IDictionary<String, ShardInfo> Shards //{ // get { return _remoteShardsInfo; } //} public bool Initialize(ClusterConfiguration configuration) //public bool Initialize(String clusterName, DeploymentConfiguration configuration) { #region Getting Local Address Logic; might be replace with getting address from service config if (configuration == null) { throw new ArgumentNullException("cluster configuration can not be null"); } if (configuration.Deployment == null) { throw new ArgumentNullException("deployment configuration can not be null"); } if (configuration.Deployment.Shards == null) { throw new ArgumentNullException("topology configuration can not be null"); } if (context != null) { context.ClusterName = configuration.Name; } if (string.IsNullOrWhiteSpace(context.LocalShardName)) { //Get Local Shard Name from config //string shardName = ConfigurationManager.AppSettings["ShardName"]; //if (String.IsNullOrEmpty(shardName)) //{ throw new ArgumentNullException("Shard Name Can not be null or empty"); //} //RTD: Needs to be moved. //context.LocalShardName = shardName; } //Get Base Data Path from config string basePath = ConfigurationSettings <DBHostSettings> .Current.BasePath; if (String.IsNullOrEmpty(basePath)) { throw new ArgumentNullException("Data Path Can not be null or empty"); } context.DataPath = basePath; context.BasePath = basePath + context.LocalShardName + Common.MiscUtil.DATA_FOLDERS_SEPERATION; //Get Base Data Path from config string deploymentPath = ConfigurationSettings <DBHostSettings> .Current.DeploymentPath; if (String.IsNullOrEmpty(deploymentPath)) { throw new ArgumentNullException("Deployment Path Can not be null or empty"); } context.DeploymentPath = deploymentPath; ShardConfiguration localShardConfig = null; IDictionary <String, ShardConfiguration> remoteShardConfigs = null; SetShardConfigs(configuration.Deployment, out localShardConfig, out remoteShardConfigs); _clusterConfigMgr = new ClusterConfigurationManager(context.ConfigurationSession, configuration); _connectionRestoration = new ConnectionRestorationManager(); _connectionRestoration.Initialize(context); if (localShardConfig != null) { _localShard = new LocalShard(context, _connectionRestoration, _clusterConfigMgr); _localShard.Initialize(localShardConfig); _localShard.RegisterShardListener(Common.MiscUtil.CLUSTER_MANAGER, this); } if (context != null) { context.ShardServer.RegisterSessionListener(SessionTypes.Shard, this); } if (remoteShardConfigs != null && remoteShardConfigs.Keys.Count > 0) { foreach (KeyValuePair <String, ShardConfiguration> pair in remoteShardConfigs) { IShard remoteShard = new RemoteShard(new DualChannelFactory(), new ShardChannelFormatter(), context, _connectionRestoration); remoteShard.Initialize(pair.Value); remoteShard.RegisterShardListener(Common.MiscUtil.CLUSTER_MANAGER, this); lock (_remoteShards) { _remoteShards.Add(pair.Key, remoteShard); } } } return(true); #endregion }