Create a remote checkpoint during replication too

Before this change, in the case of a one-way replication, the remote
checkpoint was never updated, thus the "diff" step had to check
all changes made through the whole history.

This commit fixes the problem by creating a new remote checkpoint
at the same time when a local checkpoint is created.

It is important to create the new checkpoint before the replication is
started to prevent a race condition where a remote change can end up
being associated with an already replicated checkpoint.
This commit is contained in:
Miroslav Bajtoš 2015-03-03 12:00:47 +01:00
parent 2dc230b7cf
commit 53ebddfa9f
1 changed files with 7 additions and 3 deletions

View File

@ -855,7 +855,7 @@ PersistedModel.replicate = function(since, targetModel, options, callback) {
};
var tasks = [
checkpoint,
checkpoints,
getSourceChanges,
getDiffFromTarget,
createSourceUpdates,
@ -887,9 +887,13 @@ PersistedModel.replicate = function(since, targetModel, options, callback) {
targetModel.bulkUpdate(updates, cb);
}
function checkpoint() {
function checkpoints() {
var cb = arguments[arguments.length - 1];
sourceModel.checkpoint(function(err) { cb(err); });
sourceModel.checkpoint(function(err) {
targetModel.checkpoint(function(err) {
cb(err);
});
});
}
function done(err) {