Search in sources :

Example 16 with MycatConfig

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

the class ShowMyCATCluster method getRows.

private static List<RowDataPacket> getRows(ServerConnection c) {
    List<RowDataPacket> rows = new LinkedList<RowDataPacket>();
    MycatConfig config = MycatServer.getInstance().getConfig();
    MycatCluster cluster = config.getCluster();
    Map<String, SchemaConfig> schemas = config.getSchemas();
    SchemaConfig schema = (c.getSchema() == null) ? null : schemas.get(c.getSchema());
    // 如果没有指定schema或者schema为null,则使用全部集群。
    if (schema == null) {
        Map<String, MycatNode> nodes = cluster.getNodes();
        for (MycatNode n : nodes.values()) {
            if (n != null && n.isOnline()) {
                rows.add(getRow(n, c.getCharset()));
            }
        }
    } else {
        Map<String, MycatNode> nodes = cluster.getNodes();
        for (MycatNode n : nodes.values()) {
            if (n != null && n.isOnline()) {
                rows.add(getRow(n, c.getCharset()));
            }
        }
    }
    if (rows.size() == 0) {
        alarm.error(Alarms.CLUSTER_EMPTY + c.toString());
    }
    return rows;
}
Also used : SchemaConfig(io.mycat.config.model.SchemaConfig) MycatNode(io.mycat.config.MycatNode) RowDataPacket(io.mycat.net.mysql.RowDataPacket) MycatCluster(io.mycat.config.MycatCluster) MycatConfig(io.mycat.config.MycatConfig) LinkedList(java.util.LinkedList)

Example 17 with MycatConfig

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

the class DistributedSequenceHandlerTest method testFailOver.

/**
     * 测试ZK容灾
     *
     * @throws Exception
     */
@Test
public void testFailOver() {
    Set<Long> idSet = new HashSet<>();
    try {
        int leader = failLeader(17);
        System.out.println("***断掉一个leader节点后(curator会抛对应的异常断链异常,不用在意)***:");
        for (int i = 0; i < 16; i++) {
            if (i == leader) {
                System.out.println("Node [" + i + "] used to be leader");
                continue;
            }
            distributedSequenceHandler[i].nextId("");
            System.out.println("Node [" + i + "]is leader:" + distributedSequenceHandler[i].getLeaderSelector().hasLeadership());
            System.out.println(" InstanceID:" + distributedSequenceHandler[i].getInstanceId());
            idSet.add(distributedSequenceHandler[i].getInstanceId());
        }
        Assert.assertEquals(idSet.size(), 15);
        idSet = new HashSet<>();
        int leader2 = failLeader(leader);
        System.out.println("***断掉两个leader节点后(curator会抛对应的异常断链异常,不用在意)***:");
        for (int i = 0; i < 16; i++) {
            if (i == leader || i == leader2) {
                System.out.println("Node [" + i + " used to be leader");
                continue;
            }
            distributedSequenceHandler[i].nextId("");
            System.out.println("Node [" + i + "]is leader:" + distributedSequenceHandler[i].getLeaderSelector().hasLeadership());
            System.out.println(" InstanceID:" + distributedSequenceHandler[i].getInstanceId());
            idSet.add(distributedSequenceHandler[i].getInstanceId());
        }
        Assert.assertEquals(idSet.size(), 14);
        idSet = new HashSet<>();
        MycatConfig mycatConfig = new MycatConfig();
        distributedSequenceHandler[leader] = new DistributedSequenceHandler(mycatConfig.getSystem());
        distributedSequenceHandler[leader].initializeZK(testingServer.getConnectString());
        distributedSequenceHandler[leader].nextId("");
        distributedSequenceHandler[leader2] = new DistributedSequenceHandler(mycatConfig.getSystem());
        distributedSequenceHandler[leader2].initializeZK(testingServer.getConnectString());
        distributedSequenceHandler[leader2].nextId("");
        System.out.println("新加入两个节点后");
        for (int i = 0; i < 16; i++) {
            System.out.println("Node [" + i + "]is leader:" + distributedSequenceHandler[i].getLeaderSelector().hasLeadership());
            System.out.println(" InstanceID:" + distributedSequenceHandler[i].getInstanceId());
            idSet.add(distributedSequenceHandler[i].getInstanceId());
        }
    } catch (Exception e) {
    } finally {
        Assert.assertEquals(idSet.size(), 16);
    }
}
Also used : DistributedSequenceHandler(io.mycat.route.sequence.handler.DistributedSequenceHandler) MycatConfig(io.mycat.config.MycatConfig) IOException(java.io.IOException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 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, ArrayList<String> dataNodes) {
    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);
            mysqlDN.getConnection(mysqlDN.getDatabase(), true, node, this, node);
        //				mysqlDN.getConnection(mysqlDN.getDatabase(), true,
        //						new RouteResultsetNode(dn, ServerParse.SELECT, sql),
        //						this, dn);
        } catch (Exception e) {
            LOGGER.warn("get connection err " + e);
        }
        try {
            Thread.sleep(200);
        } catch (InterruptedException 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) RouteResultsetNode(io.mycat.route.RouteResultsetNode) MycatConfig(io.mycat.config.MycatConfig) IOException(java.io.IOException) CachePool(io.mycat.cache.CachePool)

Example 19 with MycatConfig

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

the class FileSystemRepository method init.

@Override
public void init() {
    //        ConfigProperties configProperties = Configuration.getConfigProperties();
    //        String baseDir = configProperties.getLogBaseDir();
    //        String baseName = configProperties.getLogBaseName();
    MycatConfig mycatconfig = MycatServer.getInstance().getConfig();
    SystemConfig systemConfig = mycatconfig.getSystem();
    String baseDir = systemConfig.getXARecoveryLogBaseDir();
    String baseName = systemConfig.getXARecoveryLogBaseName();
    logger.debug("baseDir " + baseDir);
    logger.debug("baseName " + baseName);
    //Judge whether exist the basedir
    createBaseDir(baseDir);
    file = new VersionedFile(baseDir, baseName, ".log");
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) MycatConfig(io.mycat.config.MycatConfig)

Example 20 with MycatConfig

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

the class FirewallConfig method canConnect.

public boolean canConnect(String host, String user) {
    if (whitehost == null || whitehost.size() == 0) {
        MycatConfig config = MycatServer.getInstance().getConfig();
        Map<String, UserConfig> users = config.getUsers();
        return users.containsKey(user);
    } else {
        List<UserConfig> list = whitehost.get(host);
        if (list == null) {
            return false;
        }
        for (UserConfig userConfig : list) {
            if (userConfig.getName().equals(user)) {
                return true;
            }
        }
    }
    return false;
}
Also used : 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