You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2017/02/24 07:16:38 UTC
svn commit: r1784232 [1/9] - in
/directory/mavibot/branches/single-value/mavibot/src:
main/java/org/apache/directory/mavibot/btree/
main/java/org/apache/directory/mavibot/btree/serializer/
test/java/org/apache/directory/mavibot/btree/
Author: elecharny
Date: Fri Feb 24 07:16:37 2017
New Revision: 1784232
URL: http://svn.apache.org/viewvc?rev=1784232&view=rev
Log:
Committing the current version of Mavibot with transaction. It's far from being completed, and has compilation errors.
Added:
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransaction.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractWALObject.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManagerHeader.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RevisionOffsets.java
- copied, changed from r1706445, directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RevisionOffset.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RevisionOffsetsSerializer.java
- copied, changed from r1706445, directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RevisionOffsetSerializer.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/Transaction.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/ValueHolder.java
- copied, changed from r1711861, directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractValueHolder.java
Removed:
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransactionManager.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractValueHolder.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/KeyHolderImpl.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/PageHolderImpl.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RevisionOffset.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RevisionOffsetSerializer.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/ValueBTreeCursor.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/ValueHolderImpl.java
Modified:
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBorrowedFromSiblingResult.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractDeleteResult.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeConfiguration.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeHeader.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeImpl.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeInfo.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BorrowedFromLeftResult.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BorrowedFromRightResult.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BulkLoader.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/Cursor.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/ExistsResult.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/KeyCursor.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/KeyHolder.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/Leaf.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/LevelInfo.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/MergedWithSiblingResult.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/ModifyResult.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/NameRevisionSerializer.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/Node.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/NotPresentResult.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/Page.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/PageHolder.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/PageReclaimer.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/ReadTransaction.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RemoveResult.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/Result.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RevisionNameSerializer.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RevisionOffsetComparator.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/SplitResult.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/TransactionContext.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/TransactionManager.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/TupleCursor.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/WALObject.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/WriteTransaction.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/BooleanSerializer.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteArraySerializer.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteSerializer.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/CharArraySerializer.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/CharSerializer.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/IntSerializer.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongArraySerializer.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongSerializer.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ShortSerializer.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/StringSerializer.java
directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeBrowseTest.java
directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeBuilderTest.java
directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeTransactionTest.java
directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/PageReclaimerTest.java
directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerFreePageTest.java
directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerTest.java
Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBorrowedFromSiblingResult.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBorrowedFromSiblingResult.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBorrowedFromSiblingResult.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBorrowedFromSiblingResult.java Fri Feb 24 07:16:37 2017
@@ -87,6 +87,7 @@ import java.util.List;
/**
* {@inheritDoc}
*/
+ @Override
public Page<K, V> getModifiedSibling()
{
return modifiedSibling;
@@ -96,6 +97,7 @@ import java.util.List;
/**
* {@inheritDoc}
*/
+ @Override
public boolean isFromLeft()
{
return position == SiblingPosition.LEFT;
@@ -105,6 +107,7 @@ import java.util.List;
/**
* {@inheritDoc}
*/
+ @Override
public boolean isFromRight()
{
return position == SiblingPosition.RIGHT;
@@ -114,6 +117,7 @@ import java.util.List;
/**
* @see Object#toString()
*/
+ @Override
public String toString()
{
StringBuilder sb = new StringBuilder();
Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractDeleteResult.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractDeleteResult.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractDeleteResult.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractDeleteResult.java Fri Feb 24 07:16:37 2017
@@ -74,6 +74,7 @@ import java.util.List;
/**
* {@inheritDoc}
*/
+ @Override
public Page<K, V> getModifiedPage()
{
return modifiedPage;
@@ -83,6 +84,7 @@ import java.util.List;
/**
* {@inheritDoc}
*/
+ @Override
public Tuple<K, V> getRemovedElement()
{
return removedElement;
Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java Fri Feb 24 07:16:37 2017
@@ -23,24 +23,20 @@ package org.apache.directory.mavibot.btr
import java.io.IOException;
import java.lang.reflect.Array;
-import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
/**
* A MVCC abstract Page. It stores the field and the methods shared by the Node and Leaf
- * classes.
+ * classes (the keys and values/children).
*
* @param <K> The type for the Key
* @param <V> The type for the stored value
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-/* No qualifier*/abstract class AbstractPage<K, V> implements Page<K, V>, WALObject
+/* No qualifier*/abstract class AbstractPage<K, V> extends AbstractWALObject<K, V> implements Page<K, V>
{
- /** Parent B+Tree. */
- protected transient BTree<K, V> btree;
-
/** Keys of children nodes */
protected KeyHolder<K>[] keys;
@@ -48,20 +44,11 @@ import org.apache.directory.mavibot.btre
protected PageHolder<K, V>[] children;
/** The number of current values in the Page */
- protected int nbElems;
+ protected int nbPageElems;
- /** This BPage's revision */
+ /** This Page's revision */
protected long revision;
- /** The first {@link PageIO} storing the serialized Page on disk */
- protected long offset = -1L;
-
- /** The last {@link PageIO} storing the serialized Page on disk */
- protected long lastOffset = -1L;
-
- private long id;
-
-
/**
* Creates a default empty AbstractPage
*
@@ -78,40 +65,42 @@ import org.apache.directory.mavibot.btre
*/
@SuppressWarnings("unchecked")
// Cannot create an array of generic objects
- protected AbstractPage( BTree<K, V> btree, long revision, int nbElems )
+ protected AbstractPage( BTree<K, V> btree, long revision, int nbPageElems )
{
this.btree = btree;
this.revision = revision;
- this.nbElems = nbElems;
- this.keys = ( KeyHolder[] ) Array.newInstance( KeyHolder.class, btree.getPageSize() );
+ this.nbPageElems = nbPageElems;
+ this.keys = ( KeyHolder[] ) Array.newInstance( KeyHolder.class, btree.getPageNbElem() );
}
/**
* {@inheritDoc}
*/
- public int getNbElems()
+ @Override
+ public int getNbPageElems()
{
- return nbElems;
+ return nbPageElems;
}
/**
* Sets the number of element in this page
- * @param nbElems The number of elements
+ * @param nbPageElems The number of elements
*/
- /* no qualifier */void setNbElems( int nbElems )
+ /* no qualifier */void setNbPageElems( int nbPageElems )
{
- this.nbElems = nbElems;
+ this.nbPageElems = nbPageElems;
}
/**
* {@inheritDoc}
*/
+ @Override
public K getKey( int pos )
{
- if ( ( pos < nbElems ) && ( keys[pos] != null ) )
+ if ( ( pos < nbPageElems ) && ( keys[pos] != null ) )
{
return keys[pos].getKey();
}
@@ -150,7 +139,7 @@ import org.apache.directory.mavibot.btre
*/
/* no qualifier */Page<K, V> getReference( int pos ) throws IOException
{
- if ( pos < nbElems + 1 )
+ if ( pos < nbPageElems + 1 )
{
if ( children[pos] != null )
{
@@ -171,7 +160,8 @@ import org.apache.directory.mavibot.btre
/**
* {@inheritDoc}
*/
- public TupleCursor<K, V> browse( K key, ReadTransaction<K, V> transaction, ParentPos<K, V>[] stack, int depth )
+ @Override
+ public TupleCursor<K, V> browse( Transaction transaction, K key, ParentPos<K, V>[] stack, int depth )
throws IOException
{
int pos = findPos( key );
@@ -182,11 +172,11 @@ import org.apache.directory.mavibot.btre
}
// We first stack the current page
- stack[depth++] = new ParentPos<K, V>( this, pos );
+ stack[depth++] = new ParentPos<>( this, pos );
Page<K, V> page = children[pos].getValue();
- return page.browse( key, transaction, stack, depth );
+ return page.browse( transaction, key, stack, depth );
}
@@ -214,9 +204,10 @@ import org.apache.directory.mavibot.btre
/**
* {@inheritDoc}
*/
- public DeleteResult<K, V> delete( K key, V value, long revision ) throws IOException
+ @Override
+ public DeleteResult<K, V> delete( WriteTransaction transaction, K key ) throws IOException
{
- return delete( key, value, revision, null, -1 );
+ return delete( transaction, key, null, -1 );
}
@@ -224,21 +215,19 @@ import org.apache.directory.mavibot.btre
* The real delete implementation. It can be used for internal deletion in the B-tree.
*
* @param key The key to delete
- * @param value The value to delete
- * @param revision The revision for which we want to delete a tuple
* @param parent The parent page
* @param parentPos The position of this page in the parent page
* @return The result
* @throws IOException If we had an issue while processing the deletion
*/
- /* no qualifier */abstract DeleteResult<K, V> delete( K key, V value, long revision, Page<K, V> parent,
- int parentPos )
- throws IOException;
+ /* no qualifier */abstract DeleteResult<K, V> delete( WriteTransaction transaction, K key, Page<K, V> parent,
+ int parentPos ) throws IOException;
/**
* {@inheritDoc}
*/
+ @Override
public V get( K key ) throws IOException, KeyNotFoundException
{
int pos = findPos( key );
@@ -261,16 +250,9 @@ import org.apache.directory.mavibot.btre
*/
/* no qualifier */Page<K, V> getPage( int pos )
{
- if ( ( pos >= 0 ) && ( pos < children.length ) )
+ if ( ( pos >= 0 ) && ( pos < children.length ) && ( children[pos] != null ) )
{
- if ( children[pos] != null )
- {
- return children[pos].getValue();
- }
- else
- {
- return null;
- }
+ return children[pos].getValue();
}
else
{
@@ -295,27 +277,6 @@ import org.apache.directory.mavibot.btre
/**
- * {@inheritDoc}
- */
- @Override
- public ValueCursor<V> getValues( K key ) throws KeyNotFoundException, IOException, IllegalArgumentException
- {
- int pos = findPos( key );
-
- if ( pos < 0 )
- {
- // Here, if we have found the key in the node, then we must go down into
- // the right child, not the left one
- return children[-pos].getValue().getValues( key );
- }
- else
- {
- return children[pos].getValue().getValues( key );
- }
- }
-
-
- /**
* Sets the value at a give position
* @param pos The position in the values array
* @param value the value to inject
@@ -329,10 +290,11 @@ import org.apache.directory.mavibot.btre
/**
* {@inheritDoc}
*/
- public TupleCursor<K, V> browse( ReadTransaction<K, V> transaction, ParentPos<K, V>[] stack, int depth )
+ @Override
+ public TupleCursor<K, V> browse( Transaction transaction, ParentPos<K, V>[] stack, int depth )
throws IOException
{
- stack[depth++] = new ParentPos<K, V>( this, 0 );
+ stack[depth++] = new ParentPos<>( this, 0 );
Page<K, V> page = children[0].getValue();
@@ -343,7 +305,8 @@ import org.apache.directory.mavibot.btre
/**
* {@inheritDoc}
*/
- public KeyCursor<K> browseKeys( ReadTransaction<K, K> transaction, ParentPos<K, K>[] stack, int depth )
+ @Override
+ public KeyCursor<K> browseKeys( Transaction transaction, ParentPos<K, K>[] stack, int depth )
throws IOException
{
stack[depth++] = new ParentPos( this, 0 );
@@ -363,7 +326,7 @@ import org.apache.directory.mavibot.btre
* @return The position of the sibling, or -1 if we have'nt found any sibling
* @throws IOException If we have an error while trying to access the page
*/
- protected int selectSibling( Page<K, V> parent, int parentPos ) throws IOException
+ protected int selectSibling( Transaction transaction, Page<K, V> parent, int parentPos ) throws IOException
{
if ( parentPos == 0 )
{
@@ -372,7 +335,7 @@ import org.apache.directory.mavibot.btre
return 1;
}
- if ( parentPos == parent.getNbElems() )
+ if ( parentPos == parent.getNbPageElems() )
{
// The current page is referenced on the right of its parent's page :
// we will not have a next page with the same parent
@@ -382,8 +345,8 @@ import org.apache.directory.mavibot.btre
Page<K, V> prevPage = ( ( AbstractPage<K, V> ) parent ).getPage( parentPos - 1 );
Page<K, V> nextPage = ( ( AbstractPage<K, V> ) parent ).getPage( parentPos + 1 );
- int prevPageSize = prevPage.getNbElems();
- int nextPageSize = nextPage.getNbElems();
+ int prevPageSize = prevPage.getNbPageElems();
+ int nextPageSize = nextPage.getNbPageElems();
if ( prevPageSize >= nextPageSize )
{
@@ -399,6 +362,7 @@ import org.apache.directory.mavibot.btre
/**
* {@inheritDoc}
*/
+ @Override
public K getLeftMostKey()
{
return keys[0].getKey();
@@ -408,45 +372,10 @@ import org.apache.directory.mavibot.btre
/**
* {@inheritDoc}
*/
+ @Override
public K getRightMostKey()
{
- return keys[nbElems - 1].getKey();
- }
-
-
- /**
- * @return the offset of the first {@link PageIO} which stores the Page on disk.
- */
- /* no qualifier */long getOffset()
- {
- return offset;
- }
-
-
- /**
- * @param offset the offset to set
- */
- /* no qualifier */void setOffset( long offset )
- {
- this.offset = offset;
- }
-
-
- /**
- * @return the offset of the last {@link PageIO} which stores the Page on disk.
- */
- /* no qualifier */long getLastOffset()
- {
- return lastOffset;
- }
-
-
- /**
- * {@inheritDoc}
- */
- /* no qualifier */void setLastOffset( long lastOffset )
- {
- this.lastOffset = lastOffset;
+ return keys[nbPageElems - 1].getKey();
}
@@ -481,18 +410,9 @@ import org.apache.directory.mavibot.btre
/**
- * {@inheritDoc}
- */
- /* no qualifier */ValueHolder<V> getValue( int pos )
- {
- // Node don't have values. Leaf.getValue() will return the value
- return null;
- }
-
-
- /**
* @return the revision
*/
+ @Override
public long getRevision()
{
return revision;
@@ -555,7 +475,7 @@ import org.apache.directory.mavibot.btre
* Computing the real position is just a matter to get -(position++).
* <p/>
* If we don't find the key in the table, we will return the position of the key
- * immediately above the key we are looking for. <br/>
+ * immediately above the key we are looking for, as a positive value. <br/>
* For instance, looking for :
* <ul>
* <li>'a' will return 0</li>
@@ -573,16 +493,17 @@ import org.apache.directory.mavibot.btre
* @param key The key to find
* @return The position in the page.
*/
+ @Override
public int findPos( K key )
{
// Deal with the special key where we have an empty page
- if ( nbElems == 0 )
+ if ( nbPageElems == 0 )
{
return 0;
}
int min = 0;
- int max = nbElems - 1;
+ int max = nbPageElems - 1;
// binary search
while ( min < max )
@@ -632,7 +553,8 @@ import org.apache.directory.mavibot.btre
/**
* {@inheritDoc}
*/
- public Tuple<K, V> findLeftMost() throws EndOfFileExceededException, IOException
+ @Override
+ public Tuple<K, V> findLeftMost() throws IOException
{
return children[0].getValue().findLeftMost();
}
@@ -641,55 +563,37 @@ import org.apache.directory.mavibot.btre
/**
* {@inheritDoc}
*/
- public Tuple<K, V> findRightMost() throws EndOfFileExceededException, IOException
+ @Override
+ public Tuple<K, V> findRightMost() throws IOException
{
- return children[nbElems].getValue().findRightMost();
+ return children[nbPageElems].getValue().findRightMost();
}
-
-
+
+
/**
- * @return the btree
+ * {@inheritDoc}
*/
- public BTree<K, V> getBtree()
- {
- return btree;
- }
-
-
@Override
- public long getId()
+ public String getName()
{
- return id;
- }
-
-
- @Override
- public void setId( long id )
- {
- this.id = id;
- }
-
-
- @Override
- public PageIO[] serialize() throws IOException
- {
- return null;
+ return btree.getName();
}
/**
* {@inheritDoc}
*/
+ @Override
public String dumpPage( String tabs )
{
StringBuilder sb = new StringBuilder();
- if ( nbElems > 0 )
+ if ( nbPageElems > 0 )
{
// Start with the first child
sb.append( children[0].getValue().dumpPage( tabs + " " ) );
- for ( int i = 0; i < nbElems; i++ )
+ for ( int i = 0; i < nbPageElems; i++ )
{
sb.append( tabs );
sb.append( "<" );
@@ -705,16 +609,23 @@ import org.apache.directory.mavibot.btre
/**
* @see Object#toString()
*/
+ @Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append( "r" ).append( revision );
- sb.append( ", nbElems:" ).append( nbElems );
+ sb.append( ", nbPageElems:" ).append( nbPageElems );
+ sb.append( ", id:" ).append( id );
if ( offset > 0 )
{
- sb.append( ", offset:" ).append( offset );
+ sb.append( ", offset: 0x" ).append( Long.toHexString( offset ) );
+ }
+
+ if ( pageIOs != null )
+ {
+ sb.append( ", nb pageIOs:" ).append( pageIOs.length );
}
return sb.toString();
Added: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransaction.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransaction.java?rev=1784232&view=auto
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransaction.java (added)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransaction.java Fri Feb 24 07:16:37 2017
@@ -0,0 +1,200 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.mavibot.btree;
+
+
+import java.io.IOException;
+import java.util.Date;
+
+
+/**
+ * A read transaction is used to insure that reads are always done against
+ * one single revision.
+ * <br>
+ * A read transaction should be closed when the user is done with it, otherwise the
+ * pages associated with the given revision, and all the referenced pages, will
+ * remain on the storage.
+ * <p/>
+ * A Transaction can be hold for quite a long time, for instance while doing
+ * a browse against a big b-tree. At some point, transactions which are pending
+ * for too long will be closed by the transaction manager (the default is to keep a
+ * read transaction opened for 30 s). If one need to keep a read transaction opened
+ * for a longer time, pass a longer timeout to the constructor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class AbstractTransaction implements Transaction
+{
+ /** The date of creation */
+ private long creationDate;
+
+ /** The timeout */
+ private long timeout = Transaction.DEFAULT_TIMEOUT;
+
+ /** A flag used to tell if a transaction is closed or not */
+ private volatile boolean closed;
+
+ /** The reference to the recordManager */
+ protected RecordManager recordManager;
+
+ /** The reference to the recordManagerHeader */
+ protected RecordManagerHeader recordManagerHeader;
+
+ /**
+ * Creates a new read transaction, with a default 30 seconds timeout.
+ *
+ * @param recordManager The associated RecordManager
+ */
+ /* No qualifier*/ AbstractTransaction( RecordManager recordManager )
+ {
+ this( recordManager, DEFAULT_TIMEOUT );
+ }
+
+ /**
+ * Creates a new read transaction, with a specific tiemout. It create a new copy of
+ * the recordManager header
+ *
+ * @param recordManager The asscoated RecordManager
+ * @param timeout The transaction's timrout
+ */
+ /* No qualifier*/ AbstractTransaction( RecordManager recordManager, long timeout )
+ {
+ assert recordManager != null;
+ this.recordManager = recordManager;
+ recordManagerHeader = recordManager.getRecordManagerHeader();
+
+ this.timeout = timeout;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public RecordManager getRecordManager()
+ {
+ return recordManager;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public RecordManagerHeader getRecordManagerHeader()
+ {
+ return recordManagerHeader;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public long getRevision()
+ {
+ return recordManagerHeader.getRevision();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public long getCreationDate()
+ {
+ return creationDate;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close() throws IOException
+ {
+ closed = true;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isClosed()
+ {
+ return closed;
+ }
+
+
+ /**
+ * @return the timeout
+ */
+ public long getTimeout()
+ {
+ return timeout;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void abort() throws IOException
+ {
+ closed = true;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void commit() throws IOException
+ {
+ closed = true;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( "[rev:" );
+ sb.append( getRevision() );
+ sb.append( ", " );
+ sb.append( new Date( creationDate ) );
+ sb.append( ", " );
+ sb.append( timeout );
+
+ if ( closed )
+ {
+ sb.append( ", CLOSED" );
+ }
+
+ sb.append( "]" );
+
+ return sb.toString();
+ }
+}
Added: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractWALObject.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractWALObject.java?rev=1784232&view=auto
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractWALObject.java (added)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractWALObject.java Fri Feb 24 07:16:37 2017
@@ -0,0 +1,121 @@
+package org.apache.directory.mavibot.btree;
+
+/**
+ * An abstract class implementing the {@link WALObject} interface.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class AbstractWALObject<K, V> implements WALObject<K, V>
+{
+ /** The B-tree this header is associated with */
+ protected BTree<K, V> btree;
+
+ /** The PageIO of the serialized WALObject */
+ protected PageIO[] pageIOs;
+
+ /** The first {@link PageIO} storing the serialized Page on disk */
+ protected long offset = RecordManager.NO_PAGE;
+
+ /** This page ID */
+ protected long id;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public long getOffset()
+ {
+ return offset;
+ }
+
+
+ /**
+ * @param offset the offset to set
+ */
+ /* No qualifier */ void setOffset( long offset )
+ {
+ this.offset = offset;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getName()
+ {
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public PageIO[] getPageIOs()
+ {
+ return pageIOs;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setPageIOs( PageIO[] pageIOs )
+ {
+ this.pageIOs = pageIOs;
+ offset = pageIOs[0].getOffset();
+ }
+
+
+ /**
+ * @return the B-tree
+ */
+ @Override
+ public BTree<K, V> getBtree()
+ {
+ return btree;
+ }
+
+
+ /**
+ * Associate a B-tree with this BTreeHeader instance
+ *
+ * @param btree the B-tree to set
+ */
+ /* no qualifier */void setBtree( BTree<K, V> btree )
+ {
+ this.btree = btree;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public long getId()
+ {
+ return id;
+ }
+
+
+ /**
+ * @param id the id to set
+ */
+ /* no qualifier*/ void setId( long id )
+ {
+ this.id = id;
+ }
+
+
+ /**
+ * Initialize the Page ID, using teh RecordManagerHeader counter
+ *
+ * @param recordManagerHeader the RecordManagerHeader which contains the page ID counter
+ */
+ /* no qualifier*/ void initId( RecordManagerHeader recordManagerHeader )
+ {
+ this.id = recordManagerHeader.idCounter++;
+ }
+}
Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java Fri Feb 24 07:16:37 2017
@@ -39,7 +39,7 @@ import org.apache.directory.mavibot.btre
public interface BTree<K, V>
{
/** Default page size (number of entries per node) */
- int DEFAULT_PAGE_SIZE = 16;
+ int DEFAULT_PAGE_NBELEM = 16;
/** Default size of the buffer used to write data on disk. Around 1Mb */
int DEFAULT_WRITE_BUFFER_SIZE = 4096 * 250;
@@ -64,19 +64,19 @@ public interface BTree<K, V>
* Set the maximum number of elements we can store in a page. This must be a
* number greater than 1, and a power of 2. The default page size is 16.
* <br/>
- * If the provided size is below 2, we will default to DEFAULT_PAGE_SIZE.<br/>
+ * If the provided size is below 2, we will default to DEFAULT_PAGE_NB_ELEM.<br/>
* If the provided size is not a power of 2, we will select the closest power of 2
* higher than the given number<br/>
*
- * @param pageSize The requested page size
+ * @param pageNbElem The number of element per page
*/
- void setPageSize( int pageSize );
+ void setPageNbElem( int pageNbElem );
/**
* @return the number of elements per page
*/
- int getPageSize();
+ int getPageNbElem();
/**
@@ -90,7 +90,7 @@ public interface BTree<K, V>
* @return Existing value, if any.
* @throws IOException TODO
*/
- V insert( K key, V value ) throws IOException;
+ InsertResult<K, V> insert( WriteTransaction transaction, K key, V value ) throws IOException;
/**
@@ -100,7 +100,7 @@ public interface BTree<K, V>
* @param key The key for the entry we try to remove
* @return A Tuple<K, V> containing the removed entry, or null if it's not found.
*/
- Tuple<K, V> delete( K key ) throws IOException;
+ Tuple<K, V> delete( WriteTransaction transaction, K key ) throws IOException;
/**
@@ -113,7 +113,7 @@ public interface BTree<K, V>
* @param value The value to delete (can be null)
* @return A Tuple<K, V> containing the removed entry, or null if it's not found.
*/
- Tuple<K, V> delete( K key, V value ) throws IOException;
+ Tuple<K, V> delete( WriteTransaction transaction, K key, V value ) throws IOException;
/**
@@ -126,18 +126,7 @@ public interface BTree<K, V>
* @throws KeyNotFoundException If the key is not found in the B-tree
* @throws IOException TODO
*/
- V get( K key ) throws IOException, KeyNotFoundException;
-
-
- /**
- * Get the rootPage associated to a given revision.
- *
- * @param revision The revision we are looking for
- * @return The rootPage associated to this revision
- * @throws IOException If we had an issue while accessing the underlying file
- * @throws KeyNotFoundException If the revision does not exist for this B-tree
- */
- Page<K, V> getRootPage( long revision ) throws IOException, KeyNotFoundException;
+ V get( Transaction transaction, K key ) throws IOException, KeyNotFoundException;
/**
@@ -146,26 +135,18 @@ public interface BTree<K, V>
* @return The current rootPage
*/
Page<K, V> getRootPage();
-
-
+
+
/**
- * @see Page#getValues(Object)
+ * @return The RecordManager instance
*/
- ValueCursor<V> getValues( K key ) throws IOException, KeyNotFoundException;
-
-
+ RecordManager getRecordManager();
+
+
/**
- * Find a value in the tree, given its key, at a specific revision. If the key is not found,
- * it will throw a KeyNotFoundException. <br/>
- * Note that we can get a null value stored, or many values.
- *
- * @param revision The revision for which we want to find a key
- * @param key The key we are looking at
- * @return The found value, or null if the key is not present in the tree
- * @throws KeyNotFoundException If the key is not found in the B-tree
- * @throws IOException If there was an issue while fetching data from the disk
+ * @return The RecordManagerHeader instance
*/
- V get( long revision, K key ) throws IOException, KeyNotFoundException;
+ RecordManagerHeader getRecordManagerHeader();
/**
@@ -176,19 +157,7 @@ public interface BTree<K, V>
* @throws IOException If we have an error while trying to access the page
* @throws KeyNotFoundException If the key is not found in the B-tree
*/
- boolean hasKey( K key ) throws IOException, KeyNotFoundException;
-
-
- /**
- * Checks if the given key exists for a given revision.
- *
- * @param revision The revision for which we want to find a key
- * @param key The key we are looking at
- * @return true if the key is present, false otherwise
- * @throws IOException If we have an error while trying to access the page
- * @throws KeyNotFoundException If the key is not found in the B-tree
- */
- boolean hasKey( long revision, K key ) throws IOException, KeyNotFoundException;
+ boolean hasKey( Transaction transaction, K key ) throws IOException, KeyNotFoundException;
/**
@@ -198,39 +167,17 @@ public interface BTree<K, V>
* @param value The value associated with the given key
* @return true if the key and value are associated with each other, false otherwise
*/
- boolean contains( K key, V value ) throws IOException;
-
-
- /**
- * Checks if the B-tree contains the given key with the given value for a given revision
- *
- * @param revision The revision we would like to browse
- * @param key The key we are looking for
- * @param value The value associated with the given key
- * @return true if the key and value are associated with each other, false otherwise
- * @throws KeyNotFoundException If the key is not found in the B-tree
- */
- boolean contains( long revision, K key, V value ) throws IOException, KeyNotFoundException;
+ boolean contains( Transaction transaction, K key, V value ) throws IOException;
/**
* Creates a cursor starting at the beginning of the tree
*
+ * @param transaction The Transaction we are running in
* @return A cursor on the B-tree
* @throws IOException
*/
- TupleCursor<K, V> browse() throws IOException, KeyNotFoundException, CursorException;
-
-
- /**
- * Creates a cursor starting at the beginning of the tree, for a given revision
- *
- * @param revision The revision we would like to browse
- * @return A cursor on the B-tree
- * @throws IOException If we had an issue while fetching data from the disk
- * @throws KeyNotFoundException If the key is not found in the B-tree
- */
- TupleCursor<K, V> browse( long revision ) throws IOException, KeyNotFoundException;
+ TupleCursor<K, V> browse( Transaction transaction ) throws IOException, KeyNotFoundException, CursorException;
/**
@@ -241,20 +188,7 @@ public interface BTree<K, V>
* @return A cursor on the B-tree
* @throws IOException
*/
- TupleCursor<K, V> browseFrom( K key ) throws IOException;
-
-
- /**
- * Creates a cursor starting on the given key at the given revision
- *
- * @param The revision we are looking for
- * @param key The key which is the starting point. If the key is not found,
- * then the cursor will always return null.
- * @return A cursor on the B-tree
- * @throws IOException If wxe had an issue reading the B-tree from disk
- * @throws KeyNotFoundException If we can't find a rootPage for this revision
- */
- TupleCursor<K, V> browseFrom( long revision, K key ) throws IOException, KeyNotFoundException;
+ TupleCursor<K, V> browseFrom( Transaction transaction, K key ) throws IOException;
/**
@@ -263,7 +197,7 @@ public interface BTree<K, V>
* @return A cursor on the B-tree keys
* @throws IOException
*/
- KeyCursor<K> browseKeys() throws IOException, KeyNotFoundException;
+ //KeyCursor<K> browseKeys( Transaction transaction ) throws IOException, KeyNotFoundException;
/**
@@ -291,25 +225,6 @@ public interface BTree<K, V>
/**
- * Flush the latest revision to disk. We will replace the current file by the new one, as
- * we flush in a temporary file.
- */
- void flush() throws IOException;
-
-
- /**
- * @return the readTimeOut
- */
- long getReadTimeOut();
-
-
- /**
- * @param readTimeOut the readTimeOut to set
- */
- void setReadTimeOut( long readTimeOut );
-
-
- /**
* @return the name
*/
String getName();
@@ -322,18 +237,6 @@ public interface BTree<K, V>
/**
- * @return the writeBufferSize
- */
- int getWriteBufferSize();
-
-
- /**
- * @param writeBufferSize the writeBufferSize to set
- */
- void setWriteBufferSize( int writeBufferSize );
-
-
- /**
* @return the keySerializer
*/
ElementSerializer<K> getKeySerializer();
@@ -358,25 +261,13 @@ public interface BTree<K, V>
/**
- * @return The current B-tree revision
- */
- long getRevision();
-
-
- /**
* @return The current number of elements in the B-tree
*/
- long getNbElems();
+ long getNbElems( RecordManagerHeader recordManagerHeader );
/**
* @return the type
*/
BTreeTypeEnum getType();
-
-
- /**
- * @return The recordManager reference
- */
- RecordManager getRecordManager();
}
Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java Fri Feb 24 07:16:37 2017
@@ -24,7 +24,6 @@ package org.apache.directory.mavibot.btr
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
@@ -61,17 +60,17 @@ public class BTreeBuilder<K, V>
@SuppressWarnings("unchecked")
- public BTree<K, V> build( Iterator<Tuple<K, V>> sortedTupleItr ) throws Exception
+ public BTree<K, V> build( WriteTransaction transaction, Iterator<Tuple<K, V>> sortedTupleItr ) throws Exception
{
- BTree<K, V> btree = BTreeFactory.createPersistedBTree( name, keySerializer, valueSerializer );
+ BTree<K, V> btree = BTreeFactory.createBTree( transaction, name, keySerializer, valueSerializer );
- rm.manage( btree );
+ rm.manage( transaction, btree );
- List<Page<K, V>> lstLeaves = new ArrayList<Page<K, V>>();
+ List<Page<K, V>> lstLeaves = new ArrayList<>();
int totalTupleCount = 0;
- Leaf<K, V> leaf1 = ( Leaf<K, V> ) BTreeFactory.createLeaf( btree, 0, numKeysInNode );
+ Leaf<K, V> leaf1 = ( Leaf<K, V> ) BTreeFactory.createLeaf( btree, transaction.getRevision(), numKeysInNode );
lstLeaves.add( leaf1 );
int leafIndex = 0;
@@ -82,19 +81,20 @@ public class BTreeBuilder<K, V>
BTreeFactory.setKey( btree, leaf1, leafIndex, tuple.getKey() );
- ValueHolderImpl<V> eh = new ValueHolderImpl<V>( btree, tuple.getValue() );
+ ValueHolder<V> eh = new ValueHolder<>( btree, tuple.getValue() );
BTreeFactory.setValue( btree, leaf1, leafIndex, eh );
leafIndex++;
totalTupleCount++;
+
if ( ( totalTupleCount % numKeysInNode ) == 0 )
{
leafIndex = 0;
- PageHolder<K, V> pageHolder = rm.writePage( btree, leaf1, 1 );
+ PageHolder<K, V> pageHolder = rm.writePage( transaction, btree, leaf1, 1 );
- leaf1 = ( Leaf<K, V> ) BTreeFactory.createLeaf( btree, 0, numKeysInNode );
+ leaf1 = ( Leaf<K, V> ) BTreeFactory.createLeaf( btree, transaction.getRevision(), numKeysInNode );
lstLeaves.add( leaf1 );
}
@@ -108,22 +108,23 @@ public class BTreeBuilder<K, V>
// remove null keys and values from the last leaf and resize
Leaf<K, V> lastLeaf = ( Leaf<K, V> ) lstLeaves.get( lstLeaves.size() - 1 );
- for ( int i = 0; i < lastLeaf.getNbElems(); i++ )
+
+ for ( int i = 0; i < lastLeaf.getNbPageElems(); i++ )
{
if ( lastLeaf.getKey( i ) == null )
{
int n = i;
- lastLeaf.setNbElems( n );
+ lastLeaf.setNbPageElems( n );
KeyHolder<K>[] keys = lastLeaf.getKeys();
- lastLeaf.setKeys( ( KeyHolder[] ) Array.newInstance( KeyHolderImpl.class, n ) );
+ lastLeaf.setKeys( ( KeyHolder[] ) Array.newInstance( KeyHolder.class, n ) );
System.arraycopy( keys, 0, lastLeaf.getKeys(), 0, n );
- ValueHolder<V>[] values = lastLeaf.values;
- lastLeaf.values = ( ValueHolderImpl<V>[] ) Array.newInstance( ValueHolderImpl.class, n );
- System.arraycopy( values, 0, lastLeaf.values, 0, n );
+ ValueHolder<V>[] values = lastLeaf.getValues();
+ lastLeaf.setValues( ( ValueHolder<V>[] ) Array.newInstance( ValueHolder.class, n ) );
+ System.arraycopy( values, 0, lastLeaf.getValues(), 0, n );
- PageHolder<K, V> pageHolder = rm.writePage( btree, lastLeaf, 1 );
+ PageHolder<K, V> pageHolder = rm.writePage( transaction, btree, lastLeaf, 1 );
break;
}
@@ -131,34 +132,34 @@ public class BTreeBuilder<K, V>
// make sure either one of the root pages is reclaimed, cause when we call rm.manage()
// there is already a root page created
- Page<K, V> rootPage = attachNodes( lstLeaves, btree );
+ Page<K, V> rootPage = attachNodes( transaction, lstLeaves, btree );
//System.out.println("built rootpage : " + rootPage);
( ( BTreeImpl<K, V> ) btree ).setNbElems( totalTupleCount );
- rm.updateBtreeHeader( btree, ( ( AbstractPage<K, V> ) rootPage ).getOffset() );
+ //rm.updateBtreeHeader( btree, ( ( AbstractPage<K, V> ) rootPage ).getOffset() );
- rm.freePages( btree, btree.getRootPage().getRevision(), Arrays.asList( btree.getRootPage() ) );
+ //rm.freePages( transaction, btree, btree.getRootPage( transaction ).getRevision(), Arrays.asList( btree.getRootPage( transaction ) ) );
- ( ( AbstractBTree<K, V> ) btree ).setRootPage( rootPage );
+ ( ( BTreeImpl<K, V> ) btree ).setRootPage( rootPage );
return btree;
}
@SuppressWarnings("unchecked")
- private Page<K, V> attachNodes( List<Page<K, V>> children, BTree<K, V> btree ) throws IOException
+ private Page<K, V> attachNodes( WriteTransaction transaction, List<Page<K, V>> children, BTree<K, V> btree ) throws IOException
{
if ( children.size() == 1 )
{
return children.get( 0 );
}
- List<Page<K, V>> lstNodes = new ArrayList<Page<K, V>>();
+ List<Page<K, V>> lstNodes = new ArrayList<>();
int numChildren = numKeysInNode + 1;
- Node<K, V> node = ( Node<K, V> ) BTreeFactory.createNode( btree, 0, numKeysInNode );
+ Node<K, V> node = ( Node<K, V> ) BTreeFactory.createNode( btree, transaction.getRevision(), numKeysInNode );
lstNodes.add( node );
int i = 0;
int totalNodes = 0;
@@ -179,9 +180,9 @@ public class BTreeBuilder<K, V>
{
i = 0;
- rm.writePage( btree, node, 1 );
+ rm.writePage( transaction, btree, node, 1 );
- node = ( Node<K, V> ) BTreeFactory.createNode( btree, 0, numKeysInNode );
+ node = ( Node<K, V> ) BTreeFactory.createNode( btree, transaction.getRevision(), numKeysInNode );
lstNodes.add( node );
}
}
@@ -189,23 +190,23 @@ public class BTreeBuilder<K, V>
// remove null keys and values from the last node and resize
AbstractPage<K, V> lastNode = ( AbstractPage<K, V> ) lstNodes.get( lstNodes.size() - 1 );
- for ( int j = 0; j < lastNode.getNbElems(); j++ )
+ for ( int j = 0; j < lastNode.getNbPageElems(); j++ )
{
if ( lastNode.getKey( j ) == null )
{
int n = j;
- lastNode.setNbElems( n );
+ lastNode.setNbPageElems( n );
KeyHolder<K>[] keys = lastNode.getKeys();
lastNode.setKeys( ( KeyHolder[] ) Array.newInstance( KeyHolder.class, n ) );
System.arraycopy( keys, 0, lastNode.getKeys(), 0, n );
- rm.writePage( btree, lastNode, 1 );
+ rm.writePage( transaction, btree, lastNode, 1 );
break;
}
}
- return attachNodes( lstNodes, btree );
+ return attachNodes( transaction, lstNodes, btree );
}
}
Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeConfiguration.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeConfiguration.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeConfiguration.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeConfiguration.java Fri Feb 24 07:16:37 2017
@@ -35,7 +35,7 @@ import org.apache.directory.mavibot.btre
public class BTreeConfiguration<K, V>
{
/** Number of entries in each Page. */
- private int pageSize = BTree.DEFAULT_PAGE_SIZE;
+ private int pageNbElem = BTree.DEFAULT_PAGE_NBELEM;
/** The size of the buffer used to write data in disk */
private int writeBufferSize = BTree.DEFAULT_WRITE_BUFFER_SIZE;
@@ -54,15 +54,6 @@ public class BTreeConfiguration<K, V>
*/
private String filePath;
- /**
- * The maximum delay to wait before a revision is considered as unused.
- * This delay is necessary so that a read that does not ends does not
- * hold a revision in memory forever.
- * The default value is 10000 (10 seconds). If the value is 0 or below,
- * the delay is considered as infinite
- */
- private long readTimeOut = BTreeImpl.DEFAULT_READ_TIMEOUT;
-
/** The B-tree type */
private BTreeTypeEnum btreeType = BTreeTypeEnum.PERSISTED;
@@ -74,20 +65,20 @@ public class BTreeConfiguration<K, V>
/**
- * @return the pageSize
+ * @return the number of elements per page
*/
- public int getPageSize()
+ public int getPageNbElem()
{
- return pageSize;
+ return pageNbElem;
}
/**
- * @param pageSize the pageSize to set
+ * @param pageNbElem the number of elements per page to set
*/
- public void setPageSize( int pageSize )
+ public void setPageNbElem( int pageNbElem )
{
- this.pageSize = pageSize;
+ this.pageNbElem = pageNbElem;
}
@@ -138,24 +129,6 @@ public class BTreeConfiguration<K, V>
}
- /**
- * @return the readTimeOut
- */
- public long getReadTimeOut()
- {
- return readTimeOut;
- }
-
-
- /**
- * @param readTimeOut the readTimeOut to set
- */
- public void setReadTimeOut( long readTimeOut )
- {
- this.readTimeOut = readTimeOut;
- }
-
-
/**
* @return the filePath
*/
Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java Fri Feb 24 07:16:37 2017
@@ -26,243 +26,179 @@ import org.apache.directory.mavibot.btre
/**
- * This class construct a B-tree from a serialized version of a B-tree. We need it
- * to avoid exposing all the methods of the B-tree class.<br>
+ * This class construct a b-tree from a serialized version of a b-tree. We need it
+ * to avoid exposing all the methods of the b-tree class.<br>
*
* All its methods are static.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*
- * @param <K> The B-tree key type
- * @param <V> The B-tree value type
+ * @param <K> The b-tree key type
+ * @param <V> The b-tree value type
*/
public class BTreeFactory<K, V>
{
- //--------------------------------------------------------------------------------------------
- // Create persisted btrees
- //--------------------------------------------------------------------------------------------
- /**
- * Creates a new persisted B-tree, with no initialization.
- *
- * @return a new B-tree instance
- */
- public static <K, V> BTree<K, V> createPersistedBTree()
- {
- BTree<K, V> btree = new BTreeImpl<K, V>();
-
- return btree;
- }
-
-
/**
- * Creates a new persisted B-tree, with no initialization.
- *
- * @return a new B-tree instance
+ * Private constructor to forbid the creation of an instance
*/
- public static <K, V> BTree<K, V> createPersistedBTree( BTreeTypeEnum type )
+ private BTreeFactory()
{
- BTree<K, V> btree = new BTreeImpl<K, V>();
- ( ( AbstractBTree<K, V> ) btree ).setType( type );
-
- return btree;
+ // Does nothing
}
-
-
+
+
+ //--------------------------------------------------------------------------------------------
+ // Create b-tree
+ //--------------------------------------------------------------------------------------------
/**
- * Sets the btreeHeader offset for a Persisted BTree
+ * Creates a new b-tree, with no initialization.
*
- * @param btree The btree to update
- * @param btreeHeaderOffset The offset
+ * @return a new b-tree instance
*/
- public static <K, V> void setBtreeHeaderOffset( BTreeImpl<K, V> btree, long btreeHeaderOffset )
+ public static <K, V> BTree<K, V> createBTree()
{
- btree.setBtreeHeaderOffset( btreeHeaderOffset );
+ return new BTreeImpl<>();
}
/**
- * Creates a new persisted B-tree using the BTreeConfiguration to initialize the
- * B-tree
+ * Creates a new typed b-tree, with no initialization. The type is one
+ * of {@link BTreeTypeEnum}
*
- * @param configuration The configuration to use
- * @return a new B-tree instance
+ * @return a new b-tree instance
*/
- public static <K, V> BTree<K, V> createPersistedBTree( BTreeConfiguration<K, V> configuration )
+ public static <K, V> BTree<K, V> createBTree( BTreeTypeEnum type )
{
- BTree<K, V> btree = new BTreeImpl<K, V>( configuration );
+ BTree<K, V> btree = new BTreeImpl<>();
+ ( ( BTreeImpl<K, V> ) btree ).setType( type );
return btree;
}
/**
- * Creates a new persisted B-tree using the parameters to initialize the
- * B-tree
+ * Creates a new b-tree using the BTreeConfiguration to initialize the
+ * b-tree
*
- * @param name The B-tree's name
- * @param keySerializer Key serializer
- * @param valueSerializer Value serializer
- * @return a new B-tree instance
+ * @param configuration The configuration to use
+ * @return a new b-tree instance
*/
- public static <K, V> BTree<K, V> createPersistedBTree( String name, ElementSerializer<K> keySerializer,
- ElementSerializer<V> valueSerializer )
+ public static <K, V> BTree<K, V> createBTree( Transaction transaction, BTreeConfiguration<K, V> configuration )
{
- BTreeConfiguration<K, V> configuration = new BTreeConfiguration<K, V>();
-
- configuration.setName( name );
- configuration.setKeySerializer( keySerializer );
- configuration.setValueSerializer( valueSerializer );
- configuration.setPageSize( BTree.DEFAULT_PAGE_SIZE );
- configuration.setCacheSize( BTreeImpl.DEFAULT_CACHE_SIZE );
- configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
-
- BTree<K, V> btree = new BTreeImpl<K, V>( configuration );
-
- return btree;
+ return new BTreeImpl<>( transaction, configuration );
}
/**
- * Creates a new persisted B-tree using the parameters to initialize the
- * B-tree
+ * Creates a new b-tree using the parameters to initialize the b-tree
*
- * @param name The B-tree's name
+ * @param name The b-tree's name
* @param keySerializer Key serializer
* @param valueSerializer Value serializer
- * @param allowDuplicates Tells if the B-tree allows multiple value for a given key
- * @return a new B-tree instance
+ * @return a new b-tree instance
*/
- public static <K, V> BTree<K, V> createPersistedBTree( String name, ElementSerializer<K> keySerializer,
- ElementSerializer<V> valueSerializer, boolean allowDuplicates )
+ public static <K, V> BTree<K, V> createBTree( Transaction transaction, String name, ElementSerializer<K> keySerializer,
+ ElementSerializer<V> valueSerializer )
{
- BTreeConfiguration<K, V> configuration = new BTreeConfiguration<K, V>();
+ BTreeConfiguration<K, V> configuration = new BTreeConfiguration<>();
configuration.setName( name );
configuration.setKeySerializer( keySerializer );
configuration.setValueSerializer( valueSerializer );
- configuration.setPageSize( BTree.DEFAULT_PAGE_SIZE );
+ configuration.setPageNbElem( BTree.DEFAULT_PAGE_NBELEM );
configuration.setCacheSize( BTreeImpl.DEFAULT_CACHE_SIZE );
configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
- BTree<K, V> btree = new BTreeImpl<K, V>( configuration );
-
- return btree;
+ return new BTreeImpl<>( transaction, configuration );
}
/**
- * Creates a new persisted B-tree using the parameters to initialize the
- * B-tree
+ * Creates a new b-tree using the parameters to initialize the b-tree
*
- * @param name The B-tree's name
+ * @param name The b-tree's name
* @param keySerializer Key serializer
* @param valueSerializer Value serializer
- * @param allowDuplicates Tells if the B-tree allows multiple value for a given key
- * @param cacheSize The size to be used for this B-tree cache
- * @return a new B-tree instance
+ * @param allowDuplicates Tells if the b-tree allows multiple value for a given key
+ * @param cacheSize The size to be used for this b-tree cache
+ * @return a new b-tree instance
*/
- public static <K, V> BTree<K, V> createPersistedBTree( String name, ElementSerializer<K> keySerializer,
- ElementSerializer<V> valueSerializer, boolean allowDuplicates, int cacheSize )
+ public static <K, V> BTree<K, V> createBTree( Transaction transaction, String name, ElementSerializer<K> keySerializer,
+ ElementSerializer<V> valueSerializer, int cacheSize )
{
- BTreeConfiguration<K, V> configuration = new BTreeConfiguration<K, V>();
+ BTreeConfiguration<K, V> configuration = new BTreeConfiguration<>();
configuration.setName( name );
configuration.setKeySerializer( keySerializer );
configuration.setValueSerializer( valueSerializer );
- configuration.setPageSize( BTree.DEFAULT_PAGE_SIZE );
+ configuration.setPageNbElem( BTree.DEFAULT_PAGE_NBELEM );
configuration.setCacheSize( cacheSize );
configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
- BTree<K, V> btree = new BTreeImpl<K, V>( configuration );
-
- return btree;
+ return new BTreeImpl<>( transaction, configuration );
}
/**
- * Creates a new persisted B-tree using the parameters to initialize the
- * B-tree
+ * Creates a new b-tree using the parameters to initialize the b-tree
*
- * @param name The B-tree's name
+ * @param name The b-tree's name
+ * @param pageNbElem Number of elements per page
* @param keySerializer Key serializer
* @param valueSerializer Value serializer
- * @param pageSize Size of the page
- * @return a new B-tree instance
+ * @return a new b-tree instance
*/
- public static <K, V> BTree<K, V> createPersistedBTree( String name, ElementSerializer<K> keySerializer,
- ElementSerializer<V> valueSerializer, int pageSize )
+ public static <K, V> BTree<K, V> createBTree( Transaction transaction, String name, int pageNbElem, ElementSerializer<K> keySerializer,
+ ElementSerializer<V> valueSerializer )
{
- BTreeConfiguration<K, V> configuration = new BTreeConfiguration<K, V>();
+ BTreeConfiguration<K, V> configuration = new BTreeConfiguration<>();
configuration.setName( name );
configuration.setKeySerializer( keySerializer );
configuration.setValueSerializer( valueSerializer );
- configuration.setPageSize( pageSize );
+ configuration.setPageNbElem( pageNbElem );
configuration.setCacheSize( BTreeImpl.DEFAULT_CACHE_SIZE );
configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
- BTree<K, V> btree = new BTreeImpl<K, V>( configuration );
-
- return btree;
+ return new BTreeImpl<>( transaction, configuration );
}
/**
- * Creates a new persisted B-tree using the parameters to initialize the
- * B-tree
+ * Creates a new b-tree using the parameters to initialize the b-tree
*
- * @param name The B-tree's name
+ * @param name The b-tree's name
+ * @param pageNbElem Number of elements per page
* @param keySerializer Key serializer
* @param valueSerializer Value serializer
- * @param pageSize Size of the page
- * @param allowDuplicates Tells if the B-tree allows multiple value for a given key
- * @return a new B-tree instance
+ * @param cacheSize The size to be used for this b-tree cache
+ * @return a new b-tree instance
*/
- public static <K, V> BTree<K, V> createPersistedBTree( String name, ElementSerializer<K> keySerializer,
- ElementSerializer<V> valueSerializer, int pageSize, boolean allowDuplicates )
+ public static <K, V> BTree<K, V> createBTree( Transaction transaction, String name, int pageNbElem,
+ ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, int cacheSize )
{
- BTreeConfiguration<K, V> configuration = new BTreeConfiguration<K, V>();
+ BTreeConfiguration<K, V> configuration = new BTreeConfiguration<>();
configuration.setName( name );
configuration.setKeySerializer( keySerializer );
configuration.setValueSerializer( valueSerializer );
- configuration.setPageSize( pageSize );
- configuration.setCacheSize( BTreeImpl.DEFAULT_CACHE_SIZE );
+ configuration.setPageNbElem( pageNbElem );
+ configuration.setCacheSize( cacheSize );
configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
- BTree<K, V> btree = new BTreeImpl<K, V>( configuration );
-
- return btree;
+ return new BTreeImpl<>( transaction, configuration );
}
/**
- * Creates a new persisted B-tree using the parameters to initialize the
- * B-tree
+ * Sets the btreeHeader offset for a BTree
*
- * @param name The B-tree's name
- * @param keySerializer Key serializer
- * @param valueSerializer Value serializer
- * @param pageSize Size of the page
- * @param allowDuplicates Tells if the B-tree allows multiple value for a given key
- * @param cacheSize The size to be used for this B-tree cache
- * @return a new B-tree instance
+ * @param btree The btree to update
+ * @param btreeHeaderOffset The offset
*/
- public static <K, V> BTree<K, V> createPersistedBTree( String name, ElementSerializer<K> keySerializer,
- ElementSerializer<V> valueSerializer, int pageSize, boolean allowDuplicates, int cacheSize )
+ public static <K, V> void setBtreeHeaderOffset( BTreeImpl<K, V> btree, long btreeHeaderOffset )
{
- BTreeConfiguration<K, V> configuration = new BTreeConfiguration<K, V>();
-
- configuration.setName( name );
- configuration.setKeySerializer( keySerializer );
- configuration.setValueSerializer( valueSerializer );
- configuration.setPageSize( pageSize );
- configuration.setCacheSize( cacheSize );
- configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
-
- BTree<K, V> btree = new BTreeImpl<K, V>( configuration );
-
- return btree;
+ btree.setBtreeHeaderOffset( btreeHeaderOffset );
}
@@ -270,9 +206,9 @@ public class BTreeFactory<K, V>
// Create Pages
//--------------------------------------------------------------------------------------------
/**
- * Create a new Leaf for the given B-tree.
+ * Create a new Leaf for the given b-tree.
*
- * @param btree The B-tree which will contain this leaf
+ * @param btree The b-tree which will contain this leaf
* @param revision The Leaf's revision
* @param nbElems The number or elements in this leaf
*
@@ -280,14 +216,14 @@ public class BTreeFactory<K, V>
*/
/* no qualifier*/static <K, V> Page<K, V> createLeaf( BTree<K, V> btree, long revision, int nbElems )
{
- return new Leaf<K, V>( btree, revision, nbElems );
+ return new Leaf<>( btree, revision, nbElems );
}
/**
- * Create a new Node for the given B-tree.
+ * Create a new Node for the given b-tree.
*
- * @param btree The B-tree which will contain this node
+ * @param btree The b-tree which will contain this node
* @param revision The Node's revision
* @param nbElems The number or elements in this node
* @return A Node instance
@@ -295,7 +231,7 @@ public class BTreeFactory<K, V>
/* no qualifier*/static <K, V> Page<K, V> createNode( BTree<K, V> btree, long revision, int nbElems )
{
//System.out.println( "Creating a node with nbElems : " + nbElems );
- return new Node<K, V>( btree, revision, nbElems );
+ return new Node<>( btree, revision, nbElems );
}
@@ -305,14 +241,14 @@ public class BTreeFactory<K, V>
/**
* Set the key at a give position
*
- * @param btree The B-tree to update
+ * @param btree The b-tree to update
* @param page The page to update
* @param pos The position in the keys array
* @param key The key to inject
*/
/* no qualifier*/static <K, V> void setKey( BTree<K, V> btree, Page<K, V> page, int pos, K key )
{
- KeyHolder<K> keyHolder = new KeyHolderImpl<K>( btree.getKeySerializer(), key );
+ KeyHolder<K> keyHolder = new KeyHolder<>( btree.getKeySerializer(), key );
( ( AbstractPage<K, V> ) page ).setKey( pos, keyHolder );
}
@@ -321,7 +257,7 @@ public class BTreeFactory<K, V>
/**
* Set the value at a give position
*
- * @param btree The B-tree to update
+ * @param btree The b-tree to update
* @param page The page to update
* @param pos The position in the values array
* @param value the value to inject
@@ -335,24 +271,24 @@ public class BTreeFactory<K, V>
/**
* Set the page at a give position
*
- * @param btree The B-tree to update
+ * @param btree The b-tree to update
* @param page The page to update
* @param pos The position in the values array
* @param child the child page to inject
*/
/* no qualifier*/static <K, V> void setPage( BTree<K, V> btree, Page<K, V> page, int pos, Page<K, V> child )
{
- ( ( Node<K, V> ) page ).setValue( pos, new PageHolderImpl<K, V>( btree, child ) );
+ ( ( Node<K, V> ) page ).setValue( pos, new PageHolder<K, V>( btree, child ) );
}
//--------------------------------------------------------------------------------------------
- // Update B-tree
+ // Update b-tree
//--------------------------------------------------------------------------------------------
/**
- * Sets the KeySerializer into the B-tree
+ * Sets the KeySerializer into the b-tree
*
- * @param btree The B-tree to update
+ * @param btree The b-tree to update
* @param keySerializerFqcn the Key serializer FQCN to set
* @throws ClassNotFoundException If the key serializer class cannot be found
* @throws InstantiationException If the key serializer class cannot be instanciated
@@ -387,9 +323,9 @@ public class BTreeFactory<K, V>
/**
- * Sets the ValueSerializer into the B-tree
+ * Sets the ValueSerializer into the b-tree
*
- * @param btree The B-tree to update
+ * @param btree The b-tree to update
* @param valueSerializerFqcn the Value serializer FQCN to set
* @throws ClassNotFoundException If the value serializer class cannot be found
* @throws InstantiationException If the value serializer class cannot be instanciated
@@ -427,55 +363,55 @@ public class BTreeFactory<K, V>
* Set the new root page for this tree. Used for debug purpose only. The revision
* will always be 0;
*
- * @param btree The B-tree to update
+ * @param btree The b-tree to update
* @param root the new root page.
*/
/* no qualifier*/static <K, V> void setRootPage( BTree<K, V> btree, Page<K, V> root )
{
- ( ( AbstractBTree<K, V> ) btree ).setRootPage( root );
+ ( ( BTreeImpl<K, V> ) btree ).setRootPage( root );
}
/**
- * Return the B-tree root page
+ * Return the b-tree root page
*
- * @param btree The B-tree we want to root page from
+ * @param btree The b-tree we want to root page from
* @return The root page
*/
/* no qualifier */static <K, V> Page<K, V> getRootPage( BTree<K, V> btree )
{
- return btree.getRootPage();
+ return (( BTreeImpl<K, V> ) btree ).getRootPage();
}
/**
- * Update the B-tree number of elements
+ * Update the b-tree number of elements
*
- * @param btree The B-tree to update
+ * @param btree The b-tree to update
* @param nbElems the nbElems to set
*/
/* no qualifier */static <K, V> void setNbElems( BTree<K, V> btree, long nbElems )
{
- ( ( AbstractBTree<K, V> ) btree ).setNbElems( nbElems );
+ ( ( BTreeImpl<K, V> ) btree ).setNbElems( nbElems );
}
/**
- * Update the B-tree revision
+ * Update the b-tree revision
*
- * @param btree The B-tree to update
+ * @param btree The b-tree to update
* @param revision the revision to set
*/
/* no qualifier*/static <K, V> void setRevision( BTree<K, V> btree, long revision )
{
- ( ( AbstractBTree<K, V> ) btree ).setRevision( revision );
+ ( ( BTreeImpl<K, V> ) btree ).setRevision( revision );
}
/**
- * Set the B-tree name
+ * Set the b-tree name
*
- * @param btree The B-tree to update
+ * @param btree The b-tree to update
* @param name the name to set
*/
/* no qualifier */static <K, V> void setName( BTree<K, V> btree, String name )
@@ -487,12 +423,12 @@ public class BTreeFactory<K, V>
/**
* Set the maximum number of elements we can store in a page.
*
- * @param btree The B-tree to update
+ * @param btree The b-tree to update
* @param pageSize The requested page size
*/
- /* no qualifier */static <K, V> void setPageSize( BTree<K, V> btree, int pageSize )
+ /* no qualifier */static <K, V> void setPageNbElem( BTree<K, V> btree, int pageNbElem )
{
- btree.setPageSize( pageSize );
+ btree.setPageNbElem( pageNbElem );
}
@@ -502,20 +438,20 @@ public class BTreeFactory<K, V>
/**
* Includes the intermediate nodes in the path up to and including the right most leaf of the tree
*
- * @param btree the B-tree
+ * @param btree the b-tree
* @return a LinkedList of all the nodes and the final leaf
*/
/* no qualifier*/static <K, V> LinkedList<ParentPos<K, V>> getPathToRightMostLeaf( BTree<K, V> btree )
{
LinkedList<ParentPos<K, V>> stack = new LinkedList<ParentPos<K, V>>();
- ParentPos<K, V> last = new ParentPos<K, V>( btree.getRootPage(), btree.getRootPage().getNbElems() );
+ ParentPos<K, V> last = new ParentPos<K, V>( btree.getRootPage(), btree.getRootPage().getNbPageElems() );
stack.push( last );
if ( btree.getRootPage().isLeaf() )
{
Page<K, V> leaf = btree.getRootPage();
- ValueHolder<V> valueHolder = ( ( AbstractPage<K, V> ) leaf ).getValue( last.pos );
+ //ValueHolder<V> valueHolder = ( ( Leaf<K, V> ) leaf ).getValue( last.pos );
}
else
{
@@ -523,15 +459,15 @@ public class BTreeFactory<K, V>
while ( true )
{
- Page<K, V> p = ( ( AbstractPage<K, V> ) node ).getPage( node.getNbElems() );
+ Page<K, V> p = ( ( AbstractPage<K, V> ) node ).getPage( node.getNbPageElems() );
- last = new ParentPos<K, V>( p, p.getNbElems() );
+ last = new ParentPos<>( p, p.getNbPageElems() );
stack.push( last );
if ( p.isLeaf() )
{
Page<K, V> leaf = last.page;
- ValueHolder<V> valueHolder = ( ( AbstractPage<K, V> ) leaf ).getValue( last.pos );
+ //ValueHolder<V> valueHolder = ( ( Leaf<K, V> ) leaf ).getValue( last.pos );
break;
}
}
@@ -542,12 +478,12 @@ public class BTreeFactory<K, V>
//--------------------------------------------------------------------------------------------
- // Persisted B-tree methods
+ // Persisted b-tree methods
//--------------------------------------------------------------------------------------------
/**
- * Set the rootPage offset of the B-tree
+ * Set the rootPage offset of the b-tree
*
- * @param btree The B-tree to update
+ * @param btree The b-tree to update
* @param rootPageOffset The rootPageOffset to set
*/
/* no qualifier*/static <K, V> void setRootPageOffset( BTree<K, V> btree, long rootPageOffset )
@@ -558,7 +494,7 @@ public class BTreeFactory<K, V>
}
else
{
- throw new IllegalArgumentException( "The B-tree must be a PersistedBTree" );
+ throw new IllegalArgumentException( "The b-tree must be a PersistedBTree" );
}
}
@@ -566,7 +502,7 @@ public class BTreeFactory<K, V>
/**
* Set the RecordManager
*
- * @param btree The B-tree to update
+ * @param btree The b-tree to update
* @param recordManager The injected RecordManager
*/
/* no qualifier*/static <K, V> void setRecordManager( BTree<K, V> btree, RecordManager recordManager )
@@ -577,7 +513,7 @@ public class BTreeFactory<K, V>
}
else
{
- throw new IllegalArgumentException( "The B-tree must be a PersistedBTree" );
+ throw new IllegalArgumentException( "The b-tree must be a PersistedBTree" );
}
}
@@ -585,7 +521,7 @@ public class BTreeFactory<K, V>
/**
* Set the key at a give position
*
- * @param btree The B-tree to update
+ * @param btree The b-tree to update
* @param page The page to update
* @param pos The position of this key in the page
* @param buffer The byte[] containing the serialized key
@@ -594,12 +530,12 @@ public class BTreeFactory<K, V>
{
if ( btree instanceof BTreeImpl )
{
- KeyHolder<K> keyHolder = new KeyHolderImpl<K>( btree.getKeySerializer(), buffer );
+ KeyHolder<K> keyHolder = new KeyHolder<K>( btree.getKeySerializer(), buffer );
( ( AbstractPage<K, V> ) page ).setKey( pos, keyHolder );
}
else
{
- throw new IllegalArgumentException( "The B-tree must be a PersistedBTree" );
+ throw new IllegalArgumentException( "The b-tree must be a PersistedBTree" );
}
}
@@ -607,7 +543,7 @@ public class BTreeFactory<K, V>
/**
* Includes the intermediate nodes in the path up to and including the left most leaf of the tree
*
- * @param btree The B-tree to process
+ * @param btree The b-tree to process
* @return a LinkedList of all the nodes and the final leaf
*/
/* no qualifier*/static <K, V> LinkedList<ParentPos<K, V>> getPathToLeftMostLeaf( BTree<K, V> btree )
@@ -638,7 +574,7 @@ public class BTreeFactory<K, V>
}
else
{
- throw new IllegalArgumentException( "The B-tree must be a PersistedBTree" );
+ throw new IllegalArgumentException( "The b-tree must be a PersistedBTree" );
}
}
}