Skip to content

Commit

Permalink
cluster: support setting data on shared server
Browse files Browse the repository at this point in the history
If `obj` given to `cluster._getServer` has `_setServerData` or
`_getServerData` methods, the data will be synchronized across workers
and stored in master.
  • Loading branch information
indutny committed Jul 24, 2013
1 parent 44ed42b commit 509cfbc
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,15 @@ function masterInit() {
message.backlog,
message.fd);
}
if (!handle.data) handle.data = message.data;

// Set custom server data
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) {
reply.errno = errno;
delete handles[key]; // Gives other workers a chance to retry.
Expand Down Expand Up @@ -447,9 +454,14 @@ function workerInit() {
address: address,
port: port,
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) {
if (obj._setServerData) obj._setServerData(reply.data);

if (handle)
shared(reply, handle, cb); // Shared listen socket.
else
Expand Down

0 comments on commit 509cfbc

Please sign in to comment.