internal static async Task <DocumentLookupResult> LookupDocumentAsync(ICouchbaseCollection collection, string docId, TimeSpan?keyValueTimeout, bool fullDocument = true)
        {
            var specs = new List <LookupInSpec>()
            {
                LookupInSpec.Get(TransactionFields.TransactionInterfacePrefixOnly, isXattr: true),
                LookupInSpec.Get("$document", isXattr: true),
                LookupInSpec.Get(TransactionFields.StagedData, isXattr: true)
            };

            var opts = new LookupInOptions().Defaults(keyValueTimeout).AccessDeleted(true);

            int?txnIndex        = 0;
            int docMetaIndex    = 1;
            int?stagedDataIndex = 2;

            int?fullDocIndex = null;

            if (fullDocument)
            {
                specs.Add(LookupInSpec.GetFull());
                fullDocIndex = specs.Count - 1;
            }

            ILookupInResult lookupInResult;

            try
            {
                lookupInResult = await collection.LookupInAsync(docId, specs, opts).CAF();
            }
            catch (PathInvalidException)
            {
                throw;
            }

            var docMeta = lookupInResult.ContentAs <DocumentMetadata>(docMetaIndex);

            IContentAsWrapper?unstagedContent = fullDocIndex.HasValue
                ? new LookupInContentAsWrapper(lookupInResult, fullDocIndex.Value)
                : null;

            var stagedContent = stagedDataIndex.HasValue && lookupInResult.Exists(stagedDataIndex.Value)
                ? new LookupInContentAsWrapper(lookupInResult, stagedDataIndex.Value)
                : null;

            var result = new DocumentLookupResult(docId,
                                                  unstagedContent,
                                                  stagedContent,
                                                  lookupInResult,
                                                  docMeta,
                                                  collection);

            if (txnIndex.HasValue && lookupInResult.Exists(txnIndex.Value))
            {
                result.TransactionXattrs = lookupInResult.ContentAs <TransactionXattrs>(txnIndex.Value);
            }

            return(result);
        }
        public static LookupInOptions Timeout(this LookupInOptions opts, TimeSpan?timeout)
        {
            if (timeout.HasValue)
            {
                return(opts.Timeout(timeout.Value));
            }

            return(opts);
        }
Example #3
0
        public static LookupInOptions Defaults(this LookupInOptions opts, TimeSpan?timeout)
        {
            opts = opts.RetryStrategy(RetryStrategy);
            if (timeout.HasValue)
            {
                opts = opts.Timeout(timeout.Value);
            }

            return(opts);
        }
Example #4
0
        public async Task <(Dictionary <string, AtrEntry> attempts, ParsedHLC parsedHlc)> LookupAttempts(string atrId)
        {
            var opts  = new LookupInOptions().Timeout(_keyValueTimeout);
            var specs = new LookupInSpec[]
            {
                LookupInSpec.Get(TransactionFields.AtrFieldAttempts, isXattr: true),
                LookupInSpec.Get(ClientRecordsIndex.VBUCKET_HLC, isXattr: true)
            };

            var lookupInResult = await Collection.LookupInAsync(atrId, specs, opts).CAF();

            var attempts  = lookupInResult.ContentAs <Dictionary <string, AtrEntry> >(0);
            var parsedHlc = lookupInResult.ContentAs <ParsedHLC>(1);

            return(attempts, parsedHlc);
        }
Example #5
0
        public async Task <(ClientRecordsIndex?clientRecord, ParsedHLC parsedHlc, ulong?cas)> GetClientRecord()
        {
            var opts  = new LookupInOptions().Timeout(_keyValueTimeout);
            var specs = new LookupInSpec[]
            {
                LookupInSpec.Get(ClientRecordsIndex.FIELD_RECORDS, isXattr: true),
                LookupInSpec.Get(ClientRecordsIndex.VBUCKET_HLC, isXattr: true)
            };

            var lookupInResult = await Collection.LookupInAsync(ClientRecordsIndex.CLIENT_RECORD_DOC_ID, specs, opts).CAF();

            var parsedRecord = lookupInResult.ContentAs <ClientRecordsIndex>(0);
            var parsedHlc    = lookupInResult.ContentAs <ParsedHLC>(1);

            return(parsedRecord, parsedHlc, lookupInResult.Cas);
        }