Author: elecharny
Date: Sun Mar 10 18:47:15 2013
New Revision: 1454894
URL: http://svn.apache.org/r1454894
Log:
o Removed the ID from the BTree Page : we don't use it anymore
o The revision and nbElems are initialized when the constructor is called
o The rootPage is created before calling the init() method, so that we can
deserialize a BTree without having to create a rootPage that will anyway be
loaded from disk.
Modified:
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Node.java
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Page.java
Modified:
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java
URL:
http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java?rev=1454894&r1=1454893&r2=1454894&view=diff
==============================================================================
---
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java
(original)
+++
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java
Sun Mar 10 18:47:15 2013
@@ -40,9 +40,6 @@ public abstract class AbstractPage<K, V>
/** This BPage's revision */
protected long revision;
- /** This BPage's ID in the PageManager. */
- protected long id;
-
/** Keys of children nodes */
protected K[] keys;
@@ -76,8 +73,6 @@ public abstract class AbstractPage<K, V>
// Yes, this is an hack...
Class<?> keyType = btree.getKeyType();
this.keys = ( K[] ) Array.newInstance( keyType, nbElems );
-
- id = btree.generateRecordId();
}
@@ -262,24 +257,6 @@ public abstract class AbstractPage<K, V>
/**
- * @return the id
- */
- public long getId()
- {
- return id;
- }
-
-
- /**
- * @param id the id to set
- */
- public void setId( long id )
- {
- this.id = id;
- }
-
-
- /**
* {@inheritDoc}
*/
public K getKey( int pos )
@@ -303,7 +280,6 @@ public abstract class AbstractPage<K, V>
StringBuilder sb = new StringBuilder();
sb.append( "r" ).append( revision );
- sb.append( ", ID:" ).append( id );
sb.append( ", nbElems:" ).append( nbElems );
return sb.toString();
Modified:
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
URL:
http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java?rev=1454894&r1=1454893&r2=1454894&view=diff
==============================================================================
---
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
(original)
+++
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
Sun Mar 10 18:47:15 2013
@@ -72,10 +72,7 @@ public class BTree<K, V>
private String name;
/** A field used to generate new revisions in a thread safe way */
- private AtomicLong revision;
-
- /** A field used to generate new recordId in a thread safe way */
- private transient AtomicLong pageRecordIdGenerator;
+ private AtomicLong revision = new AtomicLong( 0L );
/** Comparator used to index entries. */
private Comparator<K> comparator;
@@ -114,7 +111,7 @@ public class BTree<K, V>
private File journal;
/** The number of elements in the current revision */
- private AtomicLong nbElems;
+ private AtomicLong nbElems = new AtomicLong( 0L );
/** A lock used to protect the write operation against concurrent access */
private ReentrantLock writeLock;
@@ -365,6 +362,10 @@ public class BTree<K, V>
throw new IllegalArgumentException( "Comparator should not be
null" );
}
+ // Create the first root page, with revision 0L. It will be empty
+ // and increment the revision at the same time
+ rootPage = new Leaf<K, V>( this );
+
// Now, initialize the BTree
init();
}
@@ -458,6 +459,10 @@ public class BTree<K, V>
this.valueSerializer = valueSerializer;
comparator = keySerializer.getComparator();
+ // Create the first root page, with revision 0L. It will be empty
+ // and increment the revision at the same time
+ rootPage = new Leaf<K, V>( this );
+
// Now, call the init() method
init();
}
@@ -479,16 +484,6 @@ public class BTree<K, V>
modificationsQueue = new LinkedBlockingDeque<Modification<K, V>>();
}
- // Initialize the PageId counter
- pageRecordIdGenerator = new AtomicLong( 0 );
-
- // Initialize the revision counter
- revision = new AtomicLong( 0 );
-
- // Create the first root page, with revision 0L. It will be empty
- // and increment the revision at the same time
- rootPage = new Leaf<K, V>( this );
-
// We will extract the Type to use for keys, using the comparator for
that
Class<?> comparatorClass = comparator.getClass();
Type[] types = comparatorClass.getGenericInterfaces();
@@ -499,7 +494,6 @@ public class BTree<K, V>
keyType = ( Class<?> ) argumentTypes[0];
}
- nbElems = new AtomicLong( 0 );
writeLock = new ReentrantLock();
// Check the files and create them if missing
@@ -650,18 +644,6 @@ public class BTree<K, V>
/**
- * Generates a new RecordId. It's only used by the Page instances.
- *
- * @return a new incremental recordId
- */
- /** No qualifier */
- long generateRecordId()
- {
- return pageRecordIdGenerator.getAndIncrement();
- }
-
-
- /**
* Generates a new revision number. It's only used by the Page instances.
*
* @return a new incremental revision number
Modified:
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Node.java
URL:
http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Node.java?rev=1454894&r1=1454893&r2=1454894&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Node.java
(original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Node.java
Sun Mar 10 18:47:15 2013
@@ -1038,7 +1038,7 @@ public class Node<K, V> extends Abstract
}
else
{
- sb.append( children[0].getId() ).append( "-r" ).append(
children[0].getRevision() );
+ sb.append( 'r' ).append( children[0].getRevision() );
}
for ( int i = 0; i < nbElems; i++ )
@@ -1051,7 +1051,7 @@ public class Node<K, V> extends Abstract
}
else
{
- sb.append( children[i + 1].getId() ).append( "-r"
).append( children[i + 1].getRevision() );
+ sb.append( 'r' ).append( children[i + 1].getRevision() );
}
}
}
Modified:
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Page.java
URL:
http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Page.java?rev=1454894&r1=1454893&r2=1454894&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Page.java
(original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/Page.java
Sun Mar 10 18:47:15 2013
@@ -128,12 +128,6 @@ public interface Page<K, V>
/**
- * @return the page ID
- */
- long getId();
-
-
- /**
* Return the key at a given position
* @param pos The position of the key we want to retrieve
* @return The key found at the given position
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]