Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

replication sync just accepts continuations from the same logger. if …

…different logger the sync restarts from 0
  • Loading branch information...
commit 4ae503baf712a28fc72da48b7615c6f2ae40bd10 1 parent ab6c7b4
@pgte authored
View
14 lib/alfred/meta/commands/replicate_from.js
@@ -27,6 +27,7 @@ ReplicateFromCommand.prototype.do = function(meta, callback) {
var connection;
var reconnect_tries;
var last_run_log_pos = 0;
+ var logger_id;
var command_queue = [];
@@ -96,9 +97,20 @@ ReplicateFromCommand.prototype.do = function(meta, callback) {
callback(new Error('Error parsing replicated line: "' + line + '": ' + excp.message));
return;
}
-
+
+ if (!logger_id) {
+ logger_id = command.__logger_id;
+ } else {
+ if (logger_id != command.__logger_id) {
+ last_run_log_pos = 0;
+ process.nextTick(connect);
+ return;
+ }
+ }
+
command_queue.push(command);
notify();
+
});
connection.on('close', function() {
var retry_timeout = self.options.reconnect_timeout + Math.floor(Math.random() * self.options.reconnect_timeout) - Math.floor(self.options.reconnect_timeout / 2);
View
5 lib/alfred/meta/replication/logger.js
@@ -17,6 +17,9 @@ var Logger = function(database, options, callback) {
this.database = database;
this.current_log_pos = 0;
this.livelog_file_paths = [];
+
+ this.logger_id = Date.now() + Math.floor(Math.random() * 1000000000);
+
this._clearOldBacklog(function(err) {
if (err) { callback(err); return; }
self._createReplicationDir(function(err) {
@@ -124,6 +127,7 @@ Logger.prototype._backlogKeyMap = function(key_map_name, key_map, callback) {
var send = function(what) {
self.current_log_pos ++;
what['__log_pos'] = self.current_log_pos;
+ what['__logger_id'] = self.logger_id;
self.backlog_file.write(JSON.stringify(what), function(err) {
if (err) { callback(err); return; }
self.emit('data', what);
@@ -180,6 +184,7 @@ Logger.prototype._startLiveLog = function(callback) {
var reallyWrite = function(what) {
self.current_log_pos ++;
what['__log_pos'] = self.current_log_pos;
+ what['__logger_id'] = self.logger_id;
self.livelog_file.write(JSON.stringify(what), function(err, pos, length) {
if (err) { callback(err); return; }
self.emit('data', what);
View
1  test/replication/test_master.js
@@ -278,6 +278,7 @@ module.exports.run = function(next) {
next(new Error('Error from master: ' + obj.error));
return;
}
+ delete obj['__logger_id'];
assert.deepEqual(expected_objects[result_count], obj);
result_count ++;
if (result_count == expected_objects.length) {
Please sign in to comment.
Something went wrong with that request. Please try again.