use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class NonBlockingSession method freshConn.
public MySQLConnection freshConn(MySQLConnection errConn, ResponseHandler queryHandler) {
for (final RouteResultsetNode node : this.getTargetKeys()) {
final MySQLConnection mysqlCon = (MySQLConnection) this.getTarget(node);
if (errConn.equals(mysqlCon)) {
ServerConfig conf = DbleServer.getInstance().getConfig();
PhysicalDBNode dn = conf.getDataNodes().get(node.getName());
try {
MySQLConnection newConn = (MySQLConnection) dn.getConnection(dn.getDatabase(), errConn.isAutocommit(), false);
newConn.setXaStatus(errConn.getXaStatus());
if (!newConn.setResponseHandler(queryHandler)) {
return errConn;
}
this.bindConnection(node, newConn);
return newConn;
} catch (Exception e) {
return errConn;
}
}
}
return errConn;
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class FetchMySQLSequenceHandler method execute.
public void execute(SequenceVal seqVal) {
ServerConfig conf = DbleServer.getInstance().getConfig();
PhysicalDBNode mysqlDN = conf.getDataNodes().get(seqVal.dataNode);
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("execute in data node " + seqVal.dataNode + " for fetch sequence sql " + seqVal.sql);
}
// change Select mode to Update mode. Make sure the query send to the write host
mysqlDN.getConnection(mysqlDN.getDatabase(), true, true, new RouteResultsetNode(seqVal.dataNode, ServerParse.UPDATE, seqVal.sql), this, seqVal);
} catch (Exception e) {
LOGGER.info("get connection err " + e);
}
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class DruidSelectParser method tryRouteSingleTable.
private void tryRouteSingleTable(SchemaConfig schema, RouteResultset rrs, LayerCachePool cachePool) throws SQLException {
if (rrs.isFinishedRoute()) {
return;
}
SortedSet<RouteResultsetNode> nodeSet = new TreeSet<>();
String table = ctx.getTables().get(0);
if (RouterUtil.isNoSharding(schema, table)) {
RouterUtil.routeToSingleNode(rrs, schema.getDataNode());
return;
}
for (RouteCalculateUnit unit : ctx.getRouteCalculateUnits()) {
RouteResultset rrsTmp = RouterUtil.tryRouteForOneTable(schema, unit, table, rrs, true, cachePool);
if (rrsTmp != null && rrsTmp.getNodes() != null) {
Collections.addAll(nodeSet, rrsTmp.getNodes());
if (rrsTmp.isGlobalTable()) {
break;
}
}
}
if (nodeSet.size() == 0) {
String msg = " find no Route:" + rrs.getStatement();
LOGGER.info(msg);
throw new SQLNonTransientException(msg);
}
RouteResultsetNode[] nodes = new RouteResultsetNode[nodeSet.size()];
int i = 0;
for (RouteResultsetNode aNodeSet : nodeSet) {
nodes[i] = aNodeSet;
i++;
}
rrs.setNodes(nodes);
rrs.setFinishedRoute(true);
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class AbstractCommitNodesHandler method commit.
@Override
public void commit() {
final int initCount = session.getTargetCount();
lock.lock();
try {
reset(initCount);
} finally {
lock.unlock();
}
int position = 0;
// then the XA transaction will be not killed, if killed ,then we will not commit
if (session.getXaState() != null && session.getXaState() == TxState.TX_ENDED_STATE) {
if (!session.cancelableStatusSet(NonBlockingSession.CANCEL_STATUS_COMMITTING)) {
return;
}
}
try {
sendFinishedFlag = false;
for (RouteResultsetNode rrn : session.getTargetKeys()) {
final BackendConnection conn = session.getTarget(rrn);
conn.setResponseHandler(this);
if (!executeCommit((MySQLConnection) conn, position++)) {
break;
}
}
} finally {
lockForErrorHandle.lock();
try {
sendFinishedFlag = true;
sendFinished.signalAll();
} finally {
lockForErrorHandle.unlock();
}
}
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class NormalRollbackNodesHandler method rollback.
public void rollback() {
final int initCount = session.getTargetCount();
lock.lock();
try {
reset(initCount);
} finally {
lock.unlock();
}
int position = 0;
for (final RouteResultsetNode node : session.getTargetKeys()) {
final BackendConnection conn = session.getTarget(node);
if (conn.isClosed()) {
lock.lock();
try {
nodeCount--;
} finally {
lock.unlock();
}
continue;
}
position++;
conn.setResponseHandler(this);
conn.rollback();
}
if (position == 0) {
if (sendData == null) {
sendData = OkPacket.OK;
}
cleanAndFeedback();
}
}
Aggregations