예제 #1
0
            private bool TryCompleteSync(bool asyncOp, out CompletionEvent flushEvent, out TAsyncResult asyncResult)
            {
                _fasterSession.UnsafeResumeThread();
                try
                {
                    Status status = _asyncOperation.DoFastOperation(_fasterKV, ref _pendingContext, _fasterSession, _currentCtx, asyncOp, out flushEvent, out Output output);

                    if (!status.IsPending)
                    {
                        _pendingContext.Dispose();
                        asyncResult = _asyncOperation.CreateResult(status, output, new RecordMetadata(_pendingContext.recordInfo, _pendingContext.logicalAddress));
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    _exception = ExceptionDispatchInfo.Capture(e);
                    flushEvent = default;
                }
                finally
                {
                    _fasterSession.UnsafeSuspendThread();
                }

                asyncResult = default;
                return(false);
            }
예제 #2
0
            internal ValueTask <RmwAsyncResult <Input, Output, Context, Functions> > CompleteAsync(CancellationToken token = default)
            {
                Debug.Assert(_fasterKV.RelaxedCPR);

                AsyncIOContext <Key, Value> newDiskRequest = default;

                if (_diskRequest.asyncOperation != null &&
                    CompletionComputeStatus != Completed &&
                    Interlocked.CompareExchange(ref CompletionComputeStatus, Completed, Pending) == Pending)
                {
                    try
                    {
                        if (_exception == default)
                        {
                            if (_clientSession.SupportAsync)
                            {
                                _clientSession.UnsafeResumeThread();
                            }
                            try
                            {
                                var status = _fasterKV.InternalCompletePendingRequestFromContext(_clientSession.ctx, _clientSession.ctx, _clientSession.FasterSession, _diskRequest, ref _pendingContext, true, out newDiskRequest);
                                _pendingContext.Dispose();
                                if (status != Status.PENDING)
                                {
                                    return(new ValueTask <RmwAsyncResult <Input, Output, Context, Functions> >(new RmwAsyncResult <Input, Output, Context, Functions>(status, default)));
                                }
                            }
                            finally
                            {
                                if (_clientSession.SupportAsync)
                                {
                                    _clientSession.UnsafeSuspendThread();
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        _exception = ExceptionDispatchInfo.Capture(e);
                    }
                    finally
                    {
                        _clientSession.ctx.ioPendingRequests.Remove(_pendingContext.id);
                        _clientSession.ctx.asyncPendingCount--;
                        _clientSession.ctx.pendingReads.Remove();
                    }
                }

                if (_exception != default)
                {
                    _exception.Throw();
                }

                return(SlowRmwAsync(_fasterKV, _clientSession, _pendingContext, newDiskRequest, token));
            }
예제 #3
0
            internal async ValueTask <TAsyncResult> CompleteAsync(CancellationToken token = default)
            {
                Debug.Assert(_fasterKV.RelaxedCPR);

                if (CompletionComputeStatus != Completed &&
                    Interlocked.CompareExchange(ref CompletionComputeStatus, Completed, Pending) == Pending)
                {
                    try
                    {
                        if (_exception == default)
                        {
                            await _flushTask.WithCancellationAsync(token);

                            _fasterSession.UnsafeResumeThread();
                            try
                            {
                                OperationStatus internalStatus;
                                do
                                {
                                    _flushTask     = _fasterKV.hlog.FlushTask;
                                    internalStatus = asyncOperation.DoFastOperation(_fasterKV, ref _pendingContext, _fasterSession, _currentCtx);
                                } while (internalStatus == OperationStatus.RETRY_NOW);

                                if (internalStatus == OperationStatus.SUCCESS || internalStatus == OperationStatus.NOTFOUND)
                                {
                                    _pendingContext.Dispose();
                                    return(asyncOperation.CreateResult(internalStatus));
                                }
                                Debug.Assert(internalStatus == OperationStatus.ALLOCATE_FAILED);
                            }
                            finally
                            {
                                _fasterSession.UnsafeSuspendThread();
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        _exception = ExceptionDispatchInfo.Capture(e);
                    }
                    finally
                    {
                        _currentCtx.asyncPendingCount--;
                    }
                }

                if (_exception != default)
                {
                    _exception.Throw();
                }
                return(await asyncOperation.DoSlowOperation(_fasterKV, _fasterSession, _currentCtx, _pendingContext, _flushTask, token));
            }
예제 #4
0
            internal (Status, Output) Complete()
            {
                (Status, Output)_result = default;
                if (_diskRequest.asyncOperation != null &&
                    CompletionComputeStatus != Completed &&
                    Interlocked.CompareExchange(ref CompletionComputeStatus, Completed, Pending) == Pending)
                {
                    try
                    {
                        if (_exception == default)
                        {
                            if (_clientSession.SupportAsync)
                            {
                                _clientSession.UnsafeResumeThread();
                            }
                            try
                            {
                                Debug.Assert(_fasterKV.RelaxedCPR);

                                var status = _fasterKV.InternalCompletePendingRequestFromContext(_clientSession.ctx, _clientSession.ctx, _clientSession.FasterSession, _diskRequest, ref _pendingContext, true, out _);
                                Debug.Assert(status != Status.PENDING);
                                _result = (status, _pendingContext.output);
                                _pendingContext.Dispose();
                            }
                            finally
                            {
                                if (_clientSession.SupportAsync)
                                {
                                    _clientSession.UnsafeSuspendThread();
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        _exception = ExceptionDispatchInfo.Capture(e);
                    }
                    finally
                    {
                        _clientSession.ctx.ioPendingRequests.Remove(_pendingContext.id);
                        _clientSession.ctx.asyncPendingCount--;
                        _clientSession.ctx.pendingReads.Remove();
                    }
                }

                if (_exception != default)
                {
                    _exception.Throw();
                }
                return(_result);
            }
예제 #5
0
            internal (Status, Output) Complete()
            {
                (Status, Output)_result = default;
                if (_diskRequest.asyncOperation != null &&
                    CompletionComputeStatus != Completed &&
                    Interlocked.CompareExchange(ref CompletionComputeStatus, Completed, Pending) == Pending)
                {
                    try
                    {
                        if (_exception == default)
                        {
                            _fasterSession.UnsafeResumeThread();
                            try
                            {
                                var status = _fasterKV.InternalCompletePendingRequestFromContext(_currentCtx, _currentCtx, _fasterSession, _diskRequest, ref _pendingContext, true, out _);
                                Debug.Assert(!status.IsPending);
                                _result         = (status, _pendingContext.output);
                                _recordMetadata = new(_pendingContext.recordInfo, _pendingContext.logicalAddress);
                                _pendingContext.Dispose();
                            }
                            finally
                            {
                                _fasterSession.UnsafeSuspendThread();
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        _exception = ExceptionDispatchInfo.Capture(e);
                    }
                    finally
                    {
                        _currentCtx.ioPendingRequests.Remove(_pendingContext.id);
                        _currentCtx.asyncPendingCount--;
                        _currentCtx.pendingReads.Remove();
                    }
                }

                if (_exception != default)
                {
                    _exception.Throw();
                }
                return(_result);
            }
예제 #6
0
파일: UpdateAsync.cs 프로젝트: tli2/FASTER
            private bool TryCompleteSync(bool asyncOp, out CompletionEvent flushEvent, out TAsyncResult asyncResult)
            {
                _fasterSession.UnsafeResumeThread();
                try
                {
                    Status status = _asyncOperation.DoFastOperation(_fasterKV, ref _pendingContext, _fasterSession, _currentCtx, asyncOp, out flushEvent, out Output output);

                    if (status != Status.PENDING)
                    {
                        _pendingContext.Dispose();
                        asyncResult = _asyncOperation.CreateResult(status, output);
                        return(true);
                    }
                }
                finally
                {
                    _fasterSession.UnsafeSuspendThread();
                }

                asyncResult = default;
                return(false);
            }