HBASE-1818 HFile code review and refinement

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@815590 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2009-09-16 02:43:43 +00:00
parent 651490942d
commit 6cd712c7be
2 changed files with 8 additions and 7 deletions

View File

@ -26,6 +26,7 @@ Release 0.21.0 - Unreleased
timestamp provided timestamp provided
HBASE-1821 Filtering by SingleColumnValueFilter bug HBASE-1821 Filtering by SingleColumnValueFilter bug
HBASE-1840 RowLock fails when used with IndexTable (Keith Thomas via Stack) HBASE-1840 RowLock fails when used with IndexTable (Keith Thomas via Stack)
HBASE-818 HFile code review and refinement (Schubert Zhang via Stack)
IMPROVEMENTS IMPROVEMENTS
HBASE-1760 Cleanup TODOs in HTable HBASE-1760 Cleanup TODOs in HTable

View File

@ -168,7 +168,7 @@ public class HFile {
protected String name; protected String name;
// Total uncompressed bytes, maybe calculate a compression ratio later. // Total uncompressed bytes, maybe calculate a compression ratio later.
private int totalBytes = 0; private long totalBytes = 0;
// Total # of key/value entries, ie: how many times add() was called. // Total # of key/value entries, ie: how many times add() was called.
private int entryCount = 0; private int entryCount = 0;
@ -320,13 +320,12 @@ public class HFile {
*/ */
private void finishBlock() throws IOException { private void finishBlock() throws IOException {
if (this.out == null) return; if (this.out == null) return;
long size = releaseCompressingStream(this.out); int size = releaseCompressingStream(this.out);
this.out = null; this.out = null;
blockKeys.add(firstKey); blockKeys.add(firstKey);
int written = longToInt(size);
blockOffsets.add(Long.valueOf(blockBegin)); blockOffsets.add(Long.valueOf(blockBegin));
blockDataSizes.add(Integer.valueOf(written)); blockDataSizes.add(Integer.valueOf(size));
this.totalBytes += written; this.totalBytes += size;
} }
/* /*
@ -620,7 +619,7 @@ public class HFile {
appendFileInfo(this.fileinfo, FileInfo.AVG_KEY_LEN, appendFileInfo(this.fileinfo, FileInfo.AVG_KEY_LEN,
Bytes.toBytes(avgKeyLen), false); Bytes.toBytes(avgKeyLen), false);
int avgValueLen = this.entryCount == 0? 0: int avgValueLen = this.entryCount == 0? 0:
(int)(this.keylength/this.entryCount); (int)(this.valuelength/this.entryCount);
appendFileInfo(this.fileinfo, FileInfo.AVG_VALUE_LEN, appendFileInfo(this.fileinfo, FileInfo.AVG_VALUE_LEN,
Bytes.toBytes(avgValueLen), false); Bytes.toBytes(avgValueLen), false);
appendFileInfo(this.fileinfo, FileInfo.COMPARATOR, appendFileInfo(this.fileinfo, FileInfo.COMPARATOR,
@ -898,7 +897,7 @@ public class HFile {
if (blockIndex == null) { if (blockIndex == null) {
throw new IOException("Block index not loaded"); throw new IOException("Block index not loaded");
} }
if (block < 0 || block > blockIndex.count) { if (block < 0 || block >= blockIndex.count) {
throw new IOException("Requested block is out of range: " + block + throw new IOException("Requested block is out of range: " + block +
", max: " + blockIndex.count); ", max: " + blockIndex.count);
} }
@ -1251,6 +1250,7 @@ public class HFile {
block.rewind(); block.rewind();
currKeyLen = block.getInt(); currKeyLen = block.getInt();
currValueLen = block.getInt(); currValueLen = block.getInt();
return true;
} }
currBlock = 0; currBlock = 0;
block = reader.readBlock(currBlock, cacheBlocks); block = reader.readBlock(currBlock, cacheBlocks);