YUKI Hiroshi
null+****@clear*****
Sun Nov 30 20:20:43 JST 2014
YUKI Hiroshi 2014-11-30 20:20:43 +0900 (Sun, 30 Nov 2014) New Revision: 9ad759feaee255a8367b8c8257000d3050f5d13b https://github.com/droonga/express-droonga/commit/9ad759feaee255a8367b8c8257000d3050f5d13b Message: Detect live engine nodes more correctly even if the protocol adapter is running on a node without engine Modified files: bin/express-droonga-report-live-engine-hosts lib/droonga-protocol/connection-pool.js lib/serf/client.js Modified: bin/express-droonga-report-live-engine-hosts (+12 -4) =================================================================== --- bin/express-droonga-report-live-engine-hosts 2014-11-30 19:59:30 +0900 (2c16bb4) +++ bin/express-droonga-report-live-engine-hosts 2014-11-30 20:20:43 +0900 (0983119) @@ -3,7 +3,13 @@ var SerfClient = require('../lib/serf/client'); var options = require('../lib/serf/options'); -options = options.define().parse(process.argv); +options = options.define() + .add('--priority-hosts <hosts>', + 'Comma-separated list of host names which is preferentially connected.', + function(newValue, oldValue) { + return newValue.trim().split(/[, ]+/); + }) + .parse(process.argv); var client = new SerfClient({ rpcAddress: options.rpcAddress, @@ -11,9 +17,11 @@ var client = new SerfClient({ tag: options.tag }); -client.getLiveEngineNodes() - .then(function(members) { - console.log(JSON.stringify(members)); +client.getLiveEngineNodes({ + priorityHosts: options.priorityHosts +}) + .then(function(result) { + console.log(JSON.stringify(result)); process.exit(0); }) .catch(function(error) { Modified: lib/droonga-protocol/connection-pool.js (+6 -3) =================================================================== --- lib/droonga-protocol/connection-pool.js 2014-11-30 19:59:30 +0900 (4b466aa) +++ lib/droonga-protocol/connection-pool.js 2014-11-30 20:20:43 +0900 (d22bf12) @@ -146,13 +146,16 @@ ConnectionPool.prototype = { commandPath, '--rpc-address=' + rpcAddress, '--droonga-engine-port=' + this._params.port, - '--tag=' + this._params.tag + '--tag=' + this._params.tag, + '--priority-hosts=' + this._initialHostNames.join(',') ].join(' '); exec(commandLine, function(error, stdin, stdout) { if (error) return reject(error); - var engines = JSON.parse(stdin.trim()); - resolve(engines); + var result = JSON.parse(stdin.trim()); + this._logger.debug('express-droonga-report-live-engine-hosts:'); + this._logger.debug(result); + resolve(result.liveEngineNodes); }); }).bind(this)); }, Modified: lib/serf/client.js (+19 -8) =================================================================== --- lib/serf/client.js 2014-11-30 19:59:30 +0900 (e4b374a) +++ lib/serf/client.js 2014-11-30 20:20:43 +0900 (1944252) @@ -33,12 +33,12 @@ function Client(options) { options = options || {}; options.rpcAddress = options.rpcAddress || '127.0.0.1'; - this._droongaEngineHost = options.rpcAddress.split(':')[0]; + this._rpcHost = options.rpcAddress.split(':')[0]; this._droongaEnginePort = options.enginePort || 10031; this._droongaTag = options.tag || 'droonga'; this._connectionOptions = { - rpc_host: this._droongaEngineHost, + rpc_host: this._rpcHost, rpc_port: parseInt(options.rpcAddress.split(':')[1] || DEFAULT_RPC_PORT) }; this._client = new SerfRPC(); @@ -71,9 +71,12 @@ Client.prototype = { }).bind(this)); }, - getLiveEngineNodes: function() { + getLiveEngineNodes: function(params) { + params = params || {} + var priorityHosts = params.priorityHosts || []; + var priorityHostsMatcher = new RegExp('^(' + priorityHosts.join('|') + ')$'); return this.getAllMembers().then((function(members) { - var clusterId; + var clusterIds = {}; var liveEngineNodes = members.filter(function(member) { if (member.Tags.role != 'engine') return false; @@ -82,20 +85,28 @@ Client.prototype = { if (matched) member.HostName = matched[1]; - if (member.HostName == this._droongaEngineHost || - member.Addr == this._droongaEngineHost) - clusterId = member.Tags.cluster_id; + if (member.HostName == this._rpcHost || + member.Addr == this._rpcHost) + clusterIds.sameHost = member.Tags.cluster_id; + if ((member.HostName && + priorityHostsMatcher.test(mmember.HostName)) || + priorityHostsMatcher.test(String(member.Addr))) + clsuterIds.priority = member.Tags.cluster_id; return matched && matched[2] == this._droongaEnginePort && matched[3] == this._droongaTag && member.Status == 'alive'; }, this); + var clusterId = clsuterIds.priority || clusterIds.sameHost; if (clusterId) liveEngineNodes = liveEngineNodes.filter(function(member) { return member.Tags.cluster_id == clusterId; }); - return liveEngineNodes; + return { + clusterIds: clusterIds, + liveEngineNodes: liveEngineNodes + }; }).bind(this)); }, -------------- next part -------------- HTML����������������������������... 下載