From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 803FB2167B for ; Wed, 6 Feb 2019 03:28:00 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 14vPZ23YxSw4 for ; Wed, 6 Feb 2019 03:28:00 -0500 (EST) Received: from smtp18.mail.ru (smtp18.mail.ru [94.100.176.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 39F81213A3 for ; Wed, 6 Feb 2019 03:28:00 -0500 (EST) From: Georgy Kirichenko Subject: [tarantool-patches] [PATCH 2/3] Enforce applier out of order protection Date: Wed, 6 Feb 2019 11:29:58 +0300 Message-Id: <6a6f606288f3a00425006d3c04b80d454d5c0095.1549441084.git.georgy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Georgy Kirichenko Do not skip row until the row is not processed. Prerequisite #2283 --- src/box/applier.cc | 48 ++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/box/applier.cc b/src/box/applier.cc index 21d2e6bcb..d87b247e2 100644 --- a/src/box/applier.cc +++ b/src/box/applier.cc @@ -512,31 +512,25 @@ applier_subscribe(struct applier *applier) applier->lag = ev_now(loop()) - row.tm; applier->last_row_time = ev_monotonic_now(loop()); - - if (vclock_get(&replicaset.vclock, row.replica_id) < row.lsn) { - /** - * Promote the replica set vclock before - * applying the row. If there is an - * exception (conflict) applying the row, - * the row is skipped when the replication - * is resumed. - */ + struct replica *replica = replica_by_id(row.replica_id); + struct latch *latch = (replica ? &replica->order_latch : + &replicaset.applier.order_latch); + /* + * In a full mesh topology, the same set + * of changes may arrive via two + * concurrently running appliers. Thanks + * to vclock_follow() above, the first row + * in the set will be skipped - but the + * remaining may execute out of order, + * when the following xstream_write() + * yields on WAL. Hence we need a latch to + * strictly order all changes which belong + * to the same server id. + */ + latch_lock(latch); + if (vclock_get(&replicaset.vclock, + row.replica_id) < row.lsn) { vclock_follow_xrow(&replicaset.vclock, &row); - struct replica *replica = replica_by_id(row.replica_id); - struct latch *latch = (replica ? &replica->order_latch : - &replicaset.applier.order_latch); - /* - * In a full mesh topology, the same set - * of changes may arrive via two - * concurrently running appliers. Thanks - * to vclock_follow() above, the first row - * in the set will be skipped - but the - * remaining may execute out of order, - * when the following xstream_write() - * yields on WAL. Hence we need a latch to - * strictly order all changes which belong - * to the same server id. - */ latch_lock(latch); int res = xstream_write(applier->subscribe_stream, &row); latch_unlock(latch); @@ -550,10 +544,14 @@ applier_subscribe(struct applier *applier) box_error_code(e) == ER_TUPLE_FOUND && replication_skip_conflict) diag_clear(diag_get()); - else + else { + latch_unlock(latch); diag_raise(); + } } } + latch_unlock(latch); + if (applier->state == APPLIER_SYNC || applier->state == APPLIER_FOLLOW) fiber_cond_signal(&applier->writer_cond); -- 2.20.1