From 7dd10014839a5881e1960912445ce51160f37010 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja.osipov@gmail.com> Date: Fri, 8 Jul 2011 18:34:27 +0400 Subject: [PATCH] feature-feeder-in-core: review fixes Update comments in the configuration file. Remove custom proc title for replication, use custom_proc_title of the main process. Renames. --- cfg/core_cfg.cfg_tmpl | 10 +- cfg/tarantool_box_cfg.c | 37 --- cfg/tarantool_box_cfg.cfg | 10 +- cfg/tarantool_box_cfg.h | 13 +- core/CMakeLists.txt | 2 +- core/{replicator.m => replication.m} | 263 ++++++++---------- core/tarantool.m | 26 +- include/{replicator.h => replication.h} | 34 +-- include/tarantool.h | 1 + mod/box/box.m | 11 - test/box/show.result | 1 - test/box_replication/cfg/hot_standby.cfg | 2 +- test/box_replication/cfg/master.cfg | 2 +- .../box_replication/cfg/master_to_replica.cfg | 2 +- test/box_replication/cfg/replica.cfg | 2 +- .../box_replication/cfg/replica_to_master.cfg | 2 +- 16 files changed, 163 insertions(+), 255 deletions(-) rename core/{replicator.m => replication.m} (71%) rename include/{replicator.h => replication.h} (67%) diff --git a/cfg/core_cfg.cfg_tmpl b/cfg/core_cfg.cfg_tmpl index e235845fd0..b73e138195 100644 --- a/cfg/core_cfg.cfg_tmpl +++ b/cfg/core_cfg.cfg_tmpl @@ -1,8 +1,8 @@ # username to switch to username=NULL, ro -# tarantool bind ip address -# all tarantools (INADDR_ANY defaul value) +# tarantool bind ip address, applies to master +# and replication ports. INADDR_ANY is the default value. bind_ipaddr="INADDR_ANY", ro # save core on abort/assert @@ -13,13 +13,9 @@ coredump=0, ro # used for admin's connections admin_port=0, ro -# replication port -# replicator accepts it's clients on bind_ipaddr:replication_port +# Replication clients should use this port (bind_ipaddr:replication_port). replication_port=0, ro -# replicator custom process title -replicator_custom_proc_title=NULL, ro - # Log verbosity, possible values: ERROR=1, CRIT=2, WARN=3, INFO=4(default), DEBUG=5 log_level=4 diff --git a/cfg/tarantool_box_cfg.c b/cfg/tarantool_box_cfg.c index 1fc091e5ac..5bd8a1c829 100644 --- a/cfg/tarantool_box_cfg.c +++ b/cfg/tarantool_box_cfg.c @@ -33,7 +33,6 @@ init_tarantool_cfg(tarantool_cfg *c) { c->coredump = 0; c->admin_port = 0; c->replication_port = 0; - c->replicator_custom_proc_title = NULL; c->log_level = 0; c->slab_alloc_arena = 0; c->slab_alloc_minimal = 0; @@ -79,7 +78,6 @@ fill_default_tarantool_cfg(tarantool_cfg *c) { c->coredump = 0; c->admin_port = 0; c->replication_port = 0; - c->replicator_custom_proc_title = NULL; c->log_level = 4; c->slab_alloc_arena = 1; c->slab_alloc_minimal = 64; @@ -167,9 +165,6 @@ static NameAtom _name__admin_port[] = { static NameAtom _name__replication_port[] = { { "replication_port", -1, NULL } }; -static NameAtom _name__replicator_custom_proc_title[] = { - { "replicator_custom_proc_title", -1, NULL } -}; static NameAtom _name__log_level[] = { { "log_level", -1, NULL } }; @@ -408,17 +403,6 @@ acceptValue(tarantool_cfg* c, OptDef* opt, int check_rdonly) { return CNF_RDONLY; c->replication_port = i32; } - else if ( cmpNameAtoms( opt->name, _name__replicator_custom_proc_title) ) { - if (opt->paramType != stringType ) - return CNF_WRONGTYPE; - c->__confetti_flags &= ~CNF_FLAG_STRUCT_NOTSET; - errno = 0; - if (check_rdonly && ( (opt->paramValue.stringval == NULL && c->replicator_custom_proc_title == NULL) || strcmp(opt->paramValue.stringval, c->replicator_custom_proc_title) != 0)) - return CNF_RDONLY; - c->replicator_custom_proc_title = (opt->paramValue.stringval) ? strdup(opt->paramValue.stringval) : NULL; - if (opt->paramValue.stringval && c->replicator_custom_proc_title == NULL) - return CNF_NOMEMORY; - } else if ( cmpNameAtoms( opt->name, _name__log_level) ) { if (opt->paramType != numberType ) return CNF_WRONGTYPE; @@ -1101,7 +1085,6 @@ typedef enum IteratorState { S_name__coredump, S_name__admin_port, S_name__replication_port, - S_name__replicator_custom_proc_title, S_name__log_level, S_name__slab_alloc_arena, S_name__slab_alloc_minimal, @@ -1222,16 +1205,6 @@ tarantool_cfg_iterator_next(tarantool_cfg_iterator_t* i, tarantool_cfg *c, char } sprintf(*v, "%"PRId32, c->replication_port); snprintf(buf, PRINTBUFLEN-1, "replication_port"); - i->state = S_name__replicator_custom_proc_title; - return buf; - case S_name__replicator_custom_proc_title: - *v = (c->replicator_custom_proc_title) ? strdup(c->replicator_custom_proc_title) : NULL; - if (*v == NULL && c->replicator_custom_proc_title) { - free(i); - out_warning(CNF_NOMEMORY, "No memory to output value"); - return NULL; - } - snprintf(buf, PRINTBUFLEN-1, "replicator_custom_proc_title"); i->state = S_name__log_level; return buf; case S_name__log_level: @@ -1868,9 +1841,6 @@ dup_tarantool_cfg(tarantool_cfg* dst, tarantool_cfg* src) { dst->coredump = src->coredump; dst->admin_port = src->admin_port; dst->replication_port = src->replication_port; - dst->replicator_custom_proc_title = src->replicator_custom_proc_title == NULL ? NULL : strdup(src->replicator_custom_proc_title); - if (src->replicator_custom_proc_title != NULL && dst->replicator_custom_proc_title == NULL) - return CNF_NOMEMORY; dst->log_level = src->log_level; dst->slab_alloc_arena = src->slab_alloc_arena; dst->slab_alloc_minimal = src->slab_alloc_minimal; @@ -1981,8 +1951,6 @@ destroy_tarantool_cfg(tarantool_cfg* c) { free(c->username); if (c->bind_ipaddr != NULL) free(c->bind_ipaddr); - if (c->replicator_custom_proc_title != NULL) - free(c->replicator_custom_proc_title); if (c->work_dir != NULL) free(c->work_dir); if (c->pid_file != NULL) @@ -2083,11 +2051,6 @@ cmp_tarantool_cfg(tarantool_cfg* c1, tarantool_cfg* c2, int only_check_rdonly) { return diff; } - if (confetti_strcmp(c1->replicator_custom_proc_title, c2->replicator_custom_proc_title) != 0) { - snprintf(diff, PRINTBUFLEN - 1, "%s", "c->replicator_custom_proc_title"); - - return diff; -} if (!only_check_rdonly) { if (c1->log_level != c2->log_level) { snprintf(diff, PRINTBUFLEN - 1, "%s", "c->log_level"); diff --git a/cfg/tarantool_box_cfg.cfg b/cfg/tarantool_box_cfg.cfg index fa4e2d58de..28a534e676 100644 --- a/cfg/tarantool_box_cfg.cfg +++ b/cfg/tarantool_box_cfg.cfg @@ -2,8 +2,8 @@ # username to switch to username = NULL -# tarantool bind ip address -# all tarantools (INADDR_ANY defaul value) +# tarantool bind ip address, applies to master +# and replication ports. INADDR_ANY is the default value. bind_ipaddr = "INADDR_ANY" # save core on abort/assert @@ -14,13 +14,9 @@ coredump = 0 # used for admin's connections admin_port = 0 -# replication port -# replicator accepts it's clients on bind_ipaddr:replication_port +# Replication clients should use this port (bind_ipaddr:replication_port). replication_port = 0 -# replicator custom process title -replicator_custom_proc_title = NULL - # Log verbosity, possible values: ERROR=1, CRIT=2, WARN=3, INFO=4(default), DEBUG=5 log_level = 4 diff --git a/cfg/tarantool_box_cfg.h b/cfg/tarantool_box_cfg.h index 22b8d5f07c..4bca0ad8c4 100644 --- a/cfg/tarantool_box_cfg.h +++ b/cfg/tarantool_box_cfg.h @@ -2,7 +2,6 @@ #define tarantool_cfg_CFG_H #include <stdio.h> -#include <stdbool.h> #include <sys/types.h> /* @@ -41,8 +40,8 @@ typedef struct tarantool_cfg { char* username; /* - * tarantool bind ip address - * all tarantools (INADDR_ANY defaul value) + * tarantool bind ip address, applies to master + * and replication ports. INADDR_ANY is the default value. */ char* bind_ipaddr; @@ -58,15 +57,9 @@ typedef struct tarantool_cfg { */ int32_t admin_port; - /* - * replication port - * replicator accepts it's clients on bind_ipaddr:replication_port - */ + /* Replication clients should use this port (bind_ipaddr:replication_port). */ int32_t replication_port; - /* replicator custom process title */ - char* replicator_custom_proc_title; - /* Log verbosity, possible values: ERROR=1, CRIT=2, WARN=3, INFO=4(default), DEBUG=5 */ int32_t log_level; diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 8f7a5f95c0..c4cc786b6f 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -52,7 +52,7 @@ set (recompiled_core_sources ${CMAKE_SOURCE_DIR}/core/tarantool.m ${CMAKE_SOURCE_DIR}/core/say.m ${CMAKE_SOURCE_DIR}/core/admin.m - ${CMAKE_SOURCE_DIR}/core/replicator.m + ${CMAKE_SOURCE_DIR}/core/replication.m ${CMAKE_SOURCE_DIR}/core/fiber.m PARENT_SCOPE) set (common_sources tbuf.m palloc.m util.m diff --git a/core/replicator.m b/core/replication.m similarity index 71% rename from core/replicator.m rename to core/replication.m index 6b389ac6d5..100da89d74 100644 --- a/core/replicator.m +++ b/core/replication.m @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#include <replicator.h> +#include <replication.h> #include <say.h> #include <fiber.h> #include TARANTOOL_CONFIG @@ -39,19 +39,6 @@ #include <arpa/inet.h> #include "fiber.h" - -/** replicator process context struct */ -struct replicator_process { - /** communication socket. */ - int sock; - /** waitpid need */ - bool need_waitpid; - /** replicator is done */ - bool is_done; - /** child process counts */ - u32 child_count; -}; - static int replicator_socks[2]; /*-----------------------------------------------------------------------------*/ @@ -70,8 +57,7 @@ acceptor_handler(void *data); static void sender_handler(void *data); -/** - * Read sender's fiber inbox. +/** Read sender's fiber inbox. * * @return On success, a file descriptor is returned. On error, -1 is returned. */ @@ -79,54 +65,56 @@ static int sender_read_inbox(); /** - * Send file descriptor to replicator process. + * Send file descriptor to replication relay spawner. * * @param fd the sending file descriptor. */ static void sender_send_sock(int sock); +/** Replication spawner process */ +static struct spawner { + /** communication socket. */ + int sock; + /** waitpid need */ + bool need_waitpid; + /** got signal */ + bool is_done; + /** child process counts */ + u32 child_count; +} spawner; -/*-----------------------------------------------------------------------------*/ -/* replicator process */ -/*-----------------------------------------------------------------------------*/ - -/** replicator process context */ -static struct replicator_process replicator_process; - -/** - * Initialize replicator spawner process. +/** Initialize spawner process. * - * @param sock the socket between tarantool and replicator. + * @param sock the socket between the main process and the spawner. */ static void spawner_init(int sock); /** - * Replicator spawner process main loop. + * Spawner main loop. */ static void spawner_main_loop(); /** - * Replicator spawner shutdown. + * Shutdown spawner and all its children. */ static void spawner_shutdown(); -/** - * Replicator's spawner process signals handler. +/** Replication spawner process signal handler. * * @param signal is signal number. */ static void -spawner_signals_handler(int signal); +spawner_signal_handler(int signal); /** - * Process waitpid childs. + * Process waitpid children. */ static void -spawner_process_wait_childs(); +spawner_wait_children(); /** * Receive replication client socket from main process. @@ -142,95 +130,82 @@ spawner_recv_client_sock(int *client_sock); * @return On success, a zero is returned. On error, -1 is returned. */ static int -spawner_create_client_handler(int client_sock); +spawner_create_replication_relay(int client_sock); /** - * Replicator spawner shutdown: kill childs. + * Replicator spawner shutdown: kill children. */ static void -spawner_shutdown_kill_childs(); +spawner_shutdown_kill_children(); /** - * Replicator spawner shutdown: wait childs. + * Replicator spawner shutdown: wait children. */ static int -spawner_shutdown_wait_childs(); +spawner_shutdown_wait_children(); /** * Initialize replicator's service process. */ static void -client_handler_init(int client_sock); +replication_relay_loop(int client_sock); /** * Receive data event to replication socket handler */ static void -client_handler_recv(struct ev_io *w, int revents); +replication_relay_recv(struct ev_io *w, int revents); /** * Send to row to client. */ static int -client_handler_send_row(struct recovery_state *r __attribute__((unused)), struct tbuf *t); +replication_relay_send_row(struct recovery_state *r __attribute__((unused)), struct tbuf *t); /*-----------------------------------------------------------------------------*/ -/* replicatior module */ +/* replication module */ /*-----------------------------------------------------------------------------*/ -/** Check replicator module configuration. */ -u32 -replicator_check_config(struct tarantool_cfg *config) +/** Check replication module configuration. */ +int +replication_check_config(struct tarantool_cfg *config) { - if (config->replication_port == 0) { - /* port not defined or setted to zero, replicator disabled */ - return 0; - } - if (config->replication_port < 0 || - config->replication_port >= 65536) { - say_error("replicator: invalid port: %"PRId32, config->replication_port); + config->replication_port >= USHRT_MAX) { + say_error("invalid replication port value: %"PRId32, + config->replication_port); return -1; } return 0; } -/** Reload replicator module configuration. */ +/** Pre-fork replication spawner process. */ void -replicator_reload_config(struct tarantool_cfg *config __attribute__((unused))) -{} - -/** Pre-fork replicator spawner process. */ -void -replicator_prefork() +replication_prefork() { if (cfg.replication_port == 0) { - /* replicator not needed, leave init function */ + /* replication is not needed, do nothing */ return; } - - if (cfg.replicator_custom_proc_title == NULL) { - cfg.replicator_custom_proc_title = ""; - } - - /* create communication sockes between tarantool and replicator processes via UNIX sockets*/ - if (socketpair(PF_LOCAL, SOCK_STREAM, 0, replicator_socks) != 0) { + /* + * Create UNIX sockets to communicate between the main and + * spawner processes. + */ + if (socketpair(PF_LOCAL, SOCK_STREAM, 0, replicator_socks) != 0) panic_syserror("socketpair"); - } - /* create replicator process */ + /* create spawner */ pid_t pid = fork(); - if (pid == -1) { + if (pid == -1) panic_syserror("fork"); - } if (pid != 0) { /* parent process: tarantool */ close(replicator_socks[1]); } else { - /* child process: replicator */ + /* child process: spawner */ close(replicator_socks[0]); spawner_init(replicator_socks[1]); } @@ -238,12 +213,10 @@ replicator_prefork() /** Intialize tarantool's replicator module. */ void -replicator_init() +replication_init() { - if (cfg.replication_port == 0) { - /* replicator not needed, leave init function */ - return; - } + if (cfg.replication_port == 0) + return; /* replication is not in use */ char fiber_name[FIBER_NAME_MAXLEN]; /* create sender fiber */ @@ -351,7 +324,7 @@ sender_read_inbox() return *((int *) message->msg->data); } -/** Send file descriptor to replicator process. */ +/** Send file descriptor to the spawner. */ static void sender_send_sock(int client_sock) { @@ -377,46 +350,43 @@ sender_send_sock(int client_sock) control_message->cmsg_type = SCM_RIGHTS; *((int *) CMSG_DATA(control_message)) = client_sock; - /* wait, when interprocess comm. socke will ready for write */ + /* wait, when interprocess comm. socket is ready for write */ fiber_io_start(EV_WRITE); fiber_io_yield(); - /* send client socket to replicator porcess */ + /* send client socket to the spawner */ if (sendmsg(fiber->fd, &msg, 0) < 0) { say_syserror("sendmsg"); } fiber_io_stop(EV_WRITE); - /* close client sock in the main process */ + /* close client socket in the main process */ close(client_sock); } /*-----------------------------------------------------------------------------*/ -/* replicator process */ +/* spawner process */ /*-----------------------------------------------------------------------------*/ -/** Initialize replicator spawner process. */ +/** Initialize the spawner. */ + static void spawner_init(int sock) { char name[sizeof(fiber->name)]; struct sigaction sa; - if (cfg.replicator_custom_proc_title == NULL) { - cfg.replicator_custom_proc_title = ""; - } - - snprintf(name, sizeof(name), "replicator%s/spawner", cfg.replicator_custom_proc_title); + snprintf(name, sizeof(name), "replication%s/spawner", custom_proc_title); fiber_set_name(fiber, name); set_proc_title(name); /* init replicator process context */ - memset(&replicator_process, 0, sizeof(replicator_process)); - replicator_process.sock = sock; - replicator_process.need_waitpid = false; - replicator_process.is_done = false; - replicator_process.child_count = 0; + memset(&spawner, 0, sizeof(spawner)); + spawner.sock = sock; + spawner.need_waitpid = false; + spawner.is_done = false; + spawner.child_count = 0; - /* init signals */ + /* init signal */ memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; @@ -426,7 +396,7 @@ spawner_init(int sock) } /* set handler for signals: SIGHUP, SIGINT, SIGTERM and SIGCHLD */ - sa.sa_handler = spawner_signals_handler; + sa.sa_handler = spawner_signal_handler; if ((sigaction(SIGHUP, &sa, NULL) == -1) || (sigaction(SIGINT, &sa, NULL) == -1) || @@ -443,11 +413,11 @@ spawner_init(int sock) static void spawner_main_loop() { - while (!replicator_process.is_done) { + while (!spawner.is_done) { int client_sock; - if (replicator_process.need_waitpid) { - spawner_process_wait_childs(); + if (spawner.need_waitpid) { + spawner_wait_children(); } if (spawner_recv_client_sock(&client_sock) != 0) { @@ -455,7 +425,7 @@ spawner_main_loop() } if (client_sock > 0) { - spawner_create_client_handler(client_sock); + spawner_create_replication_relay(client_sock); } } @@ -468,34 +438,34 @@ spawner_shutdown() { say_info("shutdown"); - /* kill all childs */ - spawner_shutdown_kill_childs(); + /* kill all children */ + spawner_shutdown_kill_children(); /* close socket */ - close(replicator_process.sock); + close(spawner.sock); exit(EXIT_SUCCESS); } -/** Replicator's spawner process signals handler. */ -static void spawner_signals_handler(int signal) +/** Replicator's spawner process signal handler. */ +static void spawner_signal_handler(int signal) { switch (signal) { case SIGHUP: case SIGINT: case SIGTERM: - replicator_process.is_done = true; + spawner.is_done = true; break; case SIGCHLD: - replicator_process.need_waitpid = true; + spawner.need_waitpid = true; break; } } -/** Process waitpid childs. */ +/** Process waitpid children. */ static void -spawner_process_wait_childs() +spawner_wait_children() { - while (replicator_process.child_count > 0) { + while (spawner.child_count > 0) { int exit_status; pid_t pid; @@ -511,10 +481,10 @@ spawner_process_wait_childs() } say_info("child finished: pid = %d, exit status = %d", pid, WEXITSTATUS(exit_status)); - replicator_process.child_count--; + spawner.child_count--; } - replicator_process.need_waitpid = false; + spawner.need_waitpid = false; } /** Receive replication client socket from main process. */ @@ -537,7 +507,7 @@ spawner_recv_client_sock(int *client_sock) msg.msg_control = control_buf; msg.msg_controllen = sizeof(control_buf); - if (recvmsg(replicator_process.sock, &msg, 0) < 0) { + if (recvmsg(spawner.sock, &msg, 0) < 0) { if (errno == EINTR) { *client_sock = 0; return 0; @@ -560,7 +530,7 @@ spawner_recv_client_sock(int *client_sock) /** Create replicator's client handler process. */ static int -spawner_create_client_handler(int client_sock) +spawner_create_replication_relay(int client_sock) { pid_t pid; @@ -571,29 +541,29 @@ spawner_create_client_handler(int client_sock) } if (pid == 0) { - client_handler_init(client_sock); + replication_relay_loop(client_sock); } else { say_info("replicator client handler spawned: pid = %d", pid); - replicator_process.child_count++; + spawner.child_count++; close(client_sock); } return 0; } -/** Replicator spawner shutdown: kill childs. */ +/** Replicator spawner shutdown: kill children. */ static void -spawner_shutdown_kill_childs() +spawner_shutdown_kill_children() { int result = 0; /* check child process count */ - if (replicator_process.child_count == 0) { + if (spawner.child_count == 0) { return; } - /* send terminate signals to childs */ - say_info("send SIGTERM to %"PRIu32" childs", replicator_process.child_count); + /* send terminate signal to children */ + say_info("send SIGTERM to %"PRIu32" children", spawner.child_count); result = kill(0, SIGTERM); if (result != 0) { say_syserror("kill"); @@ -601,20 +571,20 @@ spawner_shutdown_kill_childs() } /* wait when process is down */ - result = spawner_shutdown_wait_childs(); + result = spawner_shutdown_wait_children(); if (result != 0) { return; } /* check child process count */ - if (replicator_process.child_count == 0) { - say_info("all childs terminated"); + if (spawner.child_count == 0) { + say_info("all children terminated"); return; } - say_info("%"PRIu32" childs still alive", replicator_process.child_count); + say_info("%"PRIu32" children still alive", spawner.child_count); - /* send terminate signals to childs */ - say_info("send SIGKILL to %"PRIu32" childs", replicator_process.child_count); + /* send terminate signal to children */ + say_info("send SIGKILL to %"PRIu32" children", spawner.child_count); result = kill(0, SIGKILL); if (result != 0) { say_syserror("kill"); @@ -622,28 +592,28 @@ spawner_shutdown_kill_childs() } /* wait when process is down */ - result = spawner_shutdown_wait_childs(); + result = spawner_shutdown_wait_children(); if (result != 0) { return; } - say_info("all childs terminated"); + say_info("all children terminated"); } -/** Replicator spawner shutdown: wait childs. */ +/** Replicator spawner shutdown: wait children. */ static int -spawner_shutdown_wait_childs() +spawner_shutdown_wait_children() { const u32 wait_sec = 5; struct timeval tv; - say_info("wait for childs %"PRIu32" seconds", wait_sec); + say_info("wait for children %"PRIu32" seconds", wait_sec); tv.tv_sec = wait_sec; tv.tv_usec = 0; - /* wait childs process */ - spawner_process_wait_childs(); - while (replicator_process.child_count > 0) { + /* wait children process */ + spawner_wait_children(); + while (spawner.child_count > 0) { int result; /* wait EINTR or timeout */ @@ -654,8 +624,8 @@ spawner_shutdown_wait_childs() return - 1; } - /* wait childs process */ - spawner_process_wait_childs(); + /* wait children process */ + spawner_wait_children(); /* check timeout */ if (tv.tv_sec == 0 && tv.tv_usec == 0) { @@ -667,9 +637,10 @@ spawner_shutdown_wait_childs() return 0; } -/** Initialize replicator's service process. */ + +/** The main loop of replication client service process. */ static void -client_handler_init(int client_sock) +replication_relay_loop(int client_sock) { char name[sizeof(fiber->name)]; struct sigaction sa; @@ -681,9 +652,9 @@ client_handler_init(int client_sock) fiber->has_peer = true; fiber->fd = client_sock; - /* set replicator name */ + /* set process title and fiber name */ memset(name, 0, sizeof(name)); - snprintf(name, sizeof(name), "replicator%s/handler", cfg.replicator_custom_proc_title); + snprintf(name, sizeof(name), "replication%s/relay", custom_proc_title); fiber_set_name(fiber, name); set_proc_title("%s %s", name, fiber_peer_name(fiber)); @@ -717,7 +688,7 @@ client_handler_init(int client_sock) ver = tbuf_alloc(fiber->pool); tbuf_append(ver, &default_version, sizeof(default_version)); - client_handler_send_row(NULL, ver); + replication_relay_send_row(NULL, ver); /* init libev events handlers */ ev_default_loop(0); @@ -726,12 +697,12 @@ client_handler_init(int client_sock) struct ev_io sock_read_ev; int sock_read_fd = fiber->fd; sock_read_ev.data = (void *)&sock_read_fd; - ev_io_init(&sock_read_ev, client_handler_recv, sock_read_fd, EV_READ); + ev_io_init(&sock_read_ev, replication_relay_recv, sock_read_fd, EV_READ); ev_io_start(&sock_read_ev); /* init reovery porcess */ log_io = recover_init(NULL, cfg.wal_dir, - client_handler_send_row, INT32_MAX, 0, 64, RECOVER_READONLY, false); + replication_relay_send_row, INT32_MAX, 0, 64, RECOVER_READONLY, false); recover(log_io, lsn); recover_follow(log_io, 0.1); @@ -744,7 +715,7 @@ client_handler_init(int client_sock) /** Receive data event to replication socket handler */ static void -client_handler_recv(struct ev_io *w, int __attribute__((unused)) revents) +replication_relay_recv(struct ev_io *w, int __attribute__((unused)) revents) { int fd = *((int *)w->data); u8 data; @@ -769,7 +740,7 @@ shutdown_handler: /** Send to row to client. */ static int -client_handler_send_row(struct recovery_state *r __attribute__((unused)), struct tbuf *t) +replication_relay_send_row(struct recovery_state *r __attribute__((unused)), struct tbuf *t) { u8 *data = t->data; ssize_t bytes, len = t->len; diff --git a/core/tarantool.m b/core/tarantool.m index 900ebb8a86..d6dc3a9776 100644 --- a/core/tarantool.m +++ b/core/tarantool.m @@ -43,7 +43,7 @@ # include <sys/prctl.h> #endif #include <admin.h> -#include <replicator.h> +#include <replication.h> #include <fiber.h> #include <iproto.h> #include <latch.h> @@ -63,6 +63,8 @@ static pid_t master_pid; const char *cfg_filename = DEFAULT_CFG_FILENAME; char *cfg_filename_fullpath = NULL; char *binary_filename; +char *custom_proc_title; + struct tarantool_cfg cfg; struct recovery_state *recovery_state; @@ -98,15 +100,10 @@ load_cfg(struct tarantool_cfg *conf, i32 check_rdonly) if (n_accepted == 0 || n_skipped != 0) return -1; - if (mod_check_config(conf) != 0) { - return -1; - } - - if (replicator_check_config(conf) != 0) { + if (replication_check_config(conf) != 0) return -1; - } - return 0; + return mod_check_config(conf); } @@ -536,11 +533,20 @@ main(int argc, char **argv) atexit(remove_pid); } + /* init process title */ + if (cfg.custom_proc_title == NULL) { + custom_proc_title = ""; + } else { + custom_proc_title = palloc(eter_pool, strlen(cfg.custom_proc_title) + 2); + strcat(custom_proc_title, "@"); + strcat(custom_proc_title, cfg.custom_proc_title); + } + say_logger_init(cfg.logger_nonblock); booting = false; initialize(cfg.slab_alloc_arena, cfg.slab_alloc_minimal, cfg.slab_alloc_factor); - replicator_prefork(); + replication_prefork(); ev_default_loop(EVFLAG_AUTO); @@ -551,7 +557,7 @@ main(int argc, char **argv) signal_init(); - replicator_init(); + replication_init(); mod_init(); admin_init(); diff --git a/include/replicator.h b/include/replication.h similarity index 67% rename from include/replicator.h rename to include/replication.h index 191a7a1101..252062c50c 100644 --- a/include/replicator.h +++ b/include/replication.h @@ -1,5 +1,5 @@ -#if !defined(REPLICATOR_H_INCLUDED) -#define REPLICATOR_H_INCLUDED +#ifndef TARANTOOL_REPLICATION_H_INCLUDED +#define TARANTOOL_REPLICATION_H_INCLUDED /* * Copyright (C) 2011 Mail.RU * Copyright (C) 2011 Yuriy Vostrikov @@ -29,36 +29,30 @@ #include <util.h> /** - * Check replicator module configuration. + * Check replication configuration. * - * @param config is tarantool checking configuration. + * @param config config file to check. * - * @return On success, a zero is returned. On error, -1 is returned. + * @return 0 on success, -1 on error */ -u32 -replicator_check_config(struct tarantool_cfg *config); +int +replication_check_config(struct tarantool_cfg *config); /** - * Reload replicator module configuration. + * Pre-fork replication spawner process. * - * @param config is tarantool checking configuration. + * @return None. Panics and exits on error. */ void -replicator_reload_config(struct tarantool_cfg *config); +replication_prefork(); /** - * Pre-fork replicator spawner process. - */ -void -replicator_prefork(); - -/** - * Intialize tarantool's replicator module. + * Initialize replication module. * - * @return On success, a zero is returned. On error, -1 is returned. + * @return None. Panics and exits on error. */ void -replicator_init(); +replication_init(); -#endif // !defined(REPLICATOR_H_INCLUDED) +#endif // TARANTOOL_REPLICATION_H_INCLUDED diff --git a/include/tarantool.h b/include/tarantool.h index 29301ecdb9..e446641ea2 100644 --- a/include/tarantool.h +++ b/include/tarantool.h @@ -46,6 +46,7 @@ extern struct tarantool_cfg cfg; extern const char *cfg_filename; extern bool init_storage, booting; extern char *binary_filename; +extern char *custom_proc_title; i32 reload_cfg(struct tbuf *out); int snapshot(void * /* ev */, int /* events */); const char *tarantool_version(void); diff --git a/mod/box/box.m b/mod/box/box.m index a1c7cce9c0..a167b7023a 100644 --- a/mod/box/box.m +++ b/mod/box/box.m @@ -62,8 +62,6 @@ static char status[64] = "unknown"; static int stat_base; STRS(messages, MESSAGES); -static char *custom_proc_title; - /* hooks */ typedef int (*box_hook_t) (struct box_txn * txn); @@ -1432,15 +1430,6 @@ mod_init(void) { static iproto_callback ro_callback = box_process_ro; - /* init process title */ - if (cfg.custom_proc_title == NULL) { - custom_proc_title = ""; - } else { - custom_proc_title = palloc(eter_pool, strlen(cfg.custom_proc_title) + 2); - strcat(custom_proc_title, "@"); - strcat(custom_proc_title, cfg.custom_proc_title); - } - title("loading"); /* initialization namespaces */ diff --git a/test/box/show.result b/test/box/show.result index 741e4c9998..870a8d416f 100644 --- a/test/box/show.result +++ b/test/box/show.result @@ -31,7 +31,6 @@ configuration: coredump: "0" admin_port: "33015" replication_port: "0" - replicator_custom_proc_title: (null) log_level: "4" slab_alloc_arena: "0.1" slab_alloc_minimal: "64" diff --git a/test/box_replication/cfg/hot_standby.cfg b/test/box_replication/cfg/hot_standby.cfg index ca3980538c..9d559d6443 100644 --- a/test/box_replication/cfg/hot_standby.cfg +++ b/test/box_replication/cfg/hot_standby.cfg @@ -11,7 +11,7 @@ secondary_port = 33024 admin_port = 33025 replication_port=33016 -replicator_custom_proc_title="_hot_standby" +custom_proc_title="hot_standby" namespace[0].enabled = 1 namespace[0].index[0].type = "HASH" diff --git a/test/box_replication/cfg/master.cfg b/test/box_replication/cfg/master.cfg index 9d595be5b5..603e36ed80 100644 --- a/test/box_replication/cfg/master.cfg +++ b/test/box_replication/cfg/master.cfg @@ -8,7 +8,7 @@ secondary_port = 33014 admin_port = 33015 replication_port=33016 -replicator_custom_proc_title="_master" +custom_proc_title="master" namespace[0].enabled = 1 namespace[0].index[0].type = "HASH" diff --git a/test/box_replication/cfg/master_to_replica.cfg b/test/box_replication/cfg/master_to_replica.cfg index efb854913a..d19f749674 100644 --- a/test/box_replication/cfg/master_to_replica.cfg +++ b/test/box_replication/cfg/master_to_replica.cfg @@ -8,7 +8,7 @@ secondary_port = 33014 admin_port = 33015 replication_port=33016 -replicator_custom_proc_title="_master" +custom_proc_title="master" namespace[0].enabled = 1 namespace[0].index[0].type = "HASH" diff --git a/test/box_replication/cfg/replica.cfg b/test/box_replication/cfg/replica.cfg index b3745aa9ee..5db5788c82 100644 --- a/test/box_replication/cfg/replica.cfg +++ b/test/box_replication/cfg/replica.cfg @@ -8,7 +8,7 @@ secondary_port = 33114 admin_port = 33115 replication_port=33116 -replicator_custom_proc_title="_replica" +custom_proc_title="replica" namespace[0].enabled = 1 namespace[0].index[0].type = "HASH" diff --git a/test/box_replication/cfg/replica_to_master.cfg b/test/box_replication/cfg/replica_to_master.cfg index b7b15242cd..68bde6cc5c 100644 --- a/test/box_replication/cfg/replica_to_master.cfg +++ b/test/box_replication/cfg/replica_to_master.cfg @@ -8,7 +8,7 @@ secondary_port = 33114 admin_port = 33115 replication_port=33116 -replicator_custom_proc_title="_replica" +custom_proc_title="replica" namespace[0].enabled = 1 namespace[0].index[0].type = "HASH" -- GitLab