Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old documentation (missing .extends) and Log Replication #18

Open
GiovanniCapizzi opened this issue Aug 28, 2018 · 0 comments
Open

Old documentation (missing .extends) and Log Replication #18

GiovanniCapizzi opened this issue Aug 28, 2018 · 0 comments

Comments

@GiovanniCapizzi
Copy link

Hi there, we are working using your liferaft lib in an university project. I found an update after few months and we updated from v.0.1.1 to 1.0.0.
First we tried using something like this (taking this example from your doc):

var LifeBoat = LifeRaft.extend({
  socket: null,
  write: function write(packet, callback) {
    // code etc...
  }
});

But it cannot startup and says "extend is not a function", because it seems disappeared from lib declarations.

We saw also your example in Log Replication and we saw you use now "extends LifeRaft", so maybe it's the documentation that is not updated.
We are asking ourselves also if our idea about transport layer is correct. Before your update we were implementing an "initialize" and "write" functions in your LifeRaft extension. We did a setup with expressjs in this way:

const MsgRaft = LifeRaft.extend({

	update: function(from) {
		this.stored = Object.assign(this.stored || {}, from);
	},

	initialize: function(options) {

		const raft = this; 
		const server = express();

		server.listen(port, () => console.log('initializing on :', raft.address));

		server.use(bodyParser.json())

		server.post('/message', (req, res) => {
			if (LifeRaft.LEADER == raft.state) {
				const packet = raft.packet('store', req.body)
				return raft.message(LifeRaft.CHILD, packet, () => res.json({ "success": true })) // Risposta al client       
			}
			res.json({ "success": false, "leader": raft.leader })
		})

		server.post('/', (req, res) => {
			const msg = req.body;
			if (msg.type == 'store') {
				if (msg.address = raft.leader) {
					raft.update(msg.data);
					raft.emit('new data', raft.stored);
				}
				return res.json({ 'store': true })
			}

			raft.emit('data', msg, function reply(data) {
				res.json(data)
			});

		});

		raft.once('end', () => server.close())

	},

	write: function(packet, fn) {
		console.log('sending packet to', this.address);
		request.post({ url: this.address, body: packet, json: true }, (err, res, body) => {
			fn(err, (body || {}).store ? null : body);
		});
	}

});

We are asking if it is correct the way they reply to each others. Because in this raft explanation seems that the Leader should wait the majority of responses before commit in memory its information, but in this way something seems missing and we do not find difference in your code.
Please can you give us some advises?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant