junegunn commented on code in PR #6709:
URL: https://github.com/apache/hbase/pull/6709#discussion_r1976240570


##########
hbase-common/src/main/java/org/apache/hadoop/hbase/conf/ConfigKey.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.conf;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Predicate;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Utility class for basic validation of configuration values.
+ */
[email protected]
+public class ConfigKey {
+  private static final Logger LOG = LoggerFactory.getLogger(ConfigKey.class);
+
+  @FunctionalInterface
+  private interface Validator {
+    void validate(Configuration conf);
+  }
+
+  // Map of configuration keys to validators
+  private static final Map<String, Validator> validators = new 
ConcurrentHashMap<>();
+
+  /**
+   * Registers the configuration key that expects an integer.
+   * @param key        configuration key
+   * @param predicates additional predicates to validate the value
+   * @return the key
+   */
+  @SafeVarargs
+  public static String INT(String key, Predicate<Integer>... predicates) {
+    return register(key,
+      conf -> validateNumeric(key, "an integer", () -> conf.getInt(key, 0), 
predicates));
+  }
+
+  /**
+   * Registers the configuration key that expects a long.
+   * @param key        configuration key
+   * @param predicates additional predicates to validate the value
+   * @return the key
+   */
+  @SafeVarargs
+  public static String LONG(String key, Predicate<Long>... predicates) {
+    return register(key,
+      conf -> validateNumeric(key, "a long", () -> conf.getLong(key, 0), 
predicates));
+  }
+
+  /**
+   * Registers the configuration key that expects a float.
+   * @param key        configuration key
+   * @param predicates additional predicates to validate the value
+   * @return the key
+   */
+  @SafeVarargs
+  public static String FLOAT(String key, Predicate<Float>... predicates) {
+    return register(key,
+      conf -> validateNumeric(key, "a float", () -> conf.getFloat(key, 0), 
predicates));
+  }
+
+  /**
+   * Registers the configuration key that expects a double.
+   * @param key        configuration key
+   * @param predicates additional predicates to validate the value
+   * @return the key
+   */
+  @SafeVarargs
+  public static String DOUBLE(String key, Predicate<Double>... predicates) {
+    return register(key,
+      conf -> validateNumeric(key, "a double", () -> conf.getDouble(key, 0), 
predicates));
+  }
+
+  /**
+   * Registers the configuration key that expects a class.
+   * @param key configuration key
+   * @return the key
+   */
+  public static String CLASS(String key) {
+    return register(key, conf -> {
+      String value = conf.get(key);
+      try {
+        Class.forName(value);
+      } catch (ClassNotFoundException e) {
+        throw new IllegalArgumentException("Class " + value + " not found.");

Review Comment:
   See 239179b6664674064792b1d61c158f9885add17f
   
   ```
   ERROR: org.apache.hadoop.hbase.DoNotRetryIOException: 
'hbase.hstore.engine.class' must be a class. Set hbase.table.sanity.checks to 
false at conf or table descriptor if you want to bypass sanity checks
           at 
org.apache.hadoop.hbase.util.TableDescriptorChecker.warnOrThrowExceptionForFailure(TableDescriptorChecker.java:327)
           at 
org.apache.hadoop.hbase.util.TableDescriptorChecker.warnOrThrowExceptionForFailure(TableDescriptorChecker.java:344)
           at 
org.apache.hadoop.hbase.util.TableDescriptorChecker.sanityCheck(TableDescriptorChecker.java:84)
           at org.apache.hadoop.hbase.master.HMaster$14.run(HMaster.java:2877)
           at 
org.apache.hadoop.hbase.master.procedure.MasterProcedureUtil.submitProcedure(MasterProcedureUtil.java:137)
           at 
org.apache.hadoop.hbase.master.HMaster.modifyTable(HMaster.java:2871)
           at 
org.apache.hadoop.hbase.master.HMaster.modifyTable(HMaster.java:2907)
           at 
org.apache.hadoop.hbase.master.MasterRpcServices.modifyTable(MasterRpcServices.java:1547)
           at 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos$MasterService$2.callBlockingMethod(MasterProtos.java)
           at org.apache.hadoop.hbase.ipc.RpcServer.call(RpcServer.java:457)
           at org.apache.hadoop.hbase.ipc.CallRunner.run(CallRunner.java:124)
           at org.apache.hadoop.hbase.ipc.RpcHandler.run(RpcHandler.java:102)
           at org.apache.hadoop.hbase.ipc.RpcHandler.run(RpcHandler.java:82)
   Caused by: java.lang.IllegalArgumentException: 'hbase.hstore.engine.class' 
must be a class.
           at 
org.apache.hadoop.hbase.conf.ConfigKey.lambda$CLASS$8(ConfigKey.java:102)
           at 
org.apache.hadoop.hbase.conf.ConfigKey.lambda$validate$9(ConfigKey.java:126)
           at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
           at 
org.apache.hadoop.hbase.conf.ConfigKey.validate(ConfigKey.java:123)
           at 
org.apache.hadoop.hbase.util.TableDescriptorChecker.lambda$sanityCheck$0(TableDescriptorChecker.java:84)
           at 
org.apache.hadoop.hbase.util.TableDescriptorChecker.warnOrThrowExceptionForFailure(TableDescriptorChecker.java:342)
           ... 11 more
   Caused by: java.lang.ClassNotFoundException: 
org.apache.hadoop.hbase.regionserver.DateTieredStoreEngine2
           at 
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
           at 
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
           at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
           at java.base/java.lang.Class.forName0(Native Method)
           at java.base/java.lang.Class.forName(Class.java:375)
           at 
org.apache.hadoop.hbase.conf.ConfigKey.lambda$CLASS$8(ConfigKey.java:100)
           ... 16 more
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to