Any error is going to crash. No retry. We are going to ask the current
leader. If the leader is not there or responds with any sort of error code,
we crash. Out-of-band data is supposed to be used to abtain a mirror of an
initial state, probably through an atomic immigration entry processor, so if
the leader is unresponsive, and the government has changed, we’re not going
to be able to wait until things get better. We can’t process the log until
we’re initialized. Deadlock. Crash and start over.
The leader doesn’t necessarily need to be the leader. That is application
dependant. It only needs to have the state information necessary to
initialize the new participant. Unless the application developer wants us to
crash, we’re not going to crash if leadership changes, only if the leader at
the time of immigration has gone away or is unable to respond.
Colleague.prototype.outOfBand = cadence(function (async, name, post) {
var outOfBandNumber = this._outOfBandNumber++
logger.trace('outOfBandCall', {
message: {
name: name, post: post, invocation: outOfBandNumber
}
})
var leaderId = this.kibitzer.legislator.government.majority[0]
var properties = this.kibitzer.legislator.properties[leaderId]
var url = util.format('http://%s/oob', properties.location)
async(function () {
this._ua._ua.fetch({
url: url,
post: {
islandName: this.islandName,
islandId: this.islandId,
colleagueId: leaderId,
name: name,
post: post
},
raise: true
}, async())
}, function (result) {
logger.trace('outOfBandReturn', { invocation: outOfBandNumber, result: result })
return [ result ]
})
})
Colleague.prototype.naturalized = function () {
this.kibitzer.legislator.naturalize()
}
Colleague.prototype.health = cadence(function (async) {
return {
startedAt: this.startedAt,
requests: this._requests.turnstile.health,
islandName: this.islandName,
colleagueId: this.kibitzer.paxos.id,
islandId: this.kibitzer.paxos.islandId,
government: this.kibitzer.paxos.government
}
})
Colleague.prototype.request = cadence(function (async, type, body) {
if (!~([ 'health', 'kibitz', 'join', 'bootstrap', 'shutdown' ]).indexOf(type)) {
return [ { cookie: request.cookie, body: null } ]
}
this[type](body, async())
})
module.exports = Colleague