use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class FetchStoreNodeOfChildTableHandler method execute.
public String execute(String schema, ArrayList<String> dataNodes) {
String key = schema + ":" + sql;
CachePool cache = DbleServer.getInstance().getCacheService().getCachePool("ER_SQL2PARENTID");
if (cache != null) {
String cacheResult = (String) cache.get(key);
if (cacheResult != null) {
return cacheResult;
}
}
int totalCount = dataNodes.size();
LOGGER.debug("find child node with sql:" + sql);
for (String dn : dataNodes) {
if (!LOGGER.isDebugEnabled()) {
// no early return when debug
if (dataNode != null) {
LOGGER.debug(" found return ");
return dataNode;
}
}
PhysicalDBNode mysqlDN = DbleServer.getInstance().getConfig().getDataNodes().get(dn);
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("execute in data_node " + dn);
}
RouteResultsetNode node = new RouteResultsetNode(dn, ServerParse.SELECT, sql);
// get child node from master
node.setRunOnSlave(false);
BackendConnection conn = session.getTarget(node);
if (session.tryExistsCon(conn, node)) {
if (session.closed()) {
session.clearResources(true);
return null;
}
conn.setResponseHandler(this);
conn.setSession(session);
((MySQLConnection) conn).setComplexQuery(true);
conn.execute(node, session.getSource(), isAutoCommit());
} else {
mysqlDN.getConnection(mysqlDN.getDatabase(), session.getSource().isTxStart(), session.getSource().isAutocommit(), node, this, node);
}
} catch (Exception e) {
LOGGER.info("get connection err " + e);
}
}
lock.lock();
try {
while (dataNode == null) {
try {
result.await(50, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
break;
}
if (dataNode != null || finished.get() >= totalCount) {
break;
}
}
} finally {
lock.unlock();
}
if (!LOGGER.isDebugEnabled()) {
// no cached when debug
if (dataNode != null && cache != null) {
cache.putIfAbsent(key, dataNode);
}
}
return dataNode;
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class MultiNodeDdlHandler method execute.
public void execute() throws Exception {
lock.lock();
try {
this.reset(rrs.getNodes().length);
} finally {
lock.unlock();
}
LOGGER.debug("rrs.getRunOnSlave()-" + rrs.getRunOnSlave());
StringBuilder sb = new StringBuilder();
for (final RouteResultsetNode node : rrs.getNodes()) {
if (node.isModifySQL()) {
sb.append("[").append(node.getName()).append("]").append(node.getStatement()).append(";\n");
}
}
if (sb.length() > 0) {
TxnLogHelper.putTxnLog(session.getSource(), sb.toString());
}
for (final RouteResultsetNode node : rrs.getNodes()) {
BackendConnection conn = session.getTarget(node);
if (session.tryExistsCon(conn, node)) {
node.setRunOnSlave(rrs.getRunOnSlave());
innerExecute(conn, node);
} else {
// create new connection
node.setRunOnSlave(rrs.getRunOnSlave());
PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(node.getName());
dn.getConnection(dn.getDatabase(), true, sessionAutocommit, node, this, node);
}
}
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class MySQLConnection method query.
/**
* by wuzh ,execute a query and ignore transaction settings for performance
*/
public void query(String query) {
RouteResultsetNode rrn = new RouteResultsetNode("default", ServerParse.SELECT, query);
synAndDoExecute(null, rrn, this.charsetName, this.txIsolation, true, this.getUsrVariables(), this.getSysVariables());
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class NormalAutoRollbackNodesHandler method rollback.
@Override
public void rollback() {
if (errConnection != null && nodes.length == errConnection.size()) {
for (BackendConnection conn : errConnection) {
conn.quit();
}
errConnection.clear();
session.getSource().write(sendData);
return;
}
if (errConnection != null && errConnection.size() > 0) {
for (RouteResultsetNode node : nodes) {
final BackendConnection conn = session.getTarget(node);
if (errConnection.contains(conn)) {
session.getTargetMap().remove(node);
conn.quit();
}
}
errConnection.clear();
}
super.rollback();
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class XAAutoRollbackNodesHandler method rollback.
@Override
public void rollback() {
if (errConnection != null && nodes.length == errConnection.size()) {
for (BackendConnection conn : errConnection) {
conn.quit();
}
errConnection.clear();
session.getSource().write(sendData);
return;
}
if (errConnection != null && errConnection.size() > 0) {
for (RouteResultsetNode node : nodes) {
final BackendConnection conn = session.getTarget(node);
if (errConnection.contains(conn)) {
session.getTargetMap().remove(node);
conn.quit();
}
}
errConnection.clear();
}
super.rollback();
}
Aggregations