public async Task CreatePlaceholderClientRecord(ulong?cas = null) { var opts = new MutateInOptions().Timeout(_keyValueTimeout).StoreSemantics(StoreSemantics.Insert); if (cas != null) { // NOTE: To handle corrupt case where placeholder "_txn:client-record" was there, but 'records' XATTR was not. // This needs to be addressed in the RFC, as a misbehaving client will cause all other clients to never work. opts.Cas(0).StoreSemantics(StoreSemantics.Upsert); } var specs = new MutateInSpec[] { MutateInSpec.Insert(ClientRecordsIndex.FIELD_CLIENTS_FULL, PlaceholderEmptyJObject, isXattr: true), MutateInSpec.SetDoc(new byte?[] { null }), // ExtBinaryMetadata }; _ = await Collection.MutateInAsync(ClientRecordsIndex.CLIENT_RECORD_DOC_ID, specs, opts).CAF(); }
public async Task MutateAtrPending(ulong exp, DurabilityLevel documentDurability) { using var logScope = _logger.BeginMethodScope(); var shortDurability = new ShortStringDurabilityLevel(documentDurability).ToString(); var specs = new[] { MutateInSpec.Insert(_prefixedAtrFieldTransactionId, _overallContext.TransactionId, createPath: true, isXattr: true), MutateInSpec.Insert(_prefixedAtrFieldStatus, AttemptStates.PENDING.ToString(), isXattr: true), MutateInSpec.Insert(_prefixedAtrFieldStartTimestamp, MutationMacro.Cas), MutateInSpec.Insert(_prefixedAtrFieldExpiresAfterMsecs, exp, createPath: false, isXattr: true), MutateInSpec.Insert(_prefixedAtrFieldDurability, shortDurability, isXattr: true), MutateInSpec.SetDoc(new byte?[] { null }), // ExtBinaryMetadata }; var mutateResult = await Collection.MutateInAsync(AtrId, specs, GetMutateOpts(StoreSemantics.Upsert)).CAF(); _logger.LogInformation("Upserted ATR to PENDING {atr}/{atrRoot} (cas = {cas})", AtrId, _atrRoot, mutateResult.Cas); }
public async Task MutateAtrCommit(IEnumerable <StagedMutation> stagedMutations) { using var logScope = _logger.BeginMethodScope(); (var inserts, var replaces, var removes) = SplitMutationsForStaging(stagedMutations); var specs = new [] { MutateInSpec.Upsert(_prefixedAtrFieldStatus, AttemptStates.COMMITTED.ToString(), isXattr: true), MutateInSpec.Upsert(_prefixedAtrFieldStartCommit, MutationMacro.Cas, isXattr: true), MutateInSpec.Upsert(_prefixedAtrFieldDocsInserted, inserts, isXattr: true), MutateInSpec.Upsert(_prefixedAtrFieldDocsReplaced, replaces, isXattr: true), MutateInSpec.Upsert(_prefixedAtrFieldDocsRemoved, removes, isXattr: true), MutateInSpec.Insert(_prefixedAtrFieldsPendingSentinel, 0, isXattr: true) }; var mutateResult = await Collection.MutateInAsync(AtrId, specs, GetMutateOpts(StoreSemantics.Replace)).CAF(); _logger.LogDebug("Updated to COMMITTED ATR {atr}/{atrRoot} (cas = {cas})", AtrId, _atrRoot, mutateResult.Cas); }