public async Task UpdateClientRecord(string clientUuid, TimeSpan cleanupWindow, int numAtrs, IReadOnlyList <string> expiredClientIds) { var prefix = ClientRecordEntry.PathForEntry(clientUuid); var opts = new MutateInOptions().Timeout(_keyValueTimeout).Serializer(DefaultSerializer); var specs = new List <MutateInSpec> { MutateInSpec.Upsert(ClientRecordEntry.PathForHeartbeat(clientUuid), MutationMacro.Cas, createPath: true), MutateInSpec.Upsert(ClientRecordEntry.PathForExpires(clientUuid), (int)cleanupWindow.TotalMilliseconds + ExpiresSafetyMarginMillis, isXattr: true), MutateInSpec.Upsert(ClientRecordEntry.PathForNumAtrs(clientUuid), numAtrs, isXattr: true), MutateInSpec.SetDoc(new byte?[] { null }), // ExtBinaryMetadata }; var remainingSpecLimit = 16 - specs.Count; foreach (var clientId in expiredClientIds.Take(remainingSpecLimit)) { var spec = MutateInSpec.Remove($"{ClientRecordsIndex.FIELD_CLIENTS_FULL}.{clientId}", isXattr: true); specs.Add(spec); } try { var mutateInReuslt = await Collection.MutateInAsync(ClientRecordsIndex.CLIENT_RECORD_DOC_ID, specs, opts).CAF(); } catch (Core.Exceptions.KeyValue.XattrException ex) { throw; } }
public async Task <(ulong updatedCas, MutationToken mutationToken)> RemoveStagedInsert(TransactionGetResult doc) { var specs = new MutateInSpec[] { MutateInSpec.Remove(TransactionFields.TransactionInterfacePrefixOnly, isXattr: true) }; var opts = GetMutateInOptions(StoreSemantics.Replace).Cas(doc.Cas).AccessDeleted(true); var updatedDoc = await doc.Collection.MutateInAsync(doc.Id, specs, opts).CAF(); return(updatedDoc.Cas, updatedDoc.MutationToken); }
private List <MutateInSpec> CreateMutationSpecs(IAtrRepository atr, string opType, object content, DocumentMetadata?dm = null) { object userSerializedContent = content; if (!(_userDataSerializer is Core.IO.Serializers.DefaultSerializer)) { byte[] bytes = _userDataSerializer.Serialize(content); userSerializedContent = DefaultSerializer.Deserialize <object>(bytes) !; } var specs = new List <MutateInSpec> { MutateInSpec.Upsert(TransactionFields.TransactionId, _overallContext.TransactionId, createPath: true, isXattr: true), MutateInSpec.Upsert(TransactionFields.AttemptId, _attemptId, createPath: true, isXattr: true), MutateInSpec.Upsert(TransactionFields.AtrId, atr.AtrId, createPath: true, isXattr: true), MutateInSpec.Upsert(TransactionFields.AtrScopeName, atr.ScopeName, createPath: true, isXattr: true), MutateInSpec.Upsert(TransactionFields.AtrBucketName, atr.BucketName, createPath: true, isXattr: true), MutateInSpec.Upsert(TransactionFields.AtrCollName, atr.CollectionName, createPath: true, isXattr: true), MutateInSpec.Upsert(TransactionFields.Type, opType, createPath: true, isXattr: true), MutateInSpec.Upsert(TransactionFields.Crc32, MutationMacro.ValueCRC32c, createPath: true, isXattr: true), }; switch (opType) { case "remove": specs.Add(MutateInSpec.Upsert(TransactionFields.StagedData, new { }, isXattr: true)); specs.Add(MutateInSpec.Remove(TransactionFields.StagedData, isXattr: true)); break; case "replace": case "insert": specs.Add(MutateInSpec.Upsert(TransactionFields.StagedData, userSerializedContent, createPath: true, isXattr: true)); break; } if (dm != null) { if (dm.Cas != null) { specs.Add(MutateInSpec.Upsert(TransactionFields.PreTxnCas, dm.Cas, createPath: true, isXattr: true)); } if (dm.RevId != null) { specs.Add(MutateInSpec.Upsert(TransactionFields.PreTxnRevid, dm.RevId, createPath: true, isXattr: true)); } if (dm.ExpTime != null) { specs.Add(MutateInSpec.Upsert(TransactionFields.PreTxnExptime, dm.ExpTime, createPath: true, isXattr: true)); } } return(specs); }
public async Task RemoveClient(string clientUuid, DurabilityLevel durability = DurabilityLevel.None) { var opts = new MutateInOptions().Timeout(RemoveClientTimeout).Durability(DurabilityLevel.None); var specs = new MutateInSpec[] { MutateInSpec.Remove(ClientRecordEntry.PathForEntry(clientUuid), isXattr: true), }; _ = await Collection.MutateInAsync(ClientRecordsIndex.CLIENT_RECORD_DOC_ID, specs, opts).CAF(); }
public async Task MutateAtrRolledBack() { using var logScope = _logger.BeginMethodScope(); var specs = new MutateInSpec[] { MutateInSpec.Remove(_atrRoot, isXattr: true), }; var mutateResult = await Collection.MutateInAsync(AtrId, specs, GetMutateOpts(StoreSemantics.Replace)).CAF(); _logger.LogDebug("Removed ATR {atr}/{atrRoot} (cas = {cas})", AtrId, _atrRoot, mutateResult.Cas); }
public async Task MutateAtrComplete() { using var logScope = _logger.BeginMethodScope(); var specs = new[] { MutateInSpec.Remove(_atrRoot, isXattr: true) }; _ = await Collection.MutateInAsync(AtrId, specs, GetMutateOpts(StoreSemantics.Replace)).CAF(); _logger.LogInformation("Removed ATR {atr}/{atrRoot} on {atrCollection} ", AtrId, _atrRoot, Collection.MakeKeyspace()); }
public async Task ClearTransactionMetadata(ICouchbaseCollection collection, string docId, ulong cas, bool isDeleted) { var opts = GetMutateInOptions(StoreSemantics.Replace).Cas(cas); if (isDeleted) { opts.AccessDeleted(true); } var specs = new MutateInSpec[] { MutateInSpec.Upsert(TransactionFields.TransactionInterfacePrefixOnly, (string?)null, isXattr: true), MutateInSpec.Remove(TransactionFields.TransactionInterfacePrefixOnly, isXattr: true) }; _ = await collection.MutateInAsync(docId, specs, opts).CAF(); }