/// <summary> /// Advance the enumerator to the next element of the collection /// </summary> /// <returns></returns> public bool MoveNext() { bool result = false; if (_currentChunkEnumerator != null) { result = _currentChunkEnumerator.MoveNext(); if (!result) { if (_currentChunk != null && !_currentChunk.IsLastChunk) { _currentChunk = _cache.GetNextChunk(_currentChunk.Pointer, new OperationContext()); if (_currentChunk != null && _currentChunk.Data != null) { _currentChunkEnumerator = _currentChunk.Data.GetEnumerator(); result = _currentChunkEnumerator.MoveNext(); } } } } if (result) { _currentValue = _cache.Get(Key); } return(result); }
/// <summary> /// Makes a key and data package form the keys and values of hashtable /// </summary> /// <param name="dic">Hashtable containing the keys and values to be packaged</param> /// <param name="keys">Contains packaged keys after execution</param> /// <param name="data">Contains packaged data after execution</param> /// <param name="currentContext">Current cache</param> internal static Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse PackageKeysValues(IDictionary dic, Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse keyPackageResponse) { if (dic != null && dic.Count > 0) { if (keyPackageResponse == null) { keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse(); } ; IDictionaryEnumerator enu = dic.GetEnumerator(); while (enu.MoveNext()) { keyPackageResponse.keys.Add((string)enu.Key); CompressedValueEntry cmpEntry = (CompressedValueEntry)enu.Value; BitSet flag = cmpEntry.Flag; UserBinaryObject ubObject = Cache.SocketServerDataService.GetClientData(cmpEntry.Value, ref flag, LanguageContext.DOTNET) as UserBinaryObject; Alachisoft.NCache.Common.Protobuf.Value value = new Alachisoft.NCache.Common.Protobuf.Value(); value.data.AddRange(ubObject.DataList); keyPackageResponse.flag.Add(cmpEntry.Flag.Data); keyPackageResponse.values.Add(value); keyPackageResponse.itemType.Add(MiscUtil.EntryTypeToProtoItemType(cmpEntry.Type)); } } return(keyPackageResponse); }
/// <summary> /// Makes a key and data package form the keys and values of hashtable /// </summary> /// <param name="dic">Hashtable containing the keys and values to be packaged</param> /// <param name="keys">Contains packaged keys after execution</param> /// <param name="data">Contains packaged data after execution</param> /// <param name="currentContext">Current cache</param> internal static IList PackageKeysValues(IDictionary dic) { int estimatedSize = 0; IList ListOfKeyPackageResponse = new ClusteredArrayList(); if (dic != null && dic.Count > 0) { Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse(); IDictionaryEnumerator enu = dic.GetEnumerator(); while (enu.MoveNext()) { Alachisoft.NCache.Common.Protobuf.Value value = new Alachisoft.NCache.Common.Protobuf.Value(); CompressedValueEntry cmpEntry = (CompressedValueEntry)enu.Value; UserBinaryObject ubObject = null; if (cmpEntry != null) { if (cmpEntry.Value is UserBinaryObject) { ubObject = (UserBinaryObject)cmpEntry.Value; } else { var flag = cmpEntry.Flag; ubObject = (UserBinaryObject)Cache.SocketServerDataService.GetClientData(cmpEntry.Value, ref flag, LanguageContext.DOTNET); } } //UserBinaryObject ubObject = Cache.SocketServerDataService.GetClientData(cmpEntry.Value, ref cmpEntry.Flag, LanguageContext.DOTNET) as UserBinaryObject; value.data.AddRange(ubObject.DataList); keyPackageResponse.keys.Add((string)enu.Key); keyPackageResponse.flag.Add(cmpEntry.Flag.Data); keyPackageResponse.values.Add(value); keyPackageResponse.itemType.Add(MiscUtil.EntryTypeToProtoItemType(cmpEntry.Type)); // (Alachisoft.NCache.Common.Protobuf.CacheItemType.ItemType)); estimatedSize = estimatedSize + ubObject.Size + (((string)enu.Key).Length * sizeof(Char)); if (estimatedSize >= ServiceConfiguration.ResponseDataSize) //If size is greater than specified size then add it and create new chunck { ListOfKeyPackageResponse.Add(keyPackageResponse); keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse(); estimatedSize = 0; } } if (estimatedSize != 0) { ListOfKeyPackageResponse.Add(keyPackageResponse); } } else { ListOfKeyPackageResponse.Add(new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse()); } return(ListOfKeyPackageResponse); }
private void PopulateRows(Common.DataReader.RecordSet recordSet, List <RecordRow> rows) { try { if (recordSet != null && rows != null) { foreach (RecordRow rowProto in rows) { Common.DataReader.RecordRow row = recordSet.CreateRow(); if (recordSet.Columns != null) { for (int i = 0; i < recordSet.Columns.Count; i++) { if (rowProto.values[i] != null) { if (recordSet.Columns[i].DataType != null) { switch (recordSet.Columns[i].DataType) { case Common.Enum.ColumnDataType.AverageResult: Common.Queries.AverageResult avgResult = new Common.Queries.AverageResult(); avgResult.Sum = Convert.ToDecimal(rowProto.values[i].avgResult.sum); avgResult.Count = Convert.ToDecimal(rowProto.values[i].avgResult.count); row[i] = avgResult; break; case Common.Enum.ColumnDataType.CompressedValueEntry: Value val = rowProto.values[i].binaryObject; UserBinaryObject ubObject = UserBinaryObject.CreateUserBinaryObject(val.data.ToArray()); byte[] bytes = ubObject.GetFullObject(); CompressedValueEntry cmpEntry = new CompressedValueEntry(); cmpEntry.Flag = new BitSet((byte)rowProto.values[i].flag); cmpEntry.Value = bytes; row[i] = ConvertToUserObject(cmpEntry); break; default: row[i] = Common.DataReader.RecordSet.ToObject( rowProto.values[i].stringValue, recordSet.Columns[i].DataType); break; } } } } } recordSet.AddRow(row); } } } catch (ArgumentOutOfRangeException ex) { throw new InvalidReaderException("Reader state has been lost.: ", ex); } }
/// <summary> /// Get object for simple cache item and Get handler for the Distributed Data type for provided Bulk. /// </summary> /// <param name="keyValueDic">KeyValue Pair of Keys and CompressedValueEntries agaianst them</param> /// <param name="cache">RemoteCache instance</param> /// <typeparam name="T"></typeparam> /// <returns>Hashtable</returns> internal static Hashtable BulkGetObjectOrInitializedCollection <T>(Hashtable KeyValueDic, Cache cache) { foreach (DictionaryEntry item in KeyValueDic) { CompressedValueEntry cmpEntry = (CompressedValueEntry)item.Value; cmpEntry.Value = GetObjectOrInitializedCollection <T>(item.Key.ToString(), cmpEntry.Type, cmpEntry.Value, cache.GetCacheInstance()); } return(KeyValueDic); }
private object ConvertToUserObject(CompressedValueEntry cmpEntry) { if (cmpEntry.Value is UserBinaryObject) { UserBinaryObject ubObject = cmpEntry.Value as UserBinaryObject; cmpEntry.Value = ubObject.GetFullObject(); } if (cmpEntry.Value is CallbackEntry) { CallbackEntry e = cmpEntry.Value as CallbackEntry; cmpEntry.Value = e.Value; } return(CompactBinaryFormatter.FromByteBuffer((byte[])cmpEntry.Value, CacheId)); }
internal static bool ReturnCompressedEntryToPool(CompressedValueEntry e, PoolManager poolManager) { if (poolManager == null) { return(false); } if (e != null && e.FromPool(poolManager)) { e.ReturnLeasableToPool(); poolManager.GetCompressedValueEntryPool().Return(e); return(true); } return(false); }
public sealed override QueryResultSet SearchEntries(string query, IDictionary values, OperationContext operationContext) { try { _context.PerfStatsColl.MsecPerQueryExecutionTimeBeginSample(); QueryContext queryContext = PrepareSearch(query, values); switch (queryContext.ResultSet.Type) { case QueryType.AggregateFunction: break; default: Hashtable result = new Hashtable(); ICollection keyList = null; ArrayList updatekeys =null; queryContext.Tree.Reduce(); queryContext.CacheContext = _context.SerializationContext; if (queryContext.Tree.LeftList.Count > 0) keyList = queryContext.Tree.LeftList; if (keyList != null && keyList.Count > 0) { object[] keys = new object[keyList.Count]; keyList.CopyTo(keys, 0); IDictionary tmp = GetEntries(keys, operationContext); IDictionaryEnumerator ide = tmp.GetEnumerator(); CompressedValueEntry cmpEntry = null; while (ide.MoveNext()) { CacheEntry entry = ide.Value as CacheEntry; if (entry != null) { cmpEntry = new CompressedValueEntry(); cmpEntry.Value = entry.Value; if (cmpEntry.Value is CallbackEntry) cmpEntry.Value = ((CallbackEntry)cmpEntry.Value).Value; cmpEntry.Flag = ((CacheEntry)ide.Value).Flag; result[ide.Key] = cmpEntry; if ((entry.ExpirationHint != null && entry.ExpirationHint.IsVariant)) { if (updatekeys == null) updatekeys = new ArrayList(); updatekeys.Add(ide.Key); } } } } queryContext.ResultSet.Type = QueryType.SearchEntries; queryContext.ResultSet.SearchEntriesResult = result; queryContext.ResultSet.UpdateIndicesKeys = updatekeys; break; } _context.PerfStatsColl.MsecPerQueryExecutionTimeEndSample(); if (queryContext.ResultSet != null) { long totalRowReturn = 0; if (queryContext.ResultSet.SearchEntriesResult != null) totalRowReturn = queryContext.ResultSet.SearchEntriesResult.Count; else if (queryContext.ResultSet.SearchKeysResult != null) totalRowReturn = queryContext.ResultSet.SearchKeysResult.Count; _context.PerfStatsColl.IncrementAvgQuerySize(totalRowReturn); } _context.PerfStatsColl.IncrementQueryPerSec(); return queryContext.ResultSet; } catch (Parser.ParserException pe) { RemoveReduction(query); throw new Runtime.Exceptions.ParserException(pe.Message, pe); } catch (Exception ex) { throw ex; } }
public ReaderResultSet GetRecordSet(string readerId, int nextIndex, bool inproc, OperationContext context) { ReaderResultSet readerChunk = null; IRecordSet partialRecordSet = null; ReaderResultSet reader = null; RecordRow row = null; CacheEntry entry = null; CompressedValueEntry cmpEntry = null; int size = 0; try { if (!string.IsNullOrEmpty(readerId)) { if (_readers.ContainsKey(readerId)) { reader = _readers[readerId]; } } if (reader != null) { if (nextIndex != 0 && reader.RecordSet.SubsetInfo.LastAccessedRowID == nextIndex) { reader.RecordSet.RemoveRows(reader.RecordSet.SubsetInfo.StartIndex, nextIndex - reader.RecordSet.SubsetInfo.StartIndex); } if (reader.RecordSet.RowCount > 0) { readerChunk = new ReaderResultSet(); partialRecordSet = new RecordSet(reader.RecordSet.GetColumnMetaData()); int chunkSize = reader.ChunkSize; reader.RecordSet.SubsetInfo.StartIndex = nextIndex; int nextRowID = nextIndex; while (size <= chunkSize) { row = reader.RecordSet.GetRow(nextRowID++); if (row == null) { break; } row = row.Clone() as RecordRow; if (reader.GetData && !reader.IsGrouped) { entry = _context.CacheImpl.Get(row.GetColumnValue(QueryKeyWords.KeyColumn), context); if (entry != null) { if (inproc) { row.SetColumnValue(QueryKeyWords.ValueColumn, entry.Value); } else { cmpEntry = new CompressedValueEntry(); cmpEntry.Value = entry.Value; if (cmpEntry.Value is CallbackEntry) { cmpEntry.Value = ((CallbackEntry)cmpEntry.Value).Value; } cmpEntry.Flag = ((CacheEntry)entry).Flag; row.SetColumnValue(QueryKeyWords.ValueColumn, cmpEntry); } size += entry.Size; } if (entry != null) { partialRecordSet.AddRow(row); size += row.GetSize(); } } else { partialRecordSet.AddRow(row); size += row.GetSize(); } } //Value column has been filled if getData is true if (reader.GetData && !reader.IsGrouped) { reader.RecordSet.GetColumnMetaData()[QueryKeyWords.ValueColumn].IsFilled = true; } reader.RecordSet.SubsetInfo.LastAccessedRowID += partialRecordSet.RowCount; readerChunk.RecordSet = partialRecordSet; readerChunk.NextIndex = reader.RecordSet.SubsetInfo.LastAccessedRowID; if (!inproc && _context.Render != null) { readerChunk.NodeAddress = _context.Render.IPAddress.ToString(); //server address } readerChunk.OrderByArguments = reader.OrderByArguments; readerChunk.IsGrouped = reader.IsGrouped; readerChunk.ReaderID = reader.ReaderID; } else { DisposeReader(reader.ReaderID); } } return(readerChunk); } catch (Exception ex) { if (ex is InvalidReaderException) { DisposeReader(reader.ReaderID); } throw; } }
//PROTOBUF public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager); if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("GetCmd.Exec", "cmd parsed"); } } catch (ArgumentOutOfRangeException arEx) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("GetCommand", "command: " + command + " Error" + arEx); } _getResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(arEx, command.requestID)); } return; } catch (Exception exc) { _getResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } return; } try { object lockId = cmdInfo.LockId; DateTime lockDate = new DateTime(); NCache nCache = clientManager.CmdExecuter as NCache; CompressedValueEntry flagValueEntry = null; flagValueEntry = nCache.Cache.Get(cmdInfo.Key, cmdInfo.FlagMap, ref lockId, ref lockDate, cmdInfo.LockTimeout, cmdInfo.LockAccessType, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation)); UserBinaryObject ubObj = (flagValueEntry == null) ? null : (UserBinaryObject)flagValueEntry.Value; Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.GetResponse getResponse = new Alachisoft.NCache.Common.Protobuf.GetResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET; if (lockId != null) { getResponse.lockId = lockId.ToString(); } getResponse.lockTime = lockDate.Ticks; if (ubObj == null) { response.get = getResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } else { getResponse.flag = flagValueEntry.Flag.Data; getResponse.data.AddRange(ubObj.DataList); response.get = getResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (Exception exc) { _getResult = OperationResult.Failure; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("GetCmd.Exec", "cmd executed on cache"); } }
//PROTOBUF public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { int dataLength = 0; int overload; string exception = null; System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); try { overload = command.MethodOverload; cmdInfo = ParseCommand(command, clientManager); } catch (ArgumentOutOfRangeException arEx) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("GetCommand", "command: " + command + " Error" + arEx); } _getResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(arEx, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } catch (Exception exc) { _getResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } Alachisoft.NCache.Common.Protobuf.GetResponse getResponse = null; CompressedValueEntry flagValueEntry = null; OperationContext operationContext = null; NCache nCache = clientManager.CmdExecuter as NCache; try { object lockId = cmdInfo.LockId; ulong version = cmdInfo.CacheItemVersion; DateTime lockDate = new DateTime(); operationContext = _operationContext; operationContext.Add(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); if (cmdInfo.LockAccessType == LockAccessType.ACQUIRE) { operationContext.Add(OperationContextFieldName.ClientThreadId, clientManager.ClientID); operationContext.Add(OperationContextFieldName.ClientThreadId, cmdInfo.ThreadId); operationContext.Add(OperationContextFieldName.IsRetryOperation, command.isRetryCommand); } flagValueEntry = nCache.Cache.GetGroup(cmdInfo.Key, cmdInfo.FlagMap, null, null, ref version, ref lockId, ref lockDate, cmdInfo.LockTimeout, cmdInfo.LockAccessType, operationContext); stopWatch.Stop(); UserBinaryObject ubObj = null; getResponse = _getResponse; if (flagValueEntry != null) { if (flagValueEntry.Value is UserBinaryObject) { ubObj = (UserBinaryObject)flagValueEntry.Value; } else { var flag = flagValueEntry.Flag; ubObj = (UserBinaryObject)nCache.Cache.SocketServerDataService.GetClientData(flagValueEntry.Value, ref flag, LanguageContext.DOTNET); } if (flagValueEntry.Value != null) { getResponse.itemType = MiscUtil.EntryTypeToProtoItemType(flagValueEntry.Type);// (Alachisoft.NCache.Common.Protobuf.CacheItemType.ItemType)flagValueEntry.Type; } } if (ubObj != null) { dataLength = ubObj.Length; } if (clientManager.ClientVersion >= 5000) { if (lockId != null) { getResponse.lockId = lockId.ToString(); } getResponse.requestId = cmdInfo.RequestId; getResponse.commandID = command.commandID; getResponse.lockTime = lockDate.Ticks; getResponse.version = version; if (ubObj == null) { // response.get = getResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(getResponse, Common.Protobuf.Response.Type.GET)); } else { //_dataPackageArray = ubObj.Data; getResponse.flag = flagValueEntry.Flag.Data; getResponse.data.AddRange(ubObj.DataList); // response.get = getResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(getResponse, Common.Protobuf.Response.Type.GET)); } } else { Alachisoft.NCache.Common.Protobuf.Response response = Stash.ProtobufResponse; response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET; if (lockId != null) { getResponse.lockId = lockId.ToString(); } getResponse.lockTime = lockDate.Ticks; getResponse.version = version; if (ubObj == null) { response.get = getResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } else { getResponse.flag = flagValueEntry.Flag.Data; getResponse.data.AddRange(ubObj.DataList); response.get = getResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } } catch (Exception exc) { exception = exc.ToString(); _getResult = OperationResult.Failure; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } finally { operationContext?.MarkFree(NCModulesConstants.SocketServer); TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { int resutlt = 0; if (getResponse != null) { resutlt = dataLength; } string methodName = null; if (cmdInfo.LockAccessType == LockAccessType.ACQUIRE) { methodName = MethodsName.GET.ToLower(); } else { methodName = MethodsName.GET.ToLower(); } APILogItemBuilder log = new APILogItemBuilder(methodName); log.GenerateGetCommandAPILogItem(cmdInfo.Key, null, null, (long)cmdInfo.CacheItemVersion, cmdInfo.LockAccessType, cmdInfo.LockTimeout, cmdInfo.LockId, cmdInfo.ProviderName, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString(), resutlt); } } catch { } if (flagValueEntry != null) { MiscUtil.ReturnCompressedEntryToPool(flagValueEntry, clientManager.CacheTransactionalPool); MiscUtil.ReturnEntryToPool(flagValueEntry.Entry, clientManager.CacheTransactionalPool); } } //} //if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("GetCmd.Exec", "cmd executed on cache"); }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager); if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("RemCmd.Exec", "cmd parsed"); } } catch (Exception exc) { _removeResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } return; } NCache nCache = clientManager.CmdExecuter as NCache; try { CallbackEntry cbEntry = null; CompressedValueEntry flagValueEntry = null; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); flagValueEntry = nCache.Cache.Remove(cmdInfo.Key, cmdInfo.FlagMap, cbEntry, cmdInfo.LockId, cmdInfo.LockAccessType, operationContext); UserBinaryObject ubObject = (flagValueEntry == null) ? null : (UserBinaryObject)flagValueEntry.Value; //PROTOBUF:RESPONSE Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.RemoveResponse removeResponse = new Alachisoft.NCache.Common.Protobuf.RemoveResponse(); response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.REMOVE; response.remove = removeResponse; response.requestId = Convert.ToInt64(cmdInfo.RequestId); if (ubObject != null) { removeResponse.value.AddRange(ubObject.DataList); removeResponse.flag = flagValueEntry.Flag.Data; } _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { _removeResult = OperationResult.Failure; //PROTOBUF:RESPONSE _serializedResponsePackets.Add( Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } finally { if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("RemCmd.Exec", "cmd executed on cache"); } } }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { int overload; string exception = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { overload = command.MethodOverload; cmdInfo = ParseCommand(command, clientManager); } catch (System.Exception exc) { _removeResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } CompressedValueEntry flagValueEntry = null; NCache nCache = clientManager.CmdExecuter as NCache; if (!cmdInfo.DoAsync) { OperationContext operationContext = null; try { Notifications notification = null; if (cmdInfo.DsItemRemovedId != -1) { notification = new Notifications(clientManager.ClientID, -1, -1, -1, -1, cmdInfo.DsItemRemovedId , Runtime.Events.EventDataFilter.None, Runtime.Events.EventDataFilter.None); //DataFilter not required } operationContext = _operationContext; operationContext.Add(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.ClientId, clientManager.ClientID); operationContext.Add(OperationContextFieldName.MethodOverload, overload); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); CommandsUtil.PopulateClientIdInContext(ref operationContext, clientManager.ClientAddress); flagValueEntry = nCache.Cache.Remove(cmdInfo.Key, cmdInfo.FlagMap, notification, cmdInfo.LockId, cmdInfo.Version, cmdInfo.LockAccessType, cmdInfo.ProviderName, operationContext); stopWatch.Stop(); UserBinaryObject ubObject = null; if (flagValueEntry != null) { if (flagValueEntry.Value is UserBinaryObject) { ubObject = (UserBinaryObject)flagValueEntry.Value; } else { var flag = flagValueEntry.Flag; ubObject = (flagValueEntry == null) ? null : (UserBinaryObject)nCache.Cache.SocketServerDataService.GetClientData(flagValueEntry.Value, ref flag, LanguageContext.DOTNET); } } //PROTOBUF:RESPONSE RemoveResponse removeResponse = _removeResponse; if (ubObject != null) { removeResponse.value.AddRange(ubObject.DataList); removeResponse.flag = flagValueEntry.Flag.Data; removeResponse.itemType = MiscUtil.EntryTypeToProtoItemType(flagValueEntry.Type); } if (clientManager.ClientVersion >= 5000) { ResponseHelper.SetResponse(removeResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(removeResponse, Response.Type.REMOVE)); } else { Response response = Stash.ProtobufResponse; { response.remove = removeResponse; }; ResponseHelper.SetResponse(response, command.requestID, command.commandID, Response.Type.REMOVE); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (System.Exception exc) { _removeResult = OperationResult.Failure; exception = exc.ToString(); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } finally { operationContext?.MarkFree(NCModulesConstants.SocketServer); cmdInfo.FlagMap?.MarkFree(NCModulesConstants.SocketServer); TimeSpan executionTime = stopWatch.Elapsed; if (flagValueEntry != null) { MiscUtil.ReturnEntryToPool(flagValueEntry.Entry, clientManager.CacheTransactionalPool); MiscUtil.ReturnCompressedEntryToPool(flagValueEntry, clientManager.CacheTransactionalPool); } try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.REMOVE.ToLower()); log.GenerateRemoveAPILogItem(cmdInfo.Key, cmdInfo.FlagMap, cmdInfo.LockId, (long)cmdInfo.Version, cmdInfo.LockAccessType, cmdInfo.ProviderName, cmdInfo.DsItemRemovedId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } } else { OperationContext operationContext = null; try { cmdInfo.FlagMap = new BitSet { Data = cmdInfo.FlagMap.Data }; object[] package = null; if (cmdInfo.RequestId != -1 || cmdInfo.DsItemRemovedId != -1) { package = new object[] { cmdInfo.Key, cmdInfo.FlagMap, new Notifications(clientManager.ClientID, Convert.ToInt32(cmdInfo.RequestId), -1, -1, (short)(cmdInfo.RequestId == -1 ? -1 : 0), cmdInfo.DsItemRemovedId , Runtime.Events.EventDataFilter.None, Runtime.Events.EventDataFilter.None), cmdInfo.ProviderName }; //DataFilter not required } else { package = new object[] { cmdInfo.Key, cmdInfo.FlagMap, null, cmdInfo.ProviderName }; } operationContext = OperationContext.CreateAndMarkInUse(clientManager.CacheFakePool, NCModulesConstants.SocketServer); operationContext.Add(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); operationContext.Add(OperationContextFieldName.MethodOverload, overload); nCache.Cache.RemoveAsync(package, operationContext); stopWatch.Stop(); } finally { operationContext?.MarkFree(NCModulesConstants.SocketServer); TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.RemoveAsync.ToLower()); log.GenerateRemoveAPILogItem(cmdInfo.Key, cmdInfo.FlagMap, cmdInfo.LockId, (long)cmdInfo.Version, cmdInfo.LockAccessType, cmdInfo.ProviderName, cmdInfo.DsItemRemovedId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } } }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { int overload; string exception = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { overload = command.MethodOverload; cmdInfo = ParseCommand(command, clientManager); if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("RemCmd.Exec", "cmd parsed"); } } catch (Exception exc) { _removeResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } return; } NCache nCache = clientManager.CmdExecuter as NCache; if (!cmdInfo.DoAsync) { try { CallbackEntry cbEntry = null; if (cmdInfo.DsItemRemovedId != -1) { cbEntry = new CallbackEntry(clientManager.ClientID, -1, null, -1, -1, -1, cmdInfo.DsItemRemovedId, cmdInfo.FlagMap , Runtime.Events.EventDataFilter.None, Runtime.Events.EventDataFilter.None); //DataFilter not required } CompressedValueEntry flagValueEntry = null; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.ClientId, clientManager.ClientID); operationContext.Add(OperationContextFieldName.MethodOverload, overload); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); flagValueEntry = nCache.Cache.Remove(cmdInfo.Key, cmdInfo.FlagMap, cbEntry, cmdInfo.LockId, cmdInfo.Version, cmdInfo.LockAccessType, cmdInfo.ProviderName, operationContext); stopWatch.Stop(); UserBinaryObject ubObject = null; if (flagValueEntry != null) { if (flagValueEntry.Value is UserBinaryObject) { ubObject = (UserBinaryObject)flagValueEntry.Value; } else { ubObject = (flagValueEntry == null) ? null : (UserBinaryObject)nCache.Cache.SocketServerDataService.GetClientData(flagValueEntry.Value, ref flagValueEntry.Flag, LanguageContext.DOTNET); } } //PROTOBUF:RESPONSE Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.RemoveResponse removeResponse = new Alachisoft.NCache.Common.Protobuf.RemoveResponse(); response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.REMOVE; response.remove = removeResponse; response.commandID = command.commandID; response.requestId = Convert.ToInt64(cmdInfo.RequestId); if (ubObject != null) { removeResponse.value.AddRange(ubObject.DataList); removeResponse.flag = flagValueEntry.Flag.Data; } _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { _removeResult = OperationResult.Failure; exception = exc.ToString(); //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } finally { TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.REMOVE.ToLower()); log.GenerateRemoveAPILogItem(cmdInfo.Key, cmdInfo.FlagMap, cmdInfo.LockId, (long)cmdInfo.Version, cmdInfo.LockAccessType, cmdInfo.ProviderName, cmdInfo.DsItemRemovedId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("RemCmd.Exec", "cmd executed on cache"); } } } else { try { object[] package = null; if (!cmdInfo.RequestId.Equals("-1") || cmdInfo.DsItemRemovedId != -1) { package = new object[] { cmdInfo.Key, cmdInfo.FlagMap, new CallbackEntry(clientManager.ClientID, Convert.ToInt32(cmdInfo.RequestId), null, -1, -1, (short)(cmdInfo.RequestId.Equals("-1") ? -1 : 0), cmdInfo.DsItemRemovedId, cmdInfo.FlagMap , Runtime.Events.EventDataFilter.None, Runtime.Events.EventDataFilter.None), cmdInfo.ProviderName }; // DataFilter not required } else { package = new object[] { cmdInfo.Key, cmdInfo.FlagMap, null, cmdInfo.ProviderName }; } OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); operationContext.Add(OperationContextFieldName.MethodOverload, overload); nCache.Cache.RemoveAsync(package, operationContext); stopWatch.Stop(); } finally { TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.RemoveAsync.ToLower()); log.GenerateRemoveAPILogItem(cmdInfo.Key, cmdInfo.FlagMap, cmdInfo.LockId, (long)cmdInfo.Version, cmdInfo.LockAccessType, cmdInfo.ProviderName, cmdInfo.DsItemRemovedId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("RemCmd.Exec", "cmd executed on cache"); } } } }