diff --git a/src/box/applier.cc b/src/box/applier.cc index ae3d281a5c45..acb26b7e21e7 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 e7bfa22ab437..7b04573a44a8 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);