/// <summary>
        /// Checks the primary node for the key, if a NMV is encountered, will retry on each replica.
        /// </summary>
        /// <typeparam name="T">The Type of the body of the request.</typeparam>
        /// <param name="operation">The <see cref="IOperation" /> to execiute.</param>
        /// <returns>
        /// The result of the operation.
        /// </returns>
        public IOperationResult <T> ReadFromReplica <T>(ReplicaRead <T> operation)
        {
            //Is the cluster configured for Data services?
            if (!ConfigInfo.IsDataCapable)
            {
                throw new ServiceNotSupportedException("The cluster does not support Data services.");
            }

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

            do
            {
                var keyMapper = ConfigInfo.GetKeyMapper();
                var vBucket   = (IVBucket)keyMapper.MapKey(operation.Key);
                operation.VBucket = vBucket;

                if (vBucket.HasReplicas)
                {
                    foreach (var index in vBucket.Replicas)
                    {
                        var replica = vBucket.LocateReplica(index);
                        if (replica == null)
                        {
                            continue;
                        }
                        result = replica.Send(operation);
                        if (result.Success && !result.IsNmv())
                        {
                            return(result);
                        }
                        operation = (ReplicaRead <T>)operation.Clone();
                    }
                }
                else
                {
                    result = new OperationResult <T>
                    {
                        Id      = operation.Key,
                        Status  = ResponseStatus.NoReplicasFound,
                        Message = "No replicas found; have you configured the bucket for replica reads?",
                        Success = false
                    };
                }
            } while (result.ShouldRetry() && !result.Success && !operation.TimedOut());

            if (!result.Success)
            {
                if (operation.TimedOut() &&
                    (result.Status != ResponseStatus.NoReplicasFound && result.Status != ResponseStatus.KeyNotFound))
                {
                    const string msg = "The operation has timed out.";
                    ((OperationResult)result).Message = msg;
                    ((OperationResult)result).Status  = ResponseStatus.OperationTimeout;
                }
                LogFailure(operation, result);
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Checks the primary node for the key, if a NMV is encountered, will retry on each replica.
        /// </summary>
        /// <typeparam name="T">The Type of the body of the request.</typeparam>
        /// <param name="operation">The <see cref="IOperation" /> to execiute.</param>
        /// <returns>
        /// The result of the operation.
        /// </returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public IOperationResult <T> ReadFromReplica <T>(ReplicaRead <T> operation)
        {
            var keyMapper = ConfigInfo.GetKeyMapper();
            var vBucket   = (IVBucket)keyMapper.MapKey(operation.Key);

            operation.VBucket = vBucket;

            IOperationResult <T> result = new OperationResult <T>();

            foreach (var index in vBucket.Replicas)
            {
                var replica = vBucket.LocateReplica(index);
                if (replica == null)
                {
                    continue;
                }
                result = replica.Send(operation);
                if (result.Success && !result.IsNmv())
                {
                    return(result);
                }
                operation = (ReplicaRead <T>)operation.Clone();
            }
            return(result);
        }
Пример #3
0
        /// <summary>
        /// Checks the primary node for the key, if a NMV is encountered, will retry on each replica.
        /// </summary>
        /// <typeparam name="T">The Type of the body of the request.</typeparam>
        /// <param name="operation">The <see cref="IOperation" /> to execiute.</param>
        /// <returns>
        /// The result of the operation.
        /// </returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public IOperationResult <T> ReadFromReplica <T>(ReplicaRead <T> operation)
        {
            var keyMapper = ConfigInfo.GetKeyMapper();
            var vBucket   = (IVBucket)keyMapper.MapKey(operation.Key);

            operation.VBucket = vBucket;

            IOperationResult <T> result = null;

            if (vBucket.HasReplicas)
            {
                foreach (var index in vBucket.Replicas)
                {
                    var replica = vBucket.LocateReplica(index);
                    if (replica == null)
                    {
                        continue;
                    }
                    result = replica.Send(operation);
                    if (result.Success && !result.IsNmv())
                    {
                        return(result);
                    }
                    operation = (ReplicaRead <T>)operation.Clone();
                }
            }
            else
            {
                result = new OperationResult <T>
                {
                    Status  = ResponseStatus.NoReplicasFound,
                    Message = "No replicas found; have you configured the bucket for replica reads?",
                    Success = false
                };
            }
            return(result);
        }