protected StateTxfrInfo GetData(int bucketId) { if (_result.Count > 0) { _result.Clear(); } long sizeToSend = 0; lock (_parent._bucketStateTxfrStatus.SyncRoot) { _parent._bucketStateTxfrStatus[bucketId] = true; } if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "state txfr request for :" + bucketId + " txfrid :" + _lastTxfrId); } if (_keyList != null && _keyList.Count > 0) { return(GetCacheItems(bucketId)); } else if (_topicWiseMessageList.Count > 0) { return(GetMessages(bucketId)); } else if (_transferType == StateTransferType.MOVE_DATA) { //We need to transfer the logs. if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "sending log data for bucket: " + bucketId); } ArrayList list = new ArrayList(1); list.Add(bucketId); StateTxfrInfo info = GetLoggedData(list); if (info.transferCompleted && _transferTypeChanged) { StartCompoundFilteration(bucketId); } return(info); } else { //As transfer mode is not MOVE_DATA, therefore no logs are maintained //and hence are not transferred. StartCompoundFilteration(bucketId); return(new StateTxfrInfo(null, true, 0, null, false)); } }
/// <summary> /// Disposes the state txfr corresponder. On dispose corresponder should /// stop logger in the hashed cache if it has turned on any one. /// </summary> public void Dispose() { if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresponder.Dispose", _clientNode.ToString() + " corresponder disposed"); } if (_keyList != null) { _keyList.Clear(); } _collectionsList = null; _collectionStateTransferStarted = false; _lastStateTrxferInfo = null; if (_topicWiseMessageList != null) { _topicWiseMessageList.Clear(); } _messageCount = 0; if (_keyUpdateLogTbl != null) { _keyUpdateLogTbl.Clear(); } if (_result != null) { _result.Clear(); } if (_transferType == StateTransferType.MOVE_DATA) { if (_parent != null && _logableBuckets != null) { for (int i = 0; i < _logableBuckets.Count; i++) { if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresponder.Dispose", " removing logs for bucketid " + _logableBuckets[i]); } _parent.InternalCache.RemoveFromLogTbl((int)_logableBuckets[i]); } } } if (_transferType == StateTransferType.REPLICATE_DATA || _transferTypeChanged) { StopCompoundFilteration(); } }
public StateTxfrInfo TransferBucket(ArrayList bucketIds, bool sparsedBuckets, int expectedTxfrId, bool includeEventMessages = false) { stream.Seek(0, SeekOrigin.Begin); if (bucketIds != null) { for (int i = bucketIds.Count - 1; i >= 0; i--) { int bkId = (int)bucketIds[i]; if (_transferType == StateTransferType.MOVE_DATA && !_distMgr.VerifyTemporaryOwnership(bkId, _clientNode)) { if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresponder.TransferBucket", bkId + " ownership changed"); } } } } if (sparsedBuckets) { return(new StateTxfrInfo(true)); } else { if (bucketIds != null && bucketIds.Count > 0) { foreach (int bucketId in bucketIds) { lock (_parent._bucketStateTxfrStatus.SyncRoot) { _parent._bucketStateTxfrStatus[bucketId] = true; } } if (_currentBucket != (int)bucketIds[0]) { if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresponder.TxfrBucket", "bucketid : " + bucketIds[0] + " exptxfrId : " + expectedTxfrId); } _lastTxfrId = expectedTxfrId; //request for a new bucket. get its key list from parent. _currentBucket = (int)bucketIds[0]; bool enableLogs = _transferType == StateTransferType.MOVE_DATA ? true : false; _parent.InternalCache.GetKeyList(_currentBucket, enableLogs, out _keyList); _collectionStateTransferStarted = false; _collectionsList = null; _lastStateTrxferInfo = null; _topicWiseMessageList = _parent.InternalCache.GetMessageList(_currentBucket, includeEventMessages); _logableBuckets.Add(_currentBucket); _messageCount = 0; //reset the _lastLogTblCount sendMesages = false; } else { if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresponder.TxfrBucket", "bucketid : " + bucketIds[0] + " exptxfrId : " + expectedTxfrId); } //remove all the last sent keys from keylist that has not been //modified during this time. if (expectedTxfrId > _lastTxfrId) { if (_keyList != null && _keyList.Count > 0) { lock (_keyList.SyncRoot) { _keyList.RemoveRange(0, _keyCount); _keyCount = 0; } if (_keyList.Count == 0 && _collectionsList != null && _collectionsList.Count > 0) { _keyList = _collectionsList; _collectionStateTransferStarted = true; _collectionsList = null; } } else if (_topicWiseMessageList != null && _messageCount > 0) { ArrayList removedTopics = new ArrayList(); foreach (DictionaryEntry topicWiseMessage in _topicWiseMessageList) { ClusteredArrayList messageList = topicWiseMessage.Value as ClusteredArrayList; if (_messageCount <= 0) { break; } if (_messageCount < messageList.Count) { messageList.RemoveRange(0, _messageCount); _messageCount = 0; } else { _messageCount -= messageList.Count; removedTopics.Add(topicWiseMessage.Key); } } foreach (string topic in removedTopics) { _topicWiseMessageList.Remove(topic); } } _lastTxfrId = expectedTxfrId; _lastStateTrxferInfo = null; } else if (_lastStateTrxferInfo != null) { return(_lastStateTrxferInfo); } } } else { return(new StateTxfrInfo(new HashVector(), true, 0, null, DataType.None)); } //take care that we need to send data in chunks if //bucket is too large. _lastStateTrxferInfo = GetData(_currentBucket, includeEventMessages); return(_lastStateTrxferInfo); } }
protected virtual StateTxfrInfo GetLoggedData(ArrayList bucketIds, bool includeEventMessages) { ArrayList updatedKeys = null; ArrayList removedKeys = null; ArrayList messageOps = null; Hashtable collectionOps = null; Hashtable logTbl = null; StateTxfrInfo info = null; bool isLoggingStopped = false; ArrayList loggedOperations = null; try { isLoggingStopped = _transferTypeChanged; logTbl = _parent.InternalCache.GetLogTable(bucketIds, ref isLoggingStopped); if (logTbl != null) { _result[LoggedOperationConstants.LogTableKey] = loggedOperations = new ArrayList(); updatedKeys = logTbl["updated"] as ArrayList; removedKeys = logTbl["removed"] as ArrayList; AddInsertLoggedOperations(updatedKeys, loggedOperations); AddRemoveLoggedOperations(removedKeys, loggedOperations); messageOps = logTbl["messageops"] as ArrayList; AddMessagesLoggedOperations(messageOps, loggedOperations, includeEventMessages); if (!isLoggingStopped) { info = new StateTxfrInfo(_result, false, loggedOperations.Count, this.stream, DataType.LoggedOperations); } else { info = new StateTxfrInfo(_result, true, loggedOperations.Count, this.stream, DataType.LoggedOperations); } _parent.Context.NCacheLog.Debug("StateTxfrCorresponder.GetLoggedData()", info == null ? "returning null state-txfr-info" : "returning " + info.data.Count.ToString() + " items in state-txfr-info"); return(info); } else if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresoponder.GetLoggedData", "no logged data found"); } } catch (Exception e) { _parent.Context.NCacheLog.Error("StateTxfrCorresoponder.GetLoggedData", e.ToString()); throw; } finally { } //no operation has been logged during state transfer. //so announce completion of state transfer for this bucket. return(new StateTxfrInfo(_result, true, 0, this.stream, DataType.LoggedOperations)); }
/// <summary> /// Transfers the buckets from a its owner. We may receive data in chunks. /// It is a pull model, a node wanting state transfer a bucket makes request /// to its owner. /// </summary> /// <param name="buckets"></param> /// <param name="owner"></param> /// <returns></returns> private bool TransferBuckets(ArrayList buckets, ref Address owner, bool sparsedBuckets) { bool transferEnd; bool successfullyTxfrd = false; int expectedTxfrId = 1; bool resync = false; try { if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info(Name + ".TransferBuckets", " Starting transfer. Owner : " + owner.ToString() + " , Bucket : " + ((int)buckets[0]).ToString()); PrepareBucketsForStateTxfr(buckets); long dataRecieved = 0; long currentIternationData = 0; while (true) { if (_enableGc && _dataTransferred >= _gcThreshhold) { _dataTransferred = 0; DateTime start = DateTime.Now; GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); DateTime end = DateTime.Now; TimeSpan diff = end - start; if (_parent.NCacheLog.IsErrorEnabled) _parent.NCacheLog.CriticalInfo(this.Name + ".TransferBucket", "explicit GC called. time taken(ms) :" + diff.TotalMilliseconds + " gcThreshold :" + _gcThreshhold); } else _dataTransferred += currentIternationData; Boolean sleep = false; resync = false; transferEnd = true; StateTxfrInfo info = null; try { currentIternationData = 0; info = SafeTransferBucket(buckets, owner, sparsedBuckets, expectedTxfrId); if (info != null) { currentIternationData = info.DataSize; dataRecieved += info.DataSize; } } catch (Runtime.Exceptions.SuspectedException) { resync = true; } catch (Runtime.Exceptions.TimeoutException) { } if (resync) { if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info(Name + ".TransferBuckets", owner + " is suspected"); Address changedOwner = GetChangedOwner((int)buckets[0], owner); if (changedOwner != null) { if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info(Name + ".TransferBuckets", changedOwner + " is new owner"); if (changedOwner.Equals(owner)) { continue; } else { owner = changedOwner; expectedTxfrId = 1; continue; } } else { _parent.Context.NCacheLog.Error(Name + ".TransferBuckets", " Could not get new owner"); info = new StateTxfrInfo(true); } } if (info != null) { successfullyTxfrd = true; transferEnd = info.transferCompleted; HashVector tbl = info.data; CacheEntry entry = null; expectedTxfrId++; //muds: //add data to local cache. if (tbl != null && tbl.Count > 0) { IDictionaryEnumerator ide = tbl.GetEnumerator(); while (ide.MoveNext()) { if (!_stateTransferEventLogged) { AppUtil.LogEvent(_cacheserver, "\"" + _parent.Context.SerializationContext + "(" + _parent.Cluster.LocalAddress.ToString() + ")\"" + " has started state transfer.", System.Diagnostics.EventLogEntryType.Information, EventCategories.Information, EventID.StateTransferStart); _stateTransferEventLogged = _logStateTransferEvent = true; } try { OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); if (ide.Value != null) { entry = ide.Value as CacheEntry; CacheInsResultWithEntry result = _parent.InternalCache.Insert(ide.Key, entry, false, false, null, LockAccessType.DEFAULT, operationContext); if (result != null && result.Result == CacheInsResult.NeedsEviction) { failedKeysList.Add(ide.Key); } } else { _parent.InternalCache.Remove(ide.Key, ItemRemoveReason.Removed, false, false, null, LockAccessType.IGNORE_LOCK, operationContext); } } catch (StateTransferException se) { _parent.Context.NCacheLog.Error(Name + ".TransferBuckets", " Can not add/remove key = " + ide.Key + " : value is " + ((ide.Value == null) ? "null" : " not null") + " : " + se.Message); } catch (Exception e) { _parent.Context.NCacheLog.Error(Name + ".TransferBuckets", " Can not add/remove key = " + ide.Key + " : value is " + ((ide.Value == null) ? "null" : " not null") + " : " + e.Message); } } if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info(Name + ".TransferBuckets", " BalanceDataLoad = " + _isBalanceDataLoad.ToString()); if (_isBalanceDataLoad) _parent.Context.PerfStatsColl.IncrementDataBalPerSecStatsBy(tbl.Count); else _parent.Context.PerfStatsColl.IncrementStateTxfrPerSecStatsBy(tbl.Count); } } else successfullyTxfrd = false; if (transferEnd) { BucketsTransfered(owner, buckets); EndBucketsStateTxfr(buckets); //muds: //send ack for the state transfer over. //Ask every node to release lock on this/these bucket(s) if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info(Name + ".TransferBuckets", "Acknowledging transfer. Owner : " + owner.ToString() + " , Bucket : " + ((int)buckets[0]).ToString()); AcknowledgeStateTransferCompleted(owner, buckets); break; } if (info != null) _throttlingManager.Throttle(info.DataSize); } } catch (System.Threading.ThreadAbortException) { EndBucketsStateTxfr(buckets); throw; } return successfullyTxfrd; }
protected virtual StateTxfrInfo GetLoggedData(ArrayList bucketIds) { ArrayList updatedKeys = null; ArrayList removedKeys = null; Hashtable logTbl = null; StateTxfrInfo info = null; Hashtable result = new Hashtable(); ArrayList payLoad = new ArrayList(); ArrayList payLoadCompilationInfo = new ArrayList(); bool isLoggingStopped = false; try { logTbl = _parent.InternalCache.GetLogTable(bucketIds, ref isLoggingStopped); if (logTbl != null) { updatedKeys = logTbl["updated"] as ArrayList; removedKeys = logTbl["removed"] as ArrayList; if (updatedKeys != null && updatedKeys.Count > 0) { for (int i = 0; i < updatedKeys.Count; i++) { string key = updatedKeys[i] as string; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true); CacheEntry entry = _parent.InternalCache.Get(key, false, operationContext); UserBinaryObject ubObject = null; if (entry.Value is CallbackEntry) { ubObject = ((CallbackEntry)entry.Value).Value as UserBinaryObject; } else { ubObject = entry.Value as UserBinaryObject; } payLoad.AddRange(ubObject.Data); long size = entry.DataSize; int index = payLoadCompilationInfo.Add(size); PayloadInfo payLoadInfo = new PayloadInfo(entry.CloneWithoutValue(), index); result[key] = payLoadInfo; } } if (removedKeys != null && removedKeys.Count > 0) { for (int i = 0; i < removedKeys.Count; i++) { string key = removedKeys[i] as string; result[key] = null; } } if (!isLoggingStopped) { info = new StateTxfrInfo(result, payLoad, payLoadCompilationInfo, false); } else { info = new StateTxfrInfo(result, payLoad, payLoadCompilationInfo, true); } _parent.Context.NCacheLog.Debug("StateTxfrCorresponder.GetLoggedData()", info == null ? "returning null state-txfr-info" : "returning " + info.data.Count.ToString() + " items in state-txfr-info"); return(info); } else if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresoponder.GetLoggedData", "no logged data found"); } } catch (Exception e) { _parent.Context.NCacheLog.Error("StateTxfrCorresoponder.GetLoggedData", e.ToString()); throw; } finally { } //no operation has been logged during state transfer. //so announce completion of state transfer for this bucket. return(new StateTxfrInfo(result, payLoad, payLoadCompilationInfo, true)); }
protected virtual StateTxfrInfo GetLoggedData(ArrayList bucketIds) { ArrayList updatedKeys = null; ArrayList removedKeys = null; Hashtable logTbl = null; StateTxfrInfo info = null; bool isLoggingStopped = false; try { logTbl = _parent.InternalCache.GetLogTable(bucketIds, ref isLoggingStopped); if (logTbl != null) { updatedKeys = logTbl["updated"] as ArrayList; removedKeys = logTbl["removed"] as ArrayList; if (updatedKeys != null && updatedKeys.Count > 0) { for (int i = 0; i < updatedKeys.Count; i++) { string key = updatedKeys[i] as string; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true); CacheEntry entry = _parent.InternalCache.Get(key, false, operationContext); _result[key] = entry; } } if (removedKeys != null && removedKeys.Count > 0) { for (int i = 0; i < removedKeys.Count; i++) { string key = removedKeys[i] as string; _result[key] = null; } } if (!isLoggingStopped) info = new StateTxfrInfo(_result, false, 0, this.stream); else info = new StateTxfrInfo(_result, true, 0, this.stream); _parent.Context.NCacheLog.Debug("StateTxfrCorresponder.GetLoggedData()", info == null ? "returning null state-txfr-info" : "returning " + info.data.Count.ToString() + " items in state-txfr-info"); return info; } else if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresoponder.GetLoggedData", "no logged data found"); } catch (Exception e) { _parent.Context.NCacheLog.Error("StateTxfrCorresoponder.GetLoggedData", e.ToString()); throw; } finally { } //no operation has been logged during state transfer. //so announce completion of state transfer for this bucket. return new StateTxfrInfo(_result, true, 0, this.stream); }
protected virtual StateTxfrInfo GetLoggedData(ArrayList bucketIds) { ArrayList updatedKeys = null; ArrayList removedKeys = null; Hashtable logTbl = null; StateTxfrInfo info = null; bool isLoggingStopped = false; try { logTbl = _parent.InternalCache.GetLogTable(bucketIds, ref isLoggingStopped); if (logTbl != null) { updatedKeys = logTbl["updated"] as ArrayList; removedKeys = logTbl["removed"] as ArrayList; if (updatedKeys != null && updatedKeys.Count > 0) { for (int i = 0; i < updatedKeys.Count; i++) { string key = updatedKeys[i] as string; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true); CacheEntry entry = _parent.InternalCache.Get(key, false, operationContext); _result[key] = entry; } } if (removedKeys != null && removedKeys.Count > 0) { for (int i = 0; i < removedKeys.Count; i++) { string key = removedKeys[i] as string; _result[key] = null; } } if (!isLoggingStopped) { info = new StateTxfrInfo(_result, false, 0, this.stream); } else { info = new StateTxfrInfo(_result, true, 0, this.stream); } _parent.Context.NCacheLog.Debug("StateTxfrCorresponder.GetLoggedData()", info == null ? "returning null state-txfr-info" : "returning " + info.data.Count.ToString() + " items in state-txfr-info"); return(info); } else if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresoponder.GetLoggedData", "no logged data found"); } } catch (Exception e) { _parent.Context.NCacheLog.Error("StateTxfrCorresoponder.GetLoggedData", e.ToString()); throw; } finally { } //no operation has been logged during state transfer. //so announce completion of state transfer for this bucket. return(new StateTxfrInfo(_result, true, 0, this.stream)); }
protected virtual StateTxfrInfo GetLoggedData(ArrayList bucketIds) { ArrayList updatedKeys = null; ArrayList removedKeys = null; Hashtable logTbl = null; StateTxfrInfo info = null; Hashtable result = new Hashtable(); ArrayList payLoad = new ArrayList(); ArrayList payLoadCompilationInfo = new ArrayList(); bool isLoggingStopped = false; try { logTbl = _parent.InternalCache.GetLogTable(bucketIds, ref isLoggingStopped); if (logTbl != null) { updatedKeys = logTbl["updated"] as ArrayList; removedKeys = logTbl["removed"] as ArrayList; if (updatedKeys != null && updatedKeys.Count > 0) { for (int i = 0; i < updatedKeys.Count; i++) { string key = updatedKeys[i] as string; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true); CacheEntry entry = _parent.InternalCache.Get(key, false, operationContext); UserBinaryObject ubObject = null; if (entry.Value is CallbackEntry) { ubObject = ((CallbackEntry)entry.Value).Value as UserBinaryObject; } else ubObject = entry.Value as UserBinaryObject; payLoad.AddRange(ubObject.Data); long size = entry.DataSize; int index = payLoadCompilationInfo.Add(size); PayloadInfo payLoadInfo = new PayloadInfo(entry.CloneWithoutValue(), index); result[key] = payLoadInfo; } } if (removedKeys != null && removedKeys.Count > 0) { for (int i = 0; i < removedKeys.Count; i++) { string key = removedKeys[i] as string; result[key] = null; } } if (!isLoggingStopped) info = new StateTxfrInfo(result,payLoad,payLoadCompilationInfo, false); else info = new StateTxfrInfo(result, payLoad, payLoadCompilationInfo, true); _parent.Context.NCacheLog.Debug("StateTxfrCorresponder.GetLoggedData()", info == null ? "returning null state-txfr-info" : "returning " + info.data.Count.ToString() + " items in state-txfr-info"); return info; } else if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresoponder.GetLoggedData", "no logged data found"); } catch (Exception e) { _parent.Context.NCacheLog.Error("StateTxfrCorresoponder.GetLoggedData", e.ToString()); throw; } finally { } //no operation has been logged during state transfer. //so announce completion of state transfer for this bucket. return new StateTxfrInfo(result, payLoad, payLoadCompilationInfo, true); }