public StateTransferIdentity(String DBName, String ColName, NodeIdentity nodeInfo, StateTransferType type, Alachisoft.NosDB.Common.Toplogies.Impl.Distribution.DistributionMethod distributionType) { this.DBName = DBName; this.ColName = ColName; this.NodeInfo = nodeInfo; this.Type = type; this.DistributionType = distributionType; }
public void Initialize(ICollection map, StateTransferType transferType, bool forLocal = false) { _isLocal = forLocal; TransferType = transferType; IDictionary <String, IDistribution> collectionMap = map as IDictionary <String, IDistribution>; if (collectionMap != null && collectionMap.Count > 0) { if (LoggerManager.Instance.StateXferLogger != null && LoggerManager.Instance.StateXferLogger.IsDebugEnabled) { LoggerManager.Instance.StateXferLogger.Debug("DatabaseStateTransferManager.Start()", "State Transfer Started for " + this.dbName); } //lock (_stateTxfrMutex) //{ foreach (KeyValuePair <String, IDistribution> colInfo in collectionMap) { try { //NTD: [Normal] Kindly perform state transfer for attachment collection //if (colInfo.Key.Equals(AttachmentAttributes.ATTACHMENT_COLLECTION, StringComparison.OrdinalIgnoreCase)) continue; if (TransferType == StateTransferType.INTER_SHARD && colInfo.Value.Type == Alachisoft.NosDB.Common.Toplogies.Impl.Distribution.DistributionMethod.NonShardedDistribution) { NonShardedDistribution nonShardedDist = colInfo.Value as NonShardedDistribution; if (!nonShardedDist.Bucket.FinalShard.Equals(context.LocalShardName, StringComparison.OrdinalIgnoreCase)) { continue; } } IStateTransferTask task = null; ICollection bucketList = GetBucketsForStateTransfer((IDistribution)colInfo.Value); lock (collectionTasksMap) { if (!collectionTasksMap.ContainsKey((String)colInfo.Key)) { if (TransferType == StateTransferType.INTER_SHARD) { collectionTasksMap[(String)colInfo.Key] = new StateTransferTask(context, dbName, (String)colInfo.Key, this, colInfo.Value.Type); } //else // collectionTasksMap[(String)colInfo.Key] = new StateTrxfrOnReplicaTask(context, dbName, (String)colInfo.Key, this, colInfo.Value.Type); } task = collectionTasksMap[(String)colInfo.Key]; } if (task != null) { task.Initialize(bucketList, transferType, IsLocal); //KeyValuePair<String, IStateTransferTask> pair = new KeyValuePair<string, IStateTransferTask>(colInfo.Key, task); lock (_schMutex) { waitingColTasks.AddLast(colInfo.Key); } } } catch (Exception ex) { if (LoggerManager.Instance.StateXferLogger.IsErrorEnabled) { LoggerManager.Instance.StateXferLogger.Error("DatabaseStateTransferManager.Start()", ex.Message); } } } } }
public void Initialize(ICollection map, StateTransferType transferType, bool forLocal = false) { if (context.ClusterName.Equals(Common.MiscUtil.LOCAL, StringComparison.OrdinalIgnoreCase)) { return; } if (IsRunning) { if (LoggerManager.Instance.StateXferLogger != null && LoggerManager.Instance.StateXferLogger.IsInfoEnabled) { LoggerManager.Instance.StateXferLogger.Info("NodeStateTranferManager.Initialize()", "State Transfer Already Running"); } if (transferType == StateTransferType.INTRA_SHARD && TransferType == StateTransferType.INTER_SHARD) { if (LoggerManager.Instance.StateXferLogger != null && LoggerManager.Instance.StateXferLogger.IsInfoEnabled) { LoggerManager.Instance.StateXferLogger.Info("NodeStateTranferManager.Initialize()", "Stopping already running State Transfer"); } //Stopping already running state transfer as there is mis-match between already running Stop(); } } IDictionary <String, IDictionary <String, IDistribution> > distributionMaps = (IDictionary <String, IDictionary <String, IDistribution> >)map; TransferType = transferType; if (distributionMaps != null) { if (LoggerManager.Instance.StateXferLogger != null && LoggerManager.Instance.StateXferLogger.IsInfoEnabled) { LoggerManager.Instance.StateXferLogger.Info("NodeStateTranferManager.Initialize()", "State Transfer Initialize on " + this.context.LocalAddress.ToString()); } foreach (KeyValuePair <String, IDictionary <String, IDistribution> > dbInfo in distributionMaps) { try { DatabaseStateTransferManager dbMgr = null; lock (dbStateTxferMgrMap) { if (!dbStateTxferMgrMap.ContainsKey(dbInfo.Key)) { dbStateTxferMgrMap[dbInfo.Key] = new DatabaseStateTransferManager(context, dbInfo.Key, this, _resourceManager); } } dbMgr = dbStateTxferMgrMap[dbInfo.Key]; if (dbMgr != null) { dbMgr.Initialize((IDictionary)dbInfo.Value, transferType, forLocal); lock (_schMutex) { waitingDBTasks.AddLast(dbInfo.Key); } } } catch (Exception ex) { if (LoggerManager.Instance.StateXferLogger.IsErrorEnabled) { LoggerManager.Instance.StateXferLogger.Error("NodeStateTranferManager.Initialize()", ex.Message); } } } if (dbStateTxferMgrMap.Count > 0) { context.StatusLatch.SetStatusBit(Alachisoft.NosDB.Common.Stats.NodeStatus.InStateTxfer, Alachisoft.NosDB.Common.Stats.NodeStatus.None); IsTaskAvailable = true; } //if (transferType==StateTransferType.INTRA_SHARD && _replication.NextReplicationChunk == null) //{ // if (!forLocal) // _replication.NextReplicationChunk = _replication.GetLastOpLog(); // lock (_inStTxfrMutex) // { // _replication.NodeIsInStateTxfr = true; // } // _replication.Start(); // // Replication will be started from here and last operation will be settled from here //} } }