superfly / litefs

FUSE-based file system for replicating SQLite databases across a cluster of machines
Apache License 2.0
3.78k stars 89 forks source link

Fixed Leader #37

Closed benbjohnson closed 1 year ago

benbjohnson commented 1 year ago

Currently, LiteFS uses Consul for leader election but it could be useful to have a single, fixed leader that replicates out to read-only replicas.

jwhear commented 1 year ago

I have given this some thought as my proposed system design using LiteFS would prefer a primary located centrally (at least from a latency perspective) in the US, with replica nodes all over the place. The approaches that I seriously considered:

  1. Fixed IP/hostname, I think this is what you have in mind here. The primary node knows, based on configuration, that it is the primary. Replicas are configured with the primary's address. Big advantage here is that you could remove the Consul dependency for people who are just kicking the tires locally or doing manual deployments.
  2. A configuration option (e.g. is-primary-eligible: bool) that determines whether a particular instance is allowed to become the primary using the existing Consul system. In my case, I might run three nodes in Kansas which are primary eligible and then have all the rest of my nodes be ineligible. That way if my primary does go down, I have two machines with similar characteristics who could take over. I think the implementation might be as simple as checking a config option before attempting to acquire the primary lease in acquireLeaseOrPrimaryURL.
jwhear commented 1 year ago

Just saw #16, looks like you already have point 2 in mind.