Search in sources :

Example 1 with MycatConfig

use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.

the class MycatServer method isUseZkSwitch.

private boolean isUseZkSwitch() {
    MycatConfig mycatConfig = config;
    boolean isUseZkSwitch = mycatConfig.getSystem().isUseZKSwitch();
    String loadZk = ZkConfig.getInstance().getValue(ZkParamCfg.ZK_CFG_FLAG);
    return (isUseZkSwitch && "true".equalsIgnoreCase(loadZk));
}
Also used : MycatConfig(io.mycat.config.MycatConfig)

Example 2 with MycatConfig

use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.

the class MultiNodeQueryHandler method execute.

public void execute() throws Exception {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        this.reset(rrs.getNodes().length);
        this.fieldsReturned = false;
        this.affectedRows = 0L;
        this.insertId = 0L;
    } finally {
        lock.unlock();
    }
    MycatConfig conf = MycatServer.getInstance().getConfig();
    startTime = System.currentTimeMillis();
    LOGGER.debug("rrs.getRunOnSlave()-" + rrs.getRunOnSlave());
    for (final RouteResultsetNode node : rrs.getNodes()) {
        BackendConnection conn = session.getTarget(node);
        if (session.tryExistsCon(conn, node)) {
            LOGGER.debug("node.getRunOnSlave()-" + node.getRunOnSlave());
            // 实现 master/slave注解
            node.setRunOnSlave(rrs.getRunOnSlave());
            LOGGER.debug("node.getRunOnSlave()-" + node.getRunOnSlave());
            _execute(conn, node);
        } else {
            // create new connection
            LOGGER.debug("node.getRunOnSlave()1-" + node.getRunOnSlave());
            // 实现 master/slave注解
            node.setRunOnSlave(rrs.getRunOnSlave());
            LOGGER.debug("node.getRunOnSlave()2-" + node.getRunOnSlave());
            PhysicalDBNode dn = conf.getDataNodes().get(node.getName());
            dn.getConnection(dn.getDatabase(), autocommit, node, this, node);
        // 注意该方法不仅仅是获取连接,获取新连接成功之后,会通过层层回调,最后回调到本类 的connectionAcquired
        // 这是通过 上面方法的 this 参数的层层传递完成的。
        // connectionAcquired 进行执行操作:
        // session.bindConnection(node, conn);
        // _execute(conn, node);
        }
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) BackendConnection(io.mycat.backend.BackendConnection) RouteResultsetNode(io.mycat.route.RouteResultsetNode) MycatConfig(io.mycat.config.MycatConfig)

Example 3 with MycatConfig

use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.

the class SingleNodeHandler method execute.

public void execute() throws Exception {
    startTime = System.currentTimeMillis();
    ServerConnection sc = session.getSource();
    this.isRunning = true;
    this.packetId = 0;
    final BackendConnection conn = session.getTarget(node);
    LOGGER.debug("rrs.getRunOnSlave() " + rrs.getRunOnSlave());
    // 实现 master/slave注解
    node.setRunOnSlave(rrs.getRunOnSlave());
    LOGGER.debug("node.getRunOnSlave() " + node.getRunOnSlave());
    if (session.tryExistsCon(conn, node)) {
        _execute(conn);
    } else {
        // create new connection
        MycatConfig conf = MycatServer.getInstance().getConfig();
        LOGGER.debug("node.getRunOnSlave() " + node.getRunOnSlave());
        // 实现 master/slave注解
        node.setRunOnSlave(rrs.getRunOnSlave());
        LOGGER.debug("node.getRunOnSlave() " + node.getRunOnSlave());
        PhysicalDBNode dn = conf.getDataNodes().get(node.getName());
        dn.getConnection(dn.getDatabase(), sc.isAutocommit(), node, this, node);
    }
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) BackendConnection(io.mycat.backend.BackendConnection) ServerConnection(io.mycat.server.ServerConnection) MycatConfig(io.mycat.config.MycatConfig)

Example 4 with MycatConfig

use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.

the class FetchStoreNodeOfChildTableHandler method execute.

public String execute(String schema, String sql, List<String> dataNodes, ServerConnection sc) {
    String key = schema + ":" + sql;
    CachePool cache = MycatServer.getInstance().getCacheService().getCachePool("ER_SQL2PARENTID");
    String result = (String) cache.get(key);
    if (result != null) {
        return result;
    }
    this.sql = sql;
    int totalCount = dataNodes.size();
    long startTime = System.currentTimeMillis();
    long endTime = startTime + 5 * 60 * 1000L;
    MycatConfig conf = MycatServer.getInstance().getConfig();
    LOGGER.debug("find child node with sql:" + sql);
    for (String dn : dataNodes) {
        if (dataNode != null) {
            return dataNode;
        }
        PhysicalDBNode mysqlDN = conf.getDataNodes().get(dn);
        try {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("execute in datanode " + dn);
            }
            RouteResultsetNode node = new RouteResultsetNode(dn, ServerParse.SELECT, sql);
            // 获取 子表节点,最好走master为好
            node.setRunOnSlave(false);
            /*
				 * fix #1370 默认应该先从已经持有的连接中取连接, 否则可能因为事务隔离性看不到当前事务内更新的数据
				 * Tips: 通过mysqlDN.getConnection获取到的连接不是当前连接
				 *
				 */
            BackendConnection conn = sc.getSession2().getTarget(node);
            if (sc.getSession2().tryExistsCon(conn, node)) {
                _execute(conn, node, sc);
            } else {
                mysqlDN.getConnection(mysqlDN.getDatabase(), sc.isAutocommit(), node, this, node);
            }
        } catch (Exception e) {
            LOGGER.warn("get connection err " + e);
        }
    }
    while (dataNode == null && System.currentTimeMillis() < endTime) {
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            break;
        }
        if (dataNode != null || finished.get() >= totalCount) {
            break;
        }
    }
    if (dataNode != null) {
        cache.putIfAbsent(key, dataNode);
    }
    return dataNode;
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) BackendConnection(io.mycat.backend.BackendConnection) RouteResultsetNode(io.mycat.route.RouteResultsetNode) MycatConfig(io.mycat.config.MycatConfig) IOException(java.io.IOException) CachePool(io.mycat.cache.CachePool)

Example 5 with MycatConfig

use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.

the class LockTablesHandler method execute.

public void execute() throws Exception {
    super.reset(this.rrs.getNodes().length);
    MycatConfig conf = MycatServer.getInstance().getConfig();
    for (final RouteResultsetNode node : rrs.getNodes()) {
        BackendConnection conn = session.getTarget(node);
        if (session.tryExistsCon(conn, node)) {
            _execute(conn, node);
        } else {
            // create new connection
            PhysicalDBNode dn = conf.getDataNodes().get(node.getName());
            dn.getConnection(dn.getDatabase(), autocommit, node, this, node);
        }
    }
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) BackendConnection(io.mycat.backend.BackendConnection) RouteResultsetNode(io.mycat.route.RouteResultsetNode) 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