diff --git a/src/box/box.cc b/src/box/box.cc index 9e56cdcae9175af504effaafecdaff352f7506cc..c4595251944661b41c94b2b0d21230232b262233 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -41,6 +41,9 @@ extern "C" { #include <log_io.h> #include <pickle.h> #include <say.h> +#include <admin.h> +#include <iproto.h> +#include <replication.h> #include <stat.h> #include <tarantool.h> #include "tuple.h" @@ -264,6 +267,14 @@ box_reload_config(struct tarantool_cfg *old_conf, struct tarantool_cfg *new_conf box_enter_master_or_replica_mode(new_conf); } + if (old_conf->io_collect_interval != + new_conf->io_collect_interval) { + + ev_set_io_collect_interval(loop(), + new_conf->io_collect_interval); + } + if (old_conf->too_long_threshold != new_conf->too_long_threshold) + too_long_threshold = new_conf->too_long_threshold; return 0; } @@ -290,6 +301,7 @@ void box_init() { title("loading", NULL); + replication_prefork(cfg.snap_dir, cfg.wal_dir); stat_init(); tuple_init(cfg.slab_alloc_arena, cfg.slab_alloc_minimal, @@ -321,6 +333,11 @@ box_init() recovery_follow_local(recovery_state, cfg.wal_dir_rescan_delay); title("hot_standby", NULL); } + iproto_init(cfg.bind_ipaddr, cfg.primary_port, cfg.readahead); + admin_init(cfg.bind_ipaddr, cfg.admin_port); + if (cfg.io_collect_interval > 0) + ev_set_io_collect_interval(loop(), cfg.io_collect_interval); + too_long_threshold = cfg.too_long_threshold; } static void diff --git a/src/box/txn.cc b/src/box/txn.cc index 22ad5b442daae01e932bb51ff77aa1e036cd7300..622a6550606f618524c35ea1e7d951f44e6b52c7 100644 --- a/src/box/txn.cc +++ b/src/box/txn.cc @@ -29,12 +29,13 @@ #include "txn.h" #include "tuple.h" #include "space.h" -#include <cfg/tarantool_box_cfg.h> #include <tarantool.h> #include <recovery.h> #include <fiber.h> #include "request.h" /* for request_name */ +double too_long_threshold; + void txn_add_redo(struct txn *txn, struct request *request) { @@ -104,7 +105,7 @@ txn_commit(struct txn *txn) res = wal_write(recovery_state, packet); stop = ev_now(loop()); - if (stop - start > cfg.too_long_threshold) { + if (stop - start > too_long_threshold) { say_warn("too long %s: %.3f sec", iproto_request_name(packet->code), stop - start); diff --git a/src/box/txn.h b/src/box/txn.h index b066ebcd13fd7a1008ca5584c6214c19362dd456..e2e22bbb4d29eaafaadeb53133883029db723c05 100644 --- a/src/box/txn.h +++ b/src/box/txn.h @@ -31,6 +31,7 @@ #include "index.h" #include "trigger.h" +extern double too_long_threshold; struct tuple; struct space; diff --git a/src/iobuf.h b/src/iobuf.h index 79cb689ae5e336f200e895b2d7186bf5903a3753..e8aaa3ada549cbe1b26b780b84a6eaabc1c64c13 100644 --- a/src/iobuf.h +++ b/src/iobuf.h @@ -39,7 +39,7 @@ struct ev_io; /** {{{ Input buffer. * * Continuous piece of memory to store input. - * Allocated in factors of cfg.readahead. + * Allocated in factors of 'readahead'. * Maintains position of the data "to be processed". * * Typical use case: diff --git a/src/iproto.cc b/src/iproto.cc index 560762dcd8bd9d220887bb3709a64c530316a210..cef0f52e1bf72bef3a1188aaf397a7e0ec8e7225 100644 --- a/src/iproto.cc +++ b/src/iproto.cc @@ -802,8 +802,9 @@ iproto_on_accept(struct evio_service * /* service */, int fd, /** Initialize a read-write port. */ void -iproto_init(const char *bind_ipaddr, int primary_port) +iproto_init(const char *bind_ipaddr, int primary_port, int readahead) { + iobuf_init(readahead); /* Run a primary server. */ if (primary_port == 0) return; diff --git a/src/iproto.h b/src/iproto.h index 0a494b31e8992524414dfd8a74ce1e9e573d247a..89627d8b57e81ec2bf25bcb99bf73175bd9385c9 100644 --- a/src/iproto.h +++ b/src/iproto.h @@ -29,5 +29,5 @@ * SUCH DAMAGE. */ void -iproto_init(const char *bind_ipaddr, int primary_port); +iproto_init(const char *bind_ipaddr, int primary_port, int readahead); #endif diff --git a/src/replication.cc b/src/replication.cc index eca1dd64528ea3e635451015ec2f57bb187d9b6e..1d86e9f32a2df964e04fe2e005b7abe8b1ff82c5 100644 --- a/src/replication.cc +++ b/src/replication.cc @@ -29,10 +29,6 @@ #include <replication.h> #include <say.h> #include <fiber.h> -extern "C" { -#include <cfg/warning.h> -#include <cfg/tarantool_box_cfg.h> -} /* extern "C" */ #include <stddef.h> #include <stddef.h> @@ -78,6 +74,9 @@ extern "C" { * children and exits. */ static int master_to_spawner_socket; +static char cfg_wal_dir[PATH_MAX]; +static char cfg_snap_dir[PATH_MAX]; + /** * State of a replica. We only need one global instance @@ -154,8 +153,10 @@ replication_relay_loop(); /** Pre-fork replication spawner process. */ void -replication_prefork() +replication_prefork(const char *snap_dir, const char *wal_dir) { + snprintf(cfg_snap_dir, sizeof(cfg_snap_dir), "%s", snap_dir); + snprintf(cfg_wal_dir, sizeof(cfg_wal_dir), "%s", wal_dir); int sockpair[2]; /* * Create UNIX sockets to communicate between the main and @@ -696,7 +697,7 @@ replication_relay_loop() ev_io_start(loop(), &sock_read_ev); /* Initialize the recovery process */ - recovery_init(cfg.snap_dir, cfg.wal_dir, + recovery_init(cfg_snap_dir, cfg_wal_dir, replication_relay_send_row, NULL, NULL, INT32_MAX); /* diff --git a/src/replication.h b/src/replication.h index b42c15c36a0d6259ed843119d4b7fbf8225a9521..291f4306b8f18257b147980f95366878dce584c8 100644 --- a/src/replication.h +++ b/src/replication.h @@ -37,7 +37,7 @@ * @return None. Panics and exits on error. */ void -replication_prefork(); +replication_prefork(const char *snap_dir, const char *wal_dir); /** * Subscribe a replica to updates. diff --git a/src/tarantool.cc b/src/tarantool.cc index 88fc0b9c3bd0cb1dfa61d24ebd10992f59bc75b4..cd5f569d2b699a487f01d5f209cbf897ffbbb223 100644 --- a/src/tarantool.cc +++ b/src/tarantool.cc @@ -45,12 +45,8 @@ #if defined(TARGET_OS_LINUX) && defined(HAVE_PRCTL_H) # include <sys/prctl.h> #endif -#include <admin.h> -#include <replication.h> #include <fiber.h> #include <coeio.h> -#include "iobuf.h" -#include <iproto.h> #include "mutex.h" #include <crc32.h> #include "memory.h" @@ -166,16 +162,6 @@ load_cfg(struct tarantool_cfg *conf, int32_t check_rdonly) return box_check_config(conf); } -static int -core_reload_config(const struct tarantool_cfg *old_conf, - const struct tarantool_cfg *new_conf) -{ - if (old_conf->io_collect_interval != new_conf->io_collect_interval) - ev_set_io_collect_interval(loop(), new_conf->io_collect_interval); - - return 0; -} - int reload_cfg() { @@ -233,10 +219,6 @@ reload_cfg() return -1; } - /* Process wal-writer-related changes. */ - if (core_reload_config(&cfg, &new_cfg) != 0) - return -1; - /* Now pass the config to the module, to take action. */ if (box_reload_config(&cfg, &new_cfg) != 0) return -1; @@ -710,12 +692,15 @@ main(int argc, char **argv) if (cfg.background) { if (cfg.logger == NULL) { - say_crit("--background requires 'logger' configuration option to be set"); + say_crit("'background' requires 'logger' configuration option to be set"); + exit(EXIT_FAILURE); + } + if (cfg.pid_file == NULL) { + say_crit("'background' requires 'pid_file' configuration option to be set"); exit(EXIT_FAILURE); } background(); - } - else { + } else { create_pid(); } @@ -737,20 +722,16 @@ main(int argc, char **argv) atexit(tarantool_free); fiber_init(); - replication_prefork(); - iobuf_init(cfg.readahead); coeio_init(); signal_init(); + session_init(); + tarantool_lua_init(); bool start_loop = false; try { - tarantool_lua_init(); - box_init(); tarantool_lua_load_cfg(&cfg); int events = ev_activecnt(loop()); - iproto_init(cfg.bind_ipaddr, cfg.primary_port); - admin_init(cfg.bind_ipaddr, cfg.admin_port); - session_init(); + box_init(); /* * Load user init script. The script should have access * to Tarantool Lua API (box.cfg, box.fiber, etc...) that @@ -762,8 +743,6 @@ main(int argc, char **argv) region_free(&fiber()->gc); if (start_loop) { say_crit("entering the event loop"); - if (cfg.io_collect_interval > 0) - ev_set_io_collect_interval(loop(), cfg.io_collect_interval); ev_now_update(loop()); start_time = ev_now(loop()); signal_start();