mirror of
https://github.com/actiontech/dble.git
synced 2026-01-06 04:40:17 -06:00
database is not checked during login inner 2060
This commit is contained in:
@@ -190,6 +190,7 @@ public final class SystemConfig {
|
||||
|
||||
private boolean closeHeartBeatRecord = false;
|
||||
|
||||
private int enableCheckSchema = 1;
|
||||
public int getSamplingRate() {
|
||||
return samplingRate;
|
||||
}
|
||||
@@ -1393,6 +1394,18 @@ public final class SystemConfig {
|
||||
routePenetrationRules = sqlPenetrationRegexesTmp;
|
||||
}
|
||||
|
||||
public int getEnableCheckSchema() {
|
||||
return enableCheckSchema;
|
||||
}
|
||||
|
||||
public void setEnableCheckSchema(int enableCheckSchema) {
|
||||
if (enableCheckSchema >= 0 && enableCheckSchema <= 1) {
|
||||
this.enableCheckSchema = enableCheckSchema;
|
||||
} else if (this.problemReporter != null) {
|
||||
problemReporter.warn(String.format(WARNING_FORMAT, "enableCheckSchema", enableCheckSchema, this.enableCheckSchema));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SystemConfig [" +
|
||||
@@ -1491,6 +1504,7 @@ public final class SystemConfig {
|
||||
", closeHeartBeatRecord=" + closeHeartBeatRecord +
|
||||
", enableRoutePenetration=" + enableRoutePenetration +
|
||||
", routePenetrationRules='" + routePenetrationRules + '\'' +
|
||||
", enableCheckSchema=" + enableCheckSchema +
|
||||
"]";
|
||||
}
|
||||
|
||||
|
||||
@@ -7,17 +7,15 @@ package com.actiontech.dble.config.model.user;
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.config.ErrorCode;
|
||||
import com.actiontech.dble.config.model.SystemConfig;
|
||||
import com.actiontech.dble.services.mysqlauthenticate.MysqlDatabaseHandler;
|
||||
import com.actiontech.dble.util.StringUtil;
|
||||
import com.alibaba.druid.wall.WallProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class RwSplitUserConfig extends ServerUserConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RwSplitUserConfig.class);
|
||||
private final String dbGroup;
|
||||
|
||||
public RwSplitUserConfig(UserConfig user, String tenant, WallProvider blacklist, String dbGroup) {
|
||||
@@ -40,21 +38,17 @@ public class RwSplitUserConfig extends ServerUserConfig {
|
||||
if (schema == null) {
|
||||
return 0;
|
||||
}
|
||||
if (SystemConfig.getInstance().getEnableCheckSchema() == 0) {
|
||||
return 0;
|
||||
}
|
||||
boolean exist;
|
||||
LOGGER.info("start checkSchema");
|
||||
Set<String> schemas = new MysqlDatabaseHandler(DbleServer.getInstance().getConfig().getDbGroups()).execute(dbGroup);
|
||||
LOGGER.info("checkSchema schemas size is {}, schemas content is {}, current schema is {} ", schemas.size(), schemas, schema);
|
||||
if (DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
|
||||
Optional<String> result = schemas.stream().filter(item -> StringUtil.equals(item.toLowerCase(), schema.toLowerCase())).findFirst();
|
||||
exist = result.isPresent();
|
||||
} else {
|
||||
exist = schemas.contains(schema);
|
||||
}
|
||||
if (!exist) {
|
||||
LOGGER.warn("current schemas size is {}, schemas content is {}, current schema is {} ", schemas.size(), schemas, schema);
|
||||
LOGGER.warn("dble lowerCase is {}", DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames());
|
||||
}
|
||||
LOGGER.info("end checkSchema");
|
||||
return exist ? 0 : ErrorCode.ER_BAD_DB_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -159,15 +159,4 @@ public class ChangeUserPacket extends MySQLPacket {
|
||||
return tenant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ChangeUserPacket{" +
|
||||
"clientFlags=" + clientFlags +
|
||||
", charsetIndex=" + charsetIndex +
|
||||
", user='" + user + '\'' +
|
||||
", database='" + database + '\'' +
|
||||
", authPlugin='" + authPlugin + '\'' +
|
||||
", tenant='" + tenant + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ package com.actiontech.dble.services.mysqlauthenticate;
|
||||
import com.actiontech.dble.backend.datasource.PhysicalDbGroup;
|
||||
import com.actiontech.dble.backend.datasource.PhysicalDbInstance;
|
||||
import com.actiontech.dble.sqlengine.*;
|
||||
import com.actiontech.dble.util.TraceUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -72,7 +71,6 @@ public class MysqlDatabaseHandler {
|
||||
if (dbGroup != null) {
|
||||
ds = dbGroup.rwSelect(null, false);
|
||||
}
|
||||
LOGGER.info("current ds is {}", ds);
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("select dbInstance error", e);
|
||||
}
|
||||
@@ -113,16 +111,12 @@ public class MysqlDatabaseHandler {
|
||||
|
||||
@Override
|
||||
public void onResult(SQLQueryResult<List<Map<String, String>>> result) {
|
||||
LOGGER.info("current result size is {}, result is {}, isSuc {}", result.getResult().size(), result.getResult(), result.isSuccess());
|
||||
if (result.isSuccess()) {
|
||||
List<Map<String, String>> rows = result.getResult();
|
||||
for (Map<String, String> row : rows) {
|
||||
String databaseName = row.get(mysqlShowDataBasesCol);
|
||||
databases.add(databaseName);
|
||||
}
|
||||
LOGGER.info("current databases size is {}, databases is {}", databases.size(), databases);
|
||||
} else {
|
||||
TraceUtil.print();
|
||||
}
|
||||
handleFinished();
|
||||
}
|
||||
|
||||
@@ -18,16 +18,12 @@ import com.actiontech.dble.services.mysqlauthenticate.PluginName;
|
||||
import com.actiontech.dble.services.mysqlauthenticate.SecurityUtil;
|
||||
import com.actiontech.dble.singleton.FrontendUserManager;
|
||||
import com.actiontech.dble.util.IPAddressUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Set;
|
||||
|
||||
public final class AuthUtil {
|
||||
protected static final Logger LOGGER = LoggerFactory.getLogger(AuthUtil.class);
|
||||
|
||||
private AuthUtil() {
|
||||
}
|
||||
|
||||
@@ -56,7 +52,6 @@ public final class AuthUtil {
|
||||
}
|
||||
// check schema
|
||||
final String schema = authPacket.getDatabase();
|
||||
LOGGER.info("frontConn is {}, schema is {}", fconn, schema);
|
||||
switch (userConfig.checkSchema(schema)) {
|
||||
case ErrorCode.ER_BAD_DB_ERROR:
|
||||
return new AuthResultInfo("Unknown database '" + schema + "'");
|
||||
@@ -99,7 +94,6 @@ public final class AuthUtil {
|
||||
}
|
||||
// check schema
|
||||
final String schema = changeUserPacket.getDatabase();
|
||||
LOGGER.info("frontConn is {}, schema is {} user is {}", fconn, schema, changeUserPacket);
|
||||
switch (userConfig.checkSchema(schema)) {
|
||||
case ErrorCode.ER_BAD_DB_ERROR:
|
||||
return new AuthResultInfo("Unknown database '" + schema + "'");
|
||||
|
||||
@@ -28,7 +28,10 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
@@ -200,7 +203,6 @@ public class MySQLResponseService extends BackendService {
|
||||
if (protocolResponseHandler != defaultResponseHandler) {
|
||||
protocolResponseHandler = defaultResponseHandler;
|
||||
}
|
||||
LOGGER.info("sqySQL is {}, query is {}, conn is {}", Optional.ofNullable(synSQL).orElse(new StringBuilder("null")), query, connection);
|
||||
synAndDoExecute(synSQL, rrn.getStatement(), connection.getCharsetName());
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +135,7 @@ public final class SystemParams {
|
||||
readOnlyParams.add(new ParamInfo("closeHeartBeatRecord", sysConfig.isCloseHeartBeatRecord() + "", "close heartbeat record. if closed, `show @@dbinstance.synstatus`,`show @@dbinstance.syndetail`,`show @@heartbeat.detail` will be empty and `show @@heartbeat`'s EXECUTE_TIME will be '-' .The default value is false"));
|
||||
readOnlyParams.add(new ParamInfo("enableRoutePenetration", sysConfig.isEnableRoutePenetration() + "", "Whether enable route penetration"));
|
||||
readOnlyParams.add(new ParamInfo("routePenetrationRules", sysConfig.getRoutePenetrationRules() + "", "The config of route penetration"));
|
||||
readOnlyParams.add(new ParamInfo("enableCheckSchema", sysConfig.getEnableCheckSchema() + "", "Whether enable check schema, default value is 1(on)"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package com.actiontech.dble.sqlengine;
|
||||
|
||||
import com.actiontech.dble.util.TraceUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -34,9 +33,6 @@ public class MultiRowSQLQueryResultHandler extends OneRawSQLQueryResultHandler {
|
||||
|
||||
@Override
|
||||
public void finished(String shardingNode, boolean failed) {
|
||||
if (failed) {
|
||||
TraceUtil.print();
|
||||
}
|
||||
SQLQueryResult<List<Map<String, String>>> queryResult =
|
||||
new SQLQueryResult<>(this.resultRows, !failed, this.resultRows.isEmpty());
|
||||
if (callback != null)
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.actiontech.dble.route.RouteResultsetNode;
|
||||
import com.actiontech.dble.server.parser.ServerParse;
|
||||
import com.actiontech.dble.services.mysqlsharding.MySQLResponseService;
|
||||
import com.actiontech.dble.singleton.TraceManager;
|
||||
import com.actiontech.dble.util.TraceUtil;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -97,7 +96,6 @@ public class SQLJob implements ResponseHandler, Runnable, Cloneable {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("con query sql:" + sql + " to con:" + conn);
|
||||
}
|
||||
LOGGER.info("con query sql:" + sql + " to con:" + conn);
|
||||
conn.getBackendService().setResponseHandler(this);
|
||||
conn.getBackendService().setComplexQuery(true);
|
||||
TraceManager.TraceObject traceObject = TraceManager.serviceTrace(conn.getBackendService(), "sql-job-send-command");
|
||||
@@ -122,8 +120,6 @@ public class SQLJob implements ResponseHandler, Runnable, Cloneable {
|
||||
jobHandler.finished(shardingNode == null ? schema : shardingNode, failed);
|
||||
return true;
|
||||
}
|
||||
LOGGER.warn("[doFinished] sql is {}, conn is {}", sql, connection);
|
||||
TraceUtil.print();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -165,7 +161,6 @@ public class SQLJob implements ResponseHandler, Runnable, Cloneable {
|
||||
|
||||
@Override
|
||||
public void okResponse(byte[] ok, AbstractService service) {
|
||||
LOGGER.info("[okResponse] sql is {}, sync is {}, service is {}, conn is {}", sql, ((MySQLResponseService) service).syncAndExecute(), service, connection);
|
||||
if (((MySQLResponseService) service).syncAndExecute()) {
|
||||
if (testXid) {
|
||||
service.getConnection().businessClose("test xid existence");
|
||||
@@ -174,13 +169,11 @@ public class SQLJob implements ResponseHandler, Runnable, Cloneable {
|
||||
}
|
||||
doFinished(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fieldEofResponse(byte[] header, List<byte[]> fields, List<FieldPacket> fieldPackets, byte[] eof,
|
||||
boolean isLeft, AbstractService service) {
|
||||
LOGGER.info("[fieldEofResponse] sql is {}, service is {}, conn is {}", sql, service, connection);
|
||||
jobHandler.onHeader(fields);
|
||||
|
||||
}
|
||||
@@ -193,14 +186,12 @@ public class SQLJob implements ResponseHandler, Runnable, Cloneable {
|
||||
|
||||
@Override
|
||||
public void rowEofResponse(byte[] eof, boolean isLeft, AbstractService service) {
|
||||
LOGGER.info("[rowEofResponse] sql is {}, service is {}, conn is {}", sql, service, connection);
|
||||
((MySQLResponseService) service).release();
|
||||
doFinished(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionClose(AbstractService service, String reason) {
|
||||
LOGGER.warn("connectionClose sql {}, reason is {}, service is {}", sql, reason, service);
|
||||
doFinished(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.actiontech.dble.util;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class TraceUtil {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TraceUtil.class);
|
||||
|
||||
private TraceUtil() {
|
||||
}
|
||||
|
||||
public static void print() {
|
||||
LOGGER.warn(printStackTrace());
|
||||
}
|
||||
|
||||
public static synchronized String printStackTrace() {
|
||||
Throwable throwable = new Throwable();
|
||||
StackTraceElement[] stackElements = throwable.getStackTrace();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line = "\r\n";
|
||||
if (Objects.nonNull(stackElements)) {
|
||||
sb.append("start stack trace").append(line);
|
||||
for (int i = 0; i < stackElements.length; i++) {
|
||||
sb.append(stackElements[i].getClassName());
|
||||
sb.append(".").append(stackElements[i].getMethodName());
|
||||
sb.append("(").append(stackElements[i].getFileName()).append(":");
|
||||
sb.append(stackElements[i].getLineNumber() + ")").append(line);
|
||||
}
|
||||
sb.append("end stack trace").append(line);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user