use of com.actiontech.dble.cache.CachePool in project dble by actiontech.
the class FetchStoreNodeOfChildTableHandler method execute.
public String execute(String schema, ArrayList<String> dataNodes) {
String key = schema + ":" + sql;
CachePool cache = DbleServer.getInstance().getCacheService().getCachePool("ER_SQL2PARENTID");
if (cache != null) {
String cacheResult = (String) cache.get(key);
if (cacheResult != null) {
return cacheResult;
}
}
int totalCount = dataNodes.size();
LOGGER.debug("find child node with sql:" + sql);
for (String dn : dataNodes) {
if (!LOGGER.isDebugEnabled()) {
// no early return when debug
if (dataNode != null) {
LOGGER.debug(" found return ");
return dataNode;
}
}
PhysicalDBNode mysqlDN = DbleServer.getInstance().getConfig().getDataNodes().get(dn);
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("execute in data_node " + dn);
}
RouteResultsetNode node = new RouteResultsetNode(dn, ServerParse.SELECT, sql);
// get child node from master
node.setRunOnSlave(false);
BackendConnection conn = session.getTarget(node);
if (session.tryExistsCon(conn, node)) {
if (session.closed()) {
session.clearResources(true);
return null;
}
conn.setResponseHandler(this);
conn.setSession(session);
((MySQLConnection) conn).setComplexQuery(true);
conn.execute(node, session.getSource(), isAutoCommit());
} else {
mysqlDN.getConnection(mysqlDN.getDatabase(), session.getSource().isTxStart(), session.getSource().isAutocommit(), node, this, node);
}
} catch (Exception e) {
LOGGER.info("get connection err " + e);
}
}
lock.lock();
try {
while (dataNode == null) {
try {
result.await(50, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
break;
}
if (dataNode != null || finished.get() >= totalCount) {
break;
}
}
} finally {
lock.unlock();
}
if (!LOGGER.isDebugEnabled()) {
// no cached when debug
if (dataNode != null && cache != null) {
cache.putIfAbsent(key, dataNode);
}
}
return dataNode;
}
use of com.actiontech.dble.cache.CachePool 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);
}
Aggregations