jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1583889 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document: Revision.java VersionGarbageCollector.java util/Utils.java
Date Wed, 02 Apr 2014 06:13:02 GMT
Author: chetanm
Date: Wed Apr  2 06:13:02 2014
New Revision: 1583889

URL: http://svn.apache.org/r1583889
Log:
OAK-1295 - Recovery for missing _lastRev updates (WIP)

Moving common methods to Utils

-- Moving timestampToString to Utils
-- Adding closeIfCloseable to close objects of types closeable.
-- Remove unused methods

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollector.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java?rev=1583889&r1=1583888&r2=1583889&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
Wed Apr  2 06:13:02 2014
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.plugins.document;
 
-import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
@@ -24,6 +23,7 @@ import java.util.TreeSet;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
 import org.apache.jackrabbit.oak.stats.Clock;
 /**
  * A revision.
@@ -216,13 +216,6 @@ public class Revision {
         return new Revision(timestamp, c, clusterId, isBranch);
     }
 
-    /**
-     * Provides a readable string for given timestamp
-     */
-    public static String timestampToString(long timestamp){
-        return (new Timestamp(timestamp) + "00").substring(0, 23);
-    }
-
     @Override
     public String toString() {
         return toStringBuilder(new StringBuilder()).toString();
@@ -260,7 +253,7 @@ public class Revision {
         buff.append("revision: \"").append(toString()).append("\"");
         buff.append(", clusterId: ").append(clusterId);
         buff.append(", time: \"").
-            append(timestampToString(timestamp)).
+            append(Utils.timestampToString(timestamp)).
             append("\"");
         if (counter > 0) {
             buff.append(", counter: ").append(counter);

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=1583889&r1=1583888&r2=1583889&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
Wed Apr  2 06:13:02 2014
@@ -19,8 +19,6 @@
 
 package org.apache.jackrabbit.oak.plugins.document;
 
-import java.io.Closeable;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
@@ -33,6 +31,7 @@ import com.google.common.base.Stopwatch;
 import com.google.common.collect.ImmutableList;
 import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
 import org.apache.jackrabbit.oak.plugins.document.mongo.MongoVersionGCSupport;
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -70,14 +69,14 @@ public class VersionGarbageCollector {
         final Revision headRevision = nodeStore.getHeadRevision();
 
         log.info("Starting revision garbage collection. Revisions older than [{}] would be
" +
-                "removed",Revision.timestampToString(oldestRevTimeStamp));
+                "removed", Utils.timestampToString(oldestRevTimeStamp));
 
         //Check for any registered checkpoint which prevent the GC from running
         Revision checkpoint = nodeStore.getCheckpoints().getOldestRevisionToKeep();
         if (checkpoint != null && checkpoint.getTimestamp() < oldestRevTimeStamp)
{
             log.info("Ignoring version gc as valid checkpoint [{}] found while " +
                             "need to collect versions older than [{}]", checkpoint.toReadableString(),
-                    Revision.timestampToString(oldestRevTimeStamp)
+                    Utils.timestampToString(oldestRevTimeStamp)
             );
             stats.ignoredGCDueToCheckPoint = true;
             return stats;
@@ -114,7 +113,7 @@ public class VersionGarbageCollector {
                 }
             }
         } finally {
-            close(itr);
+            Utils.closeIfCloseable(itr);
         }
 
         if(log.isDebugEnabled()) {
@@ -141,14 +140,4 @@ public class VersionGarbageCollector {
                     '}';
         }
     }
-
-    private void close(Object obj){
-        if(obj instanceof Closeable){
-           try{
-               ((Closeable) obj).close();
-           } catch (IOException e) {
-                log.warn("Error occurred while closing", e);
-           }
-        }
-    }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java?rev=1583889&r1=1583888&r2=1583889&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
Wed Apr  2 06:13:02 2014
@@ -16,9 +16,12 @@
  */
 package org.apache.jackrabbit.oak.plugins.document.util;
 
+import java.io.Closeable;
+import java.io.IOException;
 import java.nio.charset.Charset;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
+import java.sql.Timestamp;
 import java.util.Comparator;
 import java.util.HashSet;
 import java.util.Map;
@@ -36,6 +39,8 @@ import org.apache.commons.codec.binary.H
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.plugins.document.Revision;
 import org.bson.types.ObjectId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
@@ -43,6 +48,7 @@ import static com.google.common.base.Pre
  * Utility methods.
  */
 public class Utils {
+    private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
 
     /**
      * Approximate length of a Revision string.
@@ -99,14 +105,6 @@ public class Utils {
         return depth;
     }
 
-    public static <K, V> Map<K, V> newMap() {
-        return new TreeMap<K, V>();
-    }
-
-    public static <E> Set<E> newSet() {
-        return new HashSet<E>();
-    }
-
     @SuppressWarnings("unchecked")
     public static int estimateMemoryUsage(Map<?, Object> map) {
         if (map == null) {
@@ -381,4 +379,27 @@ public class Utils {
         return checkNotNull(tag).startsWith("c-") ?
                 Revision.fromString(tag.substring(2)) : rev;
     }
+
+    /**
+     * Closes the obj its of type {@link java.io.Closeable}. It is mostly
+     * used to close Iterator/Iterables which are backed by say DBCursor
+     *
+     * @param obj object to close
+     */
+    public static void closeIfCloseable(Object obj){
+        if(obj instanceof Closeable){
+            try{
+                ((Closeable) obj).close();
+            } catch (IOException e) {
+                LOG.warn("Error occurred while closing {}", obj, e);
+            }
+        }
+    }
+
+    /**
+     * Provides a readable string for given timestamp
+     */
+    public static String timestampToString(long timestamp){
+        return (new Timestamp(timestamp) + "00").substring(0, 23);
+    }
 }



Mime
View raw message