[Mulgara-svn] r858 - projects/xa2/object-pool/src
andrae at mulgara.org
andrae at mulgara.org
Mon Apr 28 08:11:31 UTC 2008
Author: andrae
Date: 2008-04-28 01:11:30 -0700 (Mon, 28 Apr 2008)
New Revision: 858
Modified:
projects/xa2/object-pool/src/CompBlockTrie.java
projects/xa2/object-pool/src/CompBlockTrieTest.java
projects/xa2/object-pool/src/CompMemTrie.java
Log:
Fixed two bugs - the first was a block alignment error caused by moving where I put the root-reference. The
second was a capacity mis-calculation, in this case an off-by-two error that only triggered when the block was
at capacity.
Modified: projects/xa2/object-pool/src/CompBlockTrie.java
===================================================================
--- projects/xa2/object-pool/src/CompBlockTrie.java 2008-04-26 02:48:46 UTC (rev 857)
+++ projects/xa2/object-pool/src/CompBlockTrie.java 2008-04-28 08:11:30 UTC (rev 858)
@@ -44,7 +44,7 @@
assert blockSize > 1024;
assert blockSize <= 32*1024;
this.blockSize = blockSize;
- this.space = (short)((blockSize - 6) / WORST_CASE_ENTRY_SIZE); // -6 leaves room for header info.
+ this.space = (short)((blockSize - 8) / WORST_CASE_ENTRY_SIZE); // -8 leaves room for header info.
}
public CompBlockTrie(ByteBuffer index, FileChannel data) throws IOException {
@@ -57,7 +57,7 @@
// trie-block, but if we haven't we should recalculate the space available.
if (space == 0) {
int size = root.totalIndexSize();
- space = (short)((blockSize - size - 6) / WORST_CASE_ENTRY_SIZE);
+ space = (short)((blockSize - size - 8) / WORST_CASE_ENTRY_SIZE);
if (space < 0) {
throw new IllegalStateException("Overfilled CompBlockTrie");
} else if (space == 0) {
@@ -68,4 +68,13 @@
super.insert(key, value);
space--;
}
+
+ public void write(ByteBuffer index, FileChannel data) throws InsufficientSpace, IOException {
+ if (index.remaining() < blockSize) {
+ throw new InsufficientSpace("Insufficient space remaining in buffer to write block");
+ }
+ index.limit(index.position() + blockSize);
+ super.write(index, data);
+ index.position(index.limit());
+ }
}
Modified: projects/xa2/object-pool/src/CompBlockTrieTest.java
===================================================================
--- projects/xa2/object-pool/src/CompBlockTrieTest.java 2008-04-26 02:48:46 UTC (rev 857)
+++ projects/xa2/object-pool/src/CompBlockTrieTest.java 2008-04-28 08:11:30 UTC (rev 858)
@@ -22,7 +22,7 @@
*/
public class CompBlockTrieTest {
public static void main(String[] args) throws Exception {
-// testWithLimitedFile(new File("../scratch/propernames.uniq"), 1);
+ testWithLimitedFile(new File("../scratch/propernames.uniq"), 1);
testWithLimitedFile(new File("../scratch/propernames.uniq"), 2);
testWithLimitedFile(new File("../scratch/propernames.uniq"), 3);
testWithLimitedFile(new File("../scratch/propernames.uniq"), 4);
Modified: projects/xa2/object-pool/src/CompMemTrie.java
===================================================================
--- projects/xa2/object-pool/src/CompMemTrie.java 2008-04-26 02:48:46 UTC (rev 857)
+++ projects/xa2/object-pool/src/CompMemTrie.java 2008-04-28 08:11:30 UTC (rev 858)
@@ -61,6 +61,8 @@
}
int indexreq = root.totalIndexSize() + 4 + 4; // + sizeof(MAGIC) + sizeof(root_loc_type + root_loc)
if (indexreq > index.remaining()) {
+ System.err.printf("Index-Req:%d ; remaining:%d ; capacity:%d ; limit:%d ; position:%d\n", indexreq,
+ index.remaining(), index.capacity(), index.limit(), index.position());
throw new InsufficientSpace("Attempt to write trie index to bytebuffer with insufficient space");
}
if (indexreq > 0x00010000) {
More information about the Mulgara-svn
mailing list