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

Implement position file change notification #179

Closed
kentcdodds opened this issue Nov 14, 2022 · 5 comments
Closed

Implement position file change notification #179

kentcdodds opened this issue Nov 14, 2022 · 5 comments
Labels
performance Improvements to performance
Milestone

Comments

@kentcdodds
Copy link

I'm trying to implement improved consistency and one approach I started with but don't like is polling the file until it's been updated to the user session's txid. I'd rather be notified when the file is updated so I can respond quicker and don't have to poll. So I'm trying to use chokidar on that file and it doesn't seem to be working. I'm thinking that because that file didn't show up in ls -al until something fancy was done maybe it's not a real file? So maybe it doesn't work with file watching tools like chokidar?

Is there any way to be notified when the -pos file is updated?

kentcdodds added a commit to kentcdodds/kentcdodds.com that referenced this issue Nov 14, 2022
@benbjohnson benbjohnson changed the title Add the ability to listen to events when db-pos file is changed Implement inotify on position file Nov 14, 2022
@benbjohnson
Copy link
Collaborator

@kentcdodds The position file isn't really an actual file. LiteFS fakes it so it reads the litefs.DB.Pos() value and formats it when read from a handle:

litefs/fuse/pos_node.go

Lines 49 to 65 in 6ecc549

func (n *PosNode) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
pos := n.db.Pos()
data := fmt.Sprintf("%016x/%016x\n", pos.TXID, pos.PostApplyChecksum)
if req.Offset >= int64(len(data)) {
return io.EOF
}
// Size buffer to offset/size.
data = data[req.Offset:]
if len(data) > req.Size {
data = data[:req.Size]
}
resp.Data = []byte(data)
return nil
}

I think I just need to implement fuse/fs.Poller on the position node. Currently it returns ENOSYS (which just says it's not implemented):

litefs/fuse/pos_node.go

Lines 49 to 65 in 6ecc549

func (n *PosNode) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
pos := n.db.Pos()
data := fmt.Sprintf("%016x/%016x\n", pos.TXID, pos.PostApplyChecksum)
if req.Offset >= int64(len(data)) {
return io.EOF
}
// Size buffer to offset/size.
data = data[req.Offset:]
if len(data) > req.Size {
data = data[:req.Size]
}
resp.Data = []byte(data)
return nil
}

I'll take a look and see how difficult it would be to implement. Hopefully it's relatively easy.

@benbjohnson benbjohnson added this to the v0.3.0 milestone Nov 14, 2022
@benbjohnson benbjohnson added the performance Improvements to performance label Nov 14, 2022
@benbjohnson benbjohnson changed the title Implement inotify on position file Implement position file change notification Nov 15, 2022
@benbjohnson
Copy link
Collaborator

@kentcdodds I did some more research and it looks like FUSE doesn't implement file change notification (e.g. inotify). There are plans to add an event stream (#20) and that'll be accessible via something like a unix socket. The position data will be available through that handle so I'm going to close this issue in favor of #20.

@kentcdodds
Copy link
Author

Bummer. Back to polling then. I've subscribed to the other issue. Thanks!

kentcdodds added a commit to kentcdodds/kentcdodds.com that referenced this issue Nov 21, 2022
@benbjohnson
Copy link
Collaborator

@kentcdodds This is an old issue but I just wanted to let you know that I did end up adding an event stream (#401) so you can get immediate notification of the replication position & primary state changes from LiteFS. That's probably not as big of a deal now that we have the LiteFS proxy but I figured I'd give you a heads up.

@kentcdodds
Copy link
Author

Thanks!

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

No branches or pull requests

2 participants