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();
                }
            }
        }
Esempio n. 2
0
 public static void Check <T>(RefAction <T> action, ref T arg)
 {
     try
     {
         action.Invoke(ref arg);
     }
     finally
     {
         WriteDebug(action, arg);
         ThrowIfError(action);
     }
 }
Esempio n. 3
0
    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]);
        }
    }
Esempio n. 4
0
        /// <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;
            }
        }
Esempio n. 5
0
        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();
                }
            }
        }