Esempio n. 1
0
        /// <summary>
        /// Cancels the current Memcached request that is in-flight.
        /// </summary>
        public void Cancel(ResponseStatus status, Exception e = null)
        {
            Timer?.Dispose();

            var response = MemoryPool <byte> .Shared.RentAndSlice(24);

            Converter.FromUInt32(Opaque, response.Memory.Span.Slice(HeaderOffsets.Opaque));

            var state = new SocketAsyncState
            {
                Opaque = Opaque,
                // ReSharper disable once MergeConditionalExpression
                Exception     = e,
                Status        = status,
                EndPoint      = EndPoint,
                ConnectionId  = ConnectionId,
                ErrorMap      = ErrorMap,
                LocalEndpoint = LocalEndpoint
            };

            state.SetData(response);

            Callback(state);
        }
Esempio n. 2
0
        public static Exception ThrowException(this SocketAsyncState state, ErrorCode errorCode)
        {
            var statusName = Enum.GetName(typeof(ResponseStatus), state.Status);

            switch (state.Status)
            {
            case ResponseStatus.KeyNotFound:
                return(new DocumentNotFoundException
                {
                    Context = new KeyValueErrorContext
                    {
                    }
                });

            case ResponseStatus.KeyExists:
                return(new DocumentExistsException());

            case ResponseStatus.ValueTooLarge:
                return(new ValueToolargeException());

            case ResponseStatus.InvalidArguments:
                return(new InvalidArgumentException());

            case ResponseStatus.TemporaryFailure:
            case ResponseStatus.OutOfMemory:
            case ResponseStatus.Busy:
            case ResponseStatus.NotInitialized:
                return(new TemporaryFailureException());

            case ResponseStatus.OperationTimeout:
                return(new AmbiguousTimeoutException());

            case ResponseStatus.Locked:
                return(new DocumentLockedException());

            case ResponseStatus.DocumentMutationLost:
                return(new MutationLostException());

            case ResponseStatus.DurabilityInvalidLevel:
                return(new DurabilityLevelNotAvailableException());

            case ResponseStatus.DurabilityImpossible:
                return(new DurabilityImpossibleException());

            case ResponseStatus.SyncWriteInProgress:
                return(new DurableWriteInProgressException());

            case ResponseStatus.SyncWriteAmbiguous:
                return(new DurabilityAmbiguousException());

            case ResponseStatus.Eaccess:
            case ResponseStatus.AuthenticationError:
            case ResponseStatus.AuthenticationContinue:     //likely remove
            case ResponseStatus.AuthStale:
                return(new AuthenticationFailureException(errorCode?.Desc));

            case ResponseStatus.VBucketBelongsToAnotherServer:
                return(new NotMyVBucketException());

            case ResponseStatus.SubdocXattrUnknownVattr:
                return(new XattrException());

            case ResponseStatus.SubdocXattrUnknownMacro:
            case ResponseStatus.SubDocMultiPathFailure:
            case ResponseStatus.SubDocXattrInvalidFlagCombo:
            case ResponseStatus.SubDocXattrInvalidKeyCombo:
            case ResponseStatus.SubdocXattrCantModifyVattr:
            case ResponseStatus.SubdocMultiPathFailureDeleted:
            case ResponseStatus.SubdocInvalidXattrOrder:
                return(new XattrException());

            //sub doc errors
            case ResponseStatus.SubDocPathNotFound:
            case ResponseStatus.SubDocPathMismatch:
            case ResponseStatus.SubDocPathInvalid:
                return(new PathInvalidException());

            case ResponseStatus.SubDocPathTooBig:
                return(new PathTooDeepException());

            case ResponseStatus.SubDocDocTooDeep:
                return(new DocumentTooDeepException());

            case ResponseStatus.SubDocCannotInsert:
                return(new ValueNotJsonException());

            case ResponseStatus.SubDocDocNotJson:
                return(new DocumentNotJsonException());

            case ResponseStatus.SubDocNumRange:
                return(new NumberTooBigException());

            case ResponseStatus.SubDocDeltaRange:
                return(new DeltaInvalidException());

            case ResponseStatus.SubDocPathExists:
                return(new PathExistsException());

            case ResponseStatus.SubDocValueTooDeep:
                return(new DocumentTooDeepException());

            case ResponseStatus.SubDocInvalidCombo:
                return(new InvalidArgumentException());

            case ResponseStatus.DocumentMutationDetected:  //maps to nothing
            case ResponseStatus.NoReplicasFound:           //maps to nothing
            case ResponseStatus.InvalidRange:              //maps to nothing
            case ResponseStatus.ItemNotStored:             //maps to nothing
            case ResponseStatus.IncrDecrOnNonNumericValue: //maps to nothing
            case ResponseStatus.Rollback:                  //maps to nothing
            case ResponseStatus.InternalError:             //maps to nothing
            case ResponseStatus.UnknownCommand:            //maps to nothing
            case ResponseStatus.BucketNotConnected:        //maps to nothing
            case ResponseStatus.NotSupported:              //maps to nothing
                return(new CouchbaseException());

            case ResponseStatus.UnknownCollection:
                return(new CollectionOutdatedException());

            default:
                return(new ArgumentOutOfRangeException());
            }
        }
        public static Exception ThrowException(this SocketAsyncState state, ErrorCode errorCode)
        {
            var statusName = Enum.GetName(typeof(ResponseStatus), state.Status);

            switch (state.Status)
            {
            case ResponseStatus.KeyNotFound:
                return(new KeyNotFoundException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.KeyExists:
                return(new KeyExistsException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.ValueTooLarge:
                return(new ValueTooLargeException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.InvalidArguments:
                return(new InvalidArgumentException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.TemporaryFailure:
            case ResponseStatus.OutOfMemory:
            case ResponseStatus.Busy:
                return(new TempFailException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.OperationTimeout:
                return(new TimeoutException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.Locked:
                return(new KeyLockedException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.DocumentMutationLost:
            case ResponseStatus.DocumentMutationDetected:
            case ResponseStatus.NoReplicasFound:
            case ResponseStatus.DurabilityInvalidLevel:
            case ResponseStatus.DurabilityImpossible:
            case ResponseStatus.SyncWriteInProgress:
            case ResponseStatus.SyncWriteAmbiguous:
                return(new DurabilityException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.Eaccess:
            case ResponseStatus.AuthenticationError:
                return(new AuthenticationException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            //internal errors handled by the app?
            case ResponseStatus.VBucketBelongsToAnotherServer:
                return(new NotMyVBucketException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.UnknownError:
                return(new UnknownErrorException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.Rollback:
            case ResponseStatus.AuthenticationContinue:
            case ResponseStatus.AuthStale:
            case ResponseStatus.InternalError:
            case ResponseStatus.UnknownCommand:
            case ResponseStatus.BucketNotConnected:
            case ResponseStatus.NotInitialized:
            case ResponseStatus.NotSupported:
            case ResponseStatus.SubdocXattrUnknownVattr:
            case ResponseStatus.SubDocMultiPathFailure:
            case ResponseStatus.SubDocXattrInvalidFlagCombo:
            case ResponseStatus.SubDocXattrInvalidKeyCombo:
            case ResponseStatus.SubdocXattrCantModifyVattr:
            case ResponseStatus.SubdocMultiPathFailureDeleted:
            case ResponseStatus.SubdocInvalidXattrOrder:
                return(new InternalErrorException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.InvalidRange:
            case ResponseStatus.ItemNotStored:
            case ResponseStatus.IncrDecrOnNonNumericValue:
                return(new KeyValueException     //hmm?
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                });

            //sub doc errors
            case ResponseStatus.SubDocPathNotFound:
                return(new PathNotFoundException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.SubDocPathMismatch:
                return(new PathMismatchException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.SubDocPathInvalid:
                return(new PathInvalidException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.SubDocPathTooBig:
                return(new PathTooBigException(statusName, new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                }));

            case ResponseStatus.SubDocDocTooDeep:
            case ResponseStatus.SubDocCannotInsert:
            case ResponseStatus.SubDocDocNotJson:
            case ResponseStatus.SubDocNumRange:
            case ResponseStatus.SubDocDeltaRange:
            case ResponseStatus.SubDocPathExists:
            case ResponseStatus.SubDocValueTooDeep:
            case ResponseStatus.SubDocInvalidCombo:
            case ResponseStatus.SubdocXattrUnknownMacro:
                return(new KeyValueException
                {
                    Status = state.Status,
                    ErrorCode = errorCode
                });

            //remove these ones
            case ResponseStatus.Failure:
            case ResponseStatus.ClientFailure:
                break;

            case ResponseStatus.NodeUnavailable:
                break;

            case ResponseStatus.TransportFailure:
                return(state.Exception);

            default:
                return(new ArgumentOutOfRangeException());
            }

            return(new Exception("oh me oh mai..."));
        }