Skip to content

Commit

Permalink
(#5272) fix checkpointing against Cloudant/CouchDB 2.0
Browse files Browse the repository at this point in the history
An attempt to provide a better fix for #5145. It seems like
it's safe to eagerly write a checkpoint in the event there are no
changes returned (e.g. because a filter did not generate results).

This also removes some assertions around last_seq / since values
in the tests, since they don't hold in CouchDB 2.x / Cloudant.

This at least allows the tests to pass - possibly this means we
need more tests to cover situations where a small number of docs
are returned.
  • Loading branch information
willholley committed Jun 3, 2016
1 parent 3485f34 commit a893456
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/pouchdb-replication/src/replicate.js
Expand Up @@ -308,7 +308,7 @@ function replicate(src, target, opts, returnValue, result) {
};

// update the checkpoint so we start from the right seq next time
if (!currentBatch && changes.last_seq > last_seq) {
if (!currentBatch && changes.results.length === 0) {
writingCheckpoint = true;
checkpointer.writeCheckpoint(changes.last_seq,
session).then(function () {
Expand Down
11 changes: 4 additions & 7 deletions tests/integration/test.replication.js
Expand Up @@ -1568,23 +1568,20 @@ adapters.forEach(function (adapters) {
result.ok.should.equal(true);
result.docs_written.should.equal(0);
result.docs_read.should.equal(0);
changesSince.length.should.equal(2);
// the returned last_seq should match the 'since'
// requested from remote
result.last_seq.should.equal(changesSince[1]);
changesSince.length.should.equal(2, JSON.stringify(changesSince));

// the 'since' parameter should be different on the
// next request
changesSince[0].should.not.equal(changesSince[1]);

// kick off a second replication
return db.replicate.from(remote, replicationOpts);
}).then(function (result) {
result.ok.should.equal(true);
result.docs_written.should.equal(0);
result.docs_read.should.equal(0);
changesSince.length.should.equal(3);
// the returned last_seq should match the 'since'
// requested from remote
result.last_seq.should.equal(changesSince[2]);

// nothing has changed on the remote so 'since'
// should be the same
changesSince[1].should.equal(changesSince[2]);
Expand Down

0 comments on commit a893456

Please sign in to comment.