use of com.actiontech.dble.backend.datasource.PhysicalDBNode 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.backend.datasource.PhysicalDBNode in project dble by actiontech.
the class NonBlockingSession method kill.
protected void kill() {
AtomicInteger count = new AtomicInteger(0);
Map<RouteResultsetNode, BackendConnection> toKilled = new HashMap<>();
for (Map.Entry<RouteResultsetNode, BackendConnection> entry : target.entrySet()) {
BackendConnection c = entry.getValue();
if (c != null && !c.isDDL()) {
toKilled.put(entry.getKey(), c);
count.incrementAndGet();
} else if (c != null && c.isDDL()) {
// if the sql executing is a ddl,do not kill the query,just close the connection
this.terminate();
return;
}
}
for (Entry<RouteResultsetNode, BackendConnection> en : toKilled.entrySet()) {
KillConnectionHandler kill = new KillConnectionHandler(en.getValue(), this);
ServerConfig conf = DbleServer.getInstance().getConfig();
PhysicalDBNode dn = conf.getDataNodes().get(en.getKey().getName());
try {
dn.getConnectionFromSameSource(en.getValue().getSchema(), true, en.getValue(), kill, en.getKey());
} catch (Exception e) {
LOGGER.info("get killer connection failed for " + en.getKey(), e);
kill.connectionError(e, null);
}
}
}
use of com.actiontech.dble.backend.datasource.PhysicalDBNode in project dble by actiontech.
the class VarsExtractorHandler method execute.
public SystemVariables execute() {
Map.Entry<String, PhysicalDBNode> entry = dataNodes.entrySet().iterator().next();
OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(MYSQL_SHOW_VARIABLES_COLS, new MysqlVarsListener(this));
PhysicalDBNode dn = entry.getValue();
SQLJob sqlJob = new SQLJob(MYSQL_SHOW_VARIABLES, dn.getDatabase(), resultHandler, dn.getDbPool().getSource());
sqlJob.run();
waitDone();
return systemVariables;
}
use of com.actiontech.dble.backend.datasource.PhysicalDBNode in project dble by actiontech.
the class SQLJob method run.
public void run() {
try {
if (ds == null) {
RouteResultsetNode node = new RouteResultsetNode(dataNodeOrDatabase, ServerParse.SELECT, sql);
// create new connection
PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(node.getName());
dn.getConnection(dn.getDatabase(), true, true, node, this, node);
} else {
ds.getConnection(dataNodeOrDatabase, true, this, null);
}
} catch (Exception e) {
LOGGER.info("can't get connection for sql ,error:" + e);
doFinished(true);
}
}
use of com.actiontech.dble.backend.datasource.PhysicalDBNode in project dble by actiontech.
the class ShowTableDataNode method getRows.
private static List<RowDataPacket> getRows(List<String> dataNodes, String charset) {
List<RowDataPacket> list = new ArrayList<>();
int sequence = 0;
for (String dataNode : dataNodes) {
PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(dataNode);
DBHostConfig dbConfig = dn.getDbPool().getSource().getConfig();
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(dn.getName(), charset));
row.add(LongUtil.toBytes(sequence));
row.add(StringUtil.encode(dbConfig.getIp(), charset));
row.add(LongUtil.toBytes(dbConfig.getPort()));
row.add(StringUtil.encode(dn.getDatabase(), charset));
row.add(StringUtil.encode(dbConfig.getUser(), charset));
row.add(StringUtil.encode(dbConfig.getPassword(), charset));
list.add(row);
sequence++;
}
return list;
}
Aggregations