Search in sources :

Example 1 with LayerCachePool

use of com.actiontech.dble.cache.LayerCachePool in project dble by actiontech.

the class ShowCache method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = HEADER.write(buffer, c, true);
    // write fields
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = EOF.write(buffer, c, true);
    // write rows
    byte packetId = EOF.getPacketId();
    CacheService cacheService = DbleServer.getInstance().getCacheService();
    for (Map.Entry<String, CachePool> entry : cacheService.getAllCachePools().entrySet()) {
        String cacheName = entry.getKey();
        CachePool cachePool = entry.getValue();
        if (cachePool != null) {
            if (cachePool instanceof LayerCachePool) {
                for (Map.Entry<String, CacheStatic> staticsEntry : ((LayerCachePool) cachePool).getAllCacheStatic().entrySet()) {
                    RowDataPacket row = getRow(cacheName + '.' + staticsEntry.getKey(), staticsEntry.getValue(), c.getCharset().getResults());
                    row.setPacketId(++packetId);
                    buffer = row.write(buffer, c, true);
                }
            } else {
                RowDataPacket row = getRow(cacheName, cachePool.getCacheStatic(), c.getCharset().getResults());
                row.setPacketId(++packetId);
                buffer = row.write(buffer, c, true);
            }
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) CachePool(com.actiontech.dble.cache.CachePool) LayerCachePool(com.actiontech.dble.cache.LayerCachePool) CacheStatic(com.actiontech.dble.cache.CacheStatic) LayerCachePool(com.actiontech.dble.cache.LayerCachePool) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) Map(java.util.Map) CacheService(com.actiontech.dble.cache.CacheService)

Example 2 with LayerCachePool

use of com.actiontech.dble.cache.LayerCachePool in project dble by actiontech.

the class MergeBuilder method constructByStatement.

public RouteResultset constructByStatement(String sql, SQLSelectStatement select) throws SQLException {
    ServerSchemaStatVisitor visitor = new ServerSchemaStatVisitor();
    DruidParser druidParser = new DruidSingleUnitSelectParser();
    RouteResultset rrs = new RouteResultset(sql, ServerParse.SELECT);
    LayerCachePool pool = DbleServer.getInstance().getRouterService().getTableId2DataNodeCache();
    SchemaConfig schemaConfig = schemaConfigMap.get(node.getReferedTableNodes().get(0).getSchema());
    return RouterUtil.routeFromParser(druidParser, schemaConfig, rrs, select, sql, pool, visitor, session.getSource());
}
Also used : DruidSingleUnitSelectParser(com.actiontech.dble.route.parser.druid.impl.DruidSingleUnitSelectParser) ServerSchemaStatVisitor(com.actiontech.dble.route.parser.druid.ServerSchemaStatVisitor) SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) DruidParser(com.actiontech.dble.route.parser.druid.DruidParser) LayerCachePool(com.actiontech.dble.cache.LayerCachePool) RouteResultset(com.actiontech.dble.route.RouteResultset)

Example 3 with LayerCachePool

use of com.actiontech.dble.cache.LayerCachePool 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 4 with LayerCachePool

use of com.actiontech.dble.cache.LayerCachePool 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)

Aggregations

LayerCachePool (com.actiontech.dble.cache.LayerCachePool)4 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)2 CachePool (com.actiontech.dble.cache.CachePool)1 CacheService (com.actiontech.dble.cache.CacheService)1 CacheStatic (com.actiontech.dble.cache.CacheStatic)1 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)1 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)1 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)1 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)1 RouteResultset (com.actiontech.dble.route.RouteResultset)1 DruidParser (com.actiontech.dble.route.parser.druid.DruidParser)1 ServerSchemaStatVisitor (com.actiontech.dble.route.parser.druid.ServerSchemaStatVisitor)1 DruidSingleUnitSelectParser (com.actiontech.dble.route.parser.druid.impl.DruidSingleUnitSelectParser)1 ByteBuffer (java.nio.ByteBuffer)1 Map (java.util.Map)1