From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 92DB44696C0 for ; Sun, 15 Dec 2019 23:58:59 +0300 (MSK) From: sergepetrenko Date: Sun, 15 Dec 2019 23:58:43 +0300 Message-Id: <5a75434034d9e6a269b31b2f0a050c19da860646.1576443171.git.sergepetrenko@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 3/5] applier: split join processing into two stages List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: georgy@tarantool.org Cc: tarantool-patches@dev.tarantool.org From: Serge Petrenko We already have 'initial join' and 'final join' stages in applier logic. The first actually means fetching master's snapshot, and the second one -- receiving the rows which should contain replica's registration in _cluster. These stages will be used separately once anonymous replica is implemented, so split them as a preparation. Prerequisite #3186 --- src/box/applier.cc | 61 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/src/box/applier.cc b/src/box/applier.cc index 42374f886..357369025 100644 --- a/src/box/applier.cc +++ b/src/box/applier.cc @@ -388,18 +388,12 @@ done: applier_set_state(applier, APPLIER_READY); } -/** - * Execute and process JOIN request (bootstrap the instance). - */ -static void -applier_join(struct applier *applier) +static uint64_t +applier_do_fetch_snapshot(struct applier *applier) { - /* Send JOIN request */ struct ev_io *coio = &applier->io; struct ibuf *ibuf = &applier->ibuf; struct xrow_header row; - xrow_encode_join_xc(&row, &INSTANCE_UUID); - coio_write_xrow(coio, &row); /** * Tarantool < 1.7.0: if JOIN is successful, there is no "OK" @@ -423,8 +417,6 @@ applier_join(struct applier *applier) xrow_decode_vclock_xc(&row, &replicaset.vclock); } - applier_set_state(applier, APPLIER_INITIAL_JOIN); - /* * Receive initial data. */ @@ -456,9 +448,16 @@ applier_join(struct applier *applier) (uint32_t) row.type); } } - say_info("initial data received"); - applier_set_state(applier, APPLIER_FINAL_JOIN); + return row_count; +} + +static uint64_t +applier_do_register(struct applier *applier, uint64_t row_count) +{ + struct ev_io *coio = &applier->io; + struct ibuf *ibuf = &applier->ibuf; + struct xrow_header row; /* * Tarantool < 1.7.0: there is no "final join" stage. @@ -466,7 +465,7 @@ applier_join(struct applier *applier) * until replica id is received. */ if (applier->version_id < version_id(1, 7, 0)) - return; + return row_count; /* * Receive final data. @@ -485,6 +484,7 @@ applier_join(struct applier *applier) * Current vclock. This is not used now, * ignore. */ + ++row_count; break; /* end of stream */ } else if (iproto_type_is_error(row.type)) { xrow_decode_error_xc(&row); /* rethrow error */ @@ -493,6 +493,41 @@ applier_join(struct applier *applier) (uint32_t) row.type); } } + + return row_count; +} + +/** + * Execute and process JOIN request (bootstrap the instance). + */ +static void +applier_join(struct applier *applier) +{ + /* Send JOIN request */ + struct ev_io *coio = &applier->io; + struct xrow_header row; + uint64_t row_count; + + xrow_encode_join_xc(&row, &INSTANCE_UUID); + coio_write_xrow(coio, &row); + + applier_set_state(applier, APPLIER_INITIAL_JOIN); + + row_count = applier_do_fetch_snapshot(applier); + + say_info("initial data received"); + + applier_set_state(applier, APPLIER_FINAL_JOIN); + + if (applier_do_register(applier, row_count) == row_count) { + /* + * We didn't receive any rows during registration. + * Proceed to "subscribe" and do not finish bootstrap + * until replica id is received. + */ + return; + } + say_info("final data received"); applier_set_state(applier, APPLIER_JOINED); -- 2.20.1 (Apple Git-117)