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

Buffer filesystem changes and sync on world save #1456

Open
SquidDev opened this issue May 26, 2023 · 4 comments
Open

Buffer filesystem changes and sync on world save #1456

SquidDev opened this issue May 26, 2023 · 4 comments
Labels
area-Core This affects CC's core (the Lua runtime, APIs, computer internals). area-Minecraft This affects CC's Minecraft-specific content. enhancement An extension of a feature or a new feature. feedback wanted Tell me what you want, what you really really want.

Comments

@SquidDev
Copy link
Member

Currently, a computer gets a direct view of the host computer's filesystem, meaning that when a computer changes a file, it is immediately written to disk. This is fine most of the time (and easy to implement!) - however, in the event of crashes, it's possible for computers to write files to disk, but the chunk they're in rolled-back. This is especially irritating when trying to track turtle positions by saving to a file.

The solution1 here is to buffer file changes, effectively maintaining a virtual file system until the owning chunk2 is saved, at which point we can sync the files back to disk.

There are several other motivations for this:

However, there are some concerns I have here - it's a common pattern for people to touch the computer's file system directly, viewing and editing files in an external text editor. This is pretty incompatible with a buffered file system (changes in one will not be immediately visible in the other), and I'm not sure how to reconcile that3.

It may be sufficient to handle this one-way, picking up changes made externally in-game. This at least allows editing files out-of-game, but will not allow (for instance), tailing log files that a computer writes.

Not sure. I'm definitely a while away from wanting to implement this, so any thoughts welcome!

Footnotes

  1. Well, an improvement. There's always going to be crashes which leave things in an entirely corrupted state, but we can at least do better than the status quo.

  2. Or owning entity for pocket computers.

  3. We'll probably want a config option for this, but really we want a something which works Well Enough straight away.

@SquidDev SquidDev added enhancement An extension of a feature or a new feature. feedback wanted Tell me what you want, what you really really want. area-Core This affects CC's core (the Lua runtime, APIs, computer internals). area-Minecraft This affects CC's Minecraft-specific content. labels May 26, 2023
@Lupus590
Copy link
Contributor

Lupus590 commented May 26, 2023

Probably breaks the 4th wall too much but what about a magic flush on files? So the normal fileHandle.flush() would flush to the VFS but another method would flush to the real file system too - thus allowing log files to be tailed outside and position information (in another file) to be in sync with the chunk.

@SquidDev
Copy link
Member Author

SquidDev commented Jun 1, 2023

I guess there are also some questions here about how to handle case-sensitivity of filesystems. We need to make sure the in-memory representation mirrors what actually happens on the filesystem.

This would be so much easier if we could just store the filesystem as a single file (like a virtual disk image), but that's probably not very useful for people :).

@Lupus590
Copy link
Contributor

Lupus590 commented Jun 1, 2023

I guess there are also some questions here about how to handle case-sensitivity of filesystems. We need to make sure the in-memory representation mirrors what actually happens on the filesystem.

I believe that Windows 10 and later allows users to set a folder as case-sensitive, I remember something like this being introduced with WSL 2. I have no idea if it's possible to do that within Java and it might end up causing compatibility issues for older Windows systems - having said that, Microsoft has dropped support for all but the latest Windows 10 release so maybe we shouldn't worry about compatibility with Windows versions that old.

@SquidDev
Copy link
Member Author

SquidDev commented Jun 1, 2023

Oh, interesting! I thought this was a file-system wide option - hadn't realised this was per-directory. Unfortunately it looks like this requires WSL to be enabled, so not sure if it can be relied on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Core This affects CC's core (the Lua runtime, APIs, computer internals). area-Minecraft This affects CC's Minecraft-specific content. enhancement An extension of a feature or a new feature. feedback wanted Tell me what you want, what you really really want.
Projects
None yet
Development

No branches or pull requests

2 participants