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

WIP: Fix #3316: javalib FileChannel APPEND relative writes now match JVM #3323

Closed

Conversation

LeeTibbert
Copy link
Contributor

@LeeTibbert LeeTibbert commented Jun 10, 2023

Fix #3316

The Java 8 documentation for SeekableByteChannel$position(pos) says:

Setting the channel's position is not recommended when connected to an entity, 
typically a file, that is opened with the APPEND option. 

However, the JVM implementation allows it and APPEND relative writes happen at the expected place: End Of File.

As of this PR, Scala Native implements the same proscribed but not prohibited behavior.

The design center for this PR was correctness. There is no benchmark data to show it, but
both the simple and APPEND channel write(ByteBuffer) paths should be quicker
and more efficient since a number of unnecessary file movement (lseek) calls were
eliminated.

This PR also adds some improved error reporting on not-Windows and a more
direct way, and hopefully better, way of determining file size on not-Windows.

Note:

The JVM documentation states that FileChannels are thread-safe. This implementation, and probably most other,
javalib classes outside of java.util.concurrent are not.

~~ editorial opinion about having more than one thread using a FileChannel redacted ~~

Multiple threads on the same FileChannel may have undesired results.

@LeeTibbert LeeTibbert changed the title Fix #3316: javalib FileChannel APPEND relative writes now match JVM WIP: Fix #3316: javalib FileChannel APPEND relative writes now match JVM Jun 10, 2023
@LeeTibbert
Copy link
Contributor Author

Moving to Work-In-Progress sideline while I study why this PR fails across the board on CI
and works on both my macOS & Linux systems.

Issue seems to be with checking that the position is indeed 0 after an error-free position(0).

@LeeTibbert LeeTibbert force-pushed the PR_jnc_ByteChannelAppend_I3316 branch from d30b7bb to dfc1afc Compare June 11, 2023 17:44
@LeeTibbert LeeTibbert marked this pull request as draft June 17, 2023 01:02
@LeeTibbert
Copy link
Contributor Author

This WIP PR has served it purpose well. It lead to a number (5? 10?) of now merged
PRs. The most relevant is PR #3368, which solves the problem which motivated this PR.

@LeeTibbert LeeTibbert closed this Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot append to a ByteChannel
1 participant