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 static MutateInOptions Durability(this MutateInOptions opts, DurabilityLevel?durability) { if (durability != null) { return(opts.Durability(durability.Value)); } return(opts); }
public static MutateInOptions Timeout(this MutateInOptions opts, TimeSpan?timeout) { if (timeout.HasValue) { return(opts.Timeout(timeout.Value)); } return(opts); }
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 static MutateInOptions Defaults(this MutateInOptions opts, DurabilityLevel?durability, TimeSpan?timeout) { opts = new MutateInOptions().RetryStrategy(RetryStrategy); if (durability.HasValue) { opts = opts.Durability(durability.Value); } if (timeout.HasValue) { opts = opts.Timeout(timeout.Value); } return(opts); }
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(); }