mirror of
https://github.com/actiontech/dble.git
synced 2026-04-25 07:39:05 -05:00
fix analysisUser login with the database name inner 1703 (#3306)
* fix analysisUser login with the database name inner 1703 fix * fix ci
This commit is contained in:
+19
-17
@@ -3,7 +3,7 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.services.mysqlauthenticate;
|
||||
package com.actiontech.dble.config.helper;
|
||||
|
||||
import com.actiontech.dble.backend.datasource.PhysicalDbGroup;
|
||||
import com.actiontech.dble.backend.datasource.PhysicalDbInstance;
|
||||
@@ -16,17 +16,20 @@ import java.util.*;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class MysqlDatabaseHandler {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MysqlDatabaseHandler.class);
|
||||
private static final String MYSQL_SHOW_DATABASES = "show databases";
|
||||
public class ShowDatabaseHandler {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ShowDatabaseHandler.class);
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private Map<String, PhysicalDbGroup> dbGroups;
|
||||
private Set<String> databases = new HashSet<>();
|
||||
private final Condition finishCond = lock.newCondition();
|
||||
private boolean isFinish = false;
|
||||
private String showDatabases = "show databases";
|
||||
private String showDataBasesCols;
|
||||
|
||||
public MysqlDatabaseHandler(Map<String, PhysicalDbGroup> dbGroups) {
|
||||
|
||||
public ShowDatabaseHandler(Map<String, PhysicalDbGroup> dbGroups, String showDataBasesCols) {
|
||||
this.dbGroups = dbGroups;
|
||||
this.showDataBasesCols = showDataBasesCols;
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
@@ -36,11 +39,10 @@ public class MysqlDatabaseHandler {
|
||||
|
||||
public Set<String> execute(String dbGroupName) {
|
||||
reset();
|
||||
String mysqlShowDataBasesCols = "Database";
|
||||
MultiRowSQLQueryResultHandler resultHandler = new MultiRowSQLQueryResultHandler(new String[]{mysqlShowDataBasesCols}, new MySQLShowDatabasesListener(mysqlShowDataBasesCols));
|
||||
MultiRowSQLQueryResultHandler resultHandler = new MultiRowSQLQueryResultHandler(new String[]{showDataBasesCols}, new ShowDatabasesListener(showDataBasesCols));
|
||||
PhysicalDbInstance ds = getPhysicalDbInstance(dbGroupName);
|
||||
if (ds != null) {
|
||||
SQLJob sqlJob = new SQLJob(MYSQL_SHOW_DATABASES, null, resultHandler, ds);
|
||||
SQLJob sqlJob = new SQLJob(showDatabases, null, resultHandler, ds);
|
||||
sqlJob.run();
|
||||
waitDone();
|
||||
} else {
|
||||
@@ -49,13 +51,13 @@ public class MysqlDatabaseHandler {
|
||||
return new HashSet<>(databases);
|
||||
}
|
||||
|
||||
|
||||
// for dryrun
|
||||
public Set<String> execute(PhysicalDbInstance ds) {
|
||||
reset();
|
||||
String mysqlShowDataBasesCols = "Database";
|
||||
MultiRowSQLQueryResultHandler resultHandler = new MultiRowSQLQueryResultHandler(new String[]{mysqlShowDataBasesCols}, new MySQLShowDatabasesListener(mysqlShowDataBasesCols));
|
||||
MultiRowSQLQueryResultHandler resultHandler = new MultiRowSQLQueryResultHandler(new String[]{showDataBasesCols}, new ShowDatabasesListener(showDataBasesCols));
|
||||
if (ds != null) {
|
||||
OneTimeConnJob sqlJob = new OneTimeConnJob(MYSQL_SHOW_DATABASES, null, resultHandler, ds);
|
||||
OneTimeConnJob sqlJob = new OneTimeConnJob(showDatabases, null, resultHandler, ds);
|
||||
sqlJob.run();
|
||||
waitDone();
|
||||
} else {
|
||||
@@ -96,17 +98,17 @@ public class MysqlDatabaseHandler {
|
||||
finishCond.await();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.info("[MysqlDatabaseHandler] conn Interrupted: " + e);
|
||||
LOGGER.info("[ClickHouseDatabaseHandler] conn Interrupted: " + e);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private class MySQLShowDatabasesListener implements SQLQueryResultListener<SQLQueryResult<List<Map<String, String>>>> {
|
||||
private String mysqlShowDataBasesCol;
|
||||
private class ShowDatabasesListener implements SQLQueryResultListener<SQLQueryResult<List<Map<String, String>>>> {
|
||||
private String showDataBasesCol;
|
||||
|
||||
MySQLShowDatabasesListener(String mysqlShowDataBasesCol) {
|
||||
this.mysqlShowDataBasesCol = mysqlShowDataBasesCol;
|
||||
ShowDatabasesListener(String clickhouseShowDataBasesCol) {
|
||||
this.showDataBasesCol = clickhouseShowDataBasesCol;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,7 +116,7 @@ public class MysqlDatabaseHandler {
|
||||
if (result.isSuccess()) {
|
||||
List<Map<String, String>> rows = result.getResult();
|
||||
for (Map<String, String> row : rows) {
|
||||
String databaseName = row.get(mysqlShowDataBasesCol);
|
||||
String databaseName = row.get(showDataBasesCol);
|
||||
databases.add(databaseName);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ package com.actiontech.dble.config.model.user;
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.config.ErrorCode;
|
||||
import com.actiontech.dble.services.mysqlauthenticate.MysqlDatabaseHandler;
|
||||
import com.actiontech.dble.config.helper.ShowDatabaseHandler;
|
||||
import com.actiontech.dble.util.StringUtil;
|
||||
import com.alibaba.druid.wall.WallProvider;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class AnalysisUserConfig extends SingleDbGroupUserConfig {
|
||||
return 0;
|
||||
}
|
||||
boolean exist;
|
||||
Set<String> schemas = new MysqlDatabaseHandler(DbleServer.getInstance().getConfig().getDbGroups()).execute(dbGroup);
|
||||
Set<String> schemas = new ShowDatabaseHandler(DbleServer.getInstance().getConfig().getDbGroups(), "name").execute(dbGroup);
|
||||
if (DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
|
||||
Optional<String> result = schemas.stream().filter(item -> StringUtil.equals(item.toLowerCase(), schema.toLowerCase())).findFirst();
|
||||
exist = result.isPresent();
|
||||
|
||||
@@ -7,7 +7,7 @@ package com.actiontech.dble.config.model.user;
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.config.ErrorCode;
|
||||
import com.actiontech.dble.services.mysqlauthenticate.MysqlDatabaseHandler;
|
||||
import com.actiontech.dble.config.helper.ShowDatabaseHandler;
|
||||
import com.actiontech.dble.util.StringUtil;
|
||||
import com.alibaba.druid.wall.WallProvider;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class RwSplitUserConfig extends SingleDbGroupUserConfig {
|
||||
return 0;
|
||||
}
|
||||
boolean exist;
|
||||
Set<String> schemas = new MysqlDatabaseHandler(DbleServer.getInstance().getConfig().getDbGroups()).execute(dbGroup);
|
||||
Set<String> schemas = new ShowDatabaseHandler(DbleServer.getInstance().getConfig().getDbGroups(), "Database").execute(dbGroup);
|
||||
if (DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
|
||||
Optional<String> result = schemas.stream().filter(item -> StringUtil.equals(item.toLowerCase(), schema.toLowerCase())).findFirst();
|
||||
exist = result.isPresent();
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package com.actiontech.dble.services.manager.response;
|
||||
|
||||
import com.actiontech.dble.backend.datasource.PhysicalDbGroup;
|
||||
import com.actiontech.dble.backend.datasource.PhysicalDbInstance;
|
||||
import com.actiontech.dble.backend.datasource.ShardingNode;
|
||||
import com.actiontech.dble.backend.mysql.PacketUtil;
|
||||
@@ -16,8 +17,10 @@ import com.actiontech.dble.config.converter.DBConverter;
|
||||
import com.actiontech.dble.config.converter.SequenceConverter;
|
||||
import com.actiontech.dble.config.converter.ShardingConverter;
|
||||
import com.actiontech.dble.config.converter.UserConverter;
|
||||
import com.actiontech.dble.config.helper.ShowDatabaseHandler;
|
||||
import com.actiontech.dble.config.model.ClusterConfig;
|
||||
import com.actiontech.dble.config.model.SystemConfig;
|
||||
import com.actiontech.dble.config.model.db.type.DataBaseType;
|
||||
import com.actiontech.dble.config.model.sharding.SchemaConfig;
|
||||
import com.actiontech.dble.config.model.sharding.table.BaseTableConfig;
|
||||
import com.actiontech.dble.config.model.user.ManagerUserConfig;
|
||||
@@ -30,9 +33,9 @@ import com.actiontech.dble.net.mysql.*;
|
||||
import com.actiontech.dble.server.variables.SystemVariables;
|
||||
import com.actiontech.dble.server.variables.VarsExtractorHandler;
|
||||
import com.actiontech.dble.services.manager.ManagerService;
|
||||
import com.actiontech.dble.services.mysqlauthenticate.MysqlDatabaseHandler;
|
||||
import com.actiontech.dble.singleton.TraceManager;
|
||||
import com.actiontech.dble.util.StringUtil;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -160,8 +163,32 @@ public final class DryRun {
|
||||
}
|
||||
|
||||
private static Map<String, Set<String>> getExistSchemas(ServerConfig serverConfig) {
|
||||
Map<String, Set<String>> schemaMap = Maps.newHashMap();
|
||||
Map<String, PhysicalDbGroup> dbGroups = serverConfig.getDbGroups();
|
||||
Map<String, PhysicalDbGroup> mysqlDbGroups = Maps.newHashMap();
|
||||
Map<String, PhysicalDbGroup> clickHouseDbGroups = Maps.newHashMap();
|
||||
dbGroups.forEach((k, v) -> {
|
||||
DataBaseType dataBaseType = v.getDbGroupConfig().instanceDatabaseType();
|
||||
if (dataBaseType == DataBaseType.MYSQL) {
|
||||
mysqlDbGroups.put(k, v);
|
||||
} else {
|
||||
clickHouseDbGroups.put(k, v);
|
||||
}
|
||||
});
|
||||
|
||||
if (!mysqlDbGroups.isEmpty()) {
|
||||
ShowDatabaseHandler mysqlShowDatabaseHandler = new ShowDatabaseHandler(mysqlDbGroups, "Database");
|
||||
schemaMap.putAll(getSchemaMap(mysqlShowDatabaseHandler));
|
||||
}
|
||||
if (!clickHouseDbGroups.isEmpty()) {
|
||||
ShowDatabaseHandler clickHouseDatabaseHandler = new ShowDatabaseHandler(clickHouseDbGroups, "name");
|
||||
schemaMap.putAll(getSchemaMap(clickHouseDatabaseHandler));
|
||||
}
|
||||
return schemaMap;
|
||||
}
|
||||
|
||||
private static Map<String, Set<String>> getSchemaMap(ShowDatabaseHandler databaseHandler) {
|
||||
Map<String, Set<String>> schemaMap = new HashMap<>();
|
||||
MysqlDatabaseHandler databaseHandler = new MysqlDatabaseHandler(serverConfig.getDbGroups());
|
||||
List<PhysicalDbInstance> physicalDbInstances = databaseHandler.getPhysicalDbInstances();
|
||||
physicalDbInstances.forEach(ds -> {
|
||||
Set<String> schemaSet = databaseHandler.execute(ds);
|
||||
|
||||
Reference in New Issue
Block a user