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);
}
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());
}
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;
}
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;
}
Aggregations