LiteFS & Filesystem notifications

I recently got LiteFS up and running with a few read replicas.

One of the things my application relies on is being able to know when the database has changed so that it can push updates to clients.

I figured I could just watch the -pos files to do that. This works but only on the primary node.

In other words, read replicas never receive change notifications from the filesystem when the database is update via LiteFS. No change events for the DB file itself, the pos file, the shm file or wal file come through on read replicas. I know that replication is working since I can see the -pos file change if I connect to a replica open it up. The DB also has the latest rows after a write.

Is it possible to watch the -pos files on read replicas so I can know to push data to clients connected to those replicas? I can work around this by polling the file for the time being.

Unfortunately, I don’t believe file notification support is available in the FUSE protocol. There was a proposal for it at one time but I don’t think any headway was made on it.

I’m planning on adding an event stream soon which would provide replication position updates as well as other types of events in a single stream that applications can subscribe to. In the meantime, polling is the best alternative.

I’ll see if I can get the event stream work done soon. It’s requested a lot and I just need to do it.

I’ll see if I can get the event stream work done soon.

Great. Any idea if that’s a 1-2 week fix or 1-2 month sort of thing?

I just went ahead and implemented it (#401). I’ve just done some manual testing so far so I need to add automated tests next. It seems to be working pretty well though.

Can you take a look and see if it fits for your use case? I can make tweaks if there’s additional information you need. The notifications for tx events should be nearly instantaneous so it beats polling the -pos file.

One important thing to note is that if your application can’t keep up with the event stream then LiteFS will disconnect it. It’ll buffer 1024 events and there’s also an HTTP write buffer you’d have to be really slow in accepting events before it disconnects.

You can use the image built by the PR with this in your Dockerfile:

COPY --from=flyio/litefs:pr-401 /usr/local/bin/litefs /usr/local/bin/litefs
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.