-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(#6730) - fix single-sided checkpointing #6734
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly looking good to me - just a few things that could be improved in the tests, I think. Nicely done!
@@ -392,6 +392,9 @@ function replicate(src, target, opts, returnValue, result) { | |||
return; | |||
} | |||
return checkpointer.getCheckpoint().then(function (checkpoint) { | |||
if (typeof result.initial_checkpoint === 'undefined') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not keen on changing the result to support the tests here. I think you can test by intercepting the _changes call as in https://github.com/pouchdb/pouchdb/blob/master/tests/integration/test.replication.js#L2400
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I'll look into the suggested approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change and it works, although a little weird as changes()
is called twice for each call to replicate()
, first with the initial checkpoint value, and then with the final checkpoint value.
@@ -133,9 +133,21 @@ var comparisons = { | |||
|
|||
Checkpointer.prototype.getCheckpoint = function () { | |||
var self = this; | |||
|
|||
if (self.opts && self.opts.writeSourceCheckpoint && !self.opts.writeTargetCheckpoint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether this should be combined with self.readOnlySource
- it seems like we have two properties to express the same thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way I read it, there are four different options:
source \ target |
on | off |
---|---|---|
on | default | previously broken |
off | previously broken | no checkpointing |
How would you recommend combining?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.readOnlyCheckpoint
is set when we detect that we don't have write permissions on the source. It seems like, once set, we'd want the behaviour to be the same as if opts.writeSourceCheckpoint
is false
. Looking at it again, this line probably doesn't change, but we have 2 similar-looking flags adjusting checkpoint behaviour that look like they should be combined in general
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it's that simple, though. One flag is a request for behaviour, and the other is a reaction to discovered properties of a DB. E.g.
Checkpointer.prototype.updateSource = function (checkpoint, session) {
if (this.opts.writeSourceCheckpoint) {
var self = this;
if (this.readOnlySource) {
return Promise.resolve(true);
}
Perhaps the auto-detection could be removed and an error thrown if the source is discovered to be read only when the user has requested checkpointing on both sides? OTOH the current behaviour is quite helpful...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@willholley PR for combining the two at #6738
.on('complete', function (result) { | ||
result.docs_read.should.equal(1); | ||
result.docs_written.should.equal(1); | ||
result.initial_checkpoint.should.equal(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above, suggest capturing the since
parameter sent to changes()
rather than changing the schema of result
.catch(done); | ||
}); | ||
|
||
it('Test replicate on source only resumes OK', function (done) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps 'Test replication resumes when checkpointing on source only' is more descriptive
result.initial_checkpoint.should.equal(0); | ||
done(); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove whitespace
result.initial_checkpoint.should.equal(1); | ||
done(); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove whitespace
.catch(done); | ||
}); | ||
|
||
it('Test replicate on target only resumes OK', function (done) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps 'Test replication resumes when checkpointing on target only' is more descriptive
|
||
var replicateOpts = { checkpoint: 'target' }; | ||
|
||
db.bulkDocs({ docs: docs.slice(0, 1) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lots of duplication here with the previous tests. Consider refactoring so that the test body can be reused, whilst injecting different replicateOpts
@willholley thanks for the feedback 🙂 |
@@ -2643,15 +2759,13 @@ adapters.forEach(function (adapters) { | |||
var targetPut = target.put; | |||
target.put = putter; | |||
|
|||
var changes = source.changes; | |||
source.changes = function (opts) { | |||
interceptChanges(source, function(opts) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis complains about this one, function(opts)
vs. function (opts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks :¬)
Ready for review again :¬) |
Test failures for https://travis-ci.org/pouchdb/pouchdb/builds/272428063: 1.
|
For the firefox tests, I'll restart them - it's probably just saucelabs being flakey. The code coverage errors indicate that some of the new code paths aren't being exercised by the tests. This is worth looking at and, ideally, adding covering tests. |
fa979d7
to
90aa0fd
Compare
I'm not sure if this is 100% relevant, but it seems like sequence numbers can't be trusted to be ordered on CouchDB: https://stackoverflow.com/questions/44447505/sequence-number-bug-in-couchdb-2-or-is-there-another-way-to-compare-sequence-num Can we think of another way to check whether we get the desired |
.then(function () { | ||
PouchDB.replicate(db, remote) | ||
.on('error', done) | ||
.on('complete', function (result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the result contain anything that could be useful, like seq_written
or something?
This aims to fix build jobs 24 and 25
This aims to fix build jobs 24 and 25
I think I might have the tests passing. Just waiting for a full batch to complete on Travis… |
The build is passing and this is now ready for review. Happy to rebase and squash beforehand if that's helpful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome job, huge 👍 sorry for not being around more to help but good job getting this implemented, tested and all passing, will try to be a bit quicker helping out with follow ups :)
Thanks! And extra thanks for including my unedited commit message log ;¬) |
<3 |
No description provided.