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

Add package to support LiteFS in the WebSocket server #11

Merged
merged 44 commits into from
Aug 30, 2023
Merged

Conversation

tantaman
Copy link
Contributor

LiteFS is a bit more complicated when running WebSocket servers.

The reason is that all writes must go to the primary for LiteFS. In our websocket server, we determine if the received message is a write. If so, we send it on to the primary.

This isn't quite enough though. WebSocket servers are stateful by nature and we need to keep this state maintained on the edge node responsible for the websocket connection and not build up state on the primary that the writes are forwarded to.

In other words:

  • Primaries that receive forwarded writes are stateless with respect to those writes
  • The nodes that hold the websocket connection(s) are stateful

So after forwarding a write the follower will (for certain writes) await completion of that write (by following the -pos txid) and update its internal state.

LiteFS technically supports write forwarding (superfly/litefs#56) but the way it works is by passing the write lock around and is not recommended for cases with high write volume.

@tantaman tantaman changed the title Add classes to support LiteFS in the WebSocket server Add package to support LiteFS in the WebSocket server Aug 24, 2023
These are not litefs specific
instead we'll re-route write at the top of the stack at the websocket handler.
We have more information at this level and cleanup is easier to manage as the connection over which to forward writes is per-db.
- introduce DBFactory so different backends can provide different DBs. E.g., LiteFS provides one that forwards writes
- make certain db methods async given we now have async operations when forwarding writes
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

Successfully merging this pull request may close these issues.

1 participant