Description
When running garbage collection on a TarMK repository, it's in certain cases possible for the following FileNotFoundException to occur:
java.io.FileNotFoundException: /path/to/dataNNNNNNb.tar (No such file or directory) at java.io.RandomAccessFile.open(Native Method) ~[na:1.7.0_55] at java.io.RandomAccessFile.<init>(RandomAccessFile.java:241) ~[na:1.7.0_55] at org.apache.jackrabbit.oak.plugins.segment.file.TarReader.openFirstFileWithValidIndex(TarReader.java:186) [oak-run-1.0.2-SNAPSHOT.jar:1.0.2-SNAPSHOT] at org.apache.jackrabbit.oak.plugins.segment.file.TarReader.cleanup(TarReader.java:647) [oak-run-1.0.2-SNAPSHOT.jar:1.0.2-SNAPSHOT] at org.apache.jackrabbit.oak.plugins.segment.file.FileStore.flush(FileStore.java:375) [oak-run-1.0.2-SNAPSHOT.jar:1.0.2-SNAPSHOT] at org.apache.jackrabbit.oak.plugins.segment.file.FileStore.close(FileStore.java:465) [oak-run-1.0.2-SNAPSHOT.jar:1.0.2-SNAPSHOT] at org.apache.jackrabbit.oak.run.Main.compact(Main.java:177) [oak-run-1.0.2-SNAPSHOT.jar:1.0.2-SNAPSHOT] at org.apache.jackrabbit.oak.run.Main.main(Main.java:108) [oak-run-1.0.2-SNAPSHOT.jar:1.0.2-SNAPSHOT]
I originally assumed this error to be some weird platform issue, based on some online reports about a new file not being available for opening during a brief period after it was created. However, the explanation for this issue is more deterministic:
If the tar file in question was created with an Oak 0.x version from before OAK-1780, then it wouldn't contain the pre-compiled segment graph information. Due to a slight bug in the OAK-1780 implementation, this would prevent a tar file that's full of garbage from being simply removed. Instead a new, empty tar file would get generated, and due to the lazy writing implemented OAK-631 that file would actually never get created. Thus the FileNotFoundException.
To fix this problem, we need to make sure that a tar file that's full of garbage will get cleanly removed even if it doesn't contain a pre-compiled segment graph.