diff --git a/cfg/tarantool_box_cfg.c b/cfg/tarantool_box_cfg.c index 262bbf78272effb71f9c0cd9f10cc7875acb183e..71301db96394f372497b2b45ad237f86af3a9cf1 100644 --- a/cfg/tarantool_box_cfg.c +++ b/cfg/tarantool_box_cfg.c @@ -1818,10 +1818,6 @@ check_cfg_tarantool_cfg(tarantool_cfg *c) { res++; out_warning(CNF_NOTSET, "Option '%s' is not set (or has a default value)", dumpOptDef(_name__primary_port)); } - if (c->space == NULL) { - res++; - out_warning(CNF_NOTSET, "Option '%s' is not set (or has a default value)", dumpOptDef(_name__space)); - } i->idx_name__space = 0; while (c->space && c->space[i->idx_name__space]) { if (c->space[i->idx_name__space]->__confetti_flags & CNF_FLAG_STRUCT_NOTSET) { diff --git a/mod/box/box.m b/mod/box/box.m index 660daf2ae0bacf09cb63ff75e7f6051f672c2de3..6ce58161c4de66c59e7c6cbad8ae7511ed49becb 100644 --- a/mod/box/box.m +++ b/mod/box/box.m @@ -901,17 +901,14 @@ space_free(void) } } -void -space_init(void) +static void +space_config(void) { - space = palloc(eter_pool, sizeof(struct space) * BOX_SPACE_MAX); - for (int i = 0; i < BOX_SPACE_MAX; i++) { - space[i].enabled = false; - for (int j = 0; j < BOX_INDEX_MAX; j++) { - space[i].index[j] = [[Index alloc] init]; - space[i].index[j]->key_cardinality = 0; - } + /* exit if no spaces are configured */ + if (cfg.space == NULL) { + return; } + /* fill box spaces */ for (int i = 0; cfg.space[i] != NULL; ++i) { tarantool_cfg_space *cfg_space = cfg.space[i]; @@ -983,6 +980,25 @@ space_init(void) space[i].n = i; say_info("space %i successfully configured", i); } +} + +void +space_init(void) +{ + /* allocate and initialize space memory */ + space = palloc(eter_pool, sizeof(struct space) * BOX_SPACE_MAX); + for (int i = 0; i < BOX_SPACE_MAX; i++) { + space[i].enabled = false; + for (int j = 0; j < BOX_INDEX_MAX; j++) { + space[i].index[j] = [[Index alloc] init]; + space[i].index[j]->key_cardinality = 0; + } + } + + /* configure regular spaces */ + space_config(); + + /* configure memcached space */ memcached_space_init(); } @@ -1136,48 +1152,14 @@ box_leave_local_standby_mode(void *data __attribute__((unused))) box_enter_master_or_replica_mode(&cfg); } -i32 -mod_check_config(struct tarantool_cfg *conf) +static i32 +check_spaces(struct tarantool_cfg *conf) { - /* replication & hot standby modes can not work together */ - if (conf->replication_source != NULL && conf->local_hot_standby > 0) { - out_warning(0, "replication and local hot standby modes " - "can't be enabled simultaneously"); - return -1; - } - - /* check replication mode */ - if (conf->replication_source != NULL) { - /* check replication port */ - char ip_addr[32]; - int port; - - if (sscanf(conf->replication_source, "%31[^:]:%i", - ip_addr, &port) != 2) { - out_warning(0, "replication source IP address is not recognized"); - return -1; - } - if (port <= 0 || port >= USHRT_MAX) { - out_warning(0, "invalid replication source port value: %i", port); - return -1; - } - } - - /* check primary port */ - if (conf->primary_port != 0 && - (conf->primary_port <= 0 || conf->primary_port >= USHRT_MAX)) { - out_warning(0, "invalid primary port value: %i", conf->primary_port); - return -1; - } - - /* check secondary port */ - if (conf->secondary_port != 0 && - (conf->secondary_port <= 0 || conf->secondary_port >= USHRT_MAX)) { - out_warning(0, "invalid secondary port value: %i", conf->primary_port); - return -1; + /* exit if no spaces are configured */ + if (conf->space == NULL) { + return 0; } - /* check configured spaces */ for (size_t i = 0; conf->space[i] != NULL; ++i) { typeof(conf->space[i]) space = conf->space[i]; @@ -1311,6 +1293,62 @@ mod_check_config(struct tarantool_cfg *conf) } } } + + return 0; +} + +i32 +mod_check_config(struct tarantool_cfg *conf) +{ + /* replication & hot standby modes can not work together */ + if (conf->replication_source != NULL && conf->local_hot_standby > 0) { + out_warning(0, "replication and local hot standby modes " + "can't be enabled simultaneously"); + return -1; + } + + /* check replication mode */ + if (conf->replication_source != NULL) { + /* check replication port */ + char ip_addr[32]; + int port; + + if (sscanf(conf->replication_source, "%31[^:]:%i", + ip_addr, &port) != 2) { + out_warning(0, "replication source IP address is not recognized"); + return -1; + } + if (port <= 0 || port >= USHRT_MAX) { + out_warning(0, "invalid replication source port value: %i", port); + return -1; + } + } + + /* check primary port */ + if (conf->primary_port != 0 && + (conf->primary_port <= 0 || conf->primary_port >= USHRT_MAX)) { + out_warning(0, "invalid primary port value: %i", conf->primary_port); + return -1; + } + + /* check secondary port */ + if (conf->secondary_port != 0 && + (conf->secondary_port <= 0 || conf->secondary_port >= USHRT_MAX)) { + out_warning(0, "invalid secondary port value: %i", conf->primary_port); + return -1; + } + + /* check if at least one space is defined */ + if (conf->space == NULL && conf->memcached_port == 0) { + out_warning(0, "at least one space or memcached port must be defined"); + return -1; + } + + /* check configured spaces */ + if (check_spaces(conf) != 0) { + return -1; + } + /* check memcached configuration */ if (memcached_check_config(conf) != 0) { return -1; diff --git a/mod/box/box_cfg.cfg_tmpl b/mod/box/box_cfg.cfg_tmpl index 22cf25162cd7746829e34e3ea7c8b8658eba3111..d8b124e5cf4746b33aa2806990ed05ae1a90e98e 100644 --- a/mod/box/box_cfg.cfg_tmpl +++ b/mod/box/box_cfg.cfg_tmpl @@ -86,4 +86,4 @@ space = [ }, ro, required ], required }, ro -], ro, required +], ro diff --git a/test/box/reconfigure.result b/test/box/reconfigure.result index 71a03e4e6fd2211f049e7c23c09e76c069478829..f8eb5944174b8f765ebb450aff92f7cbd778c62b 100644 --- a/test/box/reconfigure.result +++ b/test/box/reconfigure.result @@ -33,7 +33,7 @@ fail: reload configuration --- fail: - - Option 'space' is not set (or has a default value) + - at least one space or memcached port must be defined ... reload configuration ---