vgritsenko 2003/12/18 18:34:24
Modified: java/src/org/apache/xindice/core/filer BTree.java
Log:
Do not split node if there are just several keys in it.
Fixes bug when trying to add record with very large (>1 page) key.
Revision Changes Path
1.22 +14 -4
xml-xindice/java/src/org/apache/xindice/core/filer/BTree.java
Index: BTree.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/filer/BTree.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- BTree.java 18 Dec 2003 15:05:20 -0000 1.21
+++ BTree.java 19 Dec 2003 02:34:24 -0000 1.22
@@ -650,7 +650,7 @@
idx = -(idx + 1);
// Check to see if we've exhausted the block
- boolean split = ph.getDataLen() + 8 +
value.getLength() + 2 > fileHeader.getWorkSize();
+ boolean split = needSplit(value);
set(insertArrayValue(values, value, idx),
insertArrayLong(ptrs, pointer, idx));
@@ -669,7 +669,7 @@
private synchronized void promoteValue(Value value, long
rightPointer) throws IOException, BTreeException {
// Check to see if we've exhausted the block
- boolean split = ph.getDataLen() + 8 + value.getLength() + 2 >
fileHeader.getWorkSize();
+ boolean split = needSplit(value);
int idx = Arrays.binarySearch(values, value);
idx = idx < 0 ? -(idx + 1) : idx + 1;
@@ -688,6 +688,16 @@
byte[] b = new byte[Math.abs(idx)];
System.arraycopy(value2.getData(), 0, b, 0, b.length);
return new Value(b);
+ }
+
+ /**
+ * Do we need to split this node after adding one more value?
+ */
+ private final boolean needSplit(Value value) {
+ // Do NOT split if just 4 key/values are in the node.
+ return this.values.length > 4 &&
+ // CurrLength + one Long pointer + value length + one
short
+ this.ph.getDataLen() + 8 + value.getLength() + 2 >
BTree.this.fileHeader.getWorkSize();
}
/**