Starting to clean up the BTree interior frame implementation.
git-svn-id: https://hyracks.googlecode.com/svn/branches/hyracks_btree_updates_next@643 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrame.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrame.java
index 728e5d7..09aadb8 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrame.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrame.java
@@ -52,10 +52,6 @@
cmpFrameTuple = tupleWriter.createTupleReference();
}
- private int getLeftChildPageOff(ITupleReference tuple) {
- return tuple.getFieldStart(tuple.getFieldCount() - 1) + tuple.getFieldLength(tuple.getFieldCount() - 1);
- }
-
@Override
public void initBuffer(byte level) {
super.initBuffer(level);
@@ -64,15 +60,15 @@
@Override
public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple) {
- int bytesRequired = tupleWriter.bytesRequired(tuple) + 8; // for the two
- // childpointers
- if (bytesRequired + slotManager.getSlotSize() <= buf.capacity() - buf.getInt(freeSpaceOff)
- - (buf.getInt(tupleCountOff) * slotManager.getSlotSize()))
+ // Tuple bytes + child pointer + slot.
+ int bytesRequired = tupleWriter.bytesRequired(tuple) + childPtrSize + slotManager.getSlotSize();
+ if (bytesRequired <= getFreeContiguousSpace()) {
return FrameOpSpaceStatus.SUFFICIENT_CONTIGUOUS_SPACE;
- else if (bytesRequired + slotManager.getSlotSize() <= buf.getInt(totalFreeSpaceOff))
+ }
+ if (bytesRequired <= getTotalFreeSpace()) {
return FrameOpSpaceStatus.SUFFICIENT_SPACE;
- else
- return FrameOpSpaceStatus.INSUFFICIENT_SPACE;
+ }
+ return FrameOpSpaceStatus.INSUFFICIENT_SPACE;
}
@Override
@@ -89,7 +85,6 @@
@Override
public int findUpdateTupleIndex(ITupleReference tuple, MultiComparator cmp) throws TreeIndexException {
- // TODO: Maybe craft the interface such that this is not possible?
throw new UnsupportedOperationException("Cannot update tuples in interior node.");
}
@@ -148,7 +143,7 @@
int tuplesToLeft = (tupleCount / 2) + (tupleCount % 2);
ITreeIndexFrame targetFrame = null;
- frameTuple.resetByTupleOffset(buf, getTupleOffset(tuplesToLeft - 1));
+ frameTuple.resetByTupleIndex(this, tuplesToLeft - 1);
if (cmp.compare(tuple, frameTuple) <= 0) {
targetFrame = this;
} else {
@@ -437,6 +432,10 @@
return rightLeafOff;
}
+ private int getLeftChildPageOff(ITupleReference tuple) {
+ return tuple.getFieldStart(tuple.getFieldCount() - 1) + tuple.getFieldLength(tuple.getFieldCount() - 1);
+ }
+
// TODO: can we put these into a common AbstractFrame or something?
@Override
public boolean getSmFlag() {
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java
index 7eff304..2895686 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java
@@ -900,8 +900,7 @@
BTreeSplitKey copyKey = ctx.splitKey.duplicate(ctx.leafFrame.getTupleWriter().createTupleReference());
tuple = copyKey.getTuple();
- frontier.lastTuple.resetByTupleOffset(frontier.page.getBuffer(),
- ctx.interiorFrame.getTupleOffset(ctx.interiorFrame.getTupleCount() - 1));
+ frontier.lastTuple.resetByTupleIndex(ctx.interiorFrame, ctx.interiorFrame.getTupleCount() - 1);
int splitKeySize = ctx.tupleWriter.bytesRequired(frontier.lastTuple, 0, cmp.getKeyFieldCount());
ctx.splitKey.initData(splitKeySize);
ctx.tupleWriter
diff --git a/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ITreeIndex.java b/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ITreeIndex.java
index d4e1703..6fe5219 100644
--- a/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ITreeIndex.java
+++ b/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ITreeIndex.java
@@ -19,6 +19,11 @@
import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
import edu.uci.ics.hyracks.storage.am.common.ophelpers.IndexOp;
+/**
+ * Interface implemented by tree-based index structures, describing their
+ * supported operations. Indexes implementing this interface can easily reuse
+ * the tree index operators for dataflow.
+ */
public interface ITreeIndex {
// init:
@@ -66,12 +71,12 @@
public IFreePageManager getFreePageManager();
- public int getRootPageId();
-
public ITreeIndexFrameFactory getLeafFrameFactory();
public ITreeIndexFrameFactory getInteriorFrameFactory();
+ public int getRootPageId();
+
public int getFieldCount();
public IndexType getIndexType();
diff --git a/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ITreeIndexFrame.java b/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ITreeIndexFrame.java
index fb32fab..01ea75f 100644
--- a/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ITreeIndexFrame.java
+++ b/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ITreeIndexFrame.java
@@ -26,6 +26,8 @@
public interface ITreeIndexFrame {
+ public void initBuffer(byte level);
+
public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple);
public void insert(ITupleReference tuple, int tupleIndex);
@@ -39,10 +41,9 @@
// returns true if slots were modified, false otherwise
public boolean compact();
+ // returns true if compressed.
public boolean compress() throws HyracksDataException;
- public void initBuffer(byte level);
-
public int getTupleCount();
public int getTupleOffset(int slotNum);
diff --git a/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/frames/TreeIndexNSMFrame.java b/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/frames/TreeIndexNSMFrame.java
index 574456e..5e5360a 100644
--- a/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/frames/TreeIndexNSMFrame.java
+++ b/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/frames/TreeIndexNSMFrame.java
@@ -309,4 +309,9 @@
public ITreeIndexTupleReference createTupleReference() {
return tupleWriter.createTupleReference();
}
+
+ public int getFreeContiguousSpace() {
+ return buf.capacity() - getFreeSpaceOff()
+ - (getTupleCount() * slotManager.getSlotSize());
+ }
}