public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { Alachisoft.NCache.Common.Protobuf.OpenStreamCommand openStreamCommand = command.openStreamCommand; NCache nCache = clientManager.CmdExecuter as NCache; Caching.Cache cache = nCache.Cache; int overload; string exception = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); overload = command.MethodOverload; string lockHandle = null; ExpirationHint expHint = null; try { if (clientManager != null) { expHint = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(cache.Configuration.ExpirationPolicy, openStreamCommand.dependency, openStreamCommand.absoluteExpiration, openStreamCommand.slidingExpiration, false, ((NCache)clientManager.CmdExecuter).CacheId); int pr = (int)openStreamCommand.priority; EvictionHint evictionHint = new PriorityEvictionHint((CacheItemPriority)pr); if (openStreamCommand.group != null) { openStreamCommand.group = openStreamCommand.group.Length == 0 ? null : openStreamCommand.group; } if (openStreamCommand.subGroup != null) { openStreamCommand.subGroup = openStreamCommand.subGroup.Length == 0 ? null : openStreamCommand.subGroup; } lockHandle = ((NCache)clientManager.CmdExecuter).Cache.OpenStream(openStreamCommand.key, (Alachisoft.NCache.Common.Enum.StreamModes)openStreamCommand.streamMode, openStreamCommand.group, openStreamCommand.subGroup, expHint, evictionHint, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation)); stopWatch.Stop(); } } catch (Exception e) { //PROTOBUF:RESPONSE exception = e.ToString(); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(e, command.requestID, command.commandID)); return; } 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.GetCacheStream.ToLower()); Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(expHint, null); log.GenerateOpenStreamAPILogItem(openStreamCommand.key, openStreamCommand.streamMode, openStreamCommand.group, openStreamCommand.subGroup, openStreamCommand.priority, expirationHint["dependency"] != null ? expirationHint["dependency"] as ArrayList : null, expirationHint["absolute-expiration"] != null ? (long)expirationHint["absolute-expiration"] : -1, expirationHint["sliding-expiration"] != null ? (long)expirationHint["sliding-expiration"] : -1, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.OpenStreamResponse openStreamResponse = new Alachisoft.NCache.Common.Protobuf.OpenStreamResponse(); response.requestId = openStreamCommand.requestId; response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.OPEN_STREAM; response.openStreamResponse = openStreamResponse; openStreamResponse.lockHandle = lockHandle; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); }
public AddAndInsertCommandBase() { _bitSet = new BitSet(); _priorityEvictionHint = new PriorityEvictionHint(); }
/// <summary> /// Recupera uma entrada do cache. /// </summary> /// <param name="key"></param> /// <param name="item"></param> /// <param name="flag"></param> /// <param name="group"></param> /// <param name="subGroup"></param> /// <param name="cacheEntry"></param> /// <returns></returns> public UserBinaryObject GetCacheEntry(string key, ProviderCacheItem item, ref BitSet flag, string group, string subGroup, out CacheEntry cacheEntry) { UserBinaryObject val = null; cacheEntry = null; object serializableObject = null; if ((item != null) && (item.Value != null)) { if ((item.Group == null) && (item.SubGroup != null)) { throw new OperationFailedException("Error occurred while synchronization with data source; group must be specified for sub group"); } if ((group != null) && !CacheHelper.CheckDataGroupsCompatibility(new GroupInfo(item.Group, item.SubGroup), new GroupInfo(group, subGroup))) { throw new OperationFailedException("Error occurred while synchronization with data source; groups are incompatible"); } if (flag == null) { flag = new BitSet(); } serializableObject = item.Value; Hashtable hashtable = new Hashtable(); TypeInfoMap typeInfoMap = _context.CacheRoot.GetTypeInfoMap(); hashtable["query-info"] = CacheLoaderUtil.GetQueryInfo(item.Value, typeInfoMap); if (item.Tags != null) { Hashtable tagInfo = CacheLoaderUtil.GetTagInfo(item.Value, item.Tags); if (tagInfo != null) { hashtable.Add("tag-info", tagInfo); } } if (item.NamedTags != null) { try { Hashtable hashtable3 = CacheLoaderUtil.GetNamedTagsInfo(item.Value, item.NamedTags, typeInfoMap); if (hashtable3 != null) { hashtable.Add("named-tag-info", hashtable3); } } catch (Exception exception) { throw new OperationFailedException("Error occurred while synchronization with data source; " + exception.Message); } } if (!item.Value.GetType().IsSerializable&& !_type.IsAssignableFrom(item.Value.GetType())) { throw new OperationFailedException("Read through provider returned an object that is not serializable."); } serializableObject = SerializationUtil.SafeSerialize(serializableObject, _context.SerializationContext, ref flag); if (_context.CompressionEnabled) { item.Value = CompressionUtil.Compress(item.Value as byte[], ref flag, _context.CompressionThreshold); } val = UserBinaryObject.CreateUserBinaryObject(serializableObject as byte[]); EvictionHint evictionHint = new PriorityEvictionHint(item.ItemPriority); ExpirationHint expiryHint = DependencyHelper.GetExpirationHint(item.Dependency, item.AbsoluteExpiration, item.SlidingExpiration); if (expiryHint != null) { expiryHint.CacheKey = key; if (item.ResyncItemOnExpiration) { expiryHint.SetBit(2); } } cacheEntry = new CacheEntry(val, expiryHint, evictionHint); cacheEntry.Flag = flag; cacheEntry.GroupInfo = new GroupInfo(item.Group, item.SubGroup); cacheEntry.QueryInfo = hashtable; cacheEntry.ResyncProviderName = (item.ResyncProviderName == null) ? null : item.ResyncProviderName.ToLower(); } return(val); }
/// <summary> /// Processa os dados carregados do LoadNext. /// </summary> /// <param name="data"></param> private void ProcessDataFromLoadNext(OrderedDictionary data) { int num = 0; byte[] buffer = null; foreach (DictionaryEntry entry in data) { EvictionHint hint2; num = 0; object key = null; ProviderCacheItem item = null; Colosoft.Caching.Expiration.ExpirationHint expiryHint = null; string resyncProviderName = null; Hashtable queryInfo = null; try { if ((!(entry.Key is string) || !(entry.Value is ProviderCacheItem))) { throw new InvalidOperationException("Invalid Key/Value type specified"); } key = entry.Key; item = (ProviderCacheItem)entry.Value; if (item == null) { continue; } CacheLoaderUtil.EvaluateExpirationParameters(item.AbsoluteExpiration, item.SlidingExpiration); expiryHint = Expiration.DependencyHelper.GetExpirationHint(item.Dependency, item.AbsoluteExpiration, item.SlidingExpiration); if ((expiryHint != null) && item.ResyncItemOnExpiration) { expiryHint.SetBit(2); } resyncProviderName = (item.ResyncProviderName == null) ? null : item.ResyncProviderName.ToLower(); queryInfo = new Hashtable(); TypeInfoMap typeInfoMap = _cache.GetTypeInfoMap(); if (typeInfoMap != null) { queryInfo["query-info"] = CacheLoaderUtil.GetQueryInfo(item.Value, typeInfoMap); } if (item.Tags != null) { queryInfo["tag-info"] = CacheLoaderUtil.GetTagInfo(item.Value, item.Tags); } if (item.NamedTags != null) { Hashtable hashtable2 = CacheLoaderUtil.GetNamedTagsInfo(item.Value, item.NamedTags, typeInfoMap); if (hashtable2 != null) { queryInfo["named-tag-info"] = hashtable2; } } } catch (Exception exception3) { OnProcessEntryError(entry, exception3); continue; } var set = new BitSet(); object currentValue = item.Value; try { hint2 = new PriorityEvictionHint(item.ItemPriority); if (!(currentValue is ICacheItemRecord)) { buffer = this.SafeSerialize(currentValue) as byte[]; if ((buffer != null) && _cache.CompressionEnabled) { buffer = IO.Compression.CompressionUtil.Compress(buffer, ref set, _cache.CompressThresholdSize); } if (buffer != null) { currentValue = UserBinaryObject.CreateUserBinaryObject(buffer); } } } catch (Exception ex) { OnLoadProcessingError(ex); continue; } while (num <= this.NoOfRetries) { if (_cache.IsRunning) { if (!CanInsertEntry(key, currentValue)) { break; } try { _cache.Insert(key, currentValue, expiryHint, null, hint2, item.Group, item.SubGroup, queryInfo, set, null, 0, LockAccessType.IGNORE_LOCK, null, resyncProviderName, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation)); } catch (Exception exception4) { num++; System.Threading.Thread.Sleep(this.RetryInterval); if (num > this.NoOfRetries) { OnInsertEntryError(key, currentValue, exception4); if (exception4 is OperationFailedException) { if (((OperationFailedException)exception4).IsTracable || !_logger.IsErrorEnabled) { continue; } _logger.Error("CacheStartupLoader.Load()".GetFormatter(), exception4); break; } if (_logger.IsErrorEnabled) { _logger.Error("CacheStartupLoader.Load()".GetFormatter(), exception4); break; } } continue; } OnInsertedEntry(key, currentValue); } break; } } }
protected CommandInfo ParseCommand(Alachisoft.NCache.Common.Protobuf.Command command, ClientManager clientManager, string cacheId) { CommandInfo cmdInfo = new CommandInfo(); int packageSize = 0; int index = 0; string version = string.Empty; NCache nCache = clientManager.CmdExecuter as NCache; Caching.Cache cache = nCache.Cache; Hashtable queryInfoHashtable = null; Hashtable tagHashtable = null; Hashtable namedTagHashtable = null; try { switch (command.type) { case Alachisoft.NCache.Common.Protobuf.Command.Type.ADD_BULK: Alachisoft.NCache.Common.Protobuf.BulkAddCommand bulkAddCommand = command.bulkAddCommand; packageSize = bulkAddCommand.addCommand.Count; cmdInfo.Keys = new string[packageSize]; cmdInfo.Entries = new CacheEntry[packageSize]; cmdInfo.OnDsItemsAddedCallback = (short)bulkAddCommand.datasourceItemAddedCallbackId; cmdInfo.ProviderName = bulkAddCommand.providerName.Length == 0 ? null : bulkAddCommand.providerName; cmdInfo.RequestId = bulkAddCommand.requestId; cmdInfo.ClientLastViewId = command.clientLastViewId; cmdInfo.IntendedRecipient = command.intendedRecipient; cmdInfo.returnVersion = bulkAddCommand.returnVersions; foreach (Alachisoft.NCache.Common.Protobuf.AddCommand addCommand in bulkAddCommand.addCommand) { cmdInfo.Keys[index] = addCommand.key; cmdInfo.ClientID = addCommand.clientID; BitSet flag = BitSet.CreateAndMarkInUse(clientManager.CacheFakePool, NCModulesConstants.SocketServer); flag.Data = ((byte)addCommand.flag); if (index == 0) { cmdInfo.Flag = flag; } object value = cache.SocketServerDataService.GetCacheData(addCommand.data.ToArray(), cmdInfo.Flag); cmdInfo.Entries[index] = CacheEntry.CreateCacheEntry(clientManager.CacheTransactionalPool, value, Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(clientManager.CacheTransactionalPool, null, addCommand.absExpiration, addCommand.sldExpiration, addCommand.isResync, serailizationContext), PriorityEvictionHint.Create(clientManager.CacheTransactionalPool, (CacheItemPriority)addCommand.priority)); cmdInfo.Entries[index].Flag.Data |= flag.Data; Notifications notification = null; if ((short)addCommand.updateCallbackId != -1 || (short)addCommand.removeCallbackId != -1 || cmdInfo.OnDsItemsAddedCallback != -1) { notification = new Notifications(!string.IsNullOrEmpty(cmdInfo.ClientID) ? cmdInfo.ClientID : clientManager.ClientID, Convert.ToInt32(cmdInfo.RequestId), (short)addCommand.removeCallbackId, (short)addCommand.updateCallbackId, (short)(cmdInfo.RequestId == -1 ? -1 : 0), cmdInfo.OnDsItemsAddedCallback, (EventDataFilter)(addCommand.updateDataFilter != -1 ? (int)addCommand.updateDataFilter : (int)EventDataFilter.None), (EventDataFilter)(addCommand.removeDataFilter != -1 ? (int)addCommand.removeDataFilter : (int)EventDataFilter.None) ); cmdInfo.Entries[index].Notifications = notification; } cmdInfo.onUpdateCallbackId = (short)addCommand.updateCallbackId; if (!String.IsNullOrEmpty(cmdInfo.Group)) { cmdInfo.Entries[index].GroupInfo = new GroupInfo(cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.type); } version = command.version; if (queryInfoHashtable != null) { if (cmdInfo.Entries[index].QueryInfo == null) { cmdInfo.Entries[index].QueryInfo = new Hashtable(); } cmdInfo.Entries[index].QueryInfo.Add("query-info", queryInfoHashtable); } cmdInfo.Entries[index].MarkInUse(NCModulesConstants.SocketServer); index++; if (addCommand?.PoolManager != null) { addCommand.PoolManager.GetProtobufAddCommandPool()?.Return(addCommand); } } break; case Alachisoft.NCache.Common.Protobuf.Command.Type.INSERT_BULK: Alachisoft.NCache.Common.Protobuf.BulkInsertCommand bulkInsertCommand = command.bulkInsertCommand; packageSize = bulkInsertCommand.insertCommand.Count; cmdInfo.Keys = new string[packageSize]; cmdInfo.Entries = new CacheEntry[packageSize]; cmdInfo.OnDsItemsAddedCallback = (short)bulkInsertCommand.datasourceUpdatedCallbackId; cmdInfo.ProviderName = bulkInsertCommand.providerName.Length == 0 ? null : bulkInsertCommand.providerName; cmdInfo.RequestId = bulkInsertCommand.requestId; cmdInfo.ClientLastViewId = command.clientLastViewId; cmdInfo.IntendedRecipient = command.intendedRecipient; cmdInfo.returnVersion = bulkInsertCommand.returnVersions; foreach (Alachisoft.NCache.Common.Protobuf.InsertCommand insertCommand in bulkInsertCommand.insertCommand) { cmdInfo.Keys[index] = insertCommand.key; cmdInfo.ClientID = insertCommand.clientID; BitSet flag = BitSet.CreateAndMarkInUse(clientManager.CacheFakePool, NCModulesConstants.SocketServer); flag.Data = ((byte)insertCommand.flag); if (index == 0) { cmdInfo.Flag = flag; } object value = cache.SocketServerDataService.GetCacheData(insertCommand.data.ToArray(), cmdInfo.Flag); cmdInfo.Entries[index] = CacheEntry.CreateCacheEntry(clientManager.CacheTransactionalPool, value, Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(clientManager.CacheTransactionalPool, null, insertCommand.absExpiration, insertCommand.sldExpiration, insertCommand.isResync, serailizationContext), PriorityEvictionHint.Create(clientManager.CacheTransactionalPool, (CacheItemPriority)insertCommand.priority)); cmdInfo.Entries[index].Flag.Data |= flag.Data; Notifications notification = null; if (insertCommand.updateCallbackId != -1 || insertCommand.removeCallbackId != -1 || cmdInfo.OnDsItemsAddedCallback != -1) { notification = new Notifications(!string.IsNullOrEmpty(cmdInfo.ClientID) ? cmdInfo.ClientID : clientManager.ClientID, Convert.ToInt32(cmdInfo.RequestId), (short)insertCommand.removeCallbackId, (short)insertCommand.updateCallbackId, (short)(cmdInfo.RequestId == -1 ? -1 : 0), cmdInfo.OnDsItemsAddedCallback, (EventDataFilter)(insertCommand.updateDataFilter != -1 ? (int)insertCommand.updateDataFilter : (int)EventDataFilter.None), (EventDataFilter)(insertCommand.removeDataFilter != -1 ? (int)insertCommand.removeDataFilter : (int)EventDataFilter.None) ); cmdInfo.Entries[index].Notifications = notification; } cmdInfo.onUpdateCallbackId = (short)insertCommand.updateCallbackId; if (!String.IsNullOrEmpty(cmdInfo.Group)) { cmdInfo.Entries[index].GroupInfo = new GroupInfo(cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.type); } version = command.version; if (queryInfoHashtable != null) { if (cmdInfo.Entries[index].QueryInfo == null) { cmdInfo.Entries[index].QueryInfo = new Hashtable(); } cmdInfo.Entries[index].QueryInfo.Add("query-info", queryInfoHashtable); } if (tagHashtable != null) { if (cmdInfo.Entries[index].QueryInfo == null) { cmdInfo.Entries[index].QueryInfo = new Hashtable(); } cmdInfo.Entries[index].QueryInfo.Add("tag-info", tagHashtable); } cmdInfo.Entries[index].MarkInUse(NCModulesConstants.SocketServer); index++; if (insertCommand?.PoolManager != null) { insertCommand.PoolManager.GetProtobufInsertCommandPool()?.Return(insertCommand); } } break; } } finally { } return(cmdInfo); }