Search in sources :

Example 41 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.

the class MultiNodeQueryHandler method rowResponse.

@Override
public boolean rowResponse(final byte[] row, RowDataPacket rowPacketNull, boolean isLeft, BackendConnection conn) {
    if (errorResponse.get()) {
        // conn.close(error);
        return true;
    }
    lock.lock();
    try {
        this.selectRows++;
        RouteResultsetNode rNode = (RouteResultsetNode) conn.getAttachment();
        String dataNode = rNode.getName();
        if (rrs.getLimitSize() >= 0) {
            if (selectRows <= rrs.getLimitStart() || (selectRows > (rrs.getLimitStart() < 0 ? 0 : rrs.getLimitStart()) + rrs.getLimitSize())) {
                return false;
            }
        }
        RowDataPacket rowDataPkg = null;
        // cache primaryKey-> dataNode
        if (primaryKeyIndex != -1) {
            rowDataPkg = new RowDataPacket(fieldCount);
            rowDataPkg.read(row);
            String primaryKey = new String(rowDataPkg.fieldValues.get(primaryKeyIndex));
            LayerCachePool pool = DbleServer.getInstance().getRouterService().getTableId2DataNodeCache();
            if (pool != null) {
                pool.putIfAbsent(primaryKeyTable, primaryKey, dataNode);
            }
        }
        row[3] = ++packetId;
        if (prepared) {
            if (rowDataPkg == null) {
                rowDataPkg = new RowDataPacket(fieldCount);
                rowDataPkg.read(row);
            }
            BinaryRowDataPacket binRowDataPk = new BinaryRowDataPacket();
            binRowDataPk.read(fieldPackets, rowDataPkg);
            binRowDataPk.write(byteBuffer, session.getSource(), true);
        } else {
            byteBuffer = session.getSource().writeToBuffer(row, byteBuffer);
        }
    } catch (Exception e) {
        handleDataProcessException(e);
    } finally {
        lock.unlock();
    }
    return false;
}
Also used : RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) LayerCachePool(com.actiontech.dble.cache.LayerCachePool)

Example 42 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.

the class MultiNodeQueryHandler method connectionAcquired.

@Override
public void connectionAcquired(final BackendConnection conn) {
    final RouteResultsetNode node = (RouteResultsetNode) conn.getAttachment();
    session.bindConnection(node, conn);
    innerExecute(conn, node);
}
Also used : RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Example 43 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.

the class SingleNodeHandler method rowResponse.

@Override
public boolean rowResponse(byte[] row, RowDataPacket rowPacket, boolean isLeft, BackendConnection conn) {
    this.netOutBytes += row.length;
    this.selectRows++;
    row[3] = ++packetId;
    RowDataPacket rowDataPk = null;
    // cache primaryKey-> dataNode
    if (primaryKeyIndex != -1) {
        rowDataPk = new RowDataPacket(fieldCount);
        rowDataPk.read(row);
        String primaryKey = new String(rowDataPk.fieldValues.get(primaryKeyIndex));
        RouteResultsetNode rNode = (RouteResultsetNode) conn.getAttachment();
        LayerCachePool pool = DbleServer.getInstance().getRouterService().getTableId2DataNodeCache();
        if (pool != null) {
            pool.putIfAbsent(primaryKeyTable, primaryKey, rNode.getName());
        }
    }
    if (prepared) {
        if (rowDataPk == null) {
            rowDataPk = new RowDataPacket(fieldCount);
            rowDataPk.read(row);
        }
        BinaryRowDataPacket binRowDataPk = new BinaryRowDataPacket();
        binRowDataPk.read(fieldPackets, rowDataPk);
        binRowDataPk.setPacketId(rowDataPk.getPacketId());
        buffer = binRowDataPk.write(buffer, session.getSource(), true);
    } else {
        buffer = session.getSource().writeToBuffer(row, allocBuffer());
    // session.getSource().write(row);
    }
    return false;
}
Also used : RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) LayerCachePool(com.actiontech.dble.cache.LayerCachePool)

Example 44 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.

the class UnLockTablesHandler method execute.

public void execute() {
    Map<RouteResultsetNode, BackendConnection> lockedCons = session.getTargetMap();
    this.reset(lockedCons.size());
    // if client just send an unlock tables, theres is no lock tables statement, just send back OK
    if (lockedCons.size() == 0) {
        LOGGER.info("find no locked backend connection!" + session.getSource());
        OkPacket ok = new OkPacket();
        ok.setPacketId(++packetId);
        // the size of unlock table's response OK packet is 7
        ok.setPacketLength(7);
        ok.setServerStatus(session.getSource().isAutocommit() ? 2 : 1);
        ok.write(session.getSource());
        return;
    }
    for (Map.Entry<RouteResultsetNode, BackendConnection> entry : lockedCons.entrySet()) {
        RouteResultsetNode dataNode = entry.getKey();
        RouteResultsetNode node = new RouteResultsetNode(dataNode.getName(), ServerParse.UNLOCK, srcStatement);
        BackendConnection conn = lockedCons.get(dataNode);
        if (clearIfSessionClosed(session)) {
            return;
        }
        conn.setResponseHandler(this);
        conn.setSession(session);
        try {
            conn.execute(node, session.getSource(), autocommit);
        } catch (Exception e) {
            connectionError(e, conn);
        }
    }
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) OkPacket(com.actiontech.dble.net.mysql.OkPacket) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) Map(java.util.Map)

Example 45 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.

the class LockTablesHandler method connectionAcquired.

@Override
public void connectionAcquired(BackendConnection conn) {
    final RouteResultsetNode node = (RouteResultsetNode) conn.getAttachment();
    session.bindConnection(node, conn);
    innerExecute(conn, node);
}
Also used : RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Aggregations

RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)48 BackendConnection (com.actiontech.dble.backend.BackendConnection)12 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)9 RouteResultset (com.actiontech.dble.route.RouteResultset)8 TableConfig (com.actiontech.dble.config.model.TableConfig)6 SQLNonTransientException (java.sql.SQLNonTransientException)6 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)5 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)5 PushDownVisitor (com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor)4 AbstractPartitionAlgorithm (com.actiontech.dble.route.function.AbstractPartitionAlgorithm)4 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)4 ServerConfig (com.actiontech.dble.config.ServerConfig)3 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)3 RouteCalculateUnit (com.actiontech.dble.route.parser.druid.RouteCalculateUnit)3 LoadData (com.actiontech.dble.sqlengine.mpp.LoadData)3 LayerCachePool (com.actiontech.dble.cache.LayerCachePool)2 DruidShardingParseInfo (com.actiontech.dble.route.parser.druid.DruidShardingParseInfo)2 SQLException (java.sql.SQLException)2 SQLSyntaxErrorException (java.sql.SQLSyntaxErrorException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2