private async Task <MultiLookup <byte[]> > ExecuteLookupIn(string id, IEnumerable <LookupInSpec> specs, LookupInOptions options)
        {
            //sanity check for deferred bootstrapping errors
            _bucket.ThrowIfBootStrapFailed();

            // convert new style specs into old style builder
            var builder = new LookupInBuilder <byte[]>(null, null, id, specs);

            //add the virtual xttar attribute to get the doc expiration time
            if (options.ExpiryValue)
            {
                builder.Get(VirtualXttrs.DocExpiryTime, SubdocPathFlags.Xattr);
            }

            var lookup = new MultiLookup <byte[]>
            {
                Key        = id,
                Builder    = builder,
                Cid        = Cid,
                CName      = Name,
                Transcoder = _transcoder
            };

            await _bucket.RetryAsync(lookup, options.TokenValue, options.TimeoutValue).ConfigureAwait(false);

            return(lookup);
        }
Ejemplo n.º 2
0
        private async Task RetryUntilTimeoutOrSuccessAsync(CancellationToken?token, TimeSpan?timeout, IOperation op)
        {
            using var cts = token.HasValue
                ? CancellationTokenSource.CreateLinkedTokenSource(token.Value)
                : new CancellationTokenSource(GetTimeout(timeout, op));

            await _bucket.RetryAsync(op, cts.Token).ConfigureAwait(false);
        }
        private async Task <MultiLookup <byte[]> > ExecuteLookupIn(string id, IEnumerable <OperationSpec> specs, LookupInOptions options)
        {
            // convert new style specs into old style builder
            var builder = new LookupInBuilder <byte[]>(null, null, id, specs);

            //add the virtual xttar attribute to get the doc expiration time
            if (options.Expiry)
            {
                builder.Get(VirtualXttrs.DocExpiryTime, SubdocPathFlags.Xattr);
            }

            var lookup = new MultiLookup <byte[]>
            {
                Key        = id,
                Builder    = builder,
                Cid        = Cid,
                Transcoder = _transcoder
            };

            await _bucket.RetryAsync(lookup, options.Token, options.Timeout);

            return(lookup);
        }
Ejemplo n.º 4
0
        public async Task <IGetResult> GetAsync(string id, GetOptions?options = null)
        {
            //sanity check for deferred bootstrapping errors
            _bucket.ThrowIfBootStrapFailed();

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

            // TODO: Since we're actually using LookupIn for Get requests, which operation name should we use?
            using var rootSpan = RootSpan(OuterRequestSpans.ServiceSpan.Kv.Get);
            options ??= GetOptions.Default;

            var projectList = options.ProjectListValue;

            var specCount = projectList.Count;

            if (options.IncludeExpiryValue)
            {
                specCount++;
            }

            if (specCount == 0)
            {
                // We aren't including the expiry value and we have no projections so fetch the whole doc using a Get operation
                var getOp = new Get <byte[]>
                {
                    Key   = id,
                    Cid   = Cid,
                    CName = Name,
                    SName = ScopeName,
                    Span  = rootSpan
                };
                _operationConfigurator.Configure(getOp, options);

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

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

            var specs = new List <LookupInSpec>();

            if (options.IncludeExpiryValue)
            {
                specs.Add(new LookupInSpec
                {
                    OpCode    = OpCode.SubGet,
                    Path      = VirtualXttrs.DocExpiryTime,
                    PathFlags = SubdocPathFlags.Xattr
                });
            }

            if (projectList.Count == 0 || specCount > 16)
            {
                // No projections or we have exceeded the max #fields returnable by sub-doc so fetch the whole doc
                specs.Add(new LookupInSpec
                {
                    Path     = "",
                    OpCode   = OpCode.Get,
                    DocFlags = SubdocDocFlags.None
                });
            }
            else
            {
                //Add the projections for fetching
                foreach (var path in projectList)
                {
                    specs.Add(new LookupInSpec
                    {
                        OpCode = OpCode.SubGet,
                        Path   = path
                    });
                }
            }

            var lookupInOptions = !ReferenceEquals(options, GetOptions.Default)
                ? new LookupInOptions()
                                  .Timeout(options.TimeoutValue)
                                  .Transcoder(options.TranscoderValue)
                : LookupInOptions.Default;

            var lookupOp = await ExecuteLookupIn(id,
                                                 specs, lookupInOptions, rootSpan)
                           .ConfigureAwait(false);

            rootSpan.WithOperationId(lookupOp);
            rootSpan.Dispose();
            return(new GetResult(lookupOp.ExtractBody(), lookupOp.Transcoder, _getLogger, specs, projectList)
            {
                Id = lookupOp.Key,
                Cas = lookupOp.Cas,
                OpCode = lookupOp.OpCode,
                Flags = lookupOp.Flags,
                Header = lookupOp.Header,
                Opaque = lookupOp.Opaque
            });
        }
Ejemplo n.º 5
0
        public async Task <IExistsResult> ExistsAsync(string id, ExistsOptions?options = null)
        {
            try
            {
                //sanity check for deferred bootstrapping errors
                _bucket.ThrowIfBootStrapFailed();

                options ??= new ExistsOptions();

                using var getMetaOp = new GetMeta
                      {
                          Key        = id,
                          Cid        = Cid,
                          CName      = Name,
                          Transcoder = _transcoder
                      };

                await _bucket.RetryAsync(getMetaOp, options.TokenValue, options.TimeoutValue).ConfigureAwait(false);

                var result = getMetaOp.GetValue();
                return(new ExistsResult
                {
                    Cas = getMetaOp.Cas,
                    Exists = !result.Deleted
                });
            }
            catch (DocumentNotFoundException)
            {
                return(new ExistsResult
                {
                    Exists = false
                });
            }
        }