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 mr...@apache.org on 2017/02/28 12:25:38 UTC

svn commit: r1784732 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorLogTest.java

Author: mreutegg
Date: Tue Feb 28 12:25:37 2017
New Revision: 1784732

URL: http://svn.apache.org/viewvc?rev=1784732&view=rev
Log:
OAK-5854: Incorrect VersionGarbageCollector log message

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorLogTest.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java?rev=1784732&r1=1784731&r2=1784732&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java Tue Feb 28 12:25:37 2017
@@ -438,7 +438,8 @@ public class VersionGarbageCollector {
          */
         void removeDocuments(VersionGCStats stats) throws IOException {
             removeLeafDocuments(stats);
-            stats.deletedDocGCCount += removeDeletedDocuments(getDocIdsToDelete(), "(other)");
+            stats.deletedDocGCCount += removeDeletedDocuments(
+                    getDocIdsToDelete(), getDocIdsToDeleteSize(), "(other)");
             // FIXME: this is incorrect because that method also removes intermediate docs
             stats.splitDocGCCount += removeDeletedPreviousDocuments();
         }
@@ -452,7 +453,8 @@ public class VersionGarbageCollector {
         }
 
         void removeLeafDocuments(VersionGCStats stats) throws IOException {
-            int removeCount = removeDeletedDocuments(getLeafDocIdsToDelete(), "(leaf)");
+            int removeCount = removeDeletedDocuments(
+                    getLeafDocIdsToDelete(), getLeafDocIdsToDeleteSize(), "(leaf)");
             leafDocIdsToDelete.clear();
             stats.deletedLeafDocGCCount += removeCount;
             stats.deletedDocGCCount += removeCount;
@@ -535,10 +537,18 @@ public class VersionGarbageCollector {
             return docIdsToDelete.getIds();
         }
 
+        private long getDocIdsToDeleteSize() {
+            return docIdsToDelete.getSize();
+        }
+
         private Iterator<String> getLeafDocIdsToDelete() throws IOException {
             return leafDocIdsToDelete.iterator();
         }
 
+        private long getLeafDocIdsToDeleteSize() {
+            return leafDocIdsToDelete.size();
+        }
+
         private void concurrentModification(NodeDocument doc) {
             Iterator<NodeDocument> it = doc.getAllPreviousDocs();
             while (it.hasNext()) {
@@ -557,8 +567,10 @@ public class VersionGarbageCollector {
             });
         }
 
-        private int removeDeletedDocuments(Iterator<String> docIdsToDelete, String label) throws IOException {
-            log.info("Proceeding to delete [{}] documents [{}]", getNumDocuments(), label);
+        private int removeDeletedDocuments(Iterator<String> docIdsToDelete,
+                                           long numDocuments,
+                                           String label) throws IOException {
+            log.info("Proceeding to delete [{}] documents [{}]", numDocuments, label);
 
             Iterator<List<String>> idListItr = partition(docIdsToDelete, DELETE_BATCH_SIZE);
             int deletedCount = 0;

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorLogTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorLogTest.java?rev=1784732&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorLogTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorLogTest.java Tue Feb 28 12:25:37 2017
@@ -0,0 +1,155 @@
+/*
+ * 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.plugins.document;
+
+import java.lang.reflect.Field;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
+
+import com.google.common.collect.Lists;
+
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.commons.junit.LogCustomizer;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.stats.Clock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import ch.qos.logback.classic.Level;
+
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.lessThan;
+import static org.junit.Assert.assertThat;
+
+public class VersionGarbageCollectorLogTest {
+
+    private static final int BATCH_SIZE;
+
+    static {
+        try {
+            Field f = VersionGarbageCollector.class.getDeclaredField("DELETE_BATCH_SIZE");
+            f.setAccessible(true);
+            BATCH_SIZE = (int) f.get(null);
+        } catch (Exception e) {
+            throw new AssertionError(e);
+        }
+    }
+
+    @Rule
+    public DocumentMKBuilderProvider builderProvider = new DocumentMKBuilderProvider();
+
+    private LogCustomizer logCustomizer = LogCustomizer.forLogger(
+            VersionGarbageCollector.class.getName()).enable(Level.INFO).create();
+
+    private Clock clock;
+
+    private DocumentNodeStore ns;
+
+    @Before
+    public void before() throws Exception {
+        clock = new Clock.Virtual();
+        clock.waitUntil(System.currentTimeMillis());
+        Revision.setClock(clock);
+        ns = new DocumentMK.Builder().setAsyncDelay(0).clock(clock).getNodeStore();
+        logCustomizer.starting();
+    }
+
+    @After
+    public void after() {
+        logCustomizer.finished();
+        Revision.resetClockToDefault();
+    }
+
+    @Test
+    public void gc() throws Exception {
+        createGarbage();
+
+        clock.waitUntil(clock.getTime() + TimeUnit.HOURS.toMillis(1));
+
+        VersionGarbageCollector gc = ns.getVersionGarbageCollector();
+        gc.gc(30, TimeUnit.MINUTES);
+        List<String> messages = getDeleteMessages();
+        assertThat(messages.size(), greaterThan(0));
+        for (String msg : messages) {
+            assertThat(getNumDeleted(msg), lessThan(BATCH_SIZE + 1));
+        }
+    }
+
+    private int getNumDeleted(String msg) {
+        int idx = msg.indexOf('[');
+        return Integer.parseInt(msg.substring(idx + 1, msg.indexOf(']')));
+    }
+
+    private void createGarbage() throws Exception {
+        Random r = new Random(42);
+        String path = "/";
+        for (int i = 0; i < 1000; i++) {
+            int v = r.nextInt(10);
+            if (v == 0 || path.equals("/")) {
+                // create new top level node
+                path = "/node-" + i;
+                addNode(path);
+            } else {
+                addNode(path + "/node-" + i);
+            }
+        }
+        for (String name : ns.getRoot().getChildNodeNames()) {
+            if (name.startsWith("node-")) {
+                if (r.nextBoolean()) {
+                    recreate(name);
+                } else {
+                    remove(name);
+                }
+            }
+        }
+    }
+
+    private List<String> getDeleteMessages() {
+        List<String> messages = Lists.newArrayList();
+        for (String msg : logCustomizer.getLogs()) {
+            if (msg.startsWith("Proceeding to delete [")) {
+                messages.add(msg);
+            }
+        }
+        return messages;
+    }
+
+    private void remove(String name) throws Exception {
+        NodeBuilder builder = ns.getRoot().builder();
+        builder.child(name).remove();
+        TestUtils.merge(ns, builder);
+    }
+
+    private void recreate(String name) throws Exception {
+        NodeBuilder builder = ns.getRoot().builder();
+        builder.child(name).remove();
+        builder.child(name);
+        TestUtils.merge(ns, builder);
+    }
+
+    private void addNode(String path) throws Exception {
+        NodeBuilder builder = ns.getRoot().builder();
+        NodeBuilder b = builder;
+        for (String name : PathUtils.elements(path)) {
+            b = b.child(name);
+        }
+        TestUtils.merge(ns, builder);
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorLogTest.java
------------------------------------------------------------------------------
    svn:eol-style = native