use of io.mycat.route.RouteResultsetNode in project Mycat-Server by MyCATApache.
the class MySQLConnection method query.
/**
* by wuzh ,execute a query and ignore transaction settings for performance
*
* @param sql
* @throws UnsupportedEncodingException
*/
public void query(String query) throws UnsupportedEncodingException {
RouteResultsetNode rrn = new RouteResultsetNode("default", ServerParse.SELECT, query);
synAndDoExecute(null, rrn, this.charsetIndex, this.txIsolation, true);
}
use of io.mycat.route.RouteResultsetNode in project Mycat-Server by MyCATApache.
the class UnLockTablesHandler method execute.
public void execute() {
Map<RouteResultsetNode, BackendConnection> lockedConns = session.getTargetMap();
Set<RouteResultsetNode> dnSet = lockedConns.keySet();
this.reset(lockedConns.size());
// 客户端直接发送unlock tables命令,由于之前未发送lock tables语句,无法获取后端绑定的连接,此时直接返回OK包
if (lockedConns.size() == 0) {
LOGGER.warn("find no locked backend connection!" + session.getSource());
OkPacket ok = new OkPacket();
ok.packetId = ++packetId;
// unlock table 命令返回MySQL协议包长度为7
ok.packetLength = 7;
ok.serverStatus = session.getSource().isAutocommit() ? 2 : 1;
ok.write(session.getSource());
return;
}
for (RouteResultsetNode dataNode : dnSet) {
RouteResultsetNode node = new RouteResultsetNode(dataNode.getName(), ServerParse.UNLOCK, srcStatement);
BackendConnection conn = lockedConns.get(dataNode);
if (clearIfSessionClosed(session)) {
return;
}
conn.setResponseHandler(this);
try {
conn.execute(node, session.getSource(), autocommit);
} catch (Exception e) {
connectionError(e, conn);
}
}
}
use of io.mycat.route.RouteResultsetNode 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.route.RouteResultsetNode 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);
}
}
}
use of io.mycat.route.RouteResultsetNode in project Mycat-Server by MyCATApache.
the class SwitchPrepareCheckRunner method checkIsInTransation.
private boolean checkIsInTransation(BackendConnection backendConnection) {
if (!taskNode.getSchema().equalsIgnoreCase(backendConnection.getSchema()))
return false;
Object attach = backendConnection.getAttachment();
if (attach instanceof RouteResultsetNode) {
RouteResultsetNode resultsetNode = (RouteResultsetNode) attach;
RouteResultset rrs = resultsetNode.getSource();
for (String table : rrs.getTables()) {
if (table.equalsIgnoreCase(taskNode.getTable())) {
int slot = resultsetNode.getSlot();
if (slot < 0 && resultsetNode.isUpdateSql()) {
return true;
} else if (resultsetNode.isUpdateSql()) {
for (PartitionByCRC32PreSlot.Range range : rangeList) {
if (slot >= range.start && slot <= range.end) {
return true;
}
}
}
}
}
}
return false;
}
Aggregations