Search in sources :

Example 11 with MycatConfig

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;
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) SchemaConfig(io.mycat.config.model.SchemaConfig) MycatCluster(io.mycat.config.MycatCluster) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) MycatConfig(io.mycat.config.MycatConfig) UserConfig(io.mycat.config.model.UserConfig) FirewallConfig(io.mycat.config.model.FirewallConfig)

Example 12 with MycatConfig

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);
    }
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) RouteResultsetNode(io.mycat.route.RouteResultsetNode) MycatConfig(io.mycat.config.MycatConfig) IOException(java.io.IOException) ConfigException(io.mycat.config.util.ConfigException)

Example 13 with MycatConfig

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);
            }
        }
    }
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) BackendConnection(io.mycat.backend.BackendConnection) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RouteResultsetNode(io.mycat.route.RouteResultsetNode) MycatConfig(io.mycat.config.MycatConfig)

Example 14 with MycatConfig

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;
                    }
                }
            }
        }
    }
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) MySQLConsistencyChecker(io.mycat.backend.heartbeat.MySQLConsistencyChecker) PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) MySQLDataSource(io.mycat.backend.mysql.nio.MySQLDataSource) TableConfig(io.mycat.config.model.TableConfig) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) ArrayList(java.util.ArrayList) List(java.util.List) MycatConfig(io.mycat.config.MycatConfig)

Example 15 with MycatConfig

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);
                    }
                }
            }
        }
    }
}
Also used : SchemaConfig(io.mycat.config.model.SchemaConfig) TableConfig(io.mycat.config.model.TableConfig) MycatConfig(io.mycat.config.MycatConfig)

Aggregations

MycatConfig (io.mycat.config.MycatConfig)32 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)15 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)10 RowDataPacket (io.mycat.net.mysql.RowDataPacket)10 PhysicalDatasource (io.mycat.backend.datasource.PhysicalDatasource)9 SchemaConfig (io.mycat.config.model.SchemaConfig)9 LinkedList (java.util.LinkedList)8 RouteResultsetNode (io.mycat.route.RouteResultsetNode)7 BackendConnection (io.mycat.backend.BackendConnection)6 DBHeartbeat (io.mycat.backend.heartbeat.DBHeartbeat)5 UserConfig (io.mycat.config.model.UserConfig)5 MycatCluster (io.mycat.config.MycatCluster)4 IOException (java.io.IOException)4 TableConfig (io.mycat.config.model.TableConfig)3 EOFPacket (io.mycat.net.mysql.EOFPacket)3 FieldPacket (io.mycat.net.mysql.FieldPacket)3 DataSourceSyncRecorder (io.mycat.statistic.DataSourceSyncRecorder)3 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 TreeSet (java.util.TreeSet)3