-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Significant refactor of membership change paths in prep for smaller
damping pull request
- Loading branch information
Showing
20 changed files
with
791 additions
and
780 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// Copyright (c) 2015 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
'use strict'; | ||
|
||
var MembershipUpdateRules = require('./membership-update-rules.js'); | ||
|
||
var LOG_10 = Math.log(10); | ||
|
||
function Dissemination(ringpop) { | ||
this.ringpop = ringpop; | ||
this.ringpop.on('changed', this.onRingChanged.bind(this)); | ||
|
||
this.changes = {}; | ||
this.maxPiggybackCount = 1; | ||
this.piggybackFactor = 15; // A lower piggyback factor leads to more full-syncs | ||
} | ||
|
||
Dissemination.prototype.adjustMaxPiggybackCount = function adjustMaxPiggybackCount() { | ||
var serverCount = this.ringpop.ring.getServerCount(); | ||
var prevPiggybackCount = this.maxPiggybackCount; | ||
var newPiggybackCount = this.piggybackFactor * Math.ceil(Math.log(serverCount + 1) / LOG_10); | ||
|
||
if (this.maxPiggybackCount !== newPiggybackCount) { | ||
this.maxPiggybackCount = newPiggybackCount; | ||
this.ringpop.stat('gauge', 'max-piggyback', this.maxPiggybackCount); | ||
this.ringpop.logger.debug('adjusted max piggyback count', { | ||
newPiggybackCount: this.maxPiggybackCount, | ||
oldPiggybackCount: prevPiggybackCount, | ||
piggybackFactor: this.piggybackFactor, | ||
serverCount: serverCount | ||
}); | ||
} | ||
}; | ||
|
||
Dissemination.prototype.fullSync = function fullSync() { | ||
var changes = []; | ||
|
||
for (var i = 0; i < this.ringpop.membership.members; i++) { | ||
var member = this.ringpop.membership.members[i]; | ||
|
||
changes.push({ | ||
source: this.ringpop.whoami(), | ||
address: member.address, | ||
status: member.status, | ||
incarnationNumber: member.incarnationNumber | ||
}); | ||
} | ||
|
||
return changes; | ||
}; | ||
|
||
Dissemination.prototype.issueChanges = function issueChanges(checksum, source) { | ||
var changesToDisseminate = []; | ||
|
||
var changedNodes = Object.keys(this.changes); | ||
|
||
for (var i = 0; i < changedNodes.length; i++) { | ||
var address = changedNodes[i]; | ||
var change = this.changes[address]; | ||
|
||
// TODO We're bumping the piggyback count even though | ||
// we don't know whether the change successfully made | ||
// it over to the other side. This can result in undesired | ||
// full-syncs. | ||
if (typeof change.piggybackCount === 'undefined') { | ||
change.piggybackCount = 0; | ||
} | ||
|
||
change.piggybackCount += 1; | ||
|
||
if (change.piggybackCount > this.maxPiggybackCount) { | ||
delete this.changes[address]; | ||
continue; | ||
} | ||
|
||
// TODO Compute change ID | ||
// TODO Include change timestamp | ||
changesToDisseminate.push({ | ||
source: change.source, | ||
address: change.address, | ||
status: change.status, | ||
incarnationNumber: change.incarnationNumber | ||
}); | ||
} | ||
|
||
this.ringpop.stat('gauge', 'changes.disseminate', changesToDisseminate.length); | ||
|
||
if (changesToDisseminate.length) { | ||
return changesToDisseminate; | ||
} else if (checksum && this.ringpop.membership.checksum !== checksum) { | ||
this.ringpop.stat('increment', 'full-sync'); | ||
this.ringpop.logger.info('full sync', { | ||
localChecksum: this.ringpop.membership.checksum, | ||
remoteChecksum: checksum, | ||
remoteNode: source | ||
}); | ||
|
||
// TODO Somehow send back indication of isFullSync | ||
return this.fullSync(); | ||
} else { | ||
return []; | ||
} | ||
}; | ||
|
||
Dissemination.prototype.onRingChanged = function onRingChanged() { | ||
this.adjustMaxPiggybackCount(); | ||
}; | ||
|
||
Dissemination.prototype.recordChange = function recordChange(change) { | ||
this.changes[change.address] = change; | ||
}; | ||
|
||
module.exports = Dissemination; |
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
Oops, something went wrong.