Repository: hbase
Updated Branches:
  refs/heads/branch-1.3 8e51adc73 -> 58ecd8f95


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/58ecd8f9
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/58ecd8f9
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/58ecd8f9

Branch: refs/heads/branch-1.3
Commit: 58ecd8f95e0592efb352b063a12f635651f23e3d
Parents: 8e51adc
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:20:01 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/58ecd8f9/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 532da5b..e810c94 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
@@ -37,6 +37,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;
@@ -570,6 +571,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/58ecd8f9/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 1966253..8249246 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
@@ -49,7 +49,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);
@@ -113,4 +114,10 @@ public class TestHColumnDescriptor {
 
     BuilderStyleTest.assertClassesAreBuilderStyle(HColumnDescriptor.class);
   }
+
+  @Test(expected=IllegalArgumentException.class)
+  public void testInvalidReplicationScope() {
+    HColumnDescriptor column = new HColumnDescriptor("f1");
+    column.setScope(5);
+  }
 }

Reply via email to