use of io.mycat.cache.CachePool in project Mycat_plus by coderczp.
the class FetchStoreNodeOfChildTableHandler method execute.
public String execute(String schema, String sql, ArrayList<String> dataNodes) {
String key = schema + ":" + sql;
CachePool cache = MycatServer.getInstance().getCacheService().getCachePool("ER_SQL2PARENTID");
String result = (String) cache.get(key);
if (result != null) {
return result;
}
this.sql = sql;
int totalCount = dataNodes.size();
long startTime = System.currentTimeMillis();
long endTime = startTime + 5 * 60 * 1000L;
MycatConfig conf = MycatServer.getInstance().getConfig();
LOGGER.debug("find child node with sql:" + sql);
for (String dn : dataNodes) {
if (dataNode != null) {
return dataNode;
}
PhysicalDBNode mysqlDN = conf.getDataNodes().get(dn);
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("execute in datanode " + dn);
}
RouteResultsetNode node = new RouteResultsetNode(dn, ServerParse.SELECT, sql);
// 获取 子表节点,最好走master为好
node.setRunOnSlave(false);
mysqlDN.getConnection(mysqlDN.getDatabase(), true, node, this, node);
// mysqlDN.getConnection(mysqlDN.getDatabase(), true,
// new RouteResultsetNode(dn, ServerParse.SELECT, sql),
// this, dn);
} catch (Exception e) {
LOGGER.warn("get connection err " + e);
}
try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
}
while (dataNode == null && System.currentTimeMillis() < endTime) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
break;
}
if (dataNode != null || finished.get() >= totalCount) {
break;
}
}
if (dataNode != null) {
cache.putIfAbsent(key, dataNode);
}
return dataNode;
}
use of io.mycat.cache.CachePool in project Mycat_plus by coderczp.
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.CachePool in project Mycat-Server by MyCATApache.
the class FetchStoreNodeOfChildTableHandler method execute.
public String execute(String schema, String sql, List<String> dataNodes, ServerConnection sc) {
String key = schema + ":" + sql;
CachePool cache = MycatServer.getInstance().getCacheService().getCachePool("ER_SQL2PARENTID");
String result = (String) cache.get(key);
if (result != null) {
return result;
}
this.sql = sql;
int totalCount = dataNodes.size();
long startTime = System.currentTimeMillis();
long endTime = startTime + 5 * 60 * 1000L;
MycatConfig conf = MycatServer.getInstance().getConfig();
LOGGER.debug("find child node with sql:" + sql);
for (String dn : dataNodes) {
if (dataNode != null) {
return dataNode;
}
PhysicalDBNode mysqlDN = conf.getDataNodes().get(dn);
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("execute in datanode " + dn);
}
RouteResultsetNode node = new RouteResultsetNode(dn, ServerParse.SELECT, sql);
// 获取 子表节点,最好走master为好
node.setRunOnSlave(false);
/*
* fix #1370 默认应该先从已经持有的连接中取连接, 否则可能因为事务隔离性看不到当前事务内更新的数据
* Tips: 通过mysqlDN.getConnection获取到的连接不是当前连接
*
*/
BackendConnection conn = sc.getSession2().getTarget(node);
if (sc.getSession2().tryExistsCon(conn, node)) {
_execute(conn, node, sc);
} else {
mysqlDN.getConnection(mysqlDN.getDatabase(), sc.isAutocommit(), node, this, node);
}
} catch (Exception e) {
LOGGER.warn("get connection err " + e);
}
}
while (dataNode == null && System.currentTimeMillis() < endTime) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
break;
}
if (dataNode != null || finished.get() >= totalCount) {
break;
}
}
if (dataNode != null) {
cache.putIfAbsent(key, dataNode);
}
return dataNode;
}
use of io.mycat.cache.CachePool 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.CachePool in project Mycat_plus by coderczp.
the class FetchStoreNodeOfChildTableHandler method execute.
public String execute(String schema, String sql, List<String> dataNodes, ServerConnection sc) {
String key = schema + ":" + sql;
CachePool cache = MycatServer.getInstance().getCacheService().getCachePool("ER_SQL2PARENTID");
String result = (String) cache.get(key);
if (result != null) {
return result;
}
this.sql = sql;
int totalCount = dataNodes.size();
long startTime = System.currentTimeMillis();
long endTime = startTime + 5 * 60 * 1000L;
MycatConfig conf = MycatServer.getInstance().getConfig();
LOGGER.debug("find child node with sql:" + sql);
for (String dn : dataNodes) {
if (dataNode != null) {
return dataNode;
}
PhysicalDBNode mysqlDN = conf.getDataNodes().get(dn);
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("execute in datanode " + dn);
}
RouteResultsetNode node = new RouteResultsetNode(dn, ServerParse.SELECT, sql);
// 获取 子表节点,最好走master为好
node.setRunOnSlave(false);
/*
* fix #1370 默认应该先从已经持有的连接中取连接, 否则可能因为事务隔离性看不到当前事务内更新的数据
* Tips: 通过mysqlDN.getConnection获取到的连接不是当前连接
*
*/
BackendConnection conn = sc.getSession2().getTarget(node);
if (sc.getSession2().tryExistsCon(conn, node)) {
_execute(conn, node, sc);
} else {
mysqlDN.getConnection(mysqlDN.getDatabase(), sc.isAutocommit(), node, this, node);
}
} catch (Exception e) {
LOGGER.warn("get connection err " + e);
}
}
while (dataNode == null && System.currentTimeMillis() < endTime) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
break;
}
if (dataNode != null || finished.get() >= totalCount) {
break;
}
}
if (dataNode != null) {
cache.putIfAbsent(key, dataNode);
}
return dataNode;
}
Aggregations