Repository: hbase Updated Branches: refs/heads/branch-1.4 b8ff539a8 -> 1889a4277
HBASE-18864 Fixed NullPointerException thrown while adding rows to a table from peer cluster, with replication factor other than 0 or 1 Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/1889a427 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1889a427 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1889a427 Branch: refs/heads/branch-1.4 Commit: 1889a4277f2089794608c939473d846d2199d8ea Parents: b8ff539 Author: Sakthi <jatsak...@dhcp-10-16-2-75.pa.cloudera.com> Authored: Fri Feb 23 12:09:19 2018 -0800 Committer: Michael Stack <st...@apache.org> Committed: Tue Mar 13 13:19:42 2018 -0700 ---------------------------------------------------------------------- .../java/org/apache/hadoop/hbase/HColumnDescriptor.java | 9 +++++++++ .../java/org/apache/hadoop/hbase/TestHColumnDescriptor.java | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/1889a427/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java index 1ac774f..55e4114 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java @@ -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; @@ -571,6 +572,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)); http://git-wip-us.apache.org/repos/asf/hbase/blob/1889a427/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java index 27d2cc8..310f928 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java @@ -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); + } }