use of io.mycat.cache.LayerCachePool in project Mycat-Server by MyCATApache.
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.packetId;
CacheService cacheService = MycatServer.getInstance().getCacheService();
for (Map.Entry<String, CachePool> entry : cacheService.getAllCachePools().entrySet()) {
String cacheName = entry.getKey();
CachePool cachePool = entry.getValue();
if (cachePool instanceof LayerCachePool) {
for (Map.Entry<String, CacheStatic> staticsEntry : ((LayerCachePool) cachePool).getAllCacheStatic().entrySet()) {
RowDataPacket row = getRow(cacheName + '.' + staticsEntry.getKey(), staticsEntry.getValue(), c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
} else {
RowDataPacket row = getRow(cacheName, cachePool.getCacheStatic(), c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of io.mycat.cache.LayerCachePool in project Mycat_plus by coderczp.
the class MultiNodeQueryHandler method rowResponse.
@Override
public void rowResponse(final byte[] row, final BackendConnection conn) {
if (errorRepsponsed.get()) {
// conn.close(error);
return;
}
lock.lock();
try {
this.selectRows++;
RouteResultsetNode rNode = (RouteResultsetNode) conn.getAttachment();
String dataNode = rNode.getName();
if (dataMergeSvr != null) {
// even through discarding the all rest data, we can't
// close the connection for tx control such as rollback or commit.
// So the "isClosedByDiscard" variable is unnecessary.
// @author Uncle-pan
// @since 2016-03-25
dataMergeSvr.onNewRecord(dataNode, row);
MiddlerResultHandler middlerResultHandler = session.getMiddlerResultHandler();
if (null != middlerResultHandler) {
if (middlerResultHandler instanceof MiddlerQueryResultHandler) {
byte[] rv = ResultSetUtil.getColumnVal(row, fields, 0);
String rowValue = rv == null ? "" : new String(rv);
middlerResultHandler.add(rowValue);
}
}
} else {
row[3] = ++packetId;
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 = MycatServer.getInstance().getRouterservice().getTableId2DataNodeCache();
pool.putIfAbsent(priamaryKeyTable, primaryKey, dataNode);
}
if (prepared) {
if (rowDataPkg == null) {
rowDataPkg = new RowDataPacket(fieldCount);
rowDataPkg.read(row);
}
BinaryRowDataPacket binRowDataPk = new BinaryRowDataPacket();
binRowDataPk.read(fieldPackets, rowDataPkg);
binRowDataPk.write(session.getSource());
} else {
// add huangyiming
MiddlerResultHandler middlerResultHandler = session.getMiddlerResultHandler();
if (null == middlerResultHandler) {
session.getSource().write(row);
} else {
if (middlerResultHandler instanceof MiddlerQueryResultHandler) {
String rowValue = ResultSetUtil.getColumnValAsString(row, fields, 0);
middlerResultHandler.add(rowValue);
}
}
}
}
} catch (Exception e) {
handleDataProcessException(e);
} finally {
lock.unlock();
}
}
use of io.mycat.cache.LayerCachePool in project Mycat_plus by coderczp.
the class DefaultDruidParserTest method getParseTables.
private Object[] getParseTables(String sql) throws Exception {
SQLStatementParser parser = new MySqlStatementParser(sql);
SQLStatement statement = parser.parseStatement();
MycatSchemaStatVisitor visitor = new MycatSchemaStatVisitor();
LayerCachePool cachePool = mock(LayerCachePool.class);
RouteResultset rrs = new RouteResultset(sql, ServerParse.SELECT);
druidParser.parser(schema, rrs, statement, sql, cachePool, visitor);
DruidShardingParseInfo ctx = druidParser.getCtx();
return ctx.getTables().toArray();
}
Aggregations