Ejemplo n.º 1
0
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            NCache    nCache = clientManager.CmdExecuter as NCache;
            int       overload;
            string    exception   = null;
            bool      itemUpdated = false;
            bool      itemRemove  = false;
            Stopwatch stopWatch   = new Stopwatch();

            stopWatch.Start();
            try
            {
                overload             = command.MethodOverload;
                serializationContext = nCache.CacheId;
                cmdInfo = base.ParseCommand(command, clientManager, serializationContext);
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("AddCmd.Exec", "cmd parsed");
                }
            }
            catch (Exception exc)
            {
                _addResult = OperationResult.Failure;
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID));
                return;
            }

            CallbackEntry callbackEntry = null;

            if (cmdInfo.UpdateCallbackId != -1 || cmdInfo.RemoveCallbackId != -1 || (!cmdInfo.RequestId.Equals("-1") && cmdInfo.DoAsync) || cmdInfo.DsItemAddedCallbackId != -1)
            {
                if (cmdInfo.RemoveCallbackId != -1)
                {
                    itemRemove = true;
                }
                if (cmdInfo.UpdateCallbackId != -1)
                {
                    itemUpdated = true;
                }

                callbackEntry = new CallbackEntry(!string.IsNullOrEmpty(cmdInfo.ClientID) ? cmdInfo.ClientID : clientManager.ClientID,
                                                  Convert.ToInt32(cmdInfo.RequestId),
                                                  cmdInfo.value,
                                                  cmdInfo.RemoveCallbackId,
                                                  cmdInfo.UpdateCallbackId,
                                                  (short)(cmdInfo.RequestId.Equals("-1") ? -1 : 0),
                                                  cmdInfo.DsItemAddedCallbackId,
                                                  cmdInfo.Flag,
                                                  (EventDataFilter)cmdInfo.UpdateDataFilter,
                                                  (EventDataFilter)cmdInfo.RemoveDataFilter);
            }

            if (!cmdInfo.DoAsync)
            {
                try
                {
                    OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                    operationContext.Add(OperationContextFieldName.RaiseCQNotification, true);

                    UInt64 itemVersion = 0;
                    if (cmdInfo.ItemVersion == 0)
                    {
                        itemVersion = (UInt64)(DateTime.Now - new System.DateTime(2016, 1, 1, 0, 0, 0)).TotalMilliseconds;
                    }
                    else
                    {
                        itemVersion = cmdInfo.ItemVersion;
                    }

                    operationContext.Add(OperationContextFieldName.ItemVersion, itemVersion);
                    operationContext.Add(OperationContextFieldName.MethodOverload, overload);

                    nCache.Cache.Add(cmdInfo.Key,
                                     callbackEntry == null ? cmdInfo.value : (object)callbackEntry,
                                     cmdInfo.ExpirationHint,
                                     cmdInfo.SyncDependency,
                                     cmdInfo.EvictionHint,
                                     cmdInfo.Group,
                                     cmdInfo.SubGroup,
                                     cmdInfo.queryInfo,
                                     cmdInfo.Flag, cmdInfo.ProviderName, cmdInfo.ResyncProviderName, operationContext, null);

                    stopWatch.Stop();

                    Alachisoft.NCache.Common.Protobuf.Response    response    = new Alachisoft.NCache.Common.Protobuf.Response();
                    Alachisoft.NCache.Common.Protobuf.AddResponse addResponse = new Alachisoft.NCache.Common.Protobuf.AddResponse();

                    // retrieve the version added...
                    itemVersion = (ulong)operationContext.GetValueByField(OperationContextFieldName.ItemVersion);

                    addResponse.itemversion = itemVersion;
                    response.requestId      = Convert.ToInt64(cmdInfo.RequestId);
                    response.commandID      = command.commandID;
                    response.responseType   = Alachisoft.NCache.Common.Protobuf.Response.Type.ADD;
                    response.addResponse    = addResponse;

                    //PROTOBUF:RESPONSE
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                }
                catch (Exception exc)
                {
                    _addResult = OperationResult.Failure;
                    exception  = exc.ToString();
                    _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.ADD.ToLower());
                            object            toInsert;
                            if (cmdInfo.value is UserBinaryObject)
                            {
                                UserBinaryObject data = (UserBinaryObject)cmdInfo.value;
                                toInsert = data.Length;
                            }
                            else
                            {
                                toInsert = cmdInfo.DataFormatValue;
                            }
                            Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo);
                            log.GenerateADDInsertAPILogItem(cmdInfo.Key, toInsert, 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, cmdInfo.EvictionHint.Priority, cmdInfo.SyncDependency, expirationHint["tag-info"] != null ? expirationHint["tag-info"] as Hashtable : null, cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.Flag, cmdInfo.ProviderName, cmdInfo.ResyncProviderName, false, expirationHint["named-tags"] != null ? expirationHint["named-tags"] as Hashtable : null, cmdInfo.UpdateCallbackId, cmdInfo.DsItemAddedCallbackId, false, itemUpdated, itemRemove, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString());
                        }
                    }
                    catch
                    {
                    }
                }
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("AddCmd.Exec", "cmd executed on cache");
                }
            }
            else
            {
                OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                operationContext.Add(OperationContextFieldName.WriteThru, cmdInfo.Flag.IsBitSet(BitSetConstants.WriteThru));
                operationContext.Add(OperationContextFieldName.WriteBehind, cmdInfo.Flag.IsBitSet(BitSetConstants.WriteBehind));

                if (cmdInfo.ProviderName != null)
                {
                    operationContext.Add(OperationContextFieldName.WriteThruProviderName, cmdInfo.ProviderName);
                }

                operationContext.Add(OperationContextFieldName.RaiseCQNotification, true);

                UInt64 itemVersion = 0;
                if (cmdInfo.ItemVersion == 0)
                {
                    itemVersion = (UInt64)(DateTime.Now - new System.DateTime(2016, 1, 1, 0, 0, 0)).TotalMilliseconds;
                }
                else
                {
                    itemVersion = cmdInfo.ItemVersion;
                }

                operationContext.Add(OperationContextFieldName.ItemVersion, itemVersion);
                operationContext.Add(OperationContextFieldName.MethodOverload, overload);

                bool onAsyncCall = false;
                if (callbackEntry != null)
                {
                    onAsyncCall = true;
                }

                nCache.Cache.AddAsync(cmdInfo.Key,
                                      callbackEntry == null ? (object)cmdInfo.value : (object)callbackEntry,
                                      cmdInfo.ExpirationHint,
                                      cmdInfo.SyncDependency,
                                      cmdInfo.EvictionHint,
                                      cmdInfo.Group,
                                      cmdInfo.SubGroup,
                                      cmdInfo.Flag,
                                      cmdInfo.queryInfo, cmdInfo.ProviderName, operationContext);
                stopWatch.Stop();
                TimeSpan executionTime = stopWatch.Elapsed;
                try
                {
                    if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging)
                    {
                        APILogItemBuilder log            = new APILogItemBuilder(MethodsName.ADDASYNC.ToLower());
                        Hashtable         expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo);
                        object            toInsert;
                        if (cmdInfo.value is UserBinaryObject)
                        {
                            UserBinaryObject data = (UserBinaryObject)cmdInfo.value;
                            toInsert = data.Length;
                        }
                        else
                        {
                            toInsert = cmdInfo.DataFormatValue;
                        }
                        log.GenerateADDInsertAPILogItem(cmdInfo.Key, toInsert, 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, cmdInfo.EvictionHint.Priority, cmdInfo.SyncDependency, expirationHint["tag-info"] != null ? expirationHint["tag-info"] as Hashtable : null, cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.Flag, cmdInfo.ProviderName, cmdInfo.ResyncProviderName, false, expirationHint["named-tags"] != null ? expirationHint["named-tags"] as Hashtable : null, cmdInfo.UpdateCallbackId, cmdInfo.DsItemAddedCallbackId, onAsyncCall, itemUpdated, itemRemove, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString());
                    }
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 2
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            NCache    nCache = clientManager.CmdExecuter as NCache;
            int       overload;
            long      dataLength  = 0;
            string    exception   = null;
            bool      itemUpdated = false;
            bool      itemRemove  = false;
            Stopwatch stopWatch   = new Stopwatch();

            stopWatch.Start();
            try
            {
                try
                {
                    overload             = command.MethodOverload;
                    serializationContext = nCache.CacheId;
                    cmdInfo = base.ParseCommand(command, clientManager, serializationContext);
                }
                catch (System.Exception exc)
                {
                    _addResult = OperationResult.Failure;
                    {
                        //PROTOBUF:RESPONSE
                        _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion));
                    }

                    return;
                }

                Notifications callbackEntry = null;

                if (cmdInfo.UpdateCallbackId != -1 || cmdInfo.RemoveCallbackId != -1 || (!cmdInfo.RequestId.Equals("-1") && cmdInfo.DoAsync) || cmdInfo.DsItemAddedCallbackId != -1)
                {
                    if (cmdInfo.RemoveCallbackId != -1)
                    {
                        itemRemove = true;
                    }
                    if (cmdInfo.UpdateCallbackId != -1)
                    {
                        itemUpdated = true;
                    }

                    callbackEntry = new Notifications(!string.IsNullOrEmpty(cmdInfo.ClientID) ? cmdInfo.ClientID : clientManager.ClientID,
                                                      Convert.ToInt32(cmdInfo.RequestId),
                                                      cmdInfo.RemoveCallbackId,
                                                      cmdInfo.UpdateCallbackId,
                                                      (short)(cmdInfo.RequestId == -1 ? -1 : 0),
                                                      cmdInfo.DsItemAddedCallbackId,
                                                      (EventDataFilter)cmdInfo.UpdateDataFilter,
                                                      (EventDataFilter)cmdInfo.RemoveDataFilter);
                }

                UserBinaryObject data = cmdInfo.value as UserBinaryObject;
                if (data != null)
                {
                    dataLength = data.Length;
                }

                if (!cmdInfo.DoAsync)
                {
                    OperationContext operationContext = null;

                    try
                    {
                        operationContext = _operationContext;
                        operationContext.Add(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);

                        CommandsUtil.PopulateClientIdInContext(ref operationContext, clientManager.ClientAddress);
                        operationContext.Add(OperationContextFieldName.RaiseCQNotification, true);

                        UInt64 itemVersion = 0;
                        if (cmdInfo.ItemVersion == 0)
                        {
                            itemVersion = (ulong)(DateTime.UtcNow - Common.Util.Time.ReferenceTime).TotalMilliseconds;
                        }
                        else
                        {
                            itemVersion = cmdInfo.ItemVersion;
                        }

                        operationContext.Add(OperationContextFieldName.ItemVersion, itemVersion);
                        operationContext.Add(OperationContextFieldName.MethodOverload, overload);

                        operationContext?.MarkInUse(NCModulesConstants.SocketServer);

                        if (cmdInfo.Group != null)
                        {
                            if (string.IsNullOrEmpty(cmdInfo.Type))
                            {
                                cmdInfo.Type = oldClientsGroupType;
                            }
                        }

                        nCache.Cache.Add(cmdInfo.Key,
                                         cmdInfo.value,
                                         cmdInfo.ExpirationHint,
                                         cmdInfo.EvictionHint,
                                         cmdInfo.Group,
                                         cmdInfo.SubGroup,
                                         cmdInfo.queryInfo,
                                         cmdInfo.Flag, cmdInfo.ProviderName, cmdInfo.ResyncProviderName, operationContext, null, callbackEntry, cmdInfo.Type);

                        stopWatch.Stop();

                        if (operationContext.Contains(OperationContextFieldName.ItemVersion))
                        {
                            itemVersion = (ulong)operationContext.GetValueByField(OperationContextFieldName.ItemVersion);
                        }

                        _addResponse.itemversion = itemVersion;

                        if (clientManager.ClientVersion >= 5000)
                        {
                            ResponseHelper.SetResponse(_addResponse, command.requestID, command.commandID);
                            _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(_addResponse, Response.Type.ADD));
                        }
                        else
                        {
                            //PROTOBUF:RESPONSE
                            var response = Stash.ProtobufResponse;
                            response.addResponse = _addResponse;
                            ResponseHelper.SetResponse(response, command.requestID, command.commandID, Response.Type.ADD);

                            _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                        }
                    }
                    catch (System.Exception exc)
                    {
                        _addResult = 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);

                        TimeSpan executionTime = stopWatch.Elapsed;

                        try
                        {
                            if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging)
                            {
                                APILogItemBuilder log = new APILogItemBuilder(MethodsName.ADD.ToLower());
                                object            toInsert;
                                if (cmdInfo.value is UserBinaryObject)
                                {
                                    toInsert = dataLength;
                                }
                                else
                                {
                                    toInsert = cmdInfo.DataFormatValue;
                                }
                                Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo);
                                log.GenerateADDInsertAPILogItem(cmdInfo.Key, toInsert, 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, cmdInfo.EvictionHint.Priority, expirationHint["tag-info"] != null ? expirationHint["tag-info"] as Hashtable : null, cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.Flag, cmdInfo.ProviderName, cmdInfo.ResyncProviderName, false, expirationHint["named-tags"] != null ? expirationHint["named-tags"] as Hashtable : null, cmdInfo.UpdateCallbackId, cmdInfo.DsItemAddedCallbackId, false, itemUpdated, itemRemove, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString());
                            }
                        }
                        catch { }
                    }
                }

                else
                {
                    OperationContext operationContext = null;

                    try
                    {
                        operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);

                        operationContext.Add(OperationContextFieldName.WriteThru, cmdInfo.Flag.IsBitSet(BitSetConstants.WriteThru));
                        operationContext.Add(OperationContextFieldName.WriteBehind, cmdInfo.Flag.IsBitSet(BitSetConstants.WriteBehind));
                        if (cmdInfo.ProviderName != null)
                        {
                            operationContext.Add(OperationContextFieldName.WriteThruProviderName, cmdInfo.ProviderName);
                        }

                        operationContext.Add(OperationContextFieldName.RaiseCQNotification, true);

                        UInt64 itemVersion = 0;
                        if (cmdInfo.ItemVersion == 0)
                        {
                            itemVersion = (ulong)(DateTime.UtcNow - Common.Util.Time.ReferenceTime).TotalMilliseconds;
                        }
                        else
                        {
                            itemVersion = cmdInfo.ItemVersion;
                        }


                        operationContext.Add(OperationContextFieldName.ItemVersion, itemVersion);
                        operationContext.Add(OperationContextFieldName.MethodOverload, overload);
                        operationContext.MarkInUse(NCModulesConstants.SocketServer);

                        bool onAsyncCall = false;
                        if (callbackEntry != null)
                        {
                            onAsyncCall = true;
                        }

                        if (cmdInfo.Group != null)
                        {
                            if (string.IsNullOrEmpty(cmdInfo.Type))
                            {
                                cmdInfo.Type = oldClientsGroupType;
                            }
                        }

                        // Fetching this from pool to avoid value corruption for eviction hint for old
                        cmdInfo.EvictionHint = Caching.EvictionPolicies.PriorityEvictionHint.Create(
                            clientManager.CacheTransactionalPool, cmdInfo.EvictionHint.Priority
                            );

                        nCache.Cache.AddAsync(cmdInfo.Key,
                                              cmdInfo.value,
                                              cmdInfo.ExpirationHint,
                                              cmdInfo.EvictionHint,
                                              cmdInfo.Group,
                                              cmdInfo.SubGroup,
                                              cmdInfo.Flag,
                                              cmdInfo.queryInfo, cmdInfo.ProviderName, operationContext, callbackEntry, cmdInfo.Type);

                        stopWatch.Stop();
                        TimeSpan executionTime = stopWatch.Elapsed;
                        try
                        {
                            if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging)
                            {
                                APILogItemBuilder log            = new APILogItemBuilder(MethodsName.ADDASYNC.ToLower());
                                Hashtable         expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo);
                                object            toInsert;
                                if (cmdInfo.value is UserBinaryObject)
                                {
                                    toInsert = dataLength;
                                }
                                else
                                {
                                    toInsert = cmdInfo.DataFormatValue;
                                }
                                log.GenerateADDInsertAPILogItem(cmdInfo.Key, toInsert, 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, cmdInfo.EvictionHint.Priority, expirationHint["tag-info"] != null ? expirationHint["tag-info"] as Hashtable : null, cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.Flag, cmdInfo.ProviderName, cmdInfo.ResyncProviderName, false, expirationHint["named-tags"] != null ? expirationHint["named-tags"] as Hashtable : null, cmdInfo.UpdateCallbackId, cmdInfo.DsItemAddedCallbackId, onAsyncCall, itemUpdated, itemRemove, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString());
                            }
                        }
                        catch { }
                    }
                    finally
                    {
                        operationContext?.MarkFree(NCModulesConstants.SocketServer);
                    }
                }
            }
            finally
            {
                cmdInfo.Flag?.MarkFree(NCModulesConstants.SocketServer);
            }
        }
Ejemplo n.º 3
0
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            NCache    nCache = clientManager.CmdExecuter as NCache;
            int       overload;
            long      dataLength = 0;
            string    exception  = null;
            Stopwatch stopWatch  = new Stopwatch();

            stopWatch.Start();
            bool itemUpdated = false;
            bool itemRemove  = false;

            try
            {
                try
                {
                    overload             = command.MethodOverload;
                    serializationContext = nCache.CacheId;
                    cmdInfo = ParseCommand(command, clientManager, serializationContext);
                }
                catch (System.Exception exc)
                {
                    _insertResult = OperationResult.Failure;
                    {
                        //PROTOBUF:RESPONSE
                        _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion));
                    }
                    return;
                }

                Notifications callbackEntry = null;

                if (cmdInfo.UpdateCallbackId != -1 || cmdInfo.RemoveCallbackId != -1 || (!cmdInfo.RequestId.Equals("-1") && cmdInfo.DoAsync) || cmdInfo.DsItemAddedCallbackId != -1)
                {
                    if (cmdInfo.RemoveCallbackId != -1)
                    {
                        itemRemove = true;
                    }
                    if (cmdInfo.UpdateCallbackId != -1)
                    {
                        itemUpdated = true;
                    }

                    callbackEntry = new Notifications(!string.IsNullOrEmpty(cmdInfo.ClientID) ? cmdInfo.ClientID : clientManager.ClientID,
                                                      Convert.ToInt32(cmdInfo.RequestId),
                                                      cmdInfo.RemoveCallbackId,
                                                      cmdInfo.UpdateCallbackId,
                                                      (short)(cmdInfo.RequestId.Equals("-1") ? -1 : 0),
                                                      cmdInfo.DsItemAddedCallbackId,
                                                      (Runtime.Events.EventDataFilter)cmdInfo.UpdateDataFilter,
                                                      (Runtime.Events.EventDataFilter)cmdInfo.RemoveDataFilter,
                                                      CallbackType(cmdInfo.CallbackType)
                                                      );
                }

                UserBinaryObject data = cmdInfo.value as UserBinaryObject;
                if (data != null)
                {
                    dataLength = data.Length;
                }

                if (!cmdInfo.DoAsync)
                {
                    OperationContext operationContext = null;

                    try
                    {
                        operationContext = _operationContext;
                        operationContext.Add(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);

                        operationContext.Add(OperationContextFieldName.RaiseCQNotification, true);
                        UInt64 itemVersion = 0;
                        if (cmdInfo.ItemVersion == 0)
                        {
                            itemVersion = (ulong)(DateTime.UtcNow - Common.Util.Time.ReferenceTime).TotalMilliseconds;
                        }
                        else
                        {
                            itemVersion = cmdInfo.ItemVersion;
                        }

                        operationContext.Add(OperationContextFieldName.ItemVersion, itemVersion);
                        operationContext.Add(OperationContextFieldName.MethodOverload, overload);

                        operationContext.MarkInUse(NCModulesConstants.SocketServer);
                        ulong version = nCache.Cache.Insert(cmdInfo.Key,
                                                            cmdInfo.value,
                                                            cmdInfo.ExpirationHint,
                                                            cmdInfo.EvictionHint,
                                                            cmdInfo.Group,
                                                            cmdInfo.SubGroup,
                                                            cmdInfo.queryInfo,
                                                            cmdInfo.Flag,
                                                            cmdInfo.LockId,
                                                            cmdInfo.ItemVersion,
                                                            cmdInfo.LockAccessType,
                                                            cmdInfo.ProviderName,
                                                            cmdInfo.ResyncProviderName,
                                                            operationContext,
                                                            callbackEntry,
                                                            cmdInfo.Type
                                                            );

                        stopWatch.Stop();

                        //PROTOBUF:RESPONSE
                        _insertResponse.version = version;

                        if (clientManager.ClientVersion >= 5000)
                        {
                            ResponseHelper.SetResponse(_insertResponse, command.requestID, command.commandID);

                            _serializedResponsePackets.Add(ResponseHelper.SerializeInsertResponse(_insertResponse, Response.Type.INSERT));
                        }
                        else
                        {
                            var response = Stash.ProtobufResponse;
                            response.insert = _insertResponse;
                            ResponseHelper.SetResponse(response, command.requestID, command.commandID, Response.Type.INSERT);

                            _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                        }
                    }
                    catch (System.Exception exc)
                    {
                        _insertResult = OperationResult.Failure;
                        exception     = exc.ToString();

                        //PROTOBUF:RESPONSE
                        _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion));
                    }
                    finally
                    {
                        operationContext?.MarkFree(NCModulesConstants.SocketServer);

                        // Returning these here explicitly because the CacheEntry created for this operation is actually
                        // fetched from Stash rather than pool. Since the return call for that entry is going to fail, the
                        // metadata (such as these objects) attached to that entry won't be returned to pool. Therefore,
                        // we return them here explicitly.
                        if (cmdInfo.value is UserBinaryObject userBinaryObject)
                        {
                            MiscUtil.ReturnUserBinaryObjectToPool(userBinaryObject, userBinaryObject.PoolManager);
                        }

                        MiscUtil.ReturnExpirationHintToPool(cmdInfo.ExpirationHint, cmdInfo.ExpirationHint?.PoolManager);
                        //MiscUtil.ReturnSyncDependencyToPool(cmdInfo.SyncDependency, cmdInfo.SyncDependency?.PoolManager);

                        TimeSpan executionTime = stopWatch.Elapsed;

                        try
                        {
                            if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging)
                            {
                                APILogItemBuilder log = new APILogItemBuilder(MethodsName.INSERT.ToLower());
                                object            toInsert;
                                if (cmdInfo.value is UserBinaryObject)
                                {
                                    toInsert = dataLength;
                                }
                                else
                                {
                                    toInsert = cmdInfo.DataFormatValue;
                                }
                                Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo);
                                log.GenerateADDInsertAPILogItem(cmdInfo.Key, toInsert, 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, cmdInfo.EvictionHint.Priority, expirationHint["tag-info"] != null ? expirationHint["tag-info"] as Hashtable : null, cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.Flag, cmdInfo.ProviderName, cmdInfo.ResyncProviderName, false, expirationHint["named-tags"] != null ? expirationHint["named-tags"] as Hashtable : null, cmdInfo.UpdateCallbackId, cmdInfo.DsItemAddedCallbackId, false, itemUpdated, itemRemove, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString());
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    OperationContext operationContext = null;

                    try
                    {
                        operationContext = new OperationContext();

                        operationContext.Add(OperationContextFieldName.WriteThru, cmdInfo.Flag.IsBitSet(BitSetConstants.WriteThru));
                        operationContext.Add(OperationContextFieldName.WriteBehind, cmdInfo.Flag.IsBitSet(BitSetConstants.WriteBehind));

                        if (cmdInfo.ProviderName != null)
                        {
                            operationContext.Add(OperationContextFieldName.WriteThruProviderName, cmdInfo.ProviderName);
                        }

                        operationContext.Add(OperationContextFieldName.RaiseCQNotification, true);

                        UInt64 itemVersion = 0;
                        if (cmdInfo.ItemVersion == 0)
                        {
                            itemVersion = (ulong)(DateTime.UtcNow - Common.Util.Time.ReferenceTime).TotalMilliseconds;
                        }
                        else
                        {
                            itemVersion = cmdInfo.ItemVersion;
                        }

                        operationContext.Add(OperationContextFieldName.ItemVersion, itemVersion);

                        operationContext.Add(OperationContextFieldName.MethodOverload, overload);

                        bool onAsyncCall = false;
                        if (callbackEntry != null)
                        {
                            onAsyncCall = true;
                        }

                        // Fetching this from pool to avoid value corruption for eviction hint
                        cmdInfo.EvictionHint = Caching.EvictionPolicies.PriorityEvictionHint.Create(
                            clientManager.CacheTransactionalPool, cmdInfo.EvictionHint.Priority
                            );

                        nCache.Cache.InsertAsync(cmdInfo.Key,
                                                 (object)cmdInfo.value,
                                                 cmdInfo.ExpirationHint,
                                                 cmdInfo.EvictionHint,
                                                 cmdInfo.Group,
                                                 cmdInfo.SubGroup,
                                                 cmdInfo.Flag,
                                                 cmdInfo.queryInfo,
                                                 cmdInfo.ProviderName,
                                                 operationContext,
                                                 callbackEntry,
                                                 cmdInfo.Type
                                                 );
                        stopWatch.Stop();
                        TimeSpan executionTime = stopWatch.Elapsed;
                        try
                        {
                            if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging)
                            {
                                APILogItemBuilder log = new APILogItemBuilder(MethodsName.INSERTASYNC.ToLower());
                                object            toInsert;
                                if (cmdInfo.value is UserBinaryObject)
                                {
                                    toInsert = dataLength;
                                }
                                else
                                {
                                    toInsert = cmdInfo.DataFormatValue;
                                }
                                Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo);
                                log.GenerateADDInsertAPILogItem(cmdInfo.Key, toInsert, 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, cmdInfo.EvictionHint.Priority, expirationHint["tag-info"] != null ? expirationHint["tag-info"] as Hashtable : null, cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.Flag, cmdInfo.ProviderName, cmdInfo.ResyncProviderName, false, expirationHint["named-tags"] != null ? expirationHint["named-tags"] as Hashtable : null, cmdInfo.UpdateCallbackId, cmdInfo.DsItemAddedCallbackId, onAsyncCall, itemUpdated, itemRemove, overload, null, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString());
                            }
                        }
                        catch
                        {
                        }
                    }
                    finally
                    {
                        operationContext?.MarkFree(NCModulesConstants.SocketServer);
                    }
                }
            }
            finally
            {
                cmdInfo.Flag?.MarkFree(NCModulesConstants.SocketServer);
            }
        }