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 md...@apache.org on 2015/09/04 23:28:48 UTC
svn commit: r1701329 -
/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompactionAndCleanupIT.java
Author: mduerig
Date: Fri Sep 4 21:28:48 2015
New Revision: 1701329
URL: http://svn.apache.org/r1701329
Log:
OAK-3348: Cross gc sessions might introduce references to pre-compacted segments
@Ignored test case
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompactionAndCleanupIT.java
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompactionAndCleanupIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompactionAndCleanupIT.java?rev=1701329&r1=1701328&r2=1701329&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompactionAndCleanupIT.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompactionAndCleanupIT.java Fri Sep 4 21:28:48 2015
@@ -20,14 +20,17 @@
package org.apache.jackrabbit.oak.plugins.segment;
import static com.google.common.collect.Lists.newArrayList;
+import static java.lang.Integer.getInteger;
import static org.apache.commons.io.FileUtils.byteCountToDisplaySize;
import static org.apache.commons.io.FileUtils.deleteDirectory;
import static org.apache.jackrabbit.oak.api.Type.STRING;
-import static org.apache.jackrabbit.oak.commons.FixturesHelper.getFixtures;
import static org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture.SEGMENT_MK;
+import static org.apache.jackrabbit.oak.commons.FixturesHelper.getFixtures;
+import static org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore.newSegmentNodeStore;
import static org.apache.jackrabbit.oak.plugins.segment.compaction.CompactionStrategy.CleanupType.CLEAN_ALL;
import static org.apache.jackrabbit.oak.plugins.segment.compaction.CompactionStrategy.CleanupType.CLEAN_NONE;
import static org.apache.jackrabbit.oak.plugins.segment.compaction.CompactionStrategy.CleanupType.CLEAN_OLD;
+import static org.apache.jackrabbit.oak.plugins.segment.file.FileStore.newFileStore;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -49,7 +52,6 @@ import java.util.concurrent.atomic.Atomi
import javax.annotation.Nonnull;
import com.google.common.io.ByteStreams;
-
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
@@ -65,6 +67,7 @@ import org.apache.jackrabbit.oak.spi.sta
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -354,6 +357,74 @@ public class CompactionAndCleanupIT {
}
}
+ /**
+ * Test asserting OAK-3348: Cross gc sessions might introduce references to pre-compacted segments
+ */
+ @Test
+ @Ignore("OAK-3348") // FIXME OAK-3348
+ public void preCompactionReferences() throws IOException, CommitFailedException, InterruptedException {
+ for (String ref : new String[] {"merge-before-compact", "merge-after-compact"}) {
+ File repoDir = new File(directory, ref);
+ FileStore fileStore = newFileStore(repoDir).withMaxFileSize(2).create();
+ final SegmentNodeStore nodeStore = newSegmentNodeStore(fileStore).create();
+ fileStore.setCompactionStrategy(new CompactionStrategy(true, false, CLEAN_NONE, 0, (byte) 5) {
+ @Override
+ public boolean compacted(Callable<Boolean> setHead) throws Exception {
+ return nodeStore.locked(setHead);
+ }
+ });
+
+ try {
+ // add some content
+ NodeBuilder root = nodeStore.getRoot().builder();
+ root.setChildNode("test").setProperty("blob", createBlob(nodeStore, 1024 * 1024));
+ nodeStore.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+ // remove it again so we have something to gc
+ root = nodeStore.getRoot().builder();
+ root.getChildNode("test").remove();
+ nodeStore.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+ // with a new builder simulate exceeding the update limit.
+ // This will cause changes to be pre-written to segments
+ root = nodeStore.getRoot().builder();
+ for (int k = 0; k < getInteger("update.limit", 10000); k += 2) {
+ root.setChildNode("test").remove();
+ }
+ root.setChildNode("test");
+
+ // case 1: merge above changes before compact
+ if ("merge-before-compact".equals(ref)) {
+ nodeStore.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+ }
+
+ fileStore.compact();
+
+ // case 2: merge above changes after compact
+ if ("merge-after-compact".equals(ref)) {
+ nodeStore.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+ }
+ } finally {
+ fileStore.close();
+ }
+
+ // Re-initialise the file store to simulate off-line gc
+ fileStore = newFileStore(repoDir).withMaxFileSize(2).create();
+ try {
+ // The 1M blob should get gc-ed. This works for case 1.
+ // However it doesn't for case 2 as merging after compaction
+ // apparently creates references from the current segment
+ // to the pre-compacted segment to which above changes have
+ // been pre-written.
+ fileStore.cleanup();
+ assertTrue(ref + " repository size " + fileStore.size() + " < " + 1024 * 1024,
+ fileStore.size() < 1024 * 1024);
+ } finally {
+ fileStore.close();
+ }
+ }
+ }
+
private static void collectSegments(SegmentNodeState s, Set<UUID> segmentIds) {
SegmentId sid = s.getRecordId().getSegmentId();
UUID id = new UUID(sid.getMostSignificantBits(),