Skip to content

Commit 39b1b6c

Browse files
authored
OAK-11425: MarkSweepGarbageColllector.iterateNodeTree() passes open file to FileIOUtils.sort() (#2017)
1 parent cb4fff3 commit 39b1b6c

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/MarkSweepGarbageCollector.java

+8-16
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import java.util.ArrayList;
4242
import java.util.Arrays;
4343
import java.util.Collections;
44-
import java.util.Comparator;
4544
import java.util.Iterator;
4645
import java.util.List;
4746
import java.util.Map;
@@ -622,9 +621,8 @@ static void saveBatchToFile(List<String> ids, BufferedWriter writer) throws IOEx
622621
* @param logPath whether to log path in the file or not
623622
*/
624623
protected void iterateNodeTree(GarbageCollectorFileState fs, final boolean logPath) throws IOException {
625-
final BufferedWriter writer = new BufferedWriter(new FileWriter(fs.getMarkedRefs(), StandardCharsets.UTF_8));
626624
final AtomicInteger count = new AtomicInteger();
627-
try {
625+
try (BufferedWriter writer = new BufferedWriter(new FileWriter(fs.getMarkedRefs(), StandardCharsets.UTF_8))) {
628626
marker.collectReferences(
629627
new ReferenceCollector() {
630628
private final boolean debugMode = LOG.isTraceEnabled();
@@ -663,21 +661,15 @@ public void addReference(String blobId, final String nodeId) {
663661
}
664662
}
665663
);
666-
LOG.info("Number of valid blob references marked under mark phase of " +
667-
"Blob garbage collection [{}]", count.get());
668-
// sort the marked references with the first part of the key
669-
sort(fs.getMarkedRefs(),
670-
new Comparator<String>() {
671-
@Override
672-
public int compare(String s1, String s2) {
673-
return s1.split(DELIM)[0].compareTo(s2.split(DELIM)[0]);
674-
}
675-
});
676-
} finally {
677-
closeQuietly(writer);
678664
}
665+
666+
LOG.info("Number of valid blob references marked under mark phase of " +
667+
"Blob garbage collection [{}]", count.get());
668+
// sort the marked references with the first part of the key
669+
sort(fs.getMarkedRefs(),
670+
(s1, s2) -> s1.split(DELIM)[0].compareTo(s2.split(DELIM)[0]));
679671
}
680-
672+
681673
@Override
682674
public long checkConsistency(boolean markOnly) throws Exception {
683675
consistencyStatsCollector.start();

0 commit comments

Comments
 (0)