HBASE-14643 - Avoid Splits from once again opening a closed reader for

fetching the first and last key (Heng Chen)
This commit is contained in:
ramkrishna 2015-10-21 10:12:38 +05:30
parent 5a5b854c2a
commit 6e3b7af0ef
3 changed files with 31 additions and 5 deletions

View File

@ -587,23 +587,23 @@ public class HRegionFileSystem {
if (top) {
//check if larger than last key.
KeyValue splitKey = KeyValueUtil.createFirstOnRow(splitRow);
Cell lastKey = f.createReader().getLastKey();
Cell lastKey = f.getLastKey();
// If lastKey is null means storefile is empty.
if (lastKey == null) {
return null;
}
if (f.getReader().getComparator().compare(splitKey, lastKey) > 0) {
if (f.getComparator().compare(splitKey, lastKey) > 0) {
return null;
}
} else {
//check if smaller than first key
KeyValue splitKey = KeyValueUtil.createLastOnRow(splitRow);
Cell firstKey = f.createReader().getFirstKey();
Cell firstKey = f.getFirstKey();
// If firstKey is null means storefile is empty.
if (firstKey == null) {
return null;
}
if (f.getReader().getComparator().compare(splitKey, firstKey) < 0) {
if (f.getComparator().compare(splitKey, firstKey) < 0) {
return null;
}
}

View File

@ -129,6 +129,25 @@ public class StoreFile {
// Set when we obtain a Reader.
private long maxMemstoreTS = -1;
// firstKey, lastkey and cellComparator will be set when openReader.
private Cell firstKey;
private Cell lastKey;
private Comparator comparator;
public Cell getFirstKey() {
return firstKey;
}
public Cell getLastKey() {
return lastKey;
}
public Comparator getComparator() {
return comparator;
}
public long getMaxMemstoreTS() {
return maxMemstoreTS;
}
@ -475,6 +494,10 @@ public class StoreFile {
"proceeding without", e);
this.reader.timeRangeTracker = null;
}
// initialize so we can reuse them after reader closed.
firstKey = reader.getFirstKey();
lastKey = reader.getLastKey();
comparator = reader.getComparator();
return this.reader;
}

View File

@ -175,6 +175,8 @@ public class TestStoreFile extends HBaseTestCase {
byte [] midRow = CellUtil.cloneRow(kv);
kv = reader.getLastKey();
byte [] finalRow = CellUtil.cloneRow(kv);
hsf.closeReader(true);
// Make a reference
HRegionInfo splitHri = new HRegionInfo(hri.getTable(), null, midRow);
Path refPath = splitStoreFile(regionFs, splitHri, TEST_FAMILY, hsf, midRow, true);
@ -275,9 +277,10 @@ public class TestStoreFile extends HBaseTestCase {
HRegionInfo splitHriA = new HRegionInfo(hri.getTable(), null, SPLITKEY);
HRegionInfo splitHriB = new HRegionInfo(hri.getTable(), SPLITKEY, null);
StoreFile f = new StoreFile(fs, linkFilePath, testConf, cacheConf, BloomType.NONE);
f.createReader();
Path pathA = splitStoreFile(cloneRegionFs, splitHriA, TEST_FAMILY, f, SPLITKEY, true); // top
Path pathB = splitStoreFile(cloneRegionFs, splitHriB, TEST_FAMILY, f, SPLITKEY, false);// bottom
f.closeReader(true);
// OK test the thing
FSUtils.logFileSystemState(fs, testDir, LOG);