private ValueTask <UpsertAsyncResult <Input, Output, Context> > UpsertAsync <Input, Output, Context>(IFasterSession <Key, Value, Input, Output, Context> fasterSession, FasterExecutionContext <Input, Output, Context> currentCtx, ref PendingContext <Input, Output, Context> pcontext, ref Key key, ref Input input, ref Value value, Context userContext, long serialNo, CancellationToken token) { CompletionEvent flushEvent; Output output = default; fasterSession.UnsafeResumeThread(); try { OperationStatus internalStatus; do { flushEvent = hlog.FlushEvent; internalStatus = InternalUpsert(ref key, ref input, ref value, ref output, ref userContext, ref pcontext, fasterSession, currentCtx, serialNo); } while (internalStatus == OperationStatus.RETRY_NOW); if (OperationStatusUtils.TryConvertToStatusCode(internalStatus, out Status status)) { return(new ValueTask <UpsertAsyncResult <Input, Output, Context> >(new UpsertAsyncResult <Input, Output, Context>(status, output, new RecordMetadata(pcontext.recordInfo, pcontext.logicalAddress)))); } Debug.Assert(internalStatus == OperationStatus.ALLOCATE_FAILED); } finally { Debug.Assert(serialNo >= currentCtx.serialNum, "Operation serial numbers must be non-decreasing"); currentCtx.serialNum = serialNo; fasterSession.UnsafeSuspendThread(); } return(SlowUpsertAsync(this, fasterSession, currentCtx, pcontext, flushEvent, token)); }
internal ValueTask <DeleteAsyncResult <Input, Output, Context> > DeleteAsync <Input, Output, Context>(IFasterSession <Key, Value, Input, Output, Context> fasterSession, FasterExecutionContext <Input, Output, Context> currentCtx, ref PendingContext <Input, Output, Context> pcontext, ref Key key, Context userContext, long serialNo, CancellationToken token) { CompletionEvent flushEvent; fasterSession.UnsafeResumeThread(); try { OperationStatus internalStatus; do { flushEvent = hlog.FlushEvent; internalStatus = InternalDelete(ref key, ref userContext, ref pcontext, fasterSession, currentCtx, serialNo); } while (internalStatus == OperationStatus.RETRY_NOW); if (OperationStatusUtils.TryConvertToStatusCode(internalStatus, out Status status)) { return(new ValueTask <DeleteAsyncResult <Input, Output, Context> >(new DeleteAsyncResult <Input, Output, Context>(new(internalStatus)))); } Debug.Assert(internalStatus == OperationStatus.ALLOCATE_FAILED); } finally { Debug.Assert(serialNo >= currentCtx.serialNum, "Operation serial numbers must be non-decreasing"); currentCtx.serialNum = serialNo; fasterSession.UnsafeSuspendThread(); } return(SlowDeleteAsync(this, fasterSession, currentCtx, pcontext, flushEvent, token)); }
private static Status TranslateStatus(OperationStatus internalStatus) { if (OperationStatusUtils.TryConvertToStatusCode(internalStatus, out Status status)) { return(status); } Debug.Assert(internalStatus == OperationStatus.ALLOCATE_FAILED); return(new(StatusCode.Pending)); }
internal ValueTask <ReadAsyncResult <Input, Output, Context> > ReadAsync <Input, Output, Context>(IFasterSession <Key, Value, Input, Output, Context> fasterSession, FasterExecutionContext <Input, Output, Context> currentCtx, ref Key key, ref Input input, ref ReadOptions readOptions, Context context, long serialNo, CancellationToken token, bool noKey = false) { var pcontext = default(PendingContext <Input, Output, Context>); var operationFlags = PendingContext <Input, Output, Context> .GetOperationFlags(MergeReadFlags(currentCtx.ReadFlags, readOptions.ReadFlags), noKey); pcontext.SetOperationFlags(operationFlags, readOptions.StopAddress); var diskRequest = default(AsyncIOContext <Key, Value>); Output output = default; fasterSession.UnsafeResumeThread(); try { OperationStatus internalStatus; do { internalStatus = InternalRead(ref key, ref input, ref output, readOptions.StartAddress, ref context, ref pcontext, fasterSession, currentCtx, serialNo); }while (internalStatus == OperationStatus.RETRY_NOW); Debug.Assert(internalStatus != OperationStatus.RETRY_LATER); if (OperationStatusUtils.TryConvertToStatusCode(internalStatus, out Status status)) { return(new ValueTask <ReadAsyncResult <Input, Output, Context> >(new ReadAsyncResult <Input, Output, Context>(new(internalStatus), output, new RecordMetadata(pcontext.recordInfo, pcontext.logicalAddress)))); } status = HandleOperationStatus(currentCtx, currentCtx, ref pcontext, fasterSession, internalStatus, true, out diskRequest); if (!status.IsPending) { return(new ValueTask <ReadAsyncResult <Input, Output, Context> >(new ReadAsyncResult <Input, Output, Context>(status, output, new RecordMetadata(pcontext.recordInfo, pcontext.logicalAddress)))); } } finally { Debug.Assert(serialNo >= currentCtx.serialNum, "Operation serial numbers must be non-decreasing"); currentCtx.serialNum = serialNo; fasterSession.UnsafeSuspendThread(); } return(SlowReadAsync(this, fasterSession, currentCtx, pcontext, diskRequest, token)); }