Re-apply the follower changes that got lost in the node 10 merge

This commit is contained in:
Naomi Seyfer
2013-11-04 10:06:16 -08:00
parent 42e9d79152
commit 8f27d2cd58
3 changed files with 21 additions and 12 deletions

View File

@@ -4,7 +4,7 @@ Package.describe({
});
Package.on_use(function (api) {
api.use(['underscore', 'livedata', 'ejson', 'follower-livedata']);
api.use(['logging', 'underscore', 'livedata', 'ejson', 'follower-livedata']);
api.use(['mongo-livedata'], {
unordered: true
});

View File

@@ -40,6 +40,7 @@ Follower = {
makeElectorTries(urlSet, { priority: 0, reset: true });
}
var tryingUrl = null;
var outstandingGetElectorate = false;
var conn = null;
var leader = null;
var connected = null;
@@ -87,8 +88,11 @@ Follower = {
};
var tryElector = function (url) {
if (tryingUrl) {
electorTries[tryingUrl]++;
}
url = url || findFewestTries();
// console.log("trying", url, electorTries, tryingUrl);
console.log("trying", url, electorTries, tryingUrl, process.env.GALAXY_JOB);
// Don't keep trying the same url as fast as we can if it's not working.
if (electorTries[url] > 2) {
@@ -103,20 +107,21 @@ Follower = {
conn = DDP.connect(url);
conn._reconnectImpl = conn.reconnect;
}
tryingUrl = url;
if (tryingUrl) {
electorTries[tryingUrl]++;
tryingUrl = url;
} else {
tryingUrl = url;
if (!outstandingGetElectorate) {
outstandingGetElectorate = true;
conn.call('getElectorate', options.group, function (err, res) {
outstandingGetElectorate = false;
connected = tryingUrl;
tryingUrl = null;
if (!_.contains(res.electorate, connected)) {
Log.warn("electorate " + res.electorate + " does not contain " + connected);
}
if (err) {
electorTries[url]++;
tryElector();
return;
}
tryingUrl = null;
if (! connectedToLeadershipGroup.isResolved()) {
connectedToLeadershipGroup["return"]();
}
@@ -135,7 +140,6 @@ Follower = {
// is connectable.
if (electorTries[res.leader] == 0) {
tryElector(res.leader);
} else {
// XXX: leader is probably down, we're probably going to elect
// soon. Wait for the next round.
@@ -144,7 +148,8 @@ Follower = {
}
updateElectorate(res);
});
};
}
};
tryElector();
@@ -157,6 +162,10 @@ Follower = {
if (err) {
electorTries[connected]++;
tryElector();
} else if (res.leader !== leader) {
// update the electorate, and then definitely try to connect to the leader.
updateElectorate(res);
tryElector(res.leader);
} else {
if (! connectedToLeadershipGroup.isResolved()) {
connectedToLeadershipGroup["return"]();

View File

@@ -4,7 +4,7 @@ Package.describe({
});
Package.on_use(function (api) {
api.use(['underscore', 'livedata', 'ejson']);
api.use(['logging', 'underscore', 'livedata', 'ejson']);
api.add_files(['follower.js'], 'server');
api.export('Follower');
});