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 th...@apache.org on 2013/08/06 11:54:37 UTC

svn commit: r1510891 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk: Commit.java MongoMK.java

Author: thomasm
Date: Tue Aug  6 09:54:36 2013
New Revision: 1510891

URL: http://svn.apache.org/r1510891
Log:
OAK-926 MongoMK: split documents when they are too large

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Commit.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Commit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Commit.java?rev=1510891&r1=1510890&r2=1510891&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Commit.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Commit.java Tue Aug  6 09:54:36 2013
@@ -38,6 +38,13 @@ import org.slf4j.LoggerFactory;
  */
 public class Commit {
 
+    /**
+     * Whether to purge old revisions if a node gets too large. If false, old
+     * revisions are stored in a separate document. If true, old revisions are
+     * removed (purged).
+     */
+    static final boolean PURGE_OLD_REVISIONS = true;
+    
     private static final Logger LOG = LoggerFactory.getLogger(Commit.class);
 
     /**
@@ -47,20 +54,7 @@ public class Commit {
     //private static final int MAX_DOCUMENT_SIZE = 16 * 1024;
     // TODO set to 512 KB currently, should be changed later on
     private static final int MAX_DOCUMENT_SIZE = 512 * 1024;
-
-    /**
-     * Whether to purge old revisions if a node gets too large. If false, old
-     * revisions are stored in a separate document. If true, old revisions are
-     * removed (purged).
-     */
-    private static final boolean PURGE_OLD_REVISIONS = true;
-    
-    /**
-     * Revisions that are newer than this (in minutes) are kept in the newest
-     * document.
-     */
-    private static final int SPLIT_MINUTES = 5;
-    
+   
     private final MongoMK mk;
     private final Revision baseRevision;
     private final Revision revision;
@@ -461,8 +455,7 @@ public class Commit {
                         main.setMap(key, propRev.toString(), v);
                     } else {
                         long ageMillis = Revision.getCurrentTimestamp() - propRev.getTimestamp();
-                        long ageMinutes = ageMillis / 1000 / 60;
-                        if (ageMinutes > SPLIT_MINUTES) {
+                        if (ageMillis > mk.getSplitDocumentAgeMillis()) {
                             old.setMapEntry(key, propRev.toString(), v);
                         } else {
                             main.setMap(key, propRev.toString(), v);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java?rev=1510891&r1=1510890&r2=1510891&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java Tue Aug  6 09:54:36 2013
@@ -141,6 +141,14 @@ public class MongoMK implements MicroKer
      * The unique cluster id, similar to the unique machine id in MongoDB.
      */
     private final int clusterId;
+    
+    /**
+     * The splitting point in milliseconds. If a document is split, revisions
+     * older than this number of milliseconds are moved to a different document.
+     * The default is 0, meaning documents are never split. Revisions that are
+     * newer than this are kept in the newest document.
+     */
+    private final long splitDocumentAgeMillis;
 
     /**
      * The node cache.
@@ -223,6 +231,7 @@ public class MongoMK implements MicroKer
         this.store = s;
         this.blobStore = builder.getBlobStore();
         int cid = builder.getClusterId();
+        splitDocumentAgeMillis = builder.getSplitDocumentAgeMillis();
         cid = Integer.getInteger("oak.mongoMK.clusterId", cid);
         if (cid == 0) {
             clusterNodeInfo = ClusterNodeInfo.getInstance(store);
@@ -563,6 +572,10 @@ public class MongoMK implements MicroKer
         }
         return false;
     }
+    
+    public long getSplitDocumentAgeMillis() {
+        return this.splitDocumentAgeMillis;
+    }
 
     /**
      * Returns <code>true</code> if the given revision
@@ -578,6 +591,12 @@ public class MongoMK implements MicroKer
     private boolean isCommitted(@Nonnull Revision revision,
                                 @Nonnull Revision readRevision,
                                 @Nullable Map<String, String> revisions) {
+        if (Commit.PURGE_OLD_REVISIONS) {
+            long diff = Revision.getTimestampDifference(Revision.getCurrentTimestamp(), revision.getTimestamp());
+            if (diff >= splitDocumentAgeMillis) {
+                return true;
+            }
+        }
         if (revision.equals(readRevision)) {
             return true;
         }
@@ -1671,6 +1690,7 @@ public class MongoMK implements MicroKer
         private long diffCacheSize;
         private long documentCacheSize;
         private boolean useSimpleRevision;
+        private long splitDocumentAgeMillis = 5 * 60 * 1000;
 
         public Builder() {
             memoryCacheSize(DEFAULT_MEMORY_CACHE_SIZE);
@@ -1814,6 +1834,15 @@ public class MongoMK implements MicroKer
         public boolean isUseSimpleRevision() {
             return useSimpleRevision;
         }
+        
+        public Builder setSplitDocumentAgeMillis(long splitDocumentAgeMillis) {
+            this.splitDocumentAgeMillis = splitDocumentAgeMillis;
+            return this;
+        }
+        
+        public long getSplitDocumentAgeMillis() {
+            return splitDocumentAgeMillis;
+        }
 
         /**
          * Open the MongoMK instance using the configured options.