use of io.mycat.net.NIOProcessor in project Mycat-Server by MyCATApache.
the class ShowConnection 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;
String charset = c.getCharset();
NIOProcessor[] processors = MycatServer.getInstance().getProcessors();
for (NIOProcessor p : processors) {
for (FrontendConnection fc : p.getFrontends().values()) {
if (fc != null) {
RowDataPacket row = getRow(fc, charset);
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.net.NIOProcessor in project Mycat-Server by MyCATApache.
the class ShowRouter 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;
for (NIOProcessor p : MycatServer.getInstance().getProcessors()) {
RowDataPacket row = getRow(p, 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.net.NIOProcessor in project Mycat-Server by MyCATApache.
the class ShowBackend method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
buffer = header.write(buffer, c, true);
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
buffer = eof.write(buffer, c, true);
byte packetId = eof.packetId;
String charset = c.getCharset();
for (NIOProcessor p : MycatServer.getInstance().getProcessors()) {
for (BackendConnection bc : p.getBackends().values()) {
if (bc != null) {
RowDataPacket row = getRow(bc, charset);
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
}
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
c.write(buffer);
}
use of io.mycat.net.NIOProcessor in project Mycat-Server by MyCATApache.
the class SwitchPrepareCheckRunner method run.
@Override
public void run() {
if (!allSwitchRunnerSet.contains(taskID)) {
return;
}
ScheduledExecutorService scheduledExecutorService = MycatServer.getInstance().getScheduler();
ConcurrentMap<String, ConcurrentMap<String, List<PartitionByCRC32PreSlot.Range>>> migrateRuleMap = RouteCheckRule.migrateRuleMap;
String schemal = taskNode.getSchema().toUpperCase();
if (!migrateRuleMap.containsKey(schemal) || !migrateRuleMap.get(schemal).containsKey(taskNode.getTable().toUpperCase())) {
scheduledExecutorService.schedule(this, 3, TimeUnit.SECONDS);
return;
}
boolean isHasInTransation = false;
NIOProcessor[] processors = MycatServer.getInstance().getProcessors();
for (NIOProcessor processor : processors) {
Collection<BackendConnection> backendConnections = processor.getBackends().values();
for (BackendConnection backendConnection : backendConnections) {
isHasInTransation = checkIsInTransation(backendConnection);
if (isHasInTransation) {
scheduledExecutorService.schedule(this, 3, TimeUnit.SECONDS);
return;
}
}
}
for (BackendConnection backendConnection : NIOProcessor.backends_old) {
isHasInTransation = checkIsInTransation(backendConnection);
if (isHasInTransation) {
scheduledExecutorService.schedule(this, 3, TimeUnit.SECONDS);
return;
}
}
//增加判断binlog完成
if (!isHasInTransation) {
try {
//先判断后端binlog都完成了才算本任务完成
boolean allIncrentmentSucess = true;
List<String> dataHosts = ZKUtils.getConnection().getChildren().forPath(taskPath);
for (String dataHostName : dataHosts) {
if ("_prepare".equals(dataHostName) || "_commit".equals(dataHostName) || "_clean".equals(dataHostName))
continue;
List<MigrateTask> migrateTaskList = JSON.parseArray(new String(ZKUtils.getConnection().getData().forPath(taskPath + "/" + dataHostName), "UTF-8"), MigrateTask.class);
for (MigrateTask migrateTask : migrateTaskList) {
String zkPath = taskPath + "/" + dataHostName + "/" + migrateTask.getFrom() + "-" + migrateTask.getTo();
if (ZKUtils.getConnection().checkExists().forPath(zkPath) != null) {
TaskStatus taskStatus = JSON.parseObject(new String(ZKUtils.getConnection().getData().forPath(zkPath), "UTF-8"), TaskStatus.class);
if (taskStatus.getStatus() != 3) {
allIncrentmentSucess = false;
break;
}
} else {
allIncrentmentSucess = false;
break;
}
}
}
if (allIncrentmentSucess) {
//需要关闭binlog,不然后续的清楚老数据会删除数据
BinlogStream stream = BinlogStreamHoder.binlogStreamMap.get(taskID);
if (stream != null) {
BinlogStreamHoder.binlogStreamMap.remove(taskID);
stream.disconnect();
}
String myID = ZkConfig.getInstance().getValue(ZkParamCfg.ZK_CFG_MYID);
String path = taskPath + "/_commit/" + myID;
if (ZKUtils.getConnection().checkExists().forPath(path) == null) {
ZKUtils.getConnection().create().creatingParentsIfNeeded().forPath(path);
}
allSwitchRunnerSet.remove(taskID);
} else {
scheduledExecutorService.schedule(this, 3, TimeUnit.SECONDS);
}
} catch (Exception e) {
LOGGER.error("error:", e);
}
}
}
use of io.mycat.net.NIOProcessor in project Mycat-Server by MyCATApache.
the class JDBCDatasource method createNewConnection.
@Override
public void createNewConnection(ResponseHandler handler, String schema) throws IOException {
DBHostConfig cfg = getConfig();
JDBCConnection c = new JDBCConnection();
c.setHost(cfg.getIp());
c.setPort(cfg.getPort());
c.setPool(this);
c.setSchema(schema);
c.setDbType(cfg.getDbType());
NIOProcessor processor = (NIOProcessor) MycatServer.getInstance().nextProcessor();
c.setProcessor(processor);
//复用mysql的Backend的ID,需要在process中存储
c.setId(NIOConnector.ID_GENERATOR.getId());
processor.addBackend(c);
try {
Connection con = getConnection();
// c.setIdleTimeout(pool.getConfig().getIdleTimeout());
c.setCon(con);
// notify handler
handler.connectionAcquired(c);
} catch (Exception e) {
handler.connectionError(e, c);
}
}
Aggregations