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 StateTxfrInfo GetData(int bucketId) { Hashtable result = new Hashtable(); ArrayList payLoad = new ArrayList(); ArrayList payLoadCompilationInfo = new ArrayList(); 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) { if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "bucket size :" + _keyList.Count); } for (_keyCount = 0; _keyCount < _keyList.Count; _keyCount++) { string key = _keyList[_keyCount] as string; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true); CacheEntry entry = _parent.InternalCache.InternalCache.Get(key, false, operationContext); if (entry != null) { long size = (entry.InMemorySize + Common.MemoryUtil.GetStringSize(key)); //.DataSize; if (sizeToSend > _threshold) { break; } 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 entrySize = entry.DataSize; int index = payLoadCompilationInfo.Add(entrySize); PayloadInfo payLoadInfo = new PayloadInfo(entry.CloneWithoutValue(), index); result[key] = payLoadInfo; sizeToSend += size; } } if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "items sent :" + _keyCount); } if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "BalanceDataLoad = " + _isBalanceDataLoad.ToString()); } if (_isBalanceDataLoad) { _parent.Context.PerfStatsColl.IncrementDataBalPerSecStatsBy(result.Count); } else { _parent.Context.PerfStatsColl.IncrementStateTxfrPerSecStatsBy(result.Count); } return(new StateTxfrInfo(result, payLoad, payLoadCompilationInfo, false, sizeToSend)); } 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); return(GetLoggedData(list)); } else { //As transfer mode is not MOVE_DATA, therefore no logs are maintained //and hence are not transferred. return(new StateTxfrInfo(null, null, null, true)); } }
protected StateTxfrInfo GetData(ArrayList bucketIds) { try { object[] keys = null; Hashtable data = null; Hashtable result = new Hashtable(); ArrayList payLoad = new ArrayList(); ArrayList payLoadCompilationInfo = new ArrayList(); if (!_sendLogData) { IEnumerator ie = bucketIds.GetEnumerator(); while (ie.MoveNext()) { int bucketId = (int)ie.Current; if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(1)", "transfering data for bucket : " + bucketId); } bool enableLogs = _transferType == StateTransferType.MOVE_DATA ? true : false; ArrayList keyList = _parent.InternalCache.GetKeyList(bucketId, enableLogs); _logableBuckets.Add(bucketId); data = null; if (keyList != null) { if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(1)", "bucket : " + bucketId + " [" + keyList.Count + " ]"); } keys = keyList.ToArray(); OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true); data = _parent.InternalCache.Get(keys, operationContext); } if (data != null && data.Count > 0) { if (result.Count == 0) { result = data.Clone() as Hashtable; } else { IDictionaryEnumerator ide = data.GetEnumerator(); while (ide.MoveNext()) { CacheEntry entry = ide.Value as CacheEntry; 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[ide.Key] = payLoadInfo; } } } } _sendLogData = true; if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("State Transfer Corresponder", "BalanceDataLoad = " + _isBalanceDataLoad.ToString()); } if (_isBalanceDataLoad) { _parent.Context.PerfStatsColl.IncrementDataBalPerSecStatsBy(result.Count); } else { _parent.Context.PerfStatsColl.IncrementStateTxfrPerSecStatsBy(result.Count); } return(new StateTxfrInfo(result, payLoad, payLoadCompilationInfo, false)); } else { return(GetLoggedData(bucketIds)); } } catch (Exception ex) { _parent.Context.NCacheLog.Error("StateTxfrCorresponder.GetData(1)", ex.ToString()); return(null); } }
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 StateTxfrInfo GetData(int bucketId) { Hashtable result = new Hashtable(); ArrayList payLoad = new ArrayList(); ArrayList payLoadCompilationInfo = new ArrayList(); 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) { if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "bucket size :" + _keyList.Count); for (_keyCount = 0; _keyCount < _keyList.Count; _keyCount++) { string key = _keyList[_keyCount] as string; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true); CacheEntry entry = _parent.InternalCache.InternalCache.Get(key, false,operationContext); if (entry != null) { long size = (entry.InMemorySize + Common.MemoryUtil.GetStringSize(key));//.DataSize; if (sizeToSend > _threshold) break; 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 entrySize = entry.DataSize; int index = payLoadCompilationInfo.Add(entrySize); PayloadInfo payLoadInfo = new PayloadInfo(entry.CloneWithoutValue(), index); result[key] = payLoadInfo; sizeToSend += size; } } if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "items sent :" + _keyCount); if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "BalanceDataLoad = " + _isBalanceDataLoad.ToString()); if (_isBalanceDataLoad) _parent.Context.PerfStatsColl.IncrementDataBalPerSecStatsBy(result.Count); else _parent.Context.PerfStatsColl.IncrementStateTxfrPerSecStatsBy(result.Count); return new StateTxfrInfo(result,payLoad,payLoadCompilationInfo, false,sizeToSend); } 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); return GetLoggedData(list); } else { //As transfer mode is not MOVE_DATA, therefore no logs are maintained //and hence are not transferred. return new StateTxfrInfo(null,null,null, true); } }
protected StateTxfrInfo GetData(ArrayList bucketIds) { try { object[] keys = null; Hashtable data = null; Hashtable result = new Hashtable(); ArrayList payLoad = new ArrayList(); ArrayList payLoadCompilationInfo = new ArrayList(); if (!_sendLogData) { IEnumerator ie = bucketIds.GetEnumerator(); while (ie.MoveNext()) { int bucketId = (int)ie.Current; if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(1)", "transfering data for bucket : " + bucketId); bool enableLogs = _transferType == StateTransferType.MOVE_DATA ? true : false; ArrayList keyList = _parent.InternalCache.GetKeyList(bucketId, enableLogs); _logableBuckets.Add(bucketId); data = null; if (keyList != null) { if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(1)", "bucket : " + bucketId + " [" + keyList.Count + " ]"); keys = keyList.ToArray(); OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true); data = _parent.InternalCache.Get(keys,operationContext); } if (data != null && data.Count > 0) { if (result.Count == 0) { result = data.Clone() as Hashtable; } else { IDictionaryEnumerator ide = data.GetEnumerator(); while (ide.MoveNext()) { CacheEntry entry = ide.Value as CacheEntry; 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[ide.Key] = payLoadInfo; } } } } _sendLogData = true; if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("State Transfer Corresponder", "BalanceDataLoad = " + _isBalanceDataLoad.ToString()); if (_isBalanceDataLoad) { _parent.Context.PerfStatsColl.IncrementDataBalPerSecStatsBy(result.Count); } else { _parent.Context.PerfStatsColl.IncrementStateTxfrPerSecStatsBy(result.Count); } return new StateTxfrInfo(result,payLoad,payLoadCompilationInfo, false); } else return GetLoggedData(bucketIds); } catch (Exception ex) { _parent.Context.NCacheLog.Error("StateTxfrCorresponder.GetData(1)", ex.ToString()); return null; } }