use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.
the class ShareRowOutPutDataHandler method onRowData.
@Override
public boolean onRowData(String dataNode, byte[] rowData) {
RowDataPacket rowDataPkgold = ResultSetUtil.parseRowData(rowData, bfields);
// 拷贝一份batchRows
Map<String, byte[]> batchRowsCopy = new ConcurrentHashMap<String, byte[]>();
batchRowsCopy.putAll(arows);
// 获取Id字段,
String id = ByteUtil.getString(rowDataPkgold.fieldValues.get(joinR));
// 查找ID对应的A表的记录
// arows.remove(id);
byte[] arow = getRow(batchRowsCopy, id, joinL);
// byte[] arow = getRow(id,joinL);//arows.remove(id);
while (arow != null) {
// ctx.getAllFields());
RowDataPacket rowDataPkg = ResultSetUtil.parseRowData(arow, afields);
for (int i = 1; i < rowDataPkgold.fieldCount; i++) {
// 设置b.name 字段
byte[] bname = rowDataPkgold.fieldValues.get(i);
rowDataPkg.add(bname);
rowDataPkg.addFieldCount(1);
}
// RowData(rowDataPkg);
// huangyiming add
MiddlerResultHandler middlerResultHandler = session.getMiddlerResultHandler();
if (null == middlerResultHandler) {
ctx.writeRow(rowDataPkg);
} else {
if (middlerResultHandler instanceof MiddlerQueryResultHandler) {
// if(middlerResultHandler.getDataType().equalsIgnoreCase("string")){
byte[] columnData = rowDataPkg.fieldValues.get(0);
if (columnData != null && columnData.length > 0) {
String rowValue = new String(columnData);
middlerResultHandler.add(rowValue);
}
// }
}
}
arow = getRow(batchRowsCopy, id, joinL);
// arow = getRow(id,joinL);
}
return false;
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.
the class SingleNodeHandler method rowResponse.
/**
* select
*
* 行数据返回时触发,将行数据写入缓冲区中
*/
@Override
public void rowResponse(byte[] row, BackendConnection conn) {
this.netOutBytes += row.length;
this.selectRows++;
if (isDefaultNodeShowTable || isDefaultNodeShowFullTable) {
RowDataPacket rowDataPacket = new RowDataPacket(1);
rowDataPacket.read(row);
String table = StringUtil.decode(rowDataPacket.fieldValues.get(0), session.getSource().getCharset());
if (shardingTablesSet.contains(table.toUpperCase())) {
return;
}
}
row[3] = ++packetId;
if (prepared) {
RowDataPacket rowDataPk = new RowDataPacket(fieldCount);
rowDataPk.read(row);
BinaryRowDataPacket binRowDataPk = new BinaryRowDataPacket();
binRowDataPk.read(fieldPackets, rowDataPk);
binRowDataPk.packetId = rowDataPk.packetId;
// binRowDataPk.write(session.getSource());
/*
* [fix bug] : 这里不能直接将包写到前端连接,
* 因为在fieldEofResponse()方法结束后buffer还没写出,
* 所以这里应该将包数据顺序写入buffer(如果buffer满了就写出),然后再将buffer写出
*/
buffer = binRowDataPk.write(buffer, session.getSource(), true);
} else {
MiddlerResultHandler middlerResultHandler = session.getMiddlerResultHandler();
if (null == middlerResultHandler) {
buffer = session.getSource().writeToBuffer(row, allocBuffer());
} else {
if (middlerResultHandler instanceof MiddlerQueryResultHandler) {
byte[] rv = ResultSetUtil.getColumnVal(row, fields, 0);
String rowValue = rv == null ? "" : new String(rv);
middlerResultHandler.add(rowValue);
}
}
}
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.
the class ShowDatasourceSyn method getRows.
private static List<RowDataPacket> getRows(String charset) {
List<RowDataPacket> list = new LinkedList<RowDataPacket>();
MycatConfig conf = MycatServer.getInstance().getConfig();
// host nodes
Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
for (PhysicalDBPool pool : dataHosts.values()) {
for (PhysicalDatasource ds : pool.getAllDataSources()) {
DBHeartbeat hb = ds.getHeartbeat();
DataSourceSyncRecorder record = hb.getAsynRecorder();
Map<String, String> states = record.getRecords();
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
if (!states.isEmpty()) {
row.add(StringUtil.encode(ds.getName(), charset));
row.add(StringUtil.encode(ds.getConfig().getIp(), charset));
row.add(LongUtil.toBytes(ds.getConfig().getPort()));
row.add(StringUtil.encode(states.get("Master_Host"), charset));
row.add(LongUtil.toBytes(Long.valueOf(states.get("Master_Port"))));
row.add(StringUtil.encode(states.get("Master_Use"), charset));
String secords = states.get("Seconds_Behind_Master");
row.add(secords == null ? null : LongUtil.toBytes(Long.valueOf(secords)));
row.add(StringUtil.encode(states.get("Slave_IO_Running"), charset));
row.add(StringUtil.encode(states.get("Slave_SQL_Running"), charset));
row.add(StringUtil.encode(states.get("Slave_IO_State"), charset));
row.add(LongUtil.toBytes(Long.valueOf(states.get("Connect_Retry"))));
row.add(StringUtil.encode(states.get("Last_IO_Error"), charset));
list.add(row);
}
}
}
return list;
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.
the class ShowDatasourceSyn method response.
public static void response(ManagerConnection c, String stmt) {
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 (RowDataPacket row : getRows(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);
// post write
c.write(buffer);
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.
the class ShowDirectMemory method showDirectMemoryDetail.
public static void showDirectMemoryDetail(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = detailHeader.write(buffer, c, true);
// write fields
for (FieldPacket field : detailFields) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = detailEof.write(buffer, c, true);
// write rows
byte packetId = detailEof.packetId;
ConcurrentHashMap<Long, Long> bufferpoolUsageMap = bufferPool.getNetDirectMemoryUsage();
try {
if (useOffHeapForMerge == 1) {
ConcurrentHashMap<Long, Long> concurrentHashMap = MycatServer.getInstance().getMyCatMemory().getResultMergeMemoryManager().getDirectMemorUsage();
for (Long key : concurrentHashMap.keySet()) {
RowDataPacket row = new RowDataPacket(DETAILl_FIELD_COUNT);
Long value = concurrentHashMap.get(key);
row.add(String.valueOf(key).getBytes(c.getCharset()));
/**
* 该DIRECTMEMORY内存被结果集处理使用了
*/
row.add("MergeMemoryPool".getBytes(c.getCharset()));
row.add(value > 0 ? JavaUtils.bytesToString2(value).getBytes(c.getCharset()) : "0".getBytes(c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
if (processorBufferPoolType == 2) {
} else {
for (Long key : bufferpoolUsageMap.keySet()) {
RowDataPacket row = new RowDataPacket(DETAILl_FIELD_COUNT);
Long value = bufferpoolUsageMap.get(key);
row.add(String.valueOf(key).getBytes(c.getCharset()));
/**
* 该DIRECTMEMORY内存属于Buffer Pool管理的!
*/
row.add("NetWorkBufferPool".getBytes(c.getCharset()));
row.add(value > 0 ? JavaUtils.bytesToString2(value).getBytes(c.getCharset()) : "0".getBytes(c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
Aggregations