[GitHub] [hbase] chrajeshbabu commented on a change in pull request #3124: HBASE-25711 Setting wrong data block encoding through ColumnFamilyDes…

2021-05-25 Thread GitBox


chrajeshbabu commented on a change in pull request #3124:
URL: https://github.com/apache/hbase/pull/3124#discussion_r639357057



##
File path: 
hbase-client/src/main/java/org/apache/hadoop/hbase/util/ColumnFamilyAttributeValidator.java
##
@@ -0,0 +1,102 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.util;
+
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.BLOCKSIZE;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.BLOOMFILTER;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.COMPRESSION;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.COMPRESSION_COMPACT;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.DATA_BLOCK_ENCODING;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.DFS_REPLICATION;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.IN_MEMORY_COMPACTION;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.KEEP_DELETED_CELLS;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.MAX_VERSIONS;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.MIN_VERSIONS;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.MOB_COMPACT_PARTITION_POLICY;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.MOB_THRESHOLD;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.REPLICATION_SCOPE;
+import static org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.TTL;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+import org.apache.hadoop.hbase.KeepDeletedCells;
+import org.apache.hadoop.hbase.MemoryCompactionPolicy;
+import org.apache.hadoop.hbase.client.MobCompactPartitionPolicy;
+import org.apache.hadoop.hbase.io.compress.Compression;
+import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
+import org.apache.hadoop.hbase.regionserver.BloomType;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@InterfaceAudience.Private
+public class ColumnFamilyAttributeValidator {
+  private static final Logger LOG = 
LoggerFactory.getLogger(ColumnFamilyAttributeValidator.class);
+  private final static Map> ATTRIBUTE_VALIDATOR 
= new HashMap<>();
+
+  static {
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(DATA_BLOCK_ENCODING)),
+  (d) -> DataBlockEncoding.valueOf(d.toString().toUpperCase()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(COMPRESSION)),
+  (ca) -> Compression.Algorithm.valueOf(ca.toString().toUpperCase()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(BLOOMFILTER)),
+  (bl) -> BloomType.valueOf(bl.toString().toUpperCase()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(REPLICATION_SCOPE)),
+  (rs) -> Integer.valueOf(rs.toString().toUpperCase()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(MIN_VERSIONS)),
+  (min) -> Integer.valueOf(min.toString()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(MAX_VERSIONS)),
+  (max) -> Integer.valueOf(max.toString()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(BLOCKSIZE)),
+  (bs) -> Integer.valueOf(bs.toString()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(KEEP_DELETED_CELLS)),
+  (k) -> KeepDeletedCells.valueOf(k.toString().toUpperCase()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(TTL)),
+  (ttl) -> Integer.valueOf(ttl.toString()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(DFS_REPLICATION)),
+  (dr) -> Integer.valueOf(dr.toString()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(MOB_THRESHOLD)),
+  (mt) -> Long.valueOf(mt.toString()));
+ATTRIBUTE_VALIDATOR.put(new 
Bytes(Bytes.toBytes(MOB_COMPACT_PARTITION_POLICY)),
+  (mc) -> MobCompactPartitionPolicy.valueOf(mc.toString().toUpperCase()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(IN_MEMORY_COMPACTION)),
+  (im) -> MemoryCompactionPolicy.valueOf(im.toString().toUpperCase()));
+

[GitHub] [hbase] chrajeshbabu commented on a change in pull request #3124: HBASE-25711 Setting wrong data block encoding through ColumnFamilyDes…

2021-05-25 Thread GitBox


chrajeshbabu commented on a change in pull request #3124:
URL: https://github.com/apache/hbase/pull/3124#discussion_r639357005



##
File path: 
hbase-client/src/main/java/org/apache/hadoop/hbase/util/ColumnFamilyAttributeValidator.java
##
@@ -0,0 +1,102 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.util;
+
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.BLOCKSIZE;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.BLOOMFILTER;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.COMPRESSION;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.COMPRESSION_COMPACT;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.DATA_BLOCK_ENCODING;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.DFS_REPLICATION;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.IN_MEMORY_COMPACTION;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.KEEP_DELETED_CELLS;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.MAX_VERSIONS;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.MIN_VERSIONS;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.MOB_COMPACT_PARTITION_POLICY;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.MOB_THRESHOLD;
+import static 
org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.REPLICATION_SCOPE;
+import static org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder.TTL;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+import org.apache.hadoop.hbase.KeepDeletedCells;
+import org.apache.hadoop.hbase.MemoryCompactionPolicy;
+import org.apache.hadoop.hbase.client.MobCompactPartitionPolicy;
+import org.apache.hadoop.hbase.io.compress.Compression;
+import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
+import org.apache.hadoop.hbase.regionserver.BloomType;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@InterfaceAudience.Private
+public class ColumnFamilyAttributeValidator {
+  private static final Logger LOG = 
LoggerFactory.getLogger(ColumnFamilyAttributeValidator.class);
+  private final static Map> ATTRIBUTE_VALIDATOR 
= new HashMap<>();
+
+  static {
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(DATA_BLOCK_ENCODING)),
+  (d) -> DataBlockEncoding.valueOf(d.toString().toUpperCase()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(COMPRESSION)),
+  (ca) -> Compression.Algorithm.valueOf(ca.toString().toUpperCase()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(BLOOMFILTER)),
+  (bl) -> BloomType.valueOf(bl.toString().toUpperCase()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(REPLICATION_SCOPE)),
+  (rs) -> Integer.valueOf(rs.toString().toUpperCase()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(MIN_VERSIONS)),
+  (min) -> Integer.valueOf(min.toString()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(MAX_VERSIONS)),
+  (max) -> Integer.valueOf(max.toString()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(BLOCKSIZE)),
+  (bs) -> Integer.valueOf(bs.toString()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(KEEP_DELETED_CELLS)),
+  (k) -> KeepDeletedCells.valueOf(k.toString().toUpperCase()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(TTL)),
+  (ttl) -> Integer.valueOf(ttl.toString()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(DFS_REPLICATION)),
+  (dr) -> Integer.valueOf(dr.toString()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(MOB_THRESHOLD)),
+  (mt) -> Long.valueOf(mt.toString()));
+ATTRIBUTE_VALIDATOR.put(new 
Bytes(Bytes.toBytes(MOB_COMPACT_PARTITION_POLICY)),
+  (mc) -> MobCompactPartitionPolicy.valueOf(mc.toString().toUpperCase()));
+ATTRIBUTE_VALIDATOR.put(new Bytes(Bytes.toBytes(IN_MEMORY_COMPACTION)),
+  (im) -> MemoryCompactionPolicy.valueOf(im.toString().toUpperCase()));
+

[GitHub] [hbase] chrajeshbabu commented on a change in pull request #3124: HBASE-25711 Setting wrong data block encoding through ColumnFamilyDes…

2021-04-06 Thread GitBox


chrajeshbabu commented on a change in pull request #3124:
URL: https://github.com/apache/hbase/pull/3124#discussion_r608280016



##
File path: 
hbase-client/src/main/java/org/apache/hadoop/hbase/client/ColumnFamilyDescriptorBuilder.java
##
@@ -282,6 +283,8 @@
 
   private final static Set RESERVED_KEYWORDS = new HashSet<>();
 
+  private final static Map> ATTRIBUTE_VALIDATOR = 
new HashMap<>();

Review comment:
   Moved those to separate class.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hbase] chrajeshbabu commented on a change in pull request #3124: HBASE-25711 Setting wrong data block encoding through ColumnFamilyDes…

2021-04-06 Thread GitBox


chrajeshbabu commented on a change in pull request #3124:
URL: https://github.com/apache/hbase/pull/3124#discussion_r608279896



##
File path: 
hbase-client/src/main/java/org/apache/hadoop/hbase/client/ColumnFamilyDescriptorBuilder.java
##
@@ -305,6 +308,30 @@
 RESERVED_KEYWORDS.add(new Bytes(Bytes.toBytes(IS_MOB)));
 RESERVED_KEYWORDS.add(new Bytes(Bytes.toBytes(MOB_THRESHOLD)));
 RESERVED_KEYWORDS.add(new 
Bytes(Bytes.toBytes(MOB_COMPACT_PARTITION_POLICY)));
+initValidator();
+  }
+
+  private static void initValidator() {
+ATTRIBUTE_VALIDATOR.put(DATA_BLOCK_ENCODING_BYTES,
+  (d) -> DataBlockEncoding.valueOf(d.toString()));
+ATTRIBUTE_VALIDATOR.put(COMPRESSION_BYTES,
+  (ca) -> Compression.Algorithm.valueOf(ca.toString()));
+ATTRIBUTE_VALIDATOR.put(BLOOMFILTER_BYTES, (bl) -> 
BloomType.valueOf(bl.toString()));
+ATTRIBUTE_VALIDATOR.put(REPLICATION_SCOPE_BYTES, (rs) -> 
Integer.valueOf(rs.toString()));
+ATTRIBUTE_VALIDATOR.put(MIN_VERSIONS_BYTES, (min) -> 
Integer.valueOf(min.toString()));
+ATTRIBUTE_VALIDATOR.put(MAX_VERSIONS_BYTES, (max) -> 
Integer.valueOf(max.toString()));
+ATTRIBUTE_VALIDATOR.put(BLOCKSIZE_BYTES, (bs) -> 
Integer.valueOf(bs.toString()));
+ATTRIBUTE_VALIDATOR.put(KEEP_DELETED_CELLS_BYTES,
+  (k) -> KeepDeletedCells.valueOf(k.toString()));
+ATTRIBUTE_VALIDATOR.put(TTL_BYTES, (ttl) -> 
Integer.valueOf(ttl.toString()));
+ATTRIBUTE_VALIDATOR.put(DFS_REPLICATION_BYTES, (dr) -> 
Integer.valueOf(dr.toString()));
+ATTRIBUTE_VALIDATOR.put(MOB_THRESHOLD_BYTES, (mt) -> 
Long.valueOf(mt.toString()));
+ATTRIBUTE_VALIDATOR.put(MOB_COMPACT_PARTITION_POLICY_BYTES,
+  (mc) -> MobCompactPartitionPolicy.valueOf(mc.toString()));
+ATTRIBUTE_VALIDATOR.put(IN_MEMORY_COMPACTION_BYTES,
+  (im) -> MemoryCompactionPolicy.valueOf(im.toString()));
+ATTRIBUTE_VALIDATOR.put(COMPRESSION_COMPACT_BYTES,
+  (ca) -> Compression.Algorithm.valueOf(ca.toString()));

Review comment:
   TableDescriptorChecker handling most of the validations but checking for 
valid data block encoding is missed so added that so it should be fine both 
create and modify cases.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hbase] chrajeshbabu commented on a change in pull request #3124: HBASE-25711 Setting wrong data block encoding through ColumnFamilyDes…

2021-04-06 Thread GitBox


chrajeshbabu commented on a change in pull request #3124:
URL: https://github.com/apache/hbase/pull/3124#discussion_r608279361



##
File path: 
hbase-client/src/main/java/org/apache/hadoop/hbase/client/ColumnFamilyDescriptorBuilder.java
##
@@ -1376,5 +1404,16 @@ public ModifyableColumnFamilyDescriptor 
setStoragePolicy(String policy) {
   return setValue(STORAGE_POLICY_BYTES, policy);
 }
 
+/**
+ * Validates values of HBase defined column family attributes.
+ * Throws {@link IllegalArgumentException} if the value of attribute is 
not proper format.
+ * @param key
+ * @param value
+ */
+public void validateAttributeValue(Bytes key, Bytes value) {
+  if(ATTRIBUTE_VALIDATOR.containsKey(key)) {
+ATTRIBUTE_VALIDATOR.get(key).apply(value);

Review comment:
   Printing error message what attribute failed to parse.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org