Skip to content

Commit

Permalink
replication: correctly check for rows to skip in applier
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sergepetrenko committed Feb 12, 2020
1 parent 0dd8be7 commit 85cfed8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/box/applier.cc
Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion src/box/replication.cc
Expand Up @@ -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);

Expand Down

0 comments on commit 85cfed8

Please sign in to comment.