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 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); }