You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by al...@apache.org on 2014/06/03 18:34:27 UTC
svn commit: r1599671 -
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
Author: alexparvulescu
Date: Tue Jun 3 16:34:27 2014
New Revision: 1599671
URL: http://svn.apache.org/r1599671
Log:
OAK-1804 TarMK compaction
- enabled scheduled compaction call
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java?rev=1599671&r1=1599670&r2=1599671&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java Tue Jun 3 16:34:27 2014
@@ -51,6 +51,7 @@ import java.util.regex.Pattern;
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob;
+import org.apache.jackrabbit.oak.plugins.segment.Compactor;
import org.apache.jackrabbit.oak.plugins.segment.RecordId;
import org.apache.jackrabbit.oak.plugins.segment.Segment;
import org.apache.jackrabbit.oak.plugins.segment.SegmentId;
@@ -125,6 +126,17 @@ public class FileStore implements Segmen
private final AtomicBoolean cleanupNeeded = new AtomicBoolean(false);
/**
+ * Flag to request segment compaction during the next flush.
+ */
+ private final AtomicBoolean compactNeeded = new AtomicBoolean(false);
+
+ /**
+ * The number of new files created at which a compaction should be
+ * triggered.
+ */
+ private int compactThreshold = 10;
+
+ /**
* List of old tar file generations that are waiting to be removed.
*/
private final LinkedList<File> toBeRemoved = newLinkedList();
@@ -233,6 +245,7 @@ public class FileStore implements Segmen
timeToClose.await(1, SECONDS);
while (timeToClose.getCount() > 0) {
long start = System.nanoTime();
+ compact();
try {
flush();
} catch (IOException e) {
@@ -394,6 +407,16 @@ public class FileStore implements Segmen
}
}
+ private void compact() {
+ if (compactNeeded.getAndSet(false)) {
+ long start = System.nanoTime();
+ Compactor.compact(this);
+ log.info("TarMK Compaction: Completed in {}ms", MILLISECONDS
+ .convert(System.nanoTime() - start, NANOSECONDS));
+ cleanupNeeded.set(true);
+ }
+ }
+
public synchronized Iterable<SegmentId> getSegmentIds() {
List<SegmentId> ids = newArrayList();
for (UUID uuid : writer.getUUIDs()) {
@@ -567,6 +590,9 @@ public class FileStore implements Segmen
directory,
String.format(FILE_NAME_FORMAT, writeNumber, "a"));
writer = new TarWriter(writeFile);
+ if (writeNumber % compactThreshold == 0) {
+ compactNeeded.set(true);
+ }
}
} catch (IOException e) {
throw new RuntimeException(e);
@@ -590,7 +616,7 @@ public class FileStore implements Segmen
@Override
public void gc() {
System.gc();
- cleanupNeeded.set(true);
+ compactNeeded.set(true);
}
public Map<String, Set<UUID>> getTarReaderIndex() {