Browse Source

cluster: support setting data on shared server

If `obj` given to `cluster._getServer` has `_setServerData` or
`_getServerData` methods, the data will be synchronized across workers
and stored in master.
v0.11.5-release
Fedor Indutny 12 years ago
parent
commit
509cfbc2b7
  1. 16
      lib/cluster.js

16
lib/cluster.js

@ -384,8 +384,15 @@ function masterInit() {
message.backlog, message.backlog,
message.fd); message.fd);
} }
if (!handle.data) handle.data = message.data;
// Set custom server data
handle.add(worker, function(errno, reply, handle) { handle.add(worker, function(errno, reply, handle) {
reply = util._extend({ ack: message.seq, key: key }, reply); reply = util._extend({
ack: message.seq,
key: key,
data: handles[key].data
}, reply);
if (errno) { if (errno) {
reply.errno = errno; reply.errno = errno;
delete handles[key]; // Gives other workers a chance to retry. delete handles[key]; // Gives other workers a chance to retry.
@ -447,9 +454,14 @@ function workerInit() {
address: address, address: address,
port: port, port: port,
act: 'queryServer', act: 'queryServer',
fd: fd fd: fd,
data: null
}; };
// Set custom data on handle (i.e. tls tickets key)
if (obj._getServerData) message.data = obj._getServerData();
send(message, function(reply, handle) { send(message, function(reply, handle) {
if (obj._setServerData) obj._setServerData(reply.data);
if (handle) if (handle)
shared(reply, handle, cb); // Shared listen socket. shared(reply, handle, cb); // Shared listen socket.
else else

Loading…
Cancel
Save