Author: kayyagari
Date: Fri Jul 26 16:26:09 2013
New Revision: 1507363
URL: http://svn.apache.org/r1507363
Log:
load duplicate trees based on their offset instead of name
Modified:
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/DuplicateKeyMemoryHolder.java
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RecordManager.java
Modified:
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/DuplicateKeyMemoryHolder.java
URL:
http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/DuplicateKeyMemoryHolder.java?rev=1507363&r1=1507362&r2=1507363&view=diff
==============================================================================
---
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/DuplicateKeyMemoryHolder.java
(original)
+++
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/DuplicateKeyMemoryHolder.java
Fri Jul 26 16:26:09 2013
@@ -28,7 +28,8 @@ import org.apache.mavibot.btree.exceptio
/**
- * A In-Memory holder for values of duplicate keys. The values are always
present in memory.
+ * A holder for values of duplicate keys. The values are either present in
memory
+ * or loaded on the fly from disk when needed.
*
* @param <K> The type of the BTree key
* @param <V> The type of the BTree value
@@ -40,9 +41,9 @@ public class DuplicateKeyMemoryHolder<K,
/** The BTree */
private BTree<K, V> btree;
- /** the name of the value container btree. This value is set only when the
parent BTree is in managed mode */
- private String name;
-
+ /** the offset of the value container btree. This value is set only when
the parent BTree is in managed mode */
+ private long valContainerOffset = -1;
+
/** The reference to the Value instance, or null if it's not present. This
will be null when the parent BTree is in managed mode */
private BTree<V, V> valueContainer;
@@ -67,11 +68,10 @@ public class DuplicateKeyMemoryHolder<K,
if ( btree.isManaged() )
{
- name = valueContainer.getName();
-
try
{
btree.getRecordManager().manage( valueContainer, true );
+ valContainerOffset = valueContainer.getBtreeOffset();
}
catch ( BTreeAlreadyManagedException e )
{
@@ -95,13 +95,25 @@ public class DuplicateKeyMemoryHolder<K,
}
+ /**
+ *
+ * Creates a new instance of DuplicateKeyMemoryHolder.
+ *
+ * Note: the valueContainer should have a valid offset, in other words
+ * the valueContainer should always be the one that is already
+ * managed by RecordManager
+ *
+ * @param btree the parent BTree
+ * @param valueContainer the BTree holding the values of a duplicate key
+ * present in the parent tree
+ */
/* No qualifier */DuplicateKeyMemoryHolder( BTree<K, V> btree, BTree<V, V>
valueContainer )
{
this.btree = btree;
if ( btree.isManaged() )
{
- name = valueContainer.getName();
+ valContainerOffset = valueContainer.getBtreeOffset();
reference = new SoftReference<BTree<V, V>>( valueContainer );
}
else
@@ -119,15 +131,15 @@ public class DuplicateKeyMemoryHolder<K,
{
if ( !btree.isManaged() )
{
+ // wrong cast to please compiler
return ( V ) valueContainer;
}
- // wrong cast to please compiler
BTree<V, V> valueContainer = reference.get();
if ( valueContainer == null )
{
- valueContainer = btree.getRecordManager().getManagedTree( name );
+ valueContainer = btree.getRecordManager().loadDupsBTree(
valContainerOffset );
reference = new SoftReference<BTree<V, V>>( valueContainer );
}
Modified:
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RecordManager.java
URL:
http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RecordManager.java?rev=1507363&r1=1507362&r2=1507363&view=diff
==============================================================================
---
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RecordManager.java
(original)
+++
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RecordManager.java
Fri Jul 26 16:26:09 2013
@@ -603,21 +603,8 @@ public class RecordManager
if ( btree.isAllowDuplicates() )
{
long value = OFFSET_SERIALIZER.deserialize( byteBuffer );
-
- pageIos = readPageIOs( value, Long.MAX_VALUE );
-
- BTree dupValueContainer = BTreeFactory.createBTree();
- dupValueContainer.setBtreeOffset( value );
-
- try
- {
- loadBTree( pageIos, dupValueContainer );
- }
- catch ( Exception e )
- {
- // should not happen
- throw new RuntimeException( e );
- }
+
+ BTree dupValueContainer = loadDupsBTree(value);
valueHolder = new DuplicateKeyMemoryHolder( btree,
dupValueContainer );
}
@@ -2719,6 +2706,35 @@ public class RecordManager
/**
+ * Loads a BTree holding the values of a duplicate key
+ * This tree is also called as dups tree or sub tree
+ *
+ * @param offset the offset of the BTree header
+ * @return the deserialized BTree
+ */
+ /* No qualifier */BTree loadDupsBTree( long offset )
+ {
+ try
+ {
+ PageIO[] pageIos = readPageIOs( offset, Long.MAX_VALUE );
+
+ BTree dupValueContainer = BTreeFactory.createBTree();
+ dupValueContainer.setBtreeOffset( offset );
+
+ loadBTree( pageIos, dupValueContainer );
+
+ return dupValueContainer;
+ }
+ catch ( Exception e )
+ {
+ // should not happen
+ throw new RuntimeException( e );
+ }
+
+ }
+
+
+ /**
* @see Object#toString()
*/
public String toString()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]