-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change adds the ability fetch a snapshot by time. The motivation for this is that fetching a document by time is quite a "natural" way to think about document history, and allows us to - for example - fetch multiple documents as they were at a given time, without having to look up their exact version numbers first. We add a new `Connection.fetchSnapshotByTimestamp` method, which follows a very similar route to `Connection.fetchSnapshot`, and where possible, as much code is re-used as possible: - both methods use a subclassed child of `SnapshotRequest` - both methods have their requests handled by the same machinery in `Connection` - both methods in the `Backend` have ops applied by a common method, but use their own methods for calls to middleware In order to make this feature possible at scale, this change also adds two new methods to the `MilestoneDB` interface: - `getMilestoneSnapshotAtOrBeforeTime` - `getMilestoneSnapshotAtOrAfterTime` These methods are used to fetch milestone snapshots either side of the requested timestamp, which means we only need to fetch the ops between the two of them to reach the desired timestamp. In the case where a milestone database is not being used, then fetching a snapshot by timestamp is still possible, but it will fetch all the ops for a document, and keep applying them from v0 until the timestamp is reached, which is not particularly scalable.
- Loading branch information
Alec Gibson
committed
Dec 3, 2018
1 parent
95c81b8
commit 513f6b6
Showing
16 changed files
with
1,091 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var SnapshotRequest = require('./snapshot-request'); | ||
var util = require('../../util'); | ||
|
||
module.exports = SnapshotTimestampRequest; | ||
|
||
function SnapshotTimestampRequest(connection, requestId, collection, id, timestamp, callback) { | ||
SnapshotRequest.call(this, connection, requestId, collection, id, callback); | ||
|
||
if (!util.isValidTimestamp(timestamp)) { | ||
throw new Error('Snapshot timestamp must be a positive integer or null'); | ||
} | ||
|
||
this.timestamp = timestamp; | ||
} | ||
|
||
SnapshotTimestampRequest.prototype = Object.create(SnapshotRequest.prototype); | ||
|
||
SnapshotTimestampRequest.prototype._message = function () { | ||
return { | ||
a: 'nt', | ||
id: this.requestId, | ||
c: this.collection, | ||
d: this.id, | ||
ts: this.timestamp, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var SnapshotRequest = require('./snapshot-request'); | ||
var util = require('../../util'); | ||
|
||
module.exports = SnapshotVersionRequest; | ||
|
||
function SnapshotVersionRequest (connection, requestId, collection, id, version, callback) { | ||
SnapshotRequest.call(this, connection, requestId, collection, id, callback); | ||
|
||
if (!util.isValidVersion(version)) { | ||
throw new Error('Snapshot version must be a positive integer or null'); | ||
} | ||
|
||
this.version = version; | ||
} | ||
|
||
SnapshotVersionRequest.prototype = Object.create(SnapshotRequest.prototype); | ||
|
||
SnapshotVersionRequest.prototype._message = function () { | ||
return { | ||
a: 'nf', | ||
id: this.requestId, | ||
c: this.collection, | ||
d: this.id, | ||
v: this.version, | ||
}; | ||
}; |
Oops, something went wrong.