Closed plbpietrz-chronicle closed 2 months ago
hi @plbpietrz-chronicle - running the minimal reproducer on an Ubuntu 22.04 VM there are 2 issues:
In order to fallocate the file the associated descriptor must be in RDWR mode. As the file is opened with a FileInputStream it lacks the WR flag, which causes the fallocate to return an EBADF error.
The OpenFlag.O_APPEND.value() does not pass the correct numerical value in this context (it's passing 8, which is the "collapse" option for fallocate). The correct numerical value here is 0.
Putting both fixes in place the minimal reproducer runs without issue. (The test file is created, and resized to 106496, with fallocate returning 0).
Could you double check the minimal reproducer and/or the original code it is base upon and let me know how things look.
Thanks
For completeness, this is a working version:
(FileInputStream
-> FileOutputStream
; 2nd arg OpenFlag.O_APPEND.value()
-> 0)
private static int getNativeFileDescriptor(FileDescriptor fd) {
return SharedSecrets.getJavaIOFileDescriptorAccess().get(fd);
}
public static void main(String[] args) throws IOException, InterruptedException {
File testFile = new File("testFile.txt");
if (!testFile.exists())
testFile.createNewFile();
try (FileOutputStream fis = new FileOutputStream(testFile)) {
FileDescriptor fd = fis.getFD();
PosixAPI posix = PosixAPI.posix();
System.out.println("fallocate=" + posix.fallocate(getNativeFileDescriptor(fd), 0, 0, 106496));
}
}
Another example of the fallocate issue would be this chronicle-map example:
public static void main(String[] args) throws IOException {
try (ChronicleMap<String, Double> map = ChronicleMapBuilder.of(String.class, Double.class)
.averageKeySize(256)
.entries(1024)
.name("chronicle-map")
.createPersistedTo(new File(".", "chronicle-map.cm3"));
) {
System.out.println("Map created: " + map);
}
}
with only this library in mvn dependencies section:
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-map</artifactId>
<version>3.25ea5</version>
</dependency>
The above works for me with unmodified Chronicle-Map ea on:
@plbpietrz-chronicle - as discussed, pls try a fresh VM of your distro (Fedora) and vanilla Chronicle-Map to rule out something awry in your local env.
Issue fixed in latest release
When trying to create a new
ChronicleMap
within a Ubuntu 22.04 docker container (and on bare metal Fedora 38, 39) we are seeing this IOException:A minimal repro project, composed of
posix:2.25ea0
andchronicle-core:2.25ea10
libraries, containing:also ends up with a
fallocate=-1
being returned. What is interesting is that this code works if we remove theasm:9.2
library from the classpath. Below is the full dep tree of the test project