I am implementing write ahead logging as part of our application data recovery (application is in JAVA). Latency is a concern so I need to do buffered write instead of sync writes.
Looking at the BufferedOutputStream implementation, I realized that buffering is still happening in the application level so if the application crashes, I may lose the un-flushed logging data (is that correct assumption? or does JVM somehow handles this?)
Ideally I would like a Java library that defers buffering to OS to safeguard against the application crash.
Java.nio.FileChannel Mem-Mapped file will serve my purpose. But I am a little hesitant. Since I also need to iterate over the log file during recovery, so I will have to maintain an additional state of EOF - the last offset where I wrote data. This is because mem-mapped buffer size will be in the fixed size page length, so the file length is not the same as valid EOF to read upto.
What are my options?