예제 #1
0
 @Override
 public boolean onRowData(String dataNode, byte[] rowData) {
   RowDataPacket rowDataPkgold = ResultSetUtil.parseRowData(rowData, bfields);
   // 获取Id字段,
   String id = ByteUtil.getString(rowDataPkgold.fieldValues.get(joinR));
   // 查找ID对应的A表的记录
   byte[] arow = getRow(id, joinL); // arows.remove(id);
   while (arow != null) {
     RowDataPacket rowDataPkg = ResultSetUtil.parseRowData(arow, afields); // ctx.getAllFields());
     for (int i = 1; i < rowDataPkgold.fieldCount; i++) {
       // 设置b.name 字段
       byte[] bname = rowDataPkgold.fieldValues.get(i);
       rowDataPkg.add(bname);
       rowDataPkg.addFieldCount(1);
     }
     // RowData(rowDataPkg);
     ctx.writeRow(rowDataPkg);
     arow = getRow(id, joinL);
   }
   return false;
 }
예제 #2
0
 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);
 }
예제 #3
0
  private static RowDataPacket getRow(BackendConnection c, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    if (c instanceof BackendAIOConnection) {
      row.add(((BackendAIOConnection) c).getProcessor().getName().getBytes());
    } else if (c instanceof JDBCConnection) {
      row.add(((JDBCConnection) c).getProcessor().getName().getBytes());
    } else {
      row.add("N/A".getBytes());
    }
    row.add(LongUtil.toBytes(c.getId()));
    long threadId = 0;
    if (c instanceof MySQLConnection) {
      threadId = ((MySQLConnection) c).getThreadId();
    }
    row.add(LongUtil.toBytes(threadId));
    row.add(StringUtil.encode(c.getHost(), charset));
    row.add(IntegerUtil.toBytes(c.getPort()));
    row.add(IntegerUtil.toBytes(c.getLocalPort()));
    row.add(LongUtil.toBytes(c.getNetInBytes()));
    row.add(LongUtil.toBytes(c.getNetOutBytes()));
    row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
    row.add(c.isClosed() ? "true".getBytes() : "false".getBytes());
    // boolean isRunning = c.isRunning();
    // row.add(isRunning ? "true".getBytes() : "false".getBytes());
    boolean isBorrowed = c.isBorrowed();
    row.add(isBorrowed ? "true".getBytes() : "false".getBytes());
    int writeQueueSize = 0;
    String schema = "";
    String charsetInf = "";
    String txLevel = "";
    String txAutommit = "";

    if (c instanceof MySQLConnection) {
      MySQLConnection mysqlC = (MySQLConnection) c;
      writeQueueSize = mysqlC.getWriteQueue().size();
      schema = mysqlC.getSchema();
      charsetInf = mysqlC.getCharset() + ":" + mysqlC.getCharsetIndex();
      txLevel = mysqlC.getTxIsolation() + "";
      txAutommit = mysqlC.isAutocommit() + "";
    }
    row.add(IntegerUtil.toBytes(writeQueueSize));
    row.add(schema.getBytes());
    row.add(charsetInf.getBytes());
    row.add(txLevel.getBytes());
    row.add(txAutommit.getBytes());
    return row;
  }