-
Notifications
You must be signed in to change notification settings - Fork 2.5k
PoolСluster auto-restore node #906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fb5a9df
5287476
021ac4d
6edc71a
7936dac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ npm-debug.log | |
/test/config.js | ||
|
||
*.sublime-* | ||
.idea | ||
|
||
.DS_Store |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ function PoolCluster(config) { | |
config = config || {}; | ||
this._canRetry = typeof config.canRetry === 'undefined' ? true : config.canRetry; | ||
this._removeNodeErrorCount = config.removeNodeErrorCount || 5; | ||
this._restoreNodeTimeout = config.restoreNodeTimeout || 0; | ||
this._defaultSelector = config.defaultSelector || 'RR'; | ||
|
||
this._closed = false; | ||
|
@@ -54,6 +55,7 @@ PoolCluster.prototype.add = function(id, config) { | |
this._nodes[id] = { | ||
id: id, | ||
errorCount: 0, | ||
online: true, | ||
pool: new Pool({config: new PoolConfig(config)}) | ||
}; | ||
|
||
|
@@ -88,7 +90,9 @@ PoolCluster.prototype.end = function() { | |
this._closed = true; | ||
|
||
for (var id in this._nodes) { | ||
this._nodes[id].pool.end(); | ||
var node = this._nodes[id]; | ||
if (node.restoreTimeoutID) clearTimeout(node.restoreTimeoutID); | ||
node.pool.end(); | ||
} | ||
}; | ||
|
||
|
@@ -124,17 +128,35 @@ PoolCluster.prototype._getNode = function(id) { | |
}; | ||
|
||
PoolCluster.prototype._increaseErrorCount = function(node) { | ||
var self = this; | ||
|
||
if (++node.errorCount >= this._removeNodeErrorCount) { | ||
var index = this._serviceableNodeIds.indexOf(node.id); | ||
if (index !== -1) { | ||
this._serviceableNodeIds.splice(index, 1); | ||
delete this._nodes[node.id]; | ||
|
||
this._clearFindCaches(); | ||
|
||
node.pool.end(); | ||
if ((this._restoreNodeTimeout > 0) && !node.restoreTimeoutID) { | ||
node.online = false; | ||
this.emit('offline', node.id); | ||
|
||
node.restoreTimeoutID = setTimeout(function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we even need to do this using a timer? Why can we not calculate the restoration time and in functions that get nodes, simply query that? (and if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi-res time is good idea. Do you approve this idea? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SGTM |
||
delete node.restoreTimeoutID; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set back to 0 or something rather than deleting and changing the hidden class of the node. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. I'll fix it |
||
node.online = true; | ||
node.errorCount = 0; | ||
|
||
self._serviceableNodeIds.push(node.id); | ||
self._clearFindCaches(); | ||
|
||
self.emit('online', node.id); | ||
}, this._restoreNodeTimeout); | ||
} else { | ||
delete this._nodes[node.id]; | ||
|
||
node.pool.end(); | ||
|
||
this.emit('remove', node.id); | ||
this.emit('remove', node.id); | ||
} | ||
} | ||
} | ||
}; | ||
|
@@ -182,7 +204,7 @@ PoolNamespace.prototype.getConnection = function(cb) { | |
var namespace = this; | ||
|
||
if (clusterNode === null) { | ||
var err = new Error('Pool does not exist.') | ||
var err = new Error('Pool does not exist.'); | ||
err.code = 'POOL_NOEXIST'; | ||
return cb(err); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this; really, editor-specific entries belong in your global ignore list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove this line, and sublime-specific things too 😃 OK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just went ahead and cleaned up the file on
master
:)