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 E2CA324D04 for ; Fri, 4 Jan 2019 05:32:52 -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 BNcMySsJtCOP for ; Fri, 4 Jan 2019 05:32:52 -0500 (EST) Received: from smtp58.i.mail.ru (smtp58.i.mail.ru [217.69.128.38]) (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 A097324D03 for ; Fri, 4 Jan 2019 05:32:52 -0500 (EST) From: Georgy Kirichenko Subject: [tarantool-patches] [PATCH 3/5] Enforce applier out of order protection Date: Fri, 4 Jan 2019 13:34:13 +0300 Message-Id: <2be473a9f1c9dd993786423b4e2a85886a794452.1546593619.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 replication row until the row is not processed by other appliers. Needed for: #980 --- src/box/applier.cc | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/box/applier.cc b/src/box/applier.cc index 1c6ed878d..fbceadb2b 100644 --- a/src/box/applier.cc +++ b/src/box/applier.cc @@ -504,30 +504,29 @@ applier_subscribe(struct applier *applier) applier->lag = ev_now(loop()) - row.tm; applier->last_row_time = ev_monotonic_now(loop()); + 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.applier.vclock, row.replica_id) < row.lsn) { /* Preserve old lsn value. */ int64_t old_lsn = vclock_get(&replicaset.applier.vclock, row.replica_id); vclock_follow_xrow(&replicaset.applier.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); if (res != 0) { struct error *e = diag_last_error(diag_get()); /** @@ -542,10 +541,12 @@ applier_subscribe(struct applier *applier) /* Rollback lsn to have a chance for a retry. */ vclock_set(&replicaset.applier.vclock, row.replica_id, old_lsn); + latch_unlock(latch); diag_raise(); } } } + latch_unlock(latch); /* * Stay 'orphan' until appliers catch up with * the remote vclock at the time of SUBSCRIBE -- 2.20.1