Skip to content

Commit

Permalink
Address Ben's PR feedback; get rid of extraneous flag to control damp…
Browse files Browse the repository at this point in the history
… and expiration timers
  • Loading branch information
jwolski committed Nov 25, 2015
1 parent 4fdc724 commit 4ac9af5
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/gossip/damper.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ function Damper(opts) {

// This damp timer runs only when there are flappy members
// add to the flappers collection above.
this.isDampTimerEnabled = false;
this.dampTimer = null;

// The expiration timer runs only when there are damped members
// in the dampedMembers collection above.
this.isExpirationTimerEnabled = false;
this.expirationTimer = null;
}

Expand Down Expand Up @@ -191,7 +189,7 @@ Damper.prototype.dampMember = function dampMember(addr) {
this.removeFlapper(member.address);
this.addDampedMember(member.address);

if (!this.isExpirationTimerEnabled) {
if (!this._isExpirationTimerEnabled()) {
this.logger.debug('ringpop damper starting expiration timer; a member has been damped', {
local: this.ringpop.whoami(),
member: member.address
Expand Down Expand Up @@ -466,17 +464,24 @@ Damper.prototype._getFlapperCount = function _getFlapperCount() {
return Object.keys(this.flappers).length;
};

Damper.prototype._isDampTimerEnabled = function _isDampTimerEnabled() {
return !!this.dampTimer;
};

Damper.prototype._isExpirationTimerEnabled = function _isExpirationTimerEnabled() {
return !!this.expirationTimer;
};

Damper.prototype._startDampTimer = function _startDampTimer() {
var self = this;

if (this.isDampTimerEnabled) {
if (this._isDampTimerEnabled()) {
this.logger.debug('ringpop damp timer already started', {
local: this.ringpop.whoami()
});
return;
}

this.isDampTimerEnabled = true;
schedule();
this.logger.debug('ringpop damper started damp timer', {
local: this.ringpop.whoami()
Expand All @@ -494,7 +499,7 @@ Damper.prototype._startDampTimer = function _startDampTimer() {
// It may be the case that the damp timer is stopped while in the
// middle of a subprotocol. Make sure we don't schedule another
// run if that happens.
if (self.isDampTimerEnabled) schedule();
if (self._isDampTimerEnabled()) schedule();
});
}, self.ringpop.config.get('dampTimerInterval'));
}
Expand All @@ -503,14 +508,13 @@ Damper.prototype._startDampTimer = function _startDampTimer() {
Damper.prototype._startExpirationTimer = function _startExpirationTimer() {
var self = this;

if (this.isExpirationTimerEnabled) {
if (this._isExpirationTimerEnabled()) {
this.logger.debug('ringpop damper expiration timer already started', {
local: this.ringpop.whoami()
});
return;
}

this.isExpirationTimerEnabled = true;
schedule();
this.logger.debug('ringpop damper expiration timer started', {
local: this.ringpop.whoami()
Expand All @@ -523,13 +527,13 @@ Damper.prototype._startExpirationTimer = function _startExpirationTimer() {
local: self.ringpop.whoami()
});
self.expireDampedMembers();
if (self.isExpirationTimerEnabled) schedule();
if (self._isExpirationTimerEnabled()) schedule();
}, self.ringpop.config.get('dampedMemberExpirationInterval'));
}
};

Damper.prototype._stopDampTimer = function _stopDampTimer() {
if (!this.isDampTimerEnabled) {
if (!this._isDampTimerEnabled()) {
this.logger.debug('ringpop damper already stopped damp timer', {
local: this.ringpop.whoami()
});
Expand All @@ -538,14 +542,13 @@ Damper.prototype._stopDampTimer = function _stopDampTimer() {

this.timers.clearTimeout(this.dampTimer);
this.dampTimer = null;
this.isDampTimerEnabled = false;
this.logger.debug('ringpop damper stopped damp timer', {
local: this.ringpop.whoami()
});
};

Damper.prototype._stopExpirationTimer = function _stopExpirationTimer() {
if (!this.isExpirationTimerEnabled) {
if (!this._isExpirationTimerEnabled()) {
this.logger.debug('ringpop damper expiration timer already stopped', {
local: this.ringpop.whoami()
});
Expand All @@ -554,7 +557,6 @@ Damper.prototype._stopExpirationTimer = function _stopExpirationTimer() {

this.timers.clearTimeout(this.expirationTimer);
this.expirationTimer = null;
this.isExpirationTimerEnabled = false;
this.logger.info('ringpop damper stopped expiration timer', {
local: this.ringpop.whoami()
});
Expand Down

0 comments on commit 4ac9af5

Please sign in to comment.