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 fr...@apache.org on 2018/04/24 13:20:43 UTC
svn commit: r1829996 - in /jackrabbit/oak/trunk/oak-segment-tar/src:
main/java/org/apache/jackrabbit/oak/segment/file/
test/java/org/apache/jackrabbit/oak/segment/file/
Author: frm
Date: Tue Apr 24 13:20:43 2018
New Revision: 1829996
URL: http://svn.apache.org/viewvc?rev=1829996&view=rev
Log:
OAK-7440 - Remove SizeDeltaGcEstimation
After the introduction of EstimationStrategy, SizeDeltaGcEstimation is now
trivial and can be inlined in DefaultGarbageCollectionStrategy.
Added:
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/FullSizeDeltaEstimationStrategyTest.java (with props)
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/TailSizeDeltaEstimationStrategyTest.java (with props)
Removed:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGcEstimation.java
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGCEstimationTest.java
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/DefaultGarbageCollectionStrategy.java
Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/DefaultGarbageCollectionStrategy.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/DefaultGarbageCollectionStrategy.java?rev=1829996&r1=1829995&r2=1829996&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/DefaultGarbageCollectionStrategy.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/DefaultGarbageCollectionStrategy.java Tue Apr 24 13:20:43 2018
@@ -37,6 +37,10 @@ import org.apache.jackrabbit.oak.spi.blo
class DefaultGarbageCollectionStrategy implements GarbageCollectionStrategy {
+ private final EstimationStrategy fullEstimationStrategy = new FullSizeDeltaEstimationStrategy();
+
+ private final EstimationStrategy tailEstimationStrategy = new TailSizeDeltaEstimationStrategy();
+
private final CompactionStrategy fullCompactionStrategy = new FullCompactionStrategy();
private final CompactionStrategy tailCompactionStrategy = new FallbackCompactionStrategy(new TailCompactionStrategy(), fullCompactionStrategy);
@@ -218,12 +222,36 @@ class DefaultGarbageCollectionStrategy i
}
private EstimationResult estimateCompactionGain(Context context, boolean full) {
- return new SizeDeltaGcEstimation(
- context.getGCOptions().getGcSizeDeltaEstimation(),
- context.getGCJournal(),
- context.getTarFiles().size(),
- full
- ).estimate();
+ EstimationStrategy strategy;
+
+ if (full) {
+ strategy = fullEstimationStrategy;
+ } else {
+ strategy = tailEstimationStrategy;
+ }
+
+ return estimateCompactionGain(context, strategy);
+ }
+
+ private EstimationResult estimateCompactionGain(Context context, EstimationStrategy strategy) {
+ return strategy.estimate(new EstimationStrategy.Context() {
+
+ @Override
+ public long getSizeDelta() {
+ return context.getGCOptions().getGcSizeDeltaEstimation();
+ }
+
+ @Override
+ public long getCurrentSize() {
+ return context.getTarFiles().size();
+ }
+
+ @Override
+ public GCJournal getGCJournal() {
+ return context.getGCJournal();
+ }
+
+ });
}
@Override
Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/FullSizeDeltaEstimationStrategyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/FullSizeDeltaEstimationStrategyTest.java?rev=1829996&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/FullSizeDeltaEstimationStrategyTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/FullSizeDeltaEstimationStrategyTest.java Tue Apr 24 13:20:43 2018
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.segment.file;
+
+import static org.apache.jackrabbit.oak.segment.file.tar.GCGeneration.newGCGeneration;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.apache.jackrabbit.oak.segment.file.EstimationStrategy.Context;
+import org.apache.jackrabbit.oak.segment.file.tar.TarPersistence;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class FullSizeDeltaEstimationStrategyTest {
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder(new File("target"));
+
+ private GCJournal journal;
+
+ @Before
+ public void setUpJournal() {
+ journal = new GCJournal(new TarPersistence(folder.getRoot()).getGCJournalFile());
+ }
+
+ @Test
+ public void testFullSkippedEstimation() {
+ assertTrue(isGarbageCollectionNeeded(0, 1000));
+ }
+
+ @Test
+ public void testFullEmptyJournal() {
+ assertTrue(isGarbageCollectionNeeded(100, 1000));
+ }
+
+ @Test
+ public void testFullGCNeededBecauseOfSize1() {
+ journal.persist(100, 1000, newGCGeneration(1, 1, true), 1000, "id");
+ journal.persist(110, 1100, newGCGeneration(2, 2, true), 1000, "id");
+ journal.persist(120, 1200, newGCGeneration(3, 3, true), 1000, "id");
+ journal.persist(130, 1000, newGCGeneration(4, 4, true), 1000, "id");
+ journal.persist(100, 1010, newGCGeneration(5, 5, true), 1000, "id");
+ journal.persist(110, 1020, newGCGeneration(6, 6, true), 1000, "id");
+ assertTrue(isGarbageCollectionNeeded(100, 1300));
+ }
+
+ @Test
+ public void testFullGCNeededBecauseOfSize2() {
+ journal.persist(100, 1000, newGCGeneration(1, 1, true), 1000, "id");
+ assertTrue(isGarbageCollectionNeeded(10, 1030));
+ }
+
+ @Test
+ public void testFullGCSkippedBecauseOfSize1() {
+ journal.persist(100, 1000, newGCGeneration(1, 1, true), 1000, "id");
+ journal.persist(110, 1100, newGCGeneration(2, 2, true), 1000, "id");
+ journal.persist(120, 1200, newGCGeneration(3, 3, true), 1000, "id");
+ journal.persist(130, 1000, newGCGeneration(4, 4, true), 1000, "id");
+ journal.persist(100, 1010, newGCGeneration(5, 5, true), 1000, "id");
+ journal.persist(110, 1020, newGCGeneration(6, 6, true), 1000, "id");
+ assertFalse(isGarbageCollectionNeeded(100, 1030));
+ }
+
+ @Test
+ public void testFullGCSkippedBecauseOfSize2() {
+ journal.persist(100, 1000, newGCGeneration(1, 1, true), 1000, "id");
+ assertFalse(isGarbageCollectionNeeded(100, 1030));
+ }
+
+ @Test
+ public void testFullGCNeededBecauseOfPreviousTail() {
+ journal.persist(100, 1000, newGCGeneration(1, 1, true), 1000, "id");
+ journal.persist(110, 1100, newGCGeneration(2, 1, true), 1000, "id");
+ journal.persist(120, 1200, newGCGeneration(3, 1, true), 1000, "id");
+ journal.persist(130, 1000, newGCGeneration(4, 2, true), 1000, "id");
+ journal.persist(100, 1010, newGCGeneration(5, 2, true), 1000, "id");
+ journal.persist(110, 1020, newGCGeneration(6, 2, true), 1000, "id");
+ assertTrue(isGarbageCollectionNeeded(100, 1030));
+ }
+
+ private boolean isGarbageCollectionNeeded(long delta, long size) {
+ return new FullSizeDeltaEstimationStrategy().estimate(new Context() {
+
+ @Override
+ public long getSizeDelta() {
+ return delta;
+ }
+
+ @Override
+ public long getCurrentSize() {
+ return size;
+ }
+
+ @Override
+ public GCJournal getGCJournal() {
+ return journal;
+ }
+
+ }).isGcNeeded();
+ }
+
+}
Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/FullSizeDeltaEstimationStrategyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/TailSizeDeltaEstimationStrategyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/TailSizeDeltaEstimationStrategyTest.java?rev=1829996&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/TailSizeDeltaEstimationStrategyTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/TailSizeDeltaEstimationStrategyTest.java Tue Apr 24 13:20:43 2018
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.segment.file;
+
+import static org.apache.jackrabbit.oak.segment.file.tar.GCGeneration.newGCGeneration;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.apache.jackrabbit.oak.segment.file.EstimationStrategy.Context;
+import org.apache.jackrabbit.oak.segment.file.tar.TarPersistence;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class TailSizeDeltaEstimationStrategyTest {
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder(new File("target"));
+
+ private GCJournal journal;
+
+ @Before
+ public void setUpJournal() {
+ journal = new GCJournal(new TarPersistence(folder.getRoot()).getGCJournalFile());
+ }
+
+ @Test
+ public void testTailSkippedEstimation() {
+ assertTrue(isGarbageCollectionNeeded(0, 1000));
+ }
+
+ @Test
+ public void testTailEmptyJournal() {
+ assertTrue(isGarbageCollectionNeeded(100, 1000));
+ }
+
+ @Test
+ public void testTailGCNeeded() {
+ journal.persist(100, 1000, newGCGeneration(1, 1, true), 1000, "id");
+ journal.persist(110, 1100, newGCGeneration(2, 1, true), 1000, "id");
+ journal.persist(120, 1200, newGCGeneration(3, 1, true), 1000, "id");
+ assertTrue(isGarbageCollectionNeeded(50, 1300));
+ }
+
+ @Test
+ public void testTailGCSkipped() {
+ journal.persist(100, 1000, newGCGeneration(1, 1, true), 1000, "id");
+ journal.persist(110, 1100, newGCGeneration(2, 1, true), 1000, "id");
+ journal.persist(120, 1200, newGCGeneration(3, 1, true), 1000, "id");
+ assertFalse(isGarbageCollectionNeeded(200, 1300));
+ }
+
+ private boolean isGarbageCollectionNeeded(long delta, long size) {
+ return new TailSizeDeltaEstimationStrategy().estimate(new Context() {
+
+ @Override
+ public long getSizeDelta() {
+ return delta;
+ }
+
+ @Override
+ public long getCurrentSize() {
+ return size;
+ }
+
+ @Override
+ public GCJournal getGCJournal() {
+ return journal;
+ }
+
+ }).isGcNeeded();
+ }
+
+}
Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/TailSizeDeltaEstimationStrategyTest.java
------------------------------------------------------------------------------
svn:eol-style = native