Exemple #1
0
        public async Task <IGetResult> GetAndLockAsync(string id, TimeSpan lockTime, GetAndLockOptions?options = null)
        {
            //sanity check for deferred bootstrapping errors
            _bucket.ThrowIfBootStrapFailed();

            //Get the collection ID
            await PopulateCidAsync().ConfigureAwait(false);

            options ??= GetAndLockOptions.Default;
            using var rootSpan     = RootSpan(OuterRequestSpans.ServiceSpan.Kv.GetAndLock);
            using var getAndLockOp = new GetL <byte[]>
                  {
                      Key    = id,
                      Cid    = Cid,
                      CName  = Name,
                      SName  = ScopeName,
                      Expiry = lockTime.ToTtl(),
                      Span   = rootSpan
                  };
            _operationConfigurator.Configure(getAndLockOp, options);

            using var cts = CreateRetryTimeoutCancellationTokenSource(options, getAndLockOp, out var tokenPair);
            await _bucket.RetryAsync(getAndLockOp, tokenPair).ConfigureAwait(false);

            return(new GetResult(getAndLockOp.ExtractBody(), getAndLockOp.Transcoder, _getLogger)
            {
                Id = getAndLockOp.Key,
                Cas = getAndLockOp.Cas,
                Flags = getAndLockOp.Flags,
                Header = getAndLockOp.Header,
                OpCode = getAndLockOp.OpCode
            });
        }
Exemple #2
0
        public async Task <IGetResult> GetAndLockAsync(string id, TimeSpan lockTime, GetAndLockOptions?options = null)
        {
            //sanity check for deferred bootstrapping errors
            _bucket.ThrowIfBootStrapFailed();

            options ??= new GetAndLockOptions();
            using var rootSpan     = RootSpan(OperationNames.GetAndLock);
            using var getAndLockOp = new GetL <byte[]>
                  {
                      Key    = id,
                      Cid    = Cid,
                      CName  = Name,
                      Expiry = lockTime.ToTtl(),
                      Span   = rootSpan
                  };
            _operationConfigurator.Configure(getAndLockOp, options);

            await RetryUntilTimeoutOrSuccessAsync(options.TokenValue, options.TimeoutValue, getAndLockOp).ConfigureAwait(false);

            return(new GetResult(getAndLockOp.ExtractBody(), getAndLockOp.Transcoder, _getLogger)
            {
                Id = getAndLockOp.Key,
                Cas = getAndLockOp.Cas,
                Flags = getAndLockOp.Flags,
                Header = getAndLockOp.Header,
                OpCode = getAndLockOp.OpCode
            });
        }