From 1334d5187b47098e6782f57ce0ce85dcb9230c87 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Tue, 28 Sep 2010 18:29:53 +0000 Subject: [PATCH] HBASE-3040 BlockIndex readIndex too slowly in heavy write scenario; add in fix to address kannan review git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1002310 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/hadoop/hbase/io/hfile/HFile.java | 43 +++---------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java b/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java index 572f71b4f38..b413ef94c7a 100644 --- a/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java +++ b/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java @@ -830,11 +830,12 @@ public class HFile { DataInputStream dis = new DataInputStream(bis); // Read in the data index. - this.blockIndex = BlockIndex.readIndexEx(this.comparator, dis, this.trailer.dataIndexCount); + this.blockIndex = + BlockIndex.readIndex(this.comparator, dis, this.trailer.dataIndexCount); // Read in the metadata index. if (trailer.metaIndexCount > 0) { - this.metaIndex = BlockIndex.readIndexEx(Bytes.BYTES_RAWCOMPARATOR, dis, + this.metaIndex = BlockIndex.readIndex(Bytes.BYTES_RAWCOMPARATOR, dis, this.trailer.metaIndexCount); } this.fileInfoLoaded = true; @@ -1670,45 +1671,13 @@ public class HFile { /* * Read in the index that is at indexOffset * Must match what was written by writeIndex in the Writer.close. + * @param c Comparator to use. * @param in - * @param indexOffset + * @param indexSize * @throws IOException */ static BlockIndex readIndex(final RawComparator c, - final FSDataInputStream in, final long indexOffset, final int indexSize) - throws IOException { - BlockIndex bi = new BlockIndex(c); - bi.blockOffsets = new long[indexSize]; - bi.blockKeys = new byte[indexSize][]; - bi.blockDataSizes = new int[indexSize]; - // If index size is zero, no index was written. - if (indexSize > 0) { - in.seek(indexOffset); - byte [] magic = new byte[INDEXBLOCKMAGIC.length]; - IOUtils.readFully(in, magic, 0, magic.length); - if (!Arrays.equals(magic, INDEXBLOCKMAGIC)) { - throw new IOException("Index block magic is wrong: " + - Arrays.toString(magic)); - } - for (int i = 0; i < indexSize; ++i ) { - long offset = in.readLong(); - int dataSize = in.readInt(); - byte [] key = Bytes.readByteArray(in); - bi.add(key, offset, dataSize); - } - } - return bi; - } - - /* - * Read in the index that is at indexOffset - * Must match what was written by writeIndex in the Writer.close. - * @param in - * @param indexOffset - * @throws IOException - */ - static BlockIndex readIndexEx(final RawComparator c, DataInputStream in, - final int indexSize) + DataInputStream in, final int indexSize) throws IOException { BlockIndex bi = new BlockIndex(c); bi.blockOffsets = new long[indexSize];