/// <summary> /// Add the object to specfied node in the cluster. /// </summary> /// <param name="dest"></param> /// <param name="key">key of the entry.</param> /// <param name="cacheEntry"></param> /// <param name="operationContext"></param> /// <returns>cache entry.</returns> /// <remarks> /// This method either invokes <see cref="handleAdd"/> on every server-node in the cluster. /// </remarks> protected CacheAddResult Clustered_Add(Address dest, object key, CacheEntry cacheEntry, OperationContext operationContext) { if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("PartCacheBase.Add_1", ""); } CacheAddResult retVal = CacheAddResult.Success; try { Function func = new Function((int)OpCodes.Add, new object[] { key, cacheEntry.CloneWithoutValue(), operationContext }); Array userPayLoad = null; if (cacheEntry.Value is CallbackEntry) { CallbackEntry cbEntry = ((CallbackEntry)cacheEntry.Value); userPayLoad = cbEntry.UserData; } else { userPayLoad = cacheEntry.UserData; } func.UserPayload = userPayLoad; object result = Cluster.SendMessage(dest, func, GroupRequest.GET_FIRST); if (result == null) { return(retVal); } if (result is CacheAddResult) { retVal = (CacheAddResult)result; } else if (result is System.Exception) { throw (Exception)result; } } catch (Runtime.Exceptions.SuspectedException se) { throw; } catch (Runtime.Exceptions.TimeoutException te) { throw; } catch (CacheException e) { throw; } catch (Exception e) { throw new GeneralFailureException(e.Message, e); } return(retVal); }
/// <summary> /// Updates or Adds the object to the cluster. /// </summary> /// <param name="dest"></param> /// <param name="key">key of the entry.</param> /// <param name="cacheEntry"></param> /// <param name="lockId"></param> /// <param name="accessType"></param> /// <param name="operationContext"></param> /// <returns>cache entry.</returns> /// <remarks> /// This method invokes <see cref="handleInsert"/> on the specified node. /// </remarks> protected CacheInsResultWithEntry Clustered_Insert(Address dest, object key, CacheEntry cacheEntry, object lockId, LockAccessType accessType, OperationContext operationContext) { if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("PartCacheBase.Insert", ""); } CacheInsResultWithEntry retVal = new CacheInsResultWithEntry(); try { Function func = new Function((int)OpCodes.Insert, new object[] { key, cacheEntry.CloneWithoutValue(), lockId, accessType, operationContext }); Array userPayLoad = null; if (cacheEntry.Value is CallbackEntry) { CallbackEntry cbEntry = ((CallbackEntry)cacheEntry.Value); userPayLoad = cbEntry.UserData; } else { userPayLoad = cacheEntry.UserData; } func.UserPayload = userPayLoad; func.ResponseExpected = true; object result = Cluster.SendMessage(dest, func, GroupRequest.GET_FIRST, false); if (result == null) { return(retVal); } retVal = (CacheInsResultWithEntry)((OperationResponse)result).SerializablePayload; if (retVal.Entry != null) { retVal.Entry.Value = ((OperationResponse)result).UserPayload; } } catch (Runtime.Exceptions.SuspectedException se) { throw; } catch (Runtime.Exceptions.TimeoutException te) { throw; } catch (CacheException e) { throw; } catch (Exception e) { throw new GeneralFailureException(e.Message, e); } return(retVal); }
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); } }
/// <summary> /// Updates or Adds the object to the cluster. /// </summary> /// <param name="dest"></param> /// <param name="key">key of the entry.</param> /// <param name="cacheEntry"></param> /// <param name="lockId"></param> /// <param name="accessType"></param> /// <param name="operationContext"></param> /// <returns>cache entry.</returns> /// <remarks> /// This method invokes <see cref="handleInsert"/> on the specified node. /// </remarks> protected CacheInsResultWithEntry Clustered_Insert(Address dest, object key, CacheEntry cacheEntry, object lockId, LockAccessType accessType, OperationContext operationContext) { if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("PartCacheBase.Insert", ""); CacheInsResultWithEntry retVal = new CacheInsResultWithEntry(); try { Function func = new Function((int)OpCodes.Insert, new object[] { key, cacheEntry.CloneWithoutValue(), lockId, accessType, operationContext }); Array userPayLoad = null; if (cacheEntry.Value is CallbackEntry) { CallbackEntry cbEntry = ((CallbackEntry)cacheEntry.Value); userPayLoad = cbEntry.UserData; } else { userPayLoad = cacheEntry.UserData; } func.UserPayload = userPayLoad; func.ResponseExpected = true; object result = Cluster.SendMessage(dest, func, GroupRequest.GET_FIRST, false); if (result == null) { return retVal; } retVal = (CacheInsResultWithEntry)((OperationResponse)result).SerializablePayload; if (retVal.Entry != null) retVal.Entry.Value = ((OperationResponse)result).UserPayload; } catch (Runtime.Exceptions.SuspectedException se) { throw; } catch (Runtime.Exceptions.TimeoutException te) { throw; } catch (CacheException e) { throw; } catch (Exception e) { throw new GeneralFailureException(e.Message, e); } return retVal; }
/// <summary> /// Add the object to specfied node in the cluster. /// </summary> /// <param name="dest"></param> /// <param name="key">key of the entry.</param> /// <param name="cacheEntry"></param> /// <param name="operationContext"></param> /// <returns>cache entry.</returns> /// <remarks> /// This method either invokes <see cref="handleAdd"/> on every server-node in the cluster. /// </remarks> protected CacheAddResult Clustered_Add(Address dest, object key, CacheEntry cacheEntry, OperationContext operationContext) { if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("PartCacheBase.Add_1", ""); CacheAddResult retVal = CacheAddResult.Success; try { Function func = new Function((int)OpCodes.Add, new object[] { key, cacheEntry.CloneWithoutValue(), operationContext }); Array userPayLoad = null; if (cacheEntry.Value is CallbackEntry) { CallbackEntry cbEntry = ((CallbackEntry)cacheEntry.Value); userPayLoad = cbEntry.UserData; } else { userPayLoad = cacheEntry.UserData; } func.UserPayload = userPayLoad; object result = Cluster.SendMessage(dest, func, GroupRequest.GET_FIRST); if (result == null) { return retVal; } if (result is CacheAddResult) retVal = (CacheAddResult)result; else if (result is System.Exception) throw (Exception)result; } catch (Runtime.Exceptions.SuspectedException se) { throw; } catch (Runtime.Exceptions.TimeoutException te) { throw; } catch (CacheException e) { throw; } catch (Exception e) { throw new GeneralFailureException(e.Message, e); } return retVal; }