use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class RollbackConfig method rollback.
public static void rollback() throws Exception {
ServerConfig conf = DbleServer.getInstance().getConfig();
Map<String, PhysicalDBPool> dataHosts = conf.getBackupDataHosts();
Map<String, UserConfig> users = conf.getBackupUsers();
Map<String, SchemaConfig> schemas = conf.getBackupSchemas();
Map<String, PhysicalDBNode> dataNodes = conf.getBackupDataNodes();
FirewallConfig firewall = conf.getBackupFirewall();
Map<ERTable, Set<ERTable>> erRelations = conf.getBackupErRelations();
boolean backDataHostWithoutWR = conf.backDataHostWithoutWR();
if (conf.canRollback()) {
conf.rollback(users, schemas, dataNodes, dataHosts, erRelations, firewall, backDataHostWithoutWR);
} else if (conf.canRollbackAll()) {
boolean rollbackStatus = true;
String errorMsg = null;
for (PhysicalDBPool dn : dataHosts.values()) {
dn.init(dn.getActiveIndex());
if (!dn.isInitSuccess()) {
rollbackStatus = false;
errorMsg = "dataHost[" + dn.getHostName() + "] inited failure";
break;
}
}
// INIT FAILED
if (!rollbackStatus) {
for (PhysicalDBPool dn : dataHosts.values()) {
dn.clearDataSources("rollbackup config");
dn.stopHeartbeat();
}
throw new Exception(errorMsg);
}
final Map<String, PhysicalDBPool> cNodes = conf.getDataHosts();
// apply
conf.rollback(users, schemas, dataNodes, dataHosts, erRelations, firewall, backDataHostWithoutWR);
// stop old resource heartbeat
for (PhysicalDBPool dn : cNodes.values()) {
dn.clearDataSources("clear old config ");
dn.stopHeartbeat();
}
AlarmAppender.rollbackConfig();
} else {
throw new Exception("there is no old version");
}
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DruidUpdateParserTest method throwExceptionParse.
public void throwExceptionParse(String sql, boolean throwException) throws NoSuchMethodException {
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement sqlStatement = statementList.get(0);
MySqlUpdateStatement update = (MySqlUpdateStatement) sqlStatement;
SchemaConfig schemaConfig = mock(SchemaConfig.class);
Map<String, TableConfig> tables = mock(Map.class);
TableConfig tableConfig = mock(TableConfig.class);
String tableName = "hotnews";
when((schemaConfig).getTables()).thenReturn(tables);
when(tables.get(tableName)).thenReturn(tableConfig);
when(tableConfig.getParentTC()).thenReturn(null);
RouteResultset routeResultset = new RouteResultset(sql, 11);
Class c = DruidUpdateParser.class;
Method method = c.getDeclaredMethod("confirmShardColumnNotUpdated", new Class[] { SQLUpdateStatement.class, SchemaConfig.class, String.class, String.class, String.class, RouteResultset.class });
method.setAccessible(true);
try {
method.invoke(c.newInstance(), update, schemaConfig, tableName, "ID", "", routeResultset);
if (throwException) {
System.out.println("Not passed without exception is not correct");
Assert.assertTrue(false);
} else {
System.out.println("Passed without exception. Maybe the partition key exists in update statement,but not update in fact");
Assert.assertTrue(true);
}
} catch (Exception e) {
if (throwException) {
System.out.println(e.getCause().getClass());
Assert.assertTrue(e.getCause() instanceof SQLNonTransientException);
System.out.println("SQLNonTransientException is expected");
} else {
System.out.println("need checked");
Assert.assertTrue(false);
}
}
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class ExplainHandler method getRouteResultset.
private static RouteResultset getRouteResultset(ServerConnection c, String stmt) {
String db = c.getSchema();
int sqlType = ServerParse.parse(stmt) & 0xff;
if (db == null) {
// TODO: EXPLAIN SCHEMA.TABLE
c.writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
return null;
}
SchemaConfig schema = DbleServer.getInstance().getConfig().getSchemas().get(db);
if (schema == null) {
c.writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '" + db + "'");
return null;
}
try {
if (ServerParse.INSERT == sqlType && isInsertSeq(c, stmt, schema)) {
c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, "insert sql using sequence,the explain result depends by sequence");
return null;
}
return DbleServer.getInstance().getRouterService().route(schema, sqlType, stmt, c);
} catch (Exception e) {
if (e instanceof SQLException && !(e instanceof SQLNonTransientException)) {
SQLException sqlException = (SQLException) e;
StringBuilder s = new StringBuilder();
LOGGER.info(s.append(c).append(stmt).toString() + " error:" + sqlException);
String msg = sqlException.getMessage();
c.writeErrMessage(sqlException.getErrorCode(), msg == null ? sqlException.getClass().getSimpleName() : msg);
return null;
} else {
StringBuilder s = new StringBuilder();
LOGGER.info(s.append(c).append(stmt).toString() + " error:" + e);
String msg = e.getMessage();
c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);
return null;
}
}
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class ServerConnection method routeSQL.
public RouteResultset routeSQL(String sql, int type) {
String db = this.schema;
if (db == null) {
writeErrMessage(ErrorCode.ERR_BAD_LOGICDB, "No Database selected");
return null;
}
SchemaConfig schema = DbleServer.getInstance().getConfig().getSchemas().get(db);
if (schema == null) {
writeErrMessage(ErrorCode.ERR_BAD_LOGICDB, "Unknown Database '" + db + "'");
return null;
}
RouteResultset rrs;
try {
rrs = DbleServer.getInstance().getRouterService().route(schema, type, sql, this);
} catch (Exception e) {
executeException(e, sql);
return null;
}
return rrs;
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class ServerConnection method execute.
public void execute(String sql, int type) {
if (this.isClosed()) {
LOGGER.info("ignore execute ,server connection is closed " + this);
return;
}
if (txInterrupted) {
writeErrMessage(ErrorCode.ER_YES, txInterruptMsg);
return;
}
String db = this.schema;
SchemaConfig schemaConfig = null;
if (db != null) {
schemaConfig = DbleServer.getInstance().getConfig().getSchemas().get(db);
if (schemaConfig == null) {
writeErrMessage(ErrorCode.ERR_BAD_LOGICDB, "Unknown Database '" + db + "'");
return;
}
}
routeEndExecuteSQL(sql, type, schemaConfig);
}
Aggregations