use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class ShowStatisticHandler method onExecute.
@Override
protected Future<Void> onExecute(SQLRequest<SQLShowStatisticStmt> request, MycatDataContext dataContext, Response response) {
SQLShowStatisticStmt ast = request.getAst();
ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
if (!ast.isFull()) {
resultSetBuilder.addColumnInfo("QPS", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("RDS_QPS", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("SLOW_QPS", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("PHYSICAL_SLOW_QPS", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("ERROR_PER_SECOND", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("MERGE_QUERY_PER_SECOND", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("ACTIVE_CONNECTIONS", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("RT(MS)", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("RDS_RT(MS)", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("NET_IN(KB/S)", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("NET_OUT(KB/S)", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("THREAD_RUNNING", JDBCType.VARCHAR);
}
if (ast.isFull()) {
resultSetBuilder.addColumnInfo("QPS", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("RDS_QPS", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("SLOW_QPS", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("PHYSICAL_SLOW_QPS", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("ERROR_PER_SECOND", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("VIOLATION_PER_SECOND", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("MERGE_QUERY_PER_SECOND", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("ACTIVE_CONNECTIONS", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("CONNECTION_CREATE_PER_SECOND", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("RT(MS)", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("RDS_RT(MS)", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("NET_IN(KB/S)", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("NET_OUT(KB/S)", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("THREAD_RUNNING", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("HINT_USED_PER_SECOND", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("HINT_USED_COUNT", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("AGGREGATE_QUERY_PER_SECOND", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("AGGREGATE_QUERY_COUNT", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("TEMP_TABLE_CREATE_PER_SECOND", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("TEMP_TABLE_CREATE_COUNT", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("MULTI_DB_JOIN_PER_SECOND", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("MULTI_DB_JOIN_COUNT", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("CPU", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("FREEMEM", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("FULLGCCOUNT", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("FULLGCTIME", JDBCType.VARCHAR);
}
return response.sendResultSet(resultSetBuilder.build());
}
use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class NewVertxConnectionImpl method toColumnMetaData.
public static MycatRowMetaData toColumnMetaData(List<ColumnDefinition> event) {
boolean isMysql = event.get(0) instanceof ColumnDefinition;
if (isMysql) {
List<ColumnDefinition> columnDefinitions = event;
List<ColumnDefPacket> columnDefPackets = new ArrayList<>(event.size());
for (ColumnDefinition columnDefinition : columnDefinitions) {
final String catalog = columnDefinition.catalog();
final String schema = columnDefinition.schema();
final String table = columnDefinition.table();
final String orgTable = columnDefinition.orgTable();
final String name = columnDefinition.name();
final String orgName = columnDefinition.orgName();
final int characterSet = columnDefinition.characterSet();
final long columnLength = columnDefinition.columnLength();
final DataType type = columnDefinition.type();
final int flags = columnDefinition.flags();
byte decimals = columnDefinition.decimals();
if (decimals == 31) {
decimals = 0;
}
ColumnDefPacketImpl mySQLFieldInfo = new ColumnDefPacketImpl();
mySQLFieldInfo.setColumnCatalog(catalog.getBytes());
mySQLFieldInfo.setColumnSchema(schema.getBytes());
mySQLFieldInfo.setColumnTable(table.getBytes());
mySQLFieldInfo.setColumnOrgTable(orgTable.getBytes());
mySQLFieldInfo.setColumnName(name.getBytes());
mySQLFieldInfo.setColumnOrgName(orgName.getBytes());
mySQLFieldInfo.setColumnCharsetSet(characterSet);
mySQLFieldInfo.setColumnLength((int) columnLength);
mySQLFieldInfo.setColumnType(type.id);
mySQLFieldInfo.setColumnFlags(flags);
mySQLFieldInfo.setColumnDecimals(decimals);
columnDefPackets.add(mySQLFieldInfo);
}
return new MycatMySQLRowMetaData(columnDefPackets);
} else {
ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
for (ColumnDefinition columnDescriptor : event) {
resultSetBuilder.addColumnInfo(columnDescriptor.name(), columnDescriptor.jdbcType());
}
RowBaseIterator build = resultSetBuilder.build();
return build.getMetaData();
}
}
use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class DefaultCommandHandler method handlePrepareStatement.
@Override
public Future<Void> handlePrepareStatement(byte[] sqlBytes, MySQLServerSession session) {
try {
MycatDataContext dataContext = session.getDataContext();
boolean deprecateEOF = session.isDeprecateEOF();
String sql = new String(sqlBytes);
// ///////////////////////////////////////////////////
SQLStatement sqlStatement = SQLUtils.parseSingleMysqlStatement(sql);
boolean allow = (sqlStatement instanceof SQLSelectStatement || sqlStatement instanceof SQLInsertStatement || sqlStatement instanceof SQLUpdateStatement || sqlStatement instanceof SQLDeleteStatement);
MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
ResultSetBuilder fieldsBuilder = ResultSetBuilder.create();
MycatRowMetaData fields = fieldsBuilder.build().getMetaData();
ResultSetBuilder paramsBuilder = ResultSetBuilder.create();
sqlStatement.accept(new MySqlASTVisitorAdapter() {
@Override
public void endVisit(SQLVariantRefExpr x) {
if ("?".equalsIgnoreCase(x.getName())) {
SQLDataType sqlDataType = x.computeDataType();
JDBCType res = JDBCType.VARCHAR;
if (sqlDataType != null) {
res = JDBCType.valueOf(sqlDataType.jdbcType());
}
paramsBuilder.addColumnInfo("", res);
}
super.endVisit(x);
}
});
MycatRowMetaData params = paramsBuilder.build().getMetaData();
long stmtId = dataContext.nextPrepareStatementId();
Map<Long, PreparedStatement> statementMap = dataContext.getPrepareInfo();
statementMap.put(stmtId, new PreparedStatement(stmtId, sqlStatement, params.getColumnCount()));
DefaultPreparedOKPacket info = new DefaultPreparedOKPacket(stmtId, fields.getColumnCount(), params.getColumnCount(), session.getWarningCount());
if (info.getPrepareOkColumnsCount() == 0 && info.getPrepareOkParametersCount() == 0) {
session.writeBytes(MySQLPacketUtil.generatePrepareOk(info), true);
return Future.succeededFuture();
}
session.writeBytes(MySQLPacketUtil.generatePrepareOk(info), false);
if (info.getPrepareOkParametersCount() > 0 && info.getPrepareOkColumnsCount() == 0) {
for (int i = 0; i < info.getPrepareOkParametersCount() - 1; i++) {
session.writeBytes(MySQLPacketUtil.generateColumnDefPayload(params, i), false);
}
if (deprecateEOF) {
session.writeBytes(MySQLPacketUtil.generateColumnDefPayload(params, info.getPrepareOkParametersCount() - 1), true);
} else {
session.writeBytes(MySQLPacketUtil.generateColumnDefPayload(params, info.getPrepareOkParametersCount() - 1), false);
session.writeBytes(MySQLPacketUtil.generateEof(session.getWarningCount(), session.getServerStatusValue()), true);
}
return Future.succeededFuture();
} else if (info.getPrepareOkParametersCount() == 0 && info.getPrepareOkColumnsCount() > 0) {
for (int i = 0; i < info.getPrepareOkColumnsCount() - 1; i++) {
session.writeBytes(MySQLPacketUtil.generateColumnDefPayload(fields, i), false);
}
if (deprecateEOF) {
session.writeBytes(MySQLPacketUtil.generateColumnDefPayload(fields, info.getPrepareOkColumnsCount() - 1), true);
} else {
session.writeBytes(MySQLPacketUtil.generateColumnDefPayload(fields, info.getPrepareOkColumnsCount() - 1), false);
session.writeBytes(MySQLPacketUtil.generateEof(session.getWarningCount(), session.getServerStatusValue()), true);
}
return Future.succeededFuture();
} else {
for (int i = 0; i < info.getPrepareOkParametersCount() - 1; i++) {
session.writeBytes(MySQLPacketUtil.generateColumnDefPayload(params, i), false);
}
session.writeColumnEndPacket(false);
for (int i = 0; i < info.getPrepareOkColumnsCount() - 1; i++) {
session.writeBytes(MySQLPacketUtil.generateColumnDefPayload(fields, i), false);
}
if (deprecateEOF) {
session.writeBytes(MySQLPacketUtil.generateColumnDefPayload(fields, info.getPrepareOkColumnsCount() - 1), true);
} else {
session.writeBytes(MySQLPacketUtil.generateColumnDefPayload(fields, info.getPrepareOkColumnsCount() - 1), false);
session.writeBytes(MySQLPacketUtil.generateEof(session.getWarningCount(), session.getServerStatusValue()), true);
}
return Future.succeededFuture();
}
} catch (Throwable throwable) {
return Future.failedFuture(throwable);
}
}
use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class NativeMycatServer method showNativeDataSources.
@Override
public RowBaseIterator showNativeDataSources() {
MycatRouterConfig mycatRouterConfig = MetaClusterCurrent.wrapper(MycatRouterConfig.class);
Map<String, DatasourceConfig> datasourceConfigMap = mycatRouterConfig.getDatasources().stream().collect(Collectors.toMap(k -> k.getName(), v -> v));
ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
resultSetBuilder.addColumnInfo("NAME", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("USERNAME", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("PASSWORD", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("MAX_CON", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("MIN_CON", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("EXIST_CON", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("USE_CON", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("MAX_RETRY_COUNT", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("MAX_CONNECT_TIMEOUT", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("DB_TYPE", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("URL", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("WEIGHT", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("INIT_SQL", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("INIT_SQL_GET_CONNECTION", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("INSTANCE_TYPE", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("IDLE_TIMEOUT", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("DRIVER", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("TYPE", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("IS_MYSQL", JDBCType.VARCHAR);
Map<String, Integer> map = getDatasourceMap().values().stream().collect(Collectors.toMap(k -> k.getName(), v -> v.getAllSessions().size()));
for (MySQLDatasource value : getDatasourceMap().values()) {
String NAME = value.getName();
Optional<DatasourceConfig> e = Optional.ofNullable(datasourceConfigMap.get(NAME));
String IP = value.getIp();
int PORT = value.getPort();
String USERNAME = value.getUsername();
String PASSWORD = value.getPassword();
int MAX_CON = value.getSessionLimitCount();
int MIN_CON = value.getSessionMinCount();
long USED_CON = map.getOrDefault(NAME, -1);
int EXIST_CON = value.getConnectionCounter();
int MAX_RETRY_COUNT = value.gerMaxRetry();
long MAX_CONNECT_TIMEOUT = value.getMaxConnectTimeout();
String DB_TYPE = "mysql";
String URL = null;
int WEIGHT = e.map(i -> i.getWeight()).orElse(-1);
String INIT_SQL = value.getInitSqlForProxy();
boolean INIT_SQL_GET_CONNECTION = false;
ReplicaSelectorManager selectorRuntime = MetaClusterCurrent.wrapper(ReplicaSelectorManager.class);
String INSTANCE_TYPE = Optional.ofNullable(selectorRuntime.getPhysicsInstanceByName(NAME)).map(i -> i.getType().name()).orElse(e.map(i -> i.getInstanceType()).orElse(null));
long IDLE_TIMEOUT = value.getIdleTimeout();
// 保留属性
String DRIVER = "native";
String TYPE = e.map(i -> i.getType()).orElse(null);
boolean IS_MYSQL = true;
resultSetBuilder.addObjectRowPayload(Arrays.asList(NAME, IP, PORT, USERNAME, PASSWORD, MAX_CON, MIN_CON, EXIST_CON, USED_CON, MAX_RETRY_COUNT, MAX_CONNECT_TIMEOUT, DB_TYPE, URL, WEIGHT, INIT_SQL, INIT_SQL_GET_CONNECTION, INSTANCE_TYPE, IDLE_TIMEOUT, DRIVER, TYPE, IS_MYSQL));
}
return resultSetBuilder.build();
}
use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class NativeMycatServer method showReactors.
@Override
public RowBaseIterator showReactors() {
ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
resultSetBuilder.addColumnInfo("THREAD_NAME", JDBCType.VARCHAR).addColumnInfo("THREAD_ID", JDBCType.BIGINT).addColumnInfo("CUR_SESSION_ID", JDBCType.BIGINT).addColumnInfo("PREPARE_STOP", JDBCType.VARCHAR).addColumnInfo("BUFFER_POOL_SNAPSHOT", JDBCType.VARCHAR).addColumnInfo("LAST_ACTIVE_TIME", JDBCType.TIMESTAMP);
for (MycatReactorThread mycatReactorThread : getReactorManager().getList()) {
String THREAD_NAME = mycatReactorThread.getName();
long THREAD_ID = mycatReactorThread.getId();
Long CUR_SESSION_ID = Optional.ofNullable(mycatReactorThread.getCurSession()).map(i -> i.sessionId()).orElse(null);
boolean PREPARE_STOP = mycatReactorThread.isPrepareStop();
String BUFFER_POOL_SNAPSHOT = Optional.ofNullable(mycatReactorThread.getBufPool()).map(i -> i.snapshot().toString("|")).orElse("");
LocalDateTime LAST_ACTIVE_TIME = new Timestamp(mycatReactorThread.getLastActiveTime()).toLocalDateTime();
resultSetBuilder.addObjectRowPayload(Arrays.asList(THREAD_NAME, THREAD_ID, CUR_SESSION_ID, PREPARE_STOP, BUFFER_POOL_SNAPSHOT, LAST_ACTIVE_TIME));
}
return resultSetBuilder.build();
}
Aggregations