HBASE-18864 Fixed NullPointerException thrown while adding rows to a table from peer cluster, with replication factor other than 0 or 1

This commit is contained in:
Sakthi 2018-02-23 12:09:19 -08:00 committed by Michael Stack
parent 91a17baaed
commit 8da331c4d7
No known key found for this signature in database
GPG Key ID: 9816C7FC8ACC93D2
2 changed files with 17 additions and 1 deletions

View File

@ -38,6 +38,7 @@ import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.BytesBytesPair;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.ColumnFamilySchema;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameStringPair;
import org.apache.hadoop.hbase.protobuf.generated.WALProtos;
import org.apache.hadoop.hbase.regionserver.BloomType;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.PrettyPrinter;
@ -573,6 +574,14 @@ public class HColumnDescriptor implements WritableComparable<HColumnDescriptor>
public HColumnDescriptor setValue(byte[] key, byte[] value) {
if (Bytes.compareTo(Bytes.toBytes(HConstants.VERSIONS), key) == 0) {
cachedMaxVersions = UNINITIALIZED;
} else if (Bytes.compareTo(REPLICATION_SCOPE_BYTES, key) == 0) {
// as bytes are encoded from string, we have to decode value as string
int scopeType = Integer.valueOf(Bytes.toString(value));
if (scopeType != WALProtos.ScopeType.REPLICATION_SCOPE_GLOBAL_VALUE &&
scopeType != WALProtos.ScopeType.REPLICATION_SCOPE_LOCAL_VALUE) {
throw new IllegalArgumentException("Invalid value '" + scopeType +
"' for REPLICATION_SCOPE.");
}
}
values.put(new ImmutableBytesWritable(key),
new ImmutableBytesWritable(value));

View File

@ -51,7 +51,8 @@ public class TestHColumnDescriptor {
hcd.setKeepDeletedCells(KeepDeletedCells.TRUE);
hcd.setInMemory(!HColumnDescriptor.DEFAULT_IN_MEMORY);
boolean inmemory = hcd.isInMemory();
hcd.setScope(v);
// Valid values for replication scope are 0 or 1.
hcd.setScope(0);
hcd.setDataBlockEncoding(DataBlockEncoding.FAST_DIFF);
hcd.setBloomFilterType(BloomType.ROW);
hcd.setCompressionType(Algorithm.SNAPPY);
@ -116,4 +117,10 @@ public class TestHColumnDescriptor {
BuilderStyleTest.assertClassesAreBuilderStyle(HColumnDescriptor.class);
}
@Test(expected=IllegalArgumentException.class)
public void testInvalidReplicationScope() {
HColumnDescriptor column = new HColumnDescriptor("f1");
column.setScope(5);
}
}