From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp44.i.mail.ru (smtp44.i.mail.ru [94.100.177.104]) (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 2FAE34696C3 for ; Wed, 22 Apr 2020 21:28:29 +0300 (MSK) From: Serge Petrenko Date: Wed, 22 Apr 2020 21:28:10 +0300 Message-Id: <20200422182810.79257-1-sergepetrenko@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH] applier: follow vclock to the last tx row List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, gorcunov@gmail.com Cc: tarantool-patches@dev.tarantool.org Since the introduction of transaction boundaries in replication protocol, appliers follow replicaset.applier.vclock to the lsn of the first row in an arrived batch. This is enough and doesn't lead to errors when replicating from other instances, respecting transaction boundaries (instances with version 2.1.2 and up). However, if there's a 1.10 instance in 2.1.2+ cluster, it sends every single tx row as a separate transaction, breaking the comparison with replicaset.applier.vclock and making the applier apply part of the changes, it has already applied when processing a full transaction coming from another 2.x instance. Such behaviour leads to ER_TUPLE_FOUND errors in the scenario described above. In order to guard from such cases, follow replicaset.applier.vclock to the lsn of the last row in tx. Closes #4924 --- https://github.com/tarantool/tarantool/issues/4924 https://github.com/tarantool/tarantool/tree/sp/gh-4924-applier-duplicate-key src/box/applier.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/box/applier.cc b/src/box/applier.cc index 68de3c08c..eb0297f73 100644 --- a/src/box/applier.cc +++ b/src/box/applier.cc @@ -736,6 +736,7 @@ applier_apply_tx(struct stailq *rows) { struct xrow_header *first_row = &stailq_first_entry(rows, struct applier_tx_row, next)->row; + struct xrow_header *last_row; struct replica *replica = replica_by_id(first_row->replica_id); /* * In a full mesh topology, the same set of changes @@ -827,8 +828,9 @@ applier_apply_tx(struct stailq *rows) goto fail; /* Transaction was sent to journal so promote vclock. */ - vclock_follow(&replicaset.applier.vclock, - first_row->replica_id, first_row->lsn); + last_row = &stailq_last_entry(rows, struct applier_tx_row, next)->row; + vclock_follow(&replicaset.applier.vclock, last_row->replica_id, + last_row->lsn); latch_unlock(latch); return 0; rollback: -- 2.21.1 (Apple Git-122.3)