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/08/22 15:18:55 UTC
svn commit: r1619800 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionGainEstimate.java
test/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionAndCleanupTest.java
Author: alexparvulescu
Date: Fri Aug 22 13:18:55 2014
New Revision: 1619800
URL: http://svn.apache.org/r1619800
Log:
OAK-2019 Compact only if needed
- added test case, and a guard against division by zero
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionGainEstimate.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionAndCleanupTest.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionGainEstimate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionGainEstimate.java?rev=1619800&r1=1619799&r2=1619800&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionGainEstimate.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionGainEstimate.java Fri Aug 22 13:18:55 2014
@@ -75,6 +75,9 @@ class CompactionGainEstimate implements
* @return percentage of disk space that could be freed with compaction
*/
public long estimateCompactionGain() {
+ if (totalSize == 0) {
+ return 0;
+ }
return 100 * (totalSize - reachableSize) / totalSize;
}
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionAndCleanupTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionAndCleanupTest.java?rev=1619800&r1=1619799&r2=1619800&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionAndCleanupTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionAndCleanupTest.java Fri Aug 22 13:18:55 2014
@@ -39,6 +39,7 @@ import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
public class CompactionAndCleanupTest {
@@ -138,4 +139,45 @@ public class CompactionAndCleanupTest {
private static long mb(long size){
return size / (1024 * 1024);
}
+
+ @Test
+ public void testGainEstimator() throws Exception {
+ final int MB = 1024 * 1024;
+ final int blobSize = 2 * MB;
+
+ FileStore fileStore = new FileStore(directory, 2, false);
+ SegmentNodeStore nodeStore = new SegmentNodeStore(fileStore);
+
+ // 1. Create some blob properties
+ NodeBuilder builder = nodeStore.getRoot().builder();
+
+ NodeBuilder c1 = builder.child("c1");
+ c1.setProperty("a", createBlob(nodeStore, blobSize));
+ c1.setProperty("b", "foo");
+
+ NodeBuilder c2 = builder.child("c2");
+ c2.setProperty("a", createBlob(nodeStore, blobSize));
+ c2.setProperty("b", "foo");
+
+ NodeBuilder c3 = builder.child("c3");
+ c3.setProperty("a", createBlob(nodeStore, blobSize));
+ c3.setProperty("b", "foo");
+ nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+ // 2. Now remove the property
+ builder = nodeStore.getRoot().builder();
+ builder.child("c1").remove();
+ builder.child("c2").remove();
+ nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+ fileStore.flush();
+ try {
+ // should be at 66%
+ assertTrue(fileStore.estimateCompactionGain()
+ .estimateCompactionGain() > 60);
+ } finally {
+ fileStore.close();
+ }
+ }
+
}