YUKI Hiroshi
null+****@clear*****
Mon Apr 20 11:24:24 JST 2015
YUKI Hiroshi 2015-04-20 11:24:24 +0900 (Mon, 20 Apr 2015) New Revision: 6356609de89d548cd67ab98d6e3091ccfc6dac30 https://github.com/droonga/express-droonga/commit/6356609de89d548cd67ab98d6e3091ccfc6dac30 Message: Don't create new connection for an engine node while cluster structure is changing Modified files: lib/adapter/http.js lib/droonga-protocol/connection-pool.js Modified: lib/adapter/http.js (+11 -0) =================================================================== --- lib/adapter/http.js 2015-04-17 23:14:16 +0900 (1a8cfdd) +++ lib/adapter/http.js 2015-04-20 11:24:24 +0900 (d21d602) @@ -3,6 +3,8 @@ var wrapper = require('./wrapper'); var api = require('./api'); var ConsoleLogger = require('../console-logger').ConsoleLogger; +var CONNECTION_RETRY_INTERVAL = 1000; + function createRequestResponseHandler(params) { params = params || {}; var connectionPool = params.connectionPool; @@ -95,6 +97,15 @@ function createGenericHandler(params) { return; } var connection = connectionPool.get(); + if (!connection) { + // When the cluster members are changing, we cannot get + // actual connection for a member, so retry later. + setTimeout(function() { + processRequest(); + }, CONNECTION_RETRY_INTERVAL); + return; + } + var wrappedConnection = new wrapper.DroongaProtocolConnectionWrapper(connection, options); try { definition.onHandle(request, response, wrappedConnection); Modified: lib/droonga-protocol/connection-pool.js (+11 -0) =================================================================== --- lib/droonga-protocol/connection-pool.js 2015-04-17 23:14:16 +0900 (3ea4ea6) +++ lib/droonga-protocol/connection-pool.js 2015-04-20 11:24:24 +0900 (4d7b3cc) @@ -69,6 +69,11 @@ ConnectionPool.prototype = { }, get: function() { + // When the cluster members are changing, we cannot get + // actual connection for a member. + if (this.updating) + return null; + var hostName = this.hostNames[this.nextIndex]; this.nextIndex++; @@ -196,6 +201,10 @@ ConnectionPool.prototype = { }, updateHostNamesFromCluster: function() { + if (this.updating) + return Q.Promise.resolve(); + + this.updating = true; return this.getEnginesFromCluster() .then((function(engines) { this.clusterId = engines[0].Tags.cluster_id; @@ -209,11 +218,13 @@ ConnectionPool.prototype = { this._logger.info('List of droonga-engine hosts is successfully initialized from the cluster.'); this._logger.info('cluster id: '+this.clusterId); this._logger.info(hostNames); + this.updating = false; return hostNames; }).bind(this)) .catch(function(error) { this._logger.error('Failed to initialize the list of droonga-engine hosts from the cluster.'); this._logger.error(error); + this.updating = false; }); }, -------------- next part -------------- HTML����������������������������...ダウンロード