-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-29526 Dynamic configuration not working for coprocessor #7514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,14 @@ | |
| */ | ||
| package org.apache.hadoop.hbase.util; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; | ||
| import org.apache.yetus.audience.InterfaceAudience; | ||
|
|
||
| import org.apache.hbase.thirdparty.com.google.common.base.Preconditions; | ||
| import org.apache.hbase.thirdparty.com.google.common.base.Strings; | ||
|
|
||
| /** | ||
| * Helper class for coprocessor host when configuration changes. | ||
|
|
@@ -32,19 +35,65 @@ public final class CoprocessorConfigurationUtil { | |
| private CoprocessorConfigurationUtil() { | ||
| } | ||
|
|
||
| public static boolean checkConfigurationChange(Configuration oldConfig, Configuration newConfig, | ||
| String... configurationKey) { | ||
| /** | ||
| * Check configuration change by comparing current loaded coprocessors with configuration values. | ||
| * This method is useful when the configuration object has been updated but we need to determine | ||
| * if coprocessor configuration has actually changed compared to what's currently loaded. | ||
| * @param coprocessorHost the coprocessor host to check current loaded coprocessors (can be null) | ||
| * @param conf the configuration to check | ||
| * @param configurationKey the configuration keys to check | ||
| * @return true if configuration has changed, false otherwise | ||
| */ | ||
| public static boolean checkConfigurationChange(CoprocessorHost<?, ?> coprocessorHost, | ||
| Configuration conf, String... configurationKey) { | ||
| Preconditions.checkArgument(configurationKey != null, "Configuration Key(s) must be provided"); | ||
| boolean isConfigurationChange = false; | ||
| Preconditions.checkArgument(conf != null, "Configuration must be provided"); | ||
|
|
||
| if (coprocessorHost == null) { | ||
| // If no coprocessor host exists, check if any coprocessors are now configured | ||
| return hasCoprocessorsConfigured(conf, configurationKey); | ||
| } | ||
|
|
||
| // Get currently loaded coprocessor class names | ||
| Set<String> currentlyLoaded = coprocessorHost.getCoprocessorClassNames(); | ||
|
|
||
| // Get coprocessor class names from configuration | ||
| Set<String> configuredClasses = new HashSet<>(); | ||
| for (String key : configurationKey) { | ||
| String[] classes = conf.getStrings(key); | ||
| if (classes != null) { | ||
| for (String className : classes) { | ||
| // Handle the className|priority|path format | ||
| String[] classNameToken = className.split("\\|"); | ||
| String actualClassName = classNameToken[0].trim(); | ||
| if (!Strings.isNullOrEmpty(actualClassName)) { | ||
| configuredClasses.add(actualClassName); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Compare the two sets | ||
| return !currentlyLoaded.equals(configuredClasses); | ||
|
Comment on lines
+64
to
+90
|
||
| } | ||
|
|
||
| /** | ||
| * Helper method to check if there are any coprocessors configured. | ||
| */ | ||
| private static boolean hasCoprocessorsConfigured(Configuration conf, String... configurationKey) { | ||
| if ( | ||
| !conf.getBoolean(CoprocessorHost.COPROCESSORS_ENABLED_CONF_KEY, | ||
| CoprocessorHost.DEFAULT_COPROCESSORS_ENABLED) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we should move this |
||
| ) { | ||
| return false; | ||
| } | ||
|
|
||
| for (String key : configurationKey) { | ||
| String oldValue = oldConfig.get(key); | ||
| String newValue = newConfig.get(key); | ||
| // check if the coprocessor key has any difference | ||
| if (!StringUtils.equalsIgnoreCase(oldValue, newValue)) { | ||
| isConfigurationChange = true; | ||
| break; | ||
| String[] coprocessors = conf.getStrings(key); | ||
| if (coprocessors != null && coprocessors.length > 0) { | ||
| return true; | ||
| } | ||
| } | ||
| return isConfigurationChange; | ||
| return false; | ||
| } | ||
|
Comment on lines
+96
to
104
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this made me rethink about the configuration change detection cannot handle
pathreload, and even if we can detect changes for classname and priority.So, can you update a note/comment in the function
checkConfigurationChange, that priority and path changes are not supported with the same classname once it's loaded?