use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.
the class RollbackConfig method rollback.
private static boolean rollback() {
MycatConfig conf = MycatServer.getInstance().getConfig();
Map<String, UserConfig> users = conf.getBackupUsers();
Map<String, SchemaConfig> schemas = conf.getBackupSchemas();
Map<String, PhysicalDBNode> dataNodes = conf.getBackupDataNodes();
Map<String, PhysicalDBPool> dataHosts = conf.getBackupDataHosts();
MycatCluster cluster = conf.getBackupCluster();
FirewallConfig firewall = conf.getBackupFirewall();
// 检查可回滚状态
if (!conf.canRollback()) {
return false;
}
// 如果回滚已经存在的pool
boolean rollbackStatus = true;
Map<String, PhysicalDBPool> cNodes = conf.getDataHosts();
for (PhysicalDBPool dn : dataHosts.values()) {
dn.init(dn.getActivedIndex());
if (!dn.isInitSuccess()) {
rollbackStatus = false;
break;
}
}
// 如果回滚不成功,则清理已初始化的资源。
if (!rollbackStatus) {
for (PhysicalDBPool dn : dataHosts.values()) {
dn.clearDataSources("rollbackup config");
dn.stopHeartbeat();
}
return false;
}
// 应用回滚
conf.rollback(users, schemas, dataNodes, dataHosts, cluster, firewall);
// 处理旧的资源
for (PhysicalDBPool dn : cNodes.values()) {
dn.clearDataSources("clear old config ");
dn.stopHeartbeat();
}
//清理缓存
MycatServer.getInstance().getCacheService().clearCache();
return true;
}
use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.
the class SequenceVal method execute.
public void execute(SequenceVal seqVal) {
MycatConfig conf = MycatServer.getInstance().getConfig();
PhysicalDBNode mysqlDN = conf.getDataNodes().get(seqVal.dataNode);
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("execute in datanode " + seqVal.dataNode + " for fetch sequnce sql " + seqVal.sql);
}
// 修正获取seq的逻辑,在读写分离的情况下只能走写节点。修改Select模式为Update模式。
mysqlDN.getConnection(mysqlDN.getDatabase(), true, new RouteResultsetNode(seqVal.dataNode, ServerParse.UPDATE, seqVal.sql), this, seqVal);
} catch (Exception e) {
LOGGER.warn("get connection err " + e);
}
}
use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.
the class NonBlockingSession method kill.
// public boolean tryExistsCon(final BackendConnection conn,
// RouteResultsetNode node) {
//
// if (conn == null) {
// return false;
// }
// if (!conn.isFromSlaveDB()
// || node.canRunnINReadDB(getSource().isAutocommit())) {
// if (LOGGER.isDebugEnabled()) {
// LOGGER.debug("found connections in session to use " + conn
// + " for " + node);
// }
// conn.setAttachment(node);
// return true;
// } else {
// // slavedb connection and can't use anymore ,release it
// if (LOGGER.isDebugEnabled()) {
// LOGGER.debug("release slave connection,can't be used in trasaction "
// + conn + " for " + node);
// }
// releaseConnection(node, LOGGER.isDebugEnabled(), false);
// }
// return false;
// }
protected void kill() {
boolean hooked = false;
AtomicInteger count = null;
Map<RouteResultsetNode, BackendConnection> killees = null;
for (RouteResultsetNode node : target.keySet()) {
BackendConnection c = target.get(node);
if (c != null) {
if (!hooked) {
hooked = true;
killees = new HashMap<RouteResultsetNode, BackendConnection>();
count = new AtomicInteger(0);
}
killees.put(node, c);
count.incrementAndGet();
}
}
if (hooked) {
for (Entry<RouteResultsetNode, BackendConnection> en : killees.entrySet()) {
KillConnectionHandler kill = new KillConnectionHandler(en.getValue(), this);
MycatConfig conf = MycatServer.getInstance().getConfig();
PhysicalDBNode dn = conf.getDataNodes().get(en.getKey().getName());
try {
dn.getConnectionFromSameSource(null, true, en.getValue(), kill, en.getKey());
} catch (Exception e) {
LOGGER.error("get killer connection failed for " + en.getKey(), e);
kill.connectionError(e, null);
}
}
}
}
use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.
the class GlobalTableUtil method reGetColumnsForTable.
/**
* 重新获得table 的列list
* @param tableName
*/
private static void reGetColumnsForTable(String tableName) {
MycatConfig config = MycatServer.getInstance().getConfig();
if (globalTableMap != null && globalTableMap.get(tableName.toUpperCase()) != null) {
TableConfig tableConfig = globalTableMap.get(tableName.toUpperCase());
if (// consistencyCheck 在运行中
tableConfig == null || isInnerColumnCheckFinished != 1)
return;
String nodeName = tableConfig.getDataNodes().get(0);
Map<String, PhysicalDBNode> map = config.getDataNodes();
for (String k2 : map.keySet()) {
PhysicalDBNode dBnode = map.get(k2);
if (nodeName.equals(dBnode.getName())) {
PhysicalDBPool pool = dBnode.getDbPool();
List<PhysicalDatasource> dsList = (List<PhysicalDatasource>) pool.genAllDataSources();
for (PhysicalDatasource ds : dsList) {
if (ds instanceof MySQLDataSource) {
MySQLDataSource mds = (MySQLDataSource) dsList.get(0);
MySQLConsistencyChecker checker = new MySQLConsistencyChecker(mds, tableConfig.getName());
checker.checkInnerColumnExist();
// 运行一次就行了,不需要像consistencyCheck那样每个db都运行一次
return;
}
}
}
}
}
}
use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.
the class GlobalTableUtil method getGlobalTable.
private static void getGlobalTable() {
MycatConfig config = MycatServer.getInstance().getConfig();
Map<String, SchemaConfig> schemaMap = config.getSchemas();
SchemaConfig schemaMconfig = null;
for (String key : schemaMap.keySet()) {
if (schemaMap.get(key) != null) {
schemaMconfig = schemaMap.get(key);
Map<String, TableConfig> tableMap = schemaMconfig.getTables();
if (tableMap != null) {
for (String k : tableMap.keySet()) {
TableConfig table = tableMap.get(k);
if (table != null && table.isGlobalTable()) {
globalTableMap.put(table.getName().toUpperCase(), table);
}
}
}
}
}
}
Aggregations