irods / irods_client_nfsrods

An nfs4j Virtual File System implementation supporting the iRODS Data Grid
BSD 3-Clause "New" or "Revised" License
8 stars 9 forks source link

truncate does not exist for nfsrods #178

Closed boydwilson closed 1 month ago

boydwilson commented 1 year ago

example to reproduce:

$echo hello, world > file $echo goodbye > file $cat file goodbye orld

korydraughn commented 1 year ago

This is going to depend on how nfs4j uses the VFS implementation to achieve truncation. The NFSRODS VFS implementation as of today does not provide any direct truncation operations, therefore the results you're seeing are expected because the write operation always opens the data object for reading and writing (i.e. it never truncates). The write operation only overwrites bytes.

See the following. https://github.com/irods/irods_client_nfsrods/blob/8c686ca0f5a1bf5da0dfa0a9443036d650a56402/irods-vfs-impl/src/main/java/org/irods/nfsrods/vfs/IRODSVirtualFileSystem.java#L1383-L1437

Is the sequence of operations required for what you're trying to achieve?

boydwilson commented 1 year ago

We are implementing nfsrods mounts that are accessed by applications that do things like this. We ran into this with VS Code Server when a file is made shorter from within the editor then the original contents remain after saving (at the end of the file) .

korydraughn commented 1 year ago

Sure. We'll investigate as soon as we can.

boydwilson commented 1 year ago

thank you!

boydwilson commented 1 year ago

So I had a thought and maybe this should be sent to the mailing list, but we are just trying to provide a mount for multiple users (not a single user or we could have used the fuse module), but if there is another approach we are open to ideas.

korydraughn commented 1 year ago

It really depends on what your users need. If your users are running shell scripts, then NFSRODS is the right tool (at this time).

We may be able to add support for truncation by modifying the following. https://github.com/irods/irods_client_nfsrods/blob/8c686ca0f5a1bf5da0dfa0a9443036d650a56402/irods-vfs-impl/src/main/java/org/irods/nfsrods/vfs/IRODSVirtualFileSystem.java#L1356-L1374

I believe we originally supported truncation, but it was removed for some reason. I'm going to see if I can track that down. Perhaps it can be supported with recent versions of iRODS.

I'll let you know what I find.

boydwilson commented 1 year ago

It looks like the initial release of nfsrods 0.8.0 had code for it (line 626) https://github.com/irods/irods_client_nfsrods/blob/0.8.0/irods-vfs-impl/src/main/java/org/irods/nfsrods/vfs/IRODSVirtualFileSystem.java

korydraughn commented 1 year ago

I believe the challenge with that implementation of truncate was that it was slow.

The best solution is to add native support for truncation to the iRODS server. Obviously that doesn't help you today, but it would in the long run.

Until we have native support in the iRODS server, I believe your only option with NFSRODS is to remove the data object before writing. Alternatively, you introduce a second tool/GUI that users can use for those cases which NFSRODS cannot handle (yet).

boydwilson commented 1 year ago

makes sense thx.

boydwilson commented 1 year ago

So we took the truncate code from 0.8.0 and put it in the latest and it does seem to fix the truncate cases, it does seem slow, but only seems slow for things that would otherwise be broken (with not very scientific tests). Do you recall any cases where it impacted non-truncate needed code? (We still agree that it should be in the core of iRODS), just not sure if you want us to push our pulling it forward?

korydraughn commented 1 year ago

One thing that may matter to you is that implementation will result in the data id changing. If you rely on consistent data ids, then you're going to run into problems.

Also, if you're running the latest version of NFSRODS, remember that it caches various pieces of information about data objects, etc. You'll need to think through if any of the caches need to be cleared for the data object being truncated. I suspect you'll need to remove the cached Stat object for that data object at the very least.

Please make sure to test things before deploying to production.

Other than that, feel free to modify your clone as you see fit. We'll look into adding support for truncate to the iRODS server in a later release. Most likely 4.3.2.

boydwilson commented 1 year ago

We are only deploying at the POC stage, this project won't go prod until after 4.3.2 I imagine, but thank you for the heads up on those items.

korydraughn commented 1 year ago

Got it. Let us know how it goes.