Skip to content

Commit

Permalink
Merge pull request #188 from uber/make-issueas-prototype
Browse files Browse the repository at this point in the history
Make _issueAt part of prototype
  • Loading branch information
jwolski2 committed Oct 4, 2015
2 parents de4a510 + 6d71545 commit ae6c4b8
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/dissemination.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Dissemination.prototype.fullSync = function fullSync() {
};

Dissemination.prototype.issueAsSender = function issueAsSender() {
return issueAs(this, null, mapChanges);
return this._issueAs(null, mapChanges);

function mapChanges(changes) {
return changes;
Expand All @@ -86,7 +86,7 @@ Dissemination.prototype.issueAsSender = function issueAsSender() {
Dissemination.prototype.issueAsReceiver = function issueAsReceiver(senderAddr, senderIncarnationNumber, senderChecksum) {
var self = this;

return issueAs(this, filterChange, mapChanges);
return this._issueAs(filterChange, mapChanges);

function filterChange(change) {
return !!(senderAddr &&
Expand Down Expand Up @@ -130,19 +130,14 @@ Dissemination.prototype.resetMaxPiggybackCount = function resetMaxPiggybackCount
this.maxPiggybackCount = Dissemination.Defaults.maxPiggybackCount;
};

Dissemination.Defaults = {
maxPiggybackCount: 1,
piggybackFactor: 15 // A lower piggyback factor leads to more full-syncs
};

function issueAs(dissemination, filterChange, mapChanges) {
Dissemination.prototype._issueAs = function _issueAs(filterChange, mapChanges) {
var changesToDisseminate = [];

var changedNodes = Object.keys(dissemination.changes);
var changedNodes = Object.keys(this.changes);

for (var i = 0; i < changedNodes.length; i++) {
var address = changedNodes[i];
var change = dissemination.changes[address];
var change = this.changes[address];

// TODO We're bumping the piggyback count even though
// we don't know whether the change successfully made
Expand All @@ -153,14 +148,14 @@ function issueAs(dissemination, filterChange, mapChanges) {
}

if (typeof filterChange === 'function' && filterChange(change)) {
dissemination.ringpop.stat('increment', 'filtered-change');
this.ringpop.stat('increment', 'filtered-change');
continue;
}

change.piggybackCount += 1;

if (change.piggybackCount > dissemination.maxPiggybackCount) {
delete dissemination.changes[address];
if (change.piggybackCount > this.maxPiggybackCount) {
delete this.changes[address];
continue;
}

Expand All @@ -175,9 +170,14 @@ function issueAs(dissemination, filterChange, mapChanges) {
});
}

dissemination.ringpop.stat('gauge', 'changes.disseminate', changesToDisseminate.length);
this.ringpop.stat('gauge', 'changes.disseminate', changesToDisseminate.length);

return mapChanges(changesToDisseminate);
}
};

Dissemination.Defaults = {
maxPiggybackCount: 1,
piggybackFactor: 15 // A lower piggyback factor leads to more full-syncs
};

module.exports = Dissemination;

0 comments on commit ae6c4b8

Please sign in to comment.