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;
}
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);
}
}
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;
}
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");
}
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;
}
Aggregations