HBASE-20135 Fixed NullPointerException during reading bloom filter when upgraded from hbase-1 to hbase-2
This commit is contained in:
parent
65bd0881e2
commit
b8f999bf33
|
@ -38,6 +38,8 @@ import org.apache.hbase.thirdparty.com.google.protobuf.UnsafeByteOperations;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.HFileProtos;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.HFileProtos;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link HFile} has a fixed trailer which contains offsets to other
|
* The {@link HFile} has a fixed trailer which contains offsets to other
|
||||||
|
@ -53,6 +55,8 @@ import org.apache.hadoop.hbase.util.Bytes;
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public class FixedFileTrailer {
|
public class FixedFileTrailer {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(FixedFileTrailer.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We store the comparator class name as a fixed-length field in the trailer.
|
* We store the comparator class name as a fixed-length field in the trailer.
|
||||||
*/
|
*/
|
||||||
|
@ -623,7 +627,13 @@ public class FixedFileTrailer {
|
||||||
public static CellComparator createComparator(
|
public static CellComparator createComparator(
|
||||||
String comparatorClassName) throws IOException {
|
String comparatorClassName) throws IOException {
|
||||||
try {
|
try {
|
||||||
return getComparatorClass(comparatorClassName).getDeclaredConstructor().newInstance();
|
|
||||||
|
Class<? extends CellComparator> comparatorClass = getComparatorClass(comparatorClassName);
|
||||||
|
if(comparatorClass != null){
|
||||||
|
return comparatorClass.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
LOG.warn("No Comparator class for " + comparatorClassName + ". Returning Null.");
|
||||||
|
return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IOException("Comparator class " + comparatorClassName +
|
throw new IOException("Comparator class " + comparatorClassName +
|
||||||
" is not instantiable", e);
|
" is not instantiable", e);
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package org.apache.hadoop.hbase.io.hfile;
|
package org.apache.hadoop.hbase.io.hfile;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
@ -33,6 +34,7 @@ import org.apache.hadoop.fs.FSDataInputStream;
|
||||||
import org.apache.hadoop.fs.FSDataOutputStream;
|
import org.apache.hadoop.fs.FSDataOutputStream;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
|
import org.apache.hadoop.hbase.CellComparator;
|
||||||
import org.apache.hadoop.hbase.CellComparatorImpl;
|
import org.apache.hadoop.hbase.CellComparatorImpl;
|
||||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
|
@ -43,8 +45,10 @@ import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
@ -82,6 +86,9 @@ public class TestFixedFileTrailer {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public ExpectedException expectedEx = ExpectedException.none();
|
||||||
|
|
||||||
@Parameters
|
@Parameters
|
||||||
public static Collection<Object[]> getParameters() {
|
public static Collection<Object[]> getParameters() {
|
||||||
List<Object[]> versionsToTest = new ArrayList<>();
|
List<Object[]> versionsToTest = new ArrayList<>();
|
||||||
|
@ -108,6 +115,34 @@ public class TestFixedFileTrailer {
|
||||||
pb.getComparatorClassName());
|
pb.getComparatorClassName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateComparator() throws IOException {
|
||||||
|
FixedFileTrailer t = new FixedFileTrailer(version, HFileReaderImpl.PBUF_TRAILER_MINOR_VERSION);
|
||||||
|
try {
|
||||||
|
assertEquals(CellComparatorImpl.class,
|
||||||
|
t.createComparator(KeyValue.COMPARATOR.getLegacyKeyComparatorName()).getClass());
|
||||||
|
assertEquals(CellComparatorImpl.class,
|
||||||
|
t.createComparator(KeyValue.COMPARATOR.getClass().getName()).getClass());
|
||||||
|
assertEquals(CellComparatorImpl.class,
|
||||||
|
t.createComparator(CellComparator.class.getName()).getClass());
|
||||||
|
assertEquals(CellComparatorImpl.MetaCellComparator.class,
|
||||||
|
t.createComparator(KeyValue.META_COMPARATOR.getLegacyKeyComparatorName()).getClass());
|
||||||
|
assertEquals(CellComparatorImpl.MetaCellComparator.class,
|
||||||
|
t.createComparator(KeyValue.META_COMPARATOR.getClass().getName()).getClass());
|
||||||
|
assertEquals(CellComparatorImpl.MetaCellComparator.class, t.createComparator(
|
||||||
|
CellComparatorImpl.MetaCellComparator.META_COMPARATOR.getClass().getName()).getClass());
|
||||||
|
assertNull(t.createComparator(Bytes.BYTES_RAWCOMPARATOR.getClass().getName()));
|
||||||
|
assertNull(t.createComparator("org.apache.hadoop.hbase.KeyValue$RawBytesComparator"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
fail("Unexpected exception while testing FixedFileTrailer#createComparator()");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test an invalid comparatorClassName
|
||||||
|
expectedEx.expect(IOException.class);
|
||||||
|
t.createComparator("");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTrailer() throws IOException {
|
public void testTrailer() throws IOException {
|
||||||
FixedFileTrailer t = new FixedFileTrailer(version,
|
FixedFileTrailer t = new FixedFileTrailer(version,
|
||||||
|
|
Loading…
Reference in New Issue