Skip to content

Commit

Permalink
nominate master
Browse files Browse the repository at this point in the history
  • Loading branch information
nomilous committed Dec 15, 2016
1 parent 704b4a2 commit 735fd41
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 7 deletions.
58 changes: 55 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
**using node ^6.0.0**

[![npm](https://img.shields.io/npm/v/vertex.svg)](https://www.npmjs.com/package/vertex)
[![Build Status](https://travis-ci.org/nomilous/vertex.svg?branch=master)](https://travis-ci.org/nomilous/vertex)
[![Coverage Status](https://coveralls.io/repos/nomilous/vertex/badge.svg?branch=master&service=github)](https://coveralls.io/github/nomilous/vertex?branch=master)
Expand Down Expand Up @@ -73,6 +71,7 @@ Notably:
```javascript
logLevel: (nfo) => {
// called to assign level as each new logger in the tree initialises
// console.log(nfo);
if (nfo.??) return 'trace';
return 'warn';
}
Expand All @@ -96,4 +95,57 @@ Host and port to listen.
#### config.cluster
...
If the cluster section is specified the vertex will join a cluster of vertexes
##### config.cluster.name
Optional cluster name. If unspecified a random name will be generated. If specified it must much the name of the cluster being joined (to).
##### config.cluster.seed
Set true on the first node joining (seeding) the cluster.
##### config.cluster.sync
Upon joining the cluster the contents of the clusters key-storage is synchronised onto the new member.
###### config.cluster.sync.limit
Maximum key-store records per synchronisation data-frame.
###### config.cluster.sync.timeout
Timeout applied on send of each data-frame.
##### config.cluster.join
At least one host already present in the cluster should be specified. It is recommended that all cluster members use the same set of join hosts. At least one of the join hosts should be running at all times.
Join hosts are attempted one at a time. Upon success the remaining hosts are not tried.
###### config.cluster.join.timeout
Timeout on each attempt to join.
##### config.cluster.leave
When one member detects the departure of another member it deletes the member from the members key-store. This action requires consensus among the cluster members independantly also detecting the departure. If consensus is not reached the member(s) making the false deletion is shut down since it is no longer fully connected to the cluster (has lost link to member that others have not lost link to)
###### config.cluster.leave.consensus
Proportion of cluster members required for consensus. 1.0 is all members. 0.5 is half of the members.
###### config.cluster.leave.expire
Allotted discovery/accumulation time for the consensus to be reached.
##### config.cluster.nominate
When the cluster master is shut down a new master is selected by the cluster. Since all members share the fill list of cluster members with a common sequence number the master is selected from that list (the next member in the sequence). All remaining members nominate the next member in the sequence as master. And again if that member also goes down while the nomination is still in progress (expire).
###### config.cluster.nominate.expire
The nomination expire time.
16 changes: 15 additions & 1 deletion lib/Cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ const deepcopy = require('deepcopy');
const {VertexSocket} = require('vertex-transport');
const {createWord} = require('vertex-names');
const {format} = require('util');
const {satisfies} = require('semver');

const KeyStore = require('./KeyStore');
const Member = require('./Member');
const {isInt, isntSelf} = require('./utils');
const {VertexError, VertexConfigError, VertexJoinError} = require('./errors');
const {VertexSocketClosedError} = require('vertex-transport').errors;
const constants = require('./constants');
const version = require('../package.json').version;

class Cluster {

Expand Down Expand Up @@ -475,6 +477,12 @@ class Cluster {
));
}

if (!satisfies(version, data.version)) {
return reply('nak', new Error(
format('Version mismatch, server is \'%s\'', version)
));
}

reply('join1', this.getMaster().then(member => {
return {
cluster: this.name,
Expand Down Expand Up @@ -672,9 +680,15 @@ class Cluster {


_join1Payload() {

var compat = version.split('.');
compat[1] = 'x';
compat[2] = 'x';

return [
this._payloadHeader(constants.CLUSTER_HANDLER_JOIN_1), {
name: this.name
name: this.name,
version: compat.join('.')
}
]
}
Expand Down
4 changes: 3 additions & 1 deletion lib/errors/VertexError.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ module.exports = class VertexError extends Error {

constructor(message) {
super(message);
this.name = this.constructor.name;
Object.defineProperty(this, 'name', {
value: this.constructor.name
});
}

};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"deep-equal": "^1.0.1",
"deepcopy": "^0.6.3",
"semver": "^5.3.0",
"vertex-logger": "^2.3.2",
"vertex-names": "^1.1.4",
"vertex-transport": "^3.1.3"
Expand Down
2 changes: 2 additions & 0 deletions test/func-Cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ describe(filename, () => {
.catch(done);
});

it('fails to join if incompatible version');

it('cannot join self', done => {

Vertex.create({
Expand Down
4 changes: 2 additions & 2 deletions test/func-KeyStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ describe(filename, function () {

});

xcontext('load', function () {
context('load', function () {

// TODO: try with/without deepcopy

Expand All @@ -723,7 +723,7 @@ describe(filename, function () {
}
};

[2, 4, 6, 8, 10, 12, 14, 16, 18, 20].forEach(clusterSize => {
[2, 4, 6, 8, 10, 12, 14, 16 /*, 18, 20 */].forEach(clusterSize => {

context('in cluster of ' + clusterSize, () => {

Expand Down

0 comments on commit 735fd41

Please sign in to comment.