From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp21.mail.ru (smtp21.mail.ru [94.100.179.250]) (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 6C39C469719 for ; Thu, 13 Feb 2020 02:51:20 +0300 (MSK) From: sergepetrenko Date: Thu, 13 Feb 2020 02:51:00 +0300 Message-Id: <85cfed8fd0cfa23c5a8504b6516fad18028edbaf.1581551227.git.sergepetrenko@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 1/2] replication: correctly check for rows to skip in applier List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: alexander.turenko@tarantool.org, v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Fix replicaset.applier.vclock initialization issues: it wasn't initialized at all previously. Moreover, there is no valid point in code to initialize it, since it may get stale right away if new entries are written to WAL. So, check for both applier and replicaset vclocks. The greater one protects the instance from applying the rows it has already applied or has already scheduled to write. Also remove an unnecessary aplier vclock initialization from replication_init(). Closes #4739 --- src/box/applier.cc | 14 ++++++++++++-- src/box/replication.cc | 1 - 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/box/applier.cc b/src/box/applier.cc index ae3d281a5..acb26b7e2 100644 --- a/src/box/applier.cc +++ b/src/box/applier.cc @@ -731,8 +731,18 @@ applier_apply_tx(struct stailq *rows) struct latch *latch = (replica ? &replica->order_latch : &replicaset.applier.order_latch); latch_lock(latch); - if (vclock_get(&replicaset.applier.vclock, - first_row->replica_id) >= first_row->lsn) { + /* + * We cannot tell which vclock is greater. There is no + * proper place to initialize applier vclock, since it + * may get stale right away if we write something to WAL + * and it gets replicated and then arrives back from the + * replica. So check against both vclocks. Replicaset + * vclock will guard us from corner cases like the one + * above. + */ + if (MAX(vclock_get(&replicaset.applier.vclock, first_row->replica_id), + vclock_get(&replicaset.vclock, first_row->replica_id)) >= + first_row->lsn) { latch_unlock(latch); return 0; } diff --git a/src/box/replication.cc b/src/box/replication.cc index e7bfa22ab..7b04573a4 100644 --- a/src/box/replication.cc +++ b/src/box/replication.cc @@ -93,7 +93,6 @@ replication_init(void) latch_create(&replicaset.applier.order_latch); vclock_create(&replicaset.applier.vclock); - vclock_copy(&replicaset.applier.vclock, &replicaset.vclock); rlist_create(&replicaset.applier.on_rollback); rlist_create(&replicaset.applier.on_commit); -- 2.20.1 (Apple Git-117)