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 2015/10/06 12:11:39 UTC
svn commit: r1706977 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/segment/CompactionMap.java
test/java/org/apache/jackrabbit/oak/plugins/segment/CompactionMapTest.java
Author: alexparvulescu
Date: Tue Oct 6 10:11:39 2015
New Revision: 1706977
URL: http://svn.apache.org/viewvc?rev=1706977&view=rev
Log:
OAK-3479 Add generation info to compaction map
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/CompactionMap.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompactionMapTest.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/CompactionMap.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/CompactionMap.java?rev=1706977&r1=1706976&r2=1706977&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/CompactionMap.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/CompactionMap.java Tue Oct 6 10:11:39 2015
@@ -40,12 +40,20 @@ public class CompactionMap {
* An empty map.
*/
public static final CompactionMap EMPTY =
- new CompactionMap(Collections.<PartialCompactionMap>emptyList());
+ new CompactionMap(Collections.<PartialCompactionMap>emptyList(), 0);
private final List<PartialCompactionMap> maps;
- private CompactionMap(@Nonnull List<PartialCompactionMap> maps) {
+ /**
+ * Generation represents the number of compaction cycles since the system
+ * came online. This is not persisted so it will be reset to 0 on each
+ * restart
+ */
+ private final int generation;
+
+ private CompactionMap(@Nonnull List<PartialCompactionMap> maps, int generation) {
this.maps = maps;
+ this.generation = generation;
}
/**
@@ -122,7 +130,7 @@ public class CompactionMap {
maps.add(map);
}
}
- return new CompactionMap(maps);
+ return new CompactionMap(maps, generation + 1);
}
/**
@@ -149,6 +157,10 @@ public class CompactionMap {
return maps.size();
}
+ public int getGeneration() {
+ return generation;
+ }
+
/**
* The weight of the compaction map is its memory consumption bytes
* @return Estimated weight of the compaction map
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompactionMapTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompactionMapTest.java?rev=1706977&r1=1706976&r2=1706977&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompactionMapTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompactionMapTest.java Tue Oct 6 10:11:39 2015
@@ -23,6 +23,7 @@ import static com.google.common.collect.
import static com.google.common.collect.Maps.newHashMap;
import static com.google.common.collect.Sets.newHashSet;
import static java.io.File.createTempFile;
+import static org.apache.commons.io.FileUtils.deleteDirectory;
import static org.apache.jackrabbit.oak.plugins.segment.CompactionMap.sum;
import static org.apache.jackrabbit.oak.plugins.segment.TestUtils.randomRecordIdMap;
import static org.junit.Assert.assertArrayEquals;
@@ -49,6 +50,8 @@ import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class CompactionMapTest {
+
+ private final File directory;
private final FileStore store;
private final Random rnd = new Random();
@@ -70,6 +73,11 @@ public class CompactionMapTest {
@After
public void tearDown() {
store.close();
+ try {
+ deleteDirectory(directory);
+ } catch (IOException e) {
+ //
+ }
}
private PartialCompactionMap createCompactionMap(boolean persisted) {
@@ -89,7 +97,8 @@ public class CompactionMapTest {
}
public CompactionMapTest(boolean usePersistedMap) throws IOException {
- store = FileStore.newFileStore(mkDir()).create();
+ directory = mkDir();
+ store = FileStore.newFileStore(directory).create();
compactionMap1 = createCompactionMap(usePersistedMap);
referenceMap1 = randomRecordIdMap(rnd, store.getTracker(), 10, 10);
@@ -169,9 +178,11 @@ public class CompactionMapTest {
assertArrayEquals(new long[] {100, 100, 100}, compactionMap.getRecordCounts());
int expectedDepth = 3;
+ int expectedGeneration = 3;
long expectedSize = countUUIDs(referenceMap.keySet());
assertEquals(expectedDepth, compactionMap.getDepth());
assertEquals(expectedSize, sum(compactionMap.getSegmentCounts()));
+ assertEquals(expectedGeneration, compactionMap.getGeneration());
for (Map<RecordId, RecordId> referenceMap : ImmutableList.of(referenceMap2, referenceMap1, referenceMap3)) {
Set<UUID> removedUUIDs = newHashSet();
@@ -185,7 +196,14 @@ public class CompactionMapTest {
assertEquals(expectedDepth + 1, consed.getDepth());
expectedSize -= removedUUIDs.size();
assertEquals(expectedSize, sum(compactionMap.getSegmentCounts()));
+ assertEquals(expectedGeneration + 1, consed.getGeneration());
}
+
+ // one final 'cons' to trigger cleanup of empty maps
+ CompactionMap consed = compactionMap.cons(createCompactionMap(false));
+ assertEquals(1, consed.getDepth());
+ assertEquals(0, sum(compactionMap.getSegmentCounts()));
+ assertEquals(expectedGeneration + 1, consed.getGeneration());
}
}