protected async Task DatabaseConfigurations(SetupFunc setupConfigurationFunc, string debug, string raftRequestId, RefAction beforeSetupConfiguration = null, Action <DynamicJsonValue, BlittableJsonReaderObject, long> fillJson = null, HttpStatusCode statusCode = HttpStatusCode.OK) { if (TryGetAllowedDbs(Database.Name, out var _, requireAdmin: true) == false) { return; } if (ResourceNameValidator.IsValidResourceName(Database.Name, ServerStore.Configuration.Core.DataDirectory.FullPath, out string errorMessage) == false) { throw new BadRequestException(errorMessage); } ServerStore.EnsureNotPassive(); using (ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context)) { var configurationJson = await context.ReadForMemoryAsync(RequestBodyStream(), debug); beforeSetupConfiguration?.Invoke(Database.Name, ref configurationJson, context); var(index, _) = await setupConfigurationFunc(context, Database.Name, configurationJson, raftRequestId); DatabaseTopology dbTopology; using (context.OpenReadTransaction()) { dbTopology = ServerStore.Cluster.ReadDatabaseTopology(context, Database.Name); } if (dbTopology.RelevantFor(ServerStore.NodeTag)) { var db = await ServerStore.DatabasesLandlord.TryGetOrCreateResourceStore(Database.Name); await db.RachisLogIndexNotifications.WaitForIndexNotification(index, ServerStore.Engine.OperationTimeout); } else { await ServerStore.Cluster.WaitForIndexNotification(index); } HttpContext.Response.StatusCode = (int)statusCode; using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream())) { var json = new DynamicJsonValue { ["RaftCommandIndex"] = index, }; fillJson?.Invoke(json, configurationJson, index); context.Write(writer, json); writer.Flush(); } } }
public static void Check <T>(RefAction <T> action, ref T arg) { try { action.Invoke(ref arg); } finally { WriteDebug(action, arg); ThrowIfError(action); } }
public static void ForEach <T>(this T[] array, RefAction <T> action) { if (action == null) { throw new ArgumentNullException(nameof(action)); } for (int i = 0; i < array.Length; i++) { action?.Invoke(ref array[i]); } }
/// <summary> /// refを使用した構造体への作用の反映 /// </summary> public static void ForEach <T>(this IList <T> list, RefAction <T> action) { if (action == null) { throw new ArgumentNullException(nameof(action)); } for (int i = 0; i < list.Count; ++i) { var item = list[i]; action?.Invoke(ref item); list[i] = item; } }
protected async Task DatabaseConfigurations(SetupFunc setupConfigurationFunc, string debug, string raftRequestId, RefAction beforeSetupConfiguration = null, Action <DynamicJsonValue, BlittableJsonReaderObject, long> fillJson = null, HttpStatusCode statusCode = HttpStatusCode.OK) { if (TryGetAllowedDbs(Database.Name, out var _, requireAdmin: true) == false) { return; } if (ResourceNameValidator.IsValidResourceName(Database.Name, ServerStore.Configuration.Core.DataDirectory.FullPath, out string errorMessage) == false) { throw new BadRequestException(errorMessage); } await ServerStore.EnsureNotPassiveAsync(); using (ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context)) { var configurationJson = await context.ReadForMemoryAsync(RequestBodyStream(), debug); beforeSetupConfiguration?.Invoke(Database.Name, ref configurationJson, context); var(index, _) = await setupConfigurationFunc(context, Database.Name, configurationJson, raftRequestId); await WaitForIndexToBeApplied(context, index); HttpContext.Response.StatusCode = (int)statusCode; using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream())) { var json = new DynamicJsonValue { ["RaftCommandIndex"] = index, }; fillJson?.Invoke(json, configurationJson, index); context.Write(writer, json); writer.Flush(); } } }