-
Notifications
You must be signed in to change notification settings - Fork 453
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
Support expiring ops from oplog #33
Changes from all commits
7e99d0a
48c8bb1
74556cf
b43b256
9f69630
bdf7d16
0489c7e
d9be12e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,7 +172,7 @@ RedisDriver.prototype.atomicSubmit = function(cName, docName, opData, options, c | |
// In this case, we should write a no-op ramp to the snapshot | ||
// version, followed by a delete & a create to fill in the missing | ||
// ops. | ||
throw Error('Missing oplog for ' + cName + ' ' + docName); | ||
return callback('Missing oplog for ' + cName + ' ' + docName); | ||
} | ||
self._redisSubmitScript(cName, docName, opData, dirtyData, version, callbackWrapper); | ||
}); | ||
|
@@ -323,7 +323,8 @@ RedisDriver.prototype._oplogGetOps = function(cName, docName, from, to, callback | |
var self = this; | ||
this.oplog.getOps(cName, docName, from, to, function(err, ops) { | ||
if (err) return callback(err); | ||
if (ops.length && ops[0].v !== from) throw Error('Oplog is returning incorrect ops'); | ||
if (ops.length && ops[0].v !== from) | ||
return callback('Missing operations'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be easier to just call |
||
|
||
for (var i = 0; i < ops.length; i++) { | ||
ops[i].v = from++; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,15 +98,10 @@ module.exports = (create) -> | |
check = (error, ops) -> | ||
throw new Error error if error | ||
assert.deepEqual ops, [] | ||
done() if ++num is 7 | ||
done() if ++num is 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test doesn't do the thing it says anymore. |
||
|
||
@db.getOps @cName, @docName, 0, 0, check | ||
@db.getOps @cName, @docName, 0, 1, check | ||
@db.getOps @cName, @docName, 0, 10, check | ||
@db.getOps @cName, @docName, 0, null, check | ||
@db.getOps @cName, @docName, 10, 10, check | ||
@db.getOps @cName, @docName, 10, 11, check | ||
@db.getOps @cName, @docName, 10, null, check | ||
|
||
it 'returns ops', (done) -> | ||
num = 0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,36 @@ describe 'livedb', -> | |
throw new Error err if err | ||
assert.equal m.language, null | ||
done() | ||
|
||
it 'errors when oplog is missing all operations', (done) -> @create => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when oplog is missing any operations |
||
@collection.submit @docName, {v:1, op:['test']}, (err, v) => | ||
throw new Error err if err | ||
|
||
getOps = @client.driver.getOps | ||
@client.driver.getOps = (cName, docName, from, to, fn) -> | ||
fn null, [] | ||
|
||
@collection.submit @docName, {v:1, op:['test']}, (err, v) => | ||
assert.equal err, 'Missing operations' | ||
@client.driver.getOps = getOps | ||
done() | ||
|
||
it 'errors when oplog is missing some operations', (done) -> @create => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is bad behaviour. If the oplog throws, that implies something has gone wrong. We shouldn't just silently eat the exception. (Exceptions ruin optimization, they shouldn't ever be used as part of the expected behaviour of a program) |
||
@collection.submit @docName, {v:1, op:['test']}, (err, v) => | ||
throw new Error err if err | ||
@collection.submit @docName, {v:2, op:['test 2']}, (err, v) => | ||
throw new Error err if err | ||
|
||
getOps = @client.driver.getOps | ||
@client.driver.getOps = (cName, docName, from, to, fn) => | ||
getOps.call @client.driver, cName, docName, from, to, (err, ops) -> | ||
throw new Error err if err | ||
fn null, ops.slice 1 | ||
|
||
@collection.submit @docName, {v:1, op:['test']}, (err, v) => | ||
assert.equal err, 'Missing operations' | ||
@client.driver.getOps = getOps | ||
done() | ||
|
||
it 'can modify a document', (done) -> @create => | ||
@collection.submit @docName, v:1, op:['hi'], (err, v) => | ||
|
@@ -375,11 +405,22 @@ describe 'livedb', -> | |
assert.deepEqual stripTs(ops), [{create:{type:textType.uri, data:''}, v:0, m:{}, src:''}, {op:['hi'], v:1, m:{}, src:''}] | ||
done() | ||
|
||
|
||
|
||
it 'errors if ops are missing from the snapshotdb and oplogs' | ||
|
||
|
||
it 'errors if ops are missing from the snapshotdb and oplogs', (done) -> @create => | ||
@collection.submit @docName, {v:1, op:['test']}, (err, v) => | ||
throw new Error err if err | ||
@collection.submit @docName, {v:1, op:['test2']}, (err, v) => | ||
throw new Error err if err | ||
|
||
getOps = @client.driver.getOps | ||
@client.driver.getOps = (cName, docName, from, to, fn) => | ||
getOps.call @client.driver, cName, docName, from, to, (err, ops) -> | ||
throw new Error err if err | ||
fn null, ops.slice 1 | ||
|
||
@collection.getOps @docName, 0, (err, ops) => | ||
assert.equal err, 'Missing operations' | ||
@client.driver.getOps = getOps | ||
done() | ||
|
||
it 'works with separate clients', (done) -> @create => | ||
return done() unless @driver.distributed | ||
|
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.
... so people can match on the error string.