Skip to content

Conversation

@cstamas
Copy link
Member

@cstamas cstamas commented Nov 26, 2025

Drop out of band deletion, let TFM delete as well. Also, simplify but do not drop locking, is needed for interoperability with 3.9.11 and 4.0.0-rc-5 and older released versions. Make FNFEx ignored in case of read/delete.

Backport to 1.9.x is here #1695.

Drop out of band deletion, let TFM delete as well. Also, simplify
but do not drop locking, is needed for interoperability with 3.9.11
and 4.0.0-rc-5 and older released versions.
@cstamas
Copy link
Member Author

cstamas commented Nov 27, 2025

@bade7n ping

@cstamas cstamas marked this pull request as ready for review November 27, 2025 10:53
@cstamas cstamas added the bug Something isn't working label Nov 27, 2025
@cstamas cstamas added this to the 2.0.14 milestone Nov 27, 2025
@bade7n
Copy link

bade7n commented Nov 27, 2025

@bade7n ping

If you'd like me to test it, feel free to release an alpha or beta build — I can provide feedback on 1.9 within a few days.

@cstamas
Copy link
Member Author

cstamas commented Nov 27, 2025

Needs test (delete)

}
synchronized (mutex(path)) {
try (FileChannel fileChannel = FileChannel.open(path, StandardOpenOption.READ);
FileLock unused = fileLock(fileChannel, Math.max(1, fileChannel.size()), true)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the purpose of using fileLock(fileChannel, x) ? Why not using fileLock(fileChannel, 0) ?
According to the javadoc:

A value of zero means to lock all bytes from the specified starting position to the end of the file, regardless of whether the file is subsequently extended or truncated

Copy link
Member Author

@cstamas cstamas Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically we lock with size 0 or 1 (so all or [0..1] bytes), based on file was just created or existed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what the code does. I don't understand why. What we want is a lock on the full file, so why just requesting 1 byte instead of the whole length (which will be extended automatically when written) ?
This parameter seems useless to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it forces to add a call to retrieve the file size...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you looked at outdated PR? As this morning I removed the 0/1 dance fully (and hence the file size call as well)

try (FileChannel fileChannel = FileChannel.open(
path, StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE);
FileLock unused = fileLock(fileChannel, Math.max(1, fileChannel.size()), false)) {
if (fileChannel.size() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there a check here and not while reading ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading will be unable to open absent file, here we may create it (and will be 0 byte)

@cstamas cstamas requested a review from gnodet November 27, 2025 20:45
fileSize = Files.size(path);
} catch (IOException e) {
fileSize = 0L;
Properties props = new Properties();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The props variable should be defined inside the try block, with the return statement moved at the end of the same block.

@cstamas cstamas requested a review from gnodet November 28, 2025 13:59
@cstamas cstamas merged commit 5bf4b92 into apache:master Nov 28, 2025
14 checks passed
@cstamas cstamas deleted the tracking-file-manager branch November 28, 2025 14:44
cstamas added a commit that referenced this pull request Nov 28, 2025
Backport from master. Needs Maven changes as well. Aligned with master fully.

Master PR: #1692
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants