activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r692709 - /activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/index/BTreeIndex.java
Date Sat, 06 Sep 2008 19:10:53 GMT
Author: chirino
Date: Sat Sep  6 12:10:52 2008
New Revision: 692709

URL: http://svn.apache.org/viewvc?rev=692709&view=rev
Log:
Don't hold on the root page referece. Just load the root page from 
the page file every time and assume that the PageFile is going
to do the proper caching for us.


Modified:
    activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/index/BTreeIndex.java

Modified: activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/index/BTreeIndex.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/index/BTreeIndex.java?rev=692709&r1=692708&r2=692709&view=diff
==============================================================================
--- activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/index/BTreeIndex.java (original)
+++ activemq/sandbox/kahadb/src/main/java/org/apache/kahadb/index/BTreeIndex.java Sat Sep
 6 12:10:52 2008
@@ -128,8 +128,6 @@
     private Marshaller<Value> valueMarshaller;
     private Prefixer<Key> prefixer;
 
-    private BTreeNode<Key,Value> root;
-
     public BTreeIndex(PageFile pageFile, long rootPageId) {
         this.pageFile = pageFile;
         this.pageId = rootPageId;
@@ -152,38 +150,39 @@
             final Page<BTreeNode<Key,Value>> p = tx.load(pageId, null);
             if( p.getType() == Page.PAGE_FREE_TYPE ) {
                  // Need to initialize it..
-                root = createNode(p, null);
+                BTreeNode<Key, Value> root = createNode(p, null);
                 storeNode(tx, root, true);
-            } else {
-                root = loadNode(tx, pageId, null);    
             }
         }
     }
     
     synchronized public void unload(Transaction tx) {
         if (loaded.compareAndSet(true, false)) {
-            root=null;
         }    
     }
     
+    private BTreeNode<Key,Value> getRoot(Transaction tx) throws IOException {
+        return loadNode(tx, pageId, null);
+    }
+    
     synchronized public boolean containsKey(Transaction tx, Key key) throws IOException {
         assertLoaded();
-        return root.contains(tx, key);
+        return getRoot(tx).contains(tx, key);
     }
 
     synchronized public Value get(Transaction tx, Key key) throws IOException {
         assertLoaded();
-        return root.get(tx, key);
+        return getRoot(tx).get(tx, key);
     }
 
     synchronized public Value put(Transaction tx, Key key, Value value) throws IOException
{
         assertLoaded();
-        return root.put(tx, key, value);
+        return getRoot(tx).put(tx, key, value);
     }
 
     synchronized public Value remove(Transaction tx, Key key) throws IOException {
         assertLoaded();
-        return root.remove(tx, key);
+        return getRoot(tx).remove(tx, key);
     }
     
     public boolean isTransient() {
@@ -191,41 +190,41 @@
     }
 
     synchronized public void clear(Transaction tx) throws IOException {
-        root.clear(tx);
+        getRoot(tx).clear(tx);
     }
 
     synchronized public int getMinLeafDepth(Transaction tx) throws IOException {
-        return root.getMinLeafDepth(tx, 0);
+        return getRoot(tx).getMinLeafDepth(tx, 0);
     }
 
     synchronized public int getMaxLeafDepth(Transaction tx) throws IOException {
-        return root.getMaxLeafDepth(tx, 0);
+        return getRoot(tx).getMaxLeafDepth(tx, 0);
     }
 
     synchronized public void printStructure(Transaction tx, PrintWriter out) throws IOException
{
-        root.printStructure(tx, out, "");
+        getRoot(tx).printStructure(tx, out, "");
     }
     
     synchronized public void printStructure(Transaction tx, OutputStream out) throws IOException
{
         PrintWriter pw = new PrintWriter(out,false);
-        root.printStructure(tx, pw, "");
+        getRoot(tx).printStructure(tx, pw, "");
         pw.flush();
     }
 
     synchronized public Iterator<Map.Entry<Key,Value>> iterator(final Transaction
tx) throws IOException {
-        return root.iterator(tx);
+        return getRoot(tx).iterator(tx);
     }
     
     synchronized public Iterator<Map.Entry<Key,Value>> iterator(final Transaction
tx, Key initialKey) throws IOException {
-        return root.iterator(tx, initialKey);
+        return getRoot(tx).iterator(tx, initialKey);
     }
     
     synchronized public void visit(Transaction tx, BTreeVisitor<Key, Value> visitor)
throws IOException {
-        root.visit(tx, visitor);
+        getRoot(tx).visit(tx, visitor);
     }
 
     synchronized Value getFirst(Transaction tx) throws IOException {
-        return root.getFirst(tx);
+        return getRoot(tx).getFirst(tx);
     }
 
     ///////////////////////////////////////////////////////////////////



Mime
View raw message