Exemplo n.º 1
0
        private void DuplicateOperation(BindableTreeNode operationNode)
        {
            IOperation operation      = (IOperation)operationNode.DataSource;
            IOperation operationClone = operation.Clone(true);

            AddOperation(operationClone, (BindableTreeNode)operationNode.Parent, operationNode.Index + 1);
            batchTreeView.SelectedNode = batchTreeView.Find(operationClone.ID);
        }
        /// <summary>
        /// Sends a <see cref="IOperation{T}" /> to the Couchbase Server using the Memcached protocol.
        /// </summary>
        /// <typeparam name="T">The Type of the body of the request.</typeparam>
        /// <param name="operation">The <see cref="IOperation{T}" /> to send.</param>
        /// <returns>
        /// An <see cref="IOperationResult" /> with the status of the request.
        /// </returns>
        /// <exception cref="ServiceNotSupportedException">The cluster does not support Data services.</exception>
        public override IOperationResult <T> SendWithRetry <T>(IOperation <T> operation)
        {
            if (Log.IsDebugEnabled && TimingEnabled)
            {
                operation.Timer = Timer;
                operation.BeginTimer(TimingLevel.Three);
            }

            //Is the cluster configured for Data services?
            if (!ConfigInfo.IsDataCapable)
            {
                return(new OperationResult <T>
                {
                    Id = operation.Key,
                    Success = false,
                    Exception = new ServiceNotSupportedException(
                        ExceptionUtil.GetMessage(ExceptionUtil.ServiceNotSupportedMsg, "Data")),
                    Status = ResponseStatus.ClientFailure
                });
            }

            IOperationResult <T> operationResult = new OperationResult <T> {
                Success = false, OpCode = operation.OperationCode
            };

            do
            {
                IVBucket vBucket;
                var      server = GetServer(operation.Key, operation.LastConfigRevisionTried, out vBucket);
                if (server == null)
                {
                    continue;
                }
                operation.VBucket = vBucket;
                operation.LastConfigRevisionTried = vBucket.Rev;
                operationResult = server.Send(operation);
                operation.Attempts++;

                if (operationResult.Success)
                {
                    Log.Debug(
                        "Operation {0} succeeded {1} for key {2} : {3}", operation.GetType().Name,
                        operation.Attempts, User(operation.Key), User(operationResult.Value));
                    break;
                }
                if (CanRetryOperation(operationResult, operation) && !operation.TimedOut())
                {
                    LogFailure(operation, operationResult);
                    operation = (IOperation <T>)operation.Clone();

                    // Get retry timeout, uses default timeout if no retry stratergy available
                    Thread.Sleep(operation.GetRetryTimeout(VBucketRetrySleepTime));
                }
                else
                {
                    ((OperationResult)operationResult).SetException();
                    Log.Debug("Operation doesn't support retries for key {0}", User(operation.Key));
                    break;
                }
            } while (!operationResult.Success && !operation.TimedOut());

            if (!operationResult.Success)
            {
                if (operation.TimedOut())
                {
                    const string msg = "The operation has timed out.";
                    ((OperationResult)operationResult).Message = msg;
                    ((OperationResult)operationResult).Status  = ResponseStatus.OperationTimeout;
                }
                LogFailure(operation, operationResult);
            }

            if (Log.IsDebugEnabled && TimingEnabled)
            {
                operation.EndTimer(TimingLevel.Three);
            }

            return(operationResult);
        }
        /// <summary>
        /// Sends a <see cref="IOperation{T}" /> to the Couchbase Server using the Memcached protocol.
        /// </summary>
        /// <typeparam name="T">The Type of the body of the request.</typeparam>
        /// <param name="operation">The <see cref="IOperation{T}" /> to send.</param>
        /// <returns>
        /// An <see cref="IOperationResult" /> with the status of the request.
        /// </returns>
        public override IOperationResult <T> SendWithRetry <T>(IOperation <T> operation)
        {
            //Is the cluster configured for Data services?
            if (!ConfigInfo.IsDataCapable)
            {
                throw new ServiceNotSupportedException("The cluster does not support Data services.");
            }

            if (Log.IsDebugEnabled && TimingEnabled)
            {
                operation.Timer = Timer;
                operation.BeginTimer(TimingLevel.Three);
            }

            IOperationResult <T> operationResult = new OperationResult <T> {
                Success = false
            };

            do
            {
                IVBucket vBucket;
                var      server = GetServer(operation.Key, out vBucket);
                if (server == null)
                {
                    continue;
                }
                operation.VBucket = vBucket;
                operationResult   = server.Send(operation);

                if (operationResult.Success)
                {
                    Log.Debug(
                        m =>
                        m("Operation {0} succeeded {1} for key {2} : {3}", operation.GetType().Name,
                          operation.Attempts, operation.Key, operationResult.Value));
                    break;
                }
                if (CanRetryOperation(operationResult, operation) && !operation.TimedOut())
                {
                    LogFailure(operation, operationResult);
                    operation = (IOperation <T>)operation.Clone();
                    Thread.Sleep((int)Math.Pow(2, operation.Attempts++));
                }
                else
                {
                    Log.Debug(m => m("Operation doesn't support retries for key {0}", operation.Key));
                    break;
                }
            } while (!operationResult.Success && !operation.TimedOut());

            if (!operationResult.Success)
            {
                if (operation.TimedOut())
                {
                    const string msg = "The operation has timed out.";
                    ((OperationResult)operationResult).Message = msg;
                    ((OperationResult)operationResult).Status  = ResponseStatus.OperationTimeout;
                }
                LogFailure(operation, operationResult);
            }

            if (Log.IsDebugEnabled && TimingEnabled)
            {
                operation.EndTimer(TimingLevel.Three);
            }

            return(operationResult);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sends a <see cref="IOperation{T}" /> to the Couchbase Server using the Memcached protocol.
        /// </summary>
        /// <typeparam name="T">The Type of the body of the request.</typeparam>
        /// <param name="operation">The <see cref="IOperation{T}" /> to send.</param>
        /// <returns>
        /// An <see cref="IOperationResult" /> with the status of the request.
        /// </returns>
        public override IOperationResult <T> SendWithRetry <T>(IOperation <T> operation)
        {
            if (Log.IsDebugEnabled && TimingEnabled)
            {
                operation.Timer = Timer;
                operation.BeginTimer(TimingLevel.Three);
            }

            IOperationResult <T> operationResult = new OperationResult <T> {
                Success = false
            };

            do
            {
                IVBucket vBucket;
                var      server = GetServer(operation.Key, out vBucket);
                if (server == null)
                {
                    continue;
                }
                operation.VBucket = vBucket;
                operationResult   = server.Send(operation);

                if (operationResult.Success)
                {
                    Log.Debug(
                        m =>
                        m("Operation {0} succeeded {1} for key {2} : {3}", operation.GetType().Name,
                          operation.Attempts, operation.Key, operationResult.Value));
                    break;
                }
                if (CanRetryOperation(operationResult, operation) && !operation.TimedOut())
                {
                    IOperation <T>       operation1 = operation;
                    IOperationResult <T> result     = operationResult;
                    Log.Debug(m => m("Operation retry {0} for key {1} using vb{2} from rev{3} and opaque{4}. Reason: {5}",
                                     operation1.Attempts, operation1.Key, operation1.VBucket.Index, operation1.VBucket.Rev, operation1.Opaque, result.Message));

                    operation = (IOperation <T>)operation.Clone();
                }
                else
                {
                    Log.Debug(m => m("Operation doesn't support retries for key {0}", operation.Key));
                    break;
                }
            } while (!operationResult.Success && !operation.TimedOut());

            if (!operationResult.Success)
            {
                if (operation.TimedOut())
                {
                    const string msg = "The operation has timed out.";
                    ((OperationResult)operationResult).Message = msg;
                    ((OperationResult)operationResult).Status  = ResponseStatus.OperationTimeout;
                }

                const string msg1 = "Operation for key {0} failed after {1} retries using vb{2} from rev{3} and opaque{4}. Reason: {5}";
                Log.Debug(m => m(msg1, operation.Key, operation.Attempts, operation.VBucket.Index, operation.VBucket.Rev, operation.Opaque, operationResult.Message));
            }

            if (Log.IsDebugEnabled && TimingEnabled)
            {
                operation.EndTimer(TimingLevel.Three);
            }

            return(operationResult);
        }