Skip to content

Commit

Permalink
replication sync just accepts continuations from the same logger. if …
Browse files Browse the repository at this point in the history
…different logger the sync restarts from 0
  • Loading branch information
pgte committed Jan 24, 2011
1 parent 4ae503b commit 0080215
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/alfred/meta/commands/replicate_from.js
Expand Up @@ -28,6 +28,7 @@ ReplicateFromCommand.prototype.do = function(meta, callback) {
var reconnect_tries;
var last_run_log_pos = 0;
var logger_id;
var reconnecting = false;

var command_queue = [];

Expand Down Expand Up @@ -88,6 +89,7 @@ ReplicateFromCommand.prototype.do = function(meta, callback) {
(function connect() {
connection = net.createConnection(self.options.source_port, self.source);
connection.on('connect', function() {
reconnecting = false;
sendCommand('sync', {from: last_run_log_pos});
carrier.carry(connection, function(line) {
var command;
Expand All @@ -102,8 +104,14 @@ ReplicateFromCommand.prototype.do = function(meta, callback) {
logger_id = command.__logger_id;
} else {
if (logger_id != command.__logger_id) {
last_run_log_pos = 0;
process.nextTick(connect);
if (!reconnecting) {
reconnecting = true;
logger_id = undefined;
last_run_log_pos = 0;
connection.end();
reconnecting = true;
process.setTimeout(connect, 1000);
}
return;
}
}
Expand Down

0 comments on commit 0080215

Please sign in to comment.