From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [RFC PATCH 08/12] box: open the port before starting local recovery Date: Wed, 6 Jun 2018 20:45:08 +0300 Message-Id: <2761e499f2503f2a6822e6765d74a5346b67b6ab.1528305232.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: In order to find out if the current instance fell too much behind its peers in the cluster and so needs to be re-bootstrapped we need to connect it to remote peers before proceeding to local recovery. The problem is box.cfg.replication may have an entry corresponding to the instance itself so before connecting we have to start listening to incoming connections. So this patch moves the call to box_listen() before recoery is started unless the instance in hot standby mode. It also folds box_bind() into box_listen() as it is no longer needed as a separate function. Needed for #461 --- src/box/box.cc | 25 ++++++------------------- src/box/box.h | 1 - src/box/iproto.cc | 23 ++++++----------------- src/box/iproto.h | 5 +---- src/box/lua/cfg.cc | 1 - 5 files changed, 13 insertions(+), 42 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index b072f788..fce5ebb1 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -681,17 +681,11 @@ box_set_replication_skip_conflict(void) } void -box_bind(void) +box_listen(void) { const char *uri = cfg_gets("listen"); box_check_uri(uri, "listen"); - iproto_bind(uri); -} - -void -box_listen(void) -{ - iproto_listen(); + iproto_listen(uri); } void @@ -1829,13 +1823,6 @@ box_cfg_xc(void) */ if (!cfg_geti("hot_standby") || last_checkpoint_lsn < 0) tnt_raise(ClientError, ER_ALREADY_RUNNING, cfg_gets("wal_dir")); - } else { - /* - * Try to bind the port before recovery, to fail - * early if the port is busy. In hot standby mode, - * the port is most likely busy. - */ - box_bind(); } bool is_bootstrap_leader = false; if (last_checkpoint_lsn >= 0) { @@ -1865,6 +1852,9 @@ box_cfg_xc(void) */ recovery_end_vclock(recovery, &replicaset.vclock); + if (wal_dir_lock >= 0) + box_listen(); + /* * recovery->vclock is needed by Vinyl to filter * WAL rows that were dumped before restart. @@ -1920,7 +1910,7 @@ box_cfg_xc(void) * applied in hot standby mode. */ vclock_copy(&replicaset.vclock, &recovery->vclock); - box_bind(); + box_listen(); } recovery_finalize(recovery); engine_end_recovery_xc(); @@ -1936,9 +1926,6 @@ box_cfg_xc(void) /* Clear the pointer to journal before it goes out of scope */ journal_set(NULL); - /** Begin listening only when the local recovery is complete. */ - box_listen(); - title("orphan"); /* Wait for the cluster to start up */ diff --git a/src/box/box.h b/src/box/box.h index d3967891..182e1b72 100644 --- a/src/box/box.h +++ b/src/box/box.h @@ -170,7 +170,6 @@ box_process_subscribe(struct ev_io *io, struct xrow_header *header); void box_check_config(); -void box_bind(void); void box_listen(void); void box_set_replication(void); void box_set_log_level(void); diff --git a/src/box/iproto.cc b/src/box/iproto.cc index 76844555..c6b13934 100644 --- a/src/box/iproto.cc +++ b/src/box/iproto.cc @@ -1763,7 +1763,6 @@ iproto_init() /** Available IProto configuration changes. */ enum iproto_cfg_op { - IPROTO_CFG_BIND, IPROTO_CFG_MSG_MAX, IPROTO_CFG_LISTEN }; @@ -1801,12 +1800,6 @@ iproto_do_cfg_f(struct cbus_call_msg *m) int old; try { switch (cfg_msg->op) { - case IPROTO_CFG_BIND: - if (evio_service_is_active(&binary)) - evio_service_stop(&binary); - if (cfg_msg->uri != NULL) - evio_service_bind(&binary, cfg_msg->uri); - break; case IPROTO_CFG_MSG_MAX: cpipe_set_max_input(&tx_pipe, cfg_msg->iproto_msg_max / 2); @@ -1817,7 +1810,11 @@ iproto_do_cfg_f(struct cbus_call_msg *m) break; case IPROTO_CFG_LISTEN: if (evio_service_is_active(&binary)) + evio_service_stop(&binary); + if (cfg_msg->uri != NULL) { + evio_service_bind(&binary, cfg_msg->uri); evio_service_listen(&binary); + } break; default: unreachable(); @@ -1837,19 +1834,11 @@ iproto_do_cfg(struct iproto_cfg_msg *msg) } void -iproto_bind(const char *uri) -{ - struct iproto_cfg_msg cfg_msg; - iproto_cfg_msg_create(&cfg_msg, IPROTO_CFG_BIND); - cfg_msg.uri = uri; - iproto_do_cfg(&cfg_msg); -} - -void -iproto_listen() +iproto_listen(const char *uri) { struct iproto_cfg_msg cfg_msg; iproto_cfg_msg_create(&cfg_msg, IPROTO_CFG_LISTEN); + cfg_msg.uri = uri; iproto_do_cfg(&cfg_msg); } diff --git a/src/box/iproto.h b/src/box/iproto.h index b6591469..b9a6cf8f 100644 --- a/src/box/iproto.h +++ b/src/box/iproto.h @@ -75,10 +75,7 @@ void iproto_init(); void -iproto_bind(const char *uri); - -void -iproto_listen(); +iproto_listen(const char *uri); void iproto_set_msg_max(int iproto_msg_max); diff --git a/src/box/lua/cfg.cc b/src/box/lua/cfg.cc index 5afebc94..0f6b8a5a 100644 --- a/src/box/lua/cfg.cc +++ b/src/box/lua/cfg.cc @@ -69,7 +69,6 @@ static int lbox_cfg_set_listen(struct lua_State *L) { try { - box_bind(); box_listen(); } catch (Exception *) { luaT_error(L); -- 2.11.0