HBASE-27246 RSGroupMappingScript#getRSGroup has thread safety problem (#4657)

Co-authored-by: Sean Xiao Yutong <sean.xiaoyt@shopee.com>
Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
Yutong Xiao 2022-08-24 15:23:21 +08:00 committed by GitHub
parent b4e5875dd9
commit b44bfc52cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 10 deletions

View File

@ -206,23 +206,22 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
static final String RS_GROUP_MAPPING_SCRIPT = "hbase.rsgroup.table.mapping.script"; static final String RS_GROUP_MAPPING_SCRIPT = "hbase.rsgroup.table.mapping.script";
static final String RS_GROUP_MAPPING_SCRIPT_TIMEOUT = static final String RS_GROUP_MAPPING_SCRIPT_TIMEOUT =
"hbase.rsgroup.table.mapping.script.timeout"; "hbase.rsgroup.table.mapping.script.timeout";
private Shell.ShellCommandExecutor rsgroupMappingScript;
private final String script;
private final long scriptTimeout;
RSGroupMappingScript(Configuration conf) { RSGroupMappingScript(Configuration conf) {
String script = conf.get(RS_GROUP_MAPPING_SCRIPT); script = conf.get(RS_GROUP_MAPPING_SCRIPT);
if (script == null || script.isEmpty()) { scriptTimeout = conf.getLong(RS_GROUP_MAPPING_SCRIPT_TIMEOUT, 5000); // 5 seconds
return;
}
rsgroupMappingScript = new Shell.ShellCommandExecutor(new String[] { script, "", "" }, null,
null, conf.getLong(RS_GROUP_MAPPING_SCRIPT_TIMEOUT, 5000) // 5 seconds
);
} }
String getRSGroup(String namespace, String tablename) { String getRSGroup(String namespace, String tablename) {
if (rsgroupMappingScript == null) { if (script == null || script.isEmpty()) {
return null; return null;
} }
Shell.ShellCommandExecutor rsgroupMappingScript =
new Shell.ShellCommandExecutor(new String[] { script, "", "" }, null, null, scriptTimeout);
String[] exec = rsgroupMappingScript.getExecString(); String[] exec = rsgroupMappingScript.getExecString();
exec[1] = namespace; exec[1] = namespace;
exec[2] = tablename; exec[2] = tablename;