jackrabbit-oak-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r1300657 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/mk/store/CopyingGC.java test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java
Date Wed, 14 Mar 2012 17:38:32 GMT
Author: dpfister
Date: Wed Mar 14 17:38:32 2012
New Revision: 1300657

URL: http://svn.apache.org/viewvc?rev=1300657&view=rev
Log:
Add copying GC for revisions
- completely ignore old revisions in GC cycle


Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java?rev=1300657&r1=1300656&r2=1300657&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
Wed Mar 14 17:38:32 2012
@@ -18,9 +18,7 @@ package org.apache.jackrabbit.mk.store;
 
 import java.io.Closeable;
 import java.io.InputStream;
-import java.util.Comparator;
 import java.util.Iterator;
-import java.util.TreeSet;
 
 import org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;
 import org.apache.jackrabbit.mk.model.ChildNodeEntry;
@@ -37,8 +35,8 @@ import org.apache.jackrabbit.oak.model.N
  * store to a "to" revision store. It assumes that both stores share the same blob
  * store.
  * 
- * In the current design, a revision is reachable, if it is either the head revision
- * or requested during the GC cycle.
+ * In the current design, the head revision and all the nodes it references are
+ * reachable.
  */
 public class CopyingGC implements RevisionStore, Closeable {
     
@@ -58,23 +56,6 @@ public class CopyingGC implements Revisi
     private volatile boolean running;
     
     /**
-     * First commit id of "to" store.
-     */
-    private Id firstCommitId;
-    
-    /**
-     * Map of commits that have been accessed while a GC cycle is running; these
-     * need to be "re-linked" with a preceding, possibly not adjacent parent
-     * commit before saving them back to the "to" revision store.
-     */
-    private final TreeSet<MutableCommit> commits = new TreeSet<MutableCommit>(
-            new Comparator<MutableCommit>() {
-                public int compare(MutableCommit o1, MutableCommit o2) {
-                    return o1.getId().compareTo(o2.getId());
-                }
-            });
-
-    /**
      * Create a new instance of this class.
      * 
      * @param rsFrom from store
@@ -91,18 +72,12 @@ public class CopyingGC implements Revisi
      * @throws Exception if an error occurs
      */
     public void start() throws Exception {
-        commits.clear();
-        firstCommitId = rsTo.getHeadCommitId();
-        
         // Copy the head commit
         MutableCommit commitTo = copy(rsFrom.getHeadCommit());
         commitTo.setParentId(rsTo.getHeadCommitId());
         Id revId = rsTo.putCommit(commitTo);
         rsTo.setHeadCommitId(revId);
 
-        // Add this as sentinel
-        commits.add(commitTo);
-
         running = true;
     }
     
@@ -112,14 +87,6 @@ public class CopyingGC implements Revisi
     public void stop() throws Exception {
         running = false;
         
-        if (commits.size() > 1) {
-            Id parentId = firstCommitId;
-            for (MutableCommit commit : commits) {
-                commit.setParentId(parentId);
-                rsTo.putCommit(commit);
-                parentId = commit.getId();
-            }
-        }
         // TODO: swap rsFrom/rsTo and reset them
         rsFrom = rsTo;
         rsTo = null;
@@ -181,11 +148,7 @@ public class CopyingGC implements Revisi
 
     public StoredNode getNode(Id id) throws NotFoundException, Exception {
         if (running) {
-            try {
-                return rsTo.getNode(id);
-            } catch (NotFoundException e) {
-                // ignore, better add a has() method
-            }
+            return rsTo.getNode(id);
         }
         return rsFrom.getNode(id);
     }
@@ -194,11 +157,7 @@ public class CopyingGC implements Revisi
             Exception {
         
         if (running) {
-            try {
-                return rsTo.getCommit(id);
-            } catch (NotFoundException e) {
-                // ignore, better add a has() method
-            }
+            return rsTo.getCommit(id);
         }
         return rsFrom.getCommit(id);
     }
@@ -207,11 +166,7 @@ public class CopyingGC implements Revisi
             Exception {
         
         if (running) {
-            try {
-                return rsTo.getCNEMap(id);
-            } catch (NotFoundException e) {
-                // ignore, better add a has() method
-            }
+            return rsTo.getCNEMap(id);
         }
         return rsFrom.getCNEMap(id);
     }
@@ -220,18 +175,9 @@ public class CopyingGC implements Revisi
             Exception {
 
         if (running) {
-            try {
-                return rsTo.getRootNode(commitId);
-            } catch (NotFoundException e) {
-                // ignore, better add a has() method
-            }
-        }
-        // Copy this commit
-        StoredCommit commit = rsFrom.getCommit(commitId);
-        if (running) {
-            commits.add(copy(commit));
+            return rsTo.getRootNode(commitId);
         }
-        return rsFrom.getNode(commit.getRootNodeId());
+        return rsFrom.getRootNode(commitId);
     }
 
     public StoredCommit getHeadCommit() throws Exception {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java?rev=1300657&r1=1300656&r2=1300657&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java
Wed Mar 14 17:38:32 2012
@@ -28,7 +28,6 @@ import org.apache.jackrabbit.mk.api.Micr
 import org.apache.jackrabbit.mk.fs.FileUtils;
 import org.apache.jackrabbit.mk.json.fast.Jsop;
 import org.apache.jackrabbit.mk.json.fast.JsopArray;
-import org.apache.jackrabbit.mk.json.fast.JsopObject;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -73,7 +72,6 @@ public class CopyHeadRevisionTest {
         gc.start();
 
         revs[4] = mk.commit("/b/e", "+\"g\" : {}", mk.getHeadRevision(), null);
-        mk.getJournal(revs[2], revs[2], "");
         
         // Simulate a GC cycle stop
         gc.stop();
@@ -81,21 +79,17 @@ public class CopyHeadRevisionTest {
         // Assert head revision is contained after GC
         assertEquals(mk.getHeadRevision(), revs[revs.length - 1]);
         
-        // Assert unused revision was GCed
-        try {
-            mk.getNodes("/", revs[0]);
-            fail("Revision should have been GCed: "+ revs[0]);
-        } catch (MicroKernelException e) {
-            // ignore
-        }
-        
-        // Verify journal integrity: referenced revision must still be available and linked
in chain
-        JsopArray a = (JsopArray) Jsop.parse(mk.getRevisions(0, Integer.MAX_VALUE));
-        for (int i = 0; i < a.size(); i++) {
-            if (((JsopObject) a.get(i)).get("id").equals(revs[2])) {
-                return; 
+        // Assert unused revisions were GCed
+        for (int i = 0; i < 3; i++) {
+            try {
+                mk.getNodes("/", revs[i]);
+                fail("Revision should have been GCed: "+ revs[i]);
+            } catch (MicroKernelException e) {
+                // ignore
             }
         }
-        fail("Revision not appearing in list of revisions: "+ revs[2]);
+        
+        // Assert MK contains 3 revisions only
+        assertEquals(3, ((JsopArray) Jsop.parse(mk.getRevisions(0, Integer.MAX_VALUE))).size());
     }
 }



Mime
View raw message