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