use of io.mycat.IOExecutor in project Mycat2 by MyCATApache.
the class MySQLLogConsumer method accept.
@Override
@SneakyThrows
public void accept(SqlEntry sqlEntry) {
if (!init) {
init = true;
try {
init();
} catch (Exception e) {
LOGGER.error("", e);
}
}
boolean isInRuntime = MetaClusterCurrent.exist(IOExecutor.class) && MetaClusterCurrent.exist(JdbcConnectionManager.class) && MetaClusterCurrent.exist(IOExecutor.class);
if (isInRuntime) {
IOExecutor ioExecutor = MetaClusterCurrent.wrapper(IOExecutor.class);
JdbcConnectionManager jdbcConnectionManager = MetaClusterCurrent.wrapper(JdbcConnectionManager.class);
MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
ioExecutor.executeBlocking((Handler<Promise<Void>>) event -> {
try {
try (DefaultConnection connection = jdbcConnectionManager.getConnection(metadataManager.getPrototype())) {
JdbcUtils.execute(connection.getRawConnection(), "INSERT INTO `mycat`.`sql_log` (" + "`instanceId`," + "user," + "connectionId," + "ip," + "port," + "traceId," + "hash," + "sqlType," + "`sql`," + "transactionId," + "sqlTime," + "responseTime," + "affectRow," + "result," + "externalMessage)" + "values(?,?,?,?,?," + "?,?,?,?,?," + "?,?,?,?,?)", Arrays.asList(sqlEntry.getInstanceId(), sqlEntry.getUser(), sqlEntry.getConnectionId(), sqlEntry.getIp(), sqlEntry.getPort(), sqlEntry.getTraceId(), sqlEntry.getHash(), Objects.toString(sqlEntry.getSqlType()), sqlEntry.getSql(), sqlEntry.getTransactionId(), sqlEntry.getSqlTime(), sqlEntry.getResponseTime(), sqlEntry.getAffectRow(), sqlEntry.isResult(), sqlEntry.getExternalMessage()));
}
} catch (Exception e) {
LOGGER.info(" warning sql:{} , info:{}", sqlEntry.getSql(), sqlEntry);
LOGGER.error("", e);
} finally {
event.tryComplete();
}
});
}
}
use of io.mycat.IOExecutor in project Mycat2 by MyCATApache.
the class ThreadPoolCollector method collect.
@Override
public List<MetricFamilySamples> collect() {
try {
List<String> columnList = ImmutableList.of("ACTIVE_COUNT");
GaugeMetricFamily gaugeMetricFamily = new GaugeMetricFamily("thread_pool_active", "thread_pool_active", columnList);
long count = 0;
if (MetaClusterCurrent.exist(IOExecutor.class)) {
IOExecutor ioExecutor = MetaClusterCurrent.wrapper(IOExecutor.class);
count = ioExecutor.count();
}
gaugeMetricFamily.addMetric(columnList, count);
return ImmutableList.of(gaugeMetricFamily);
} catch (Throwable e) {
LOGGER.error("", e);
throw e;
}
}
use of io.mycat.IOExecutor in project Mycat2 by MyCATApache.
the class ThreadMycatConnectionImplWrapper method insert.
@Override
public Future<SqlResult> insert(String sql, List<Object> params) {
IOExecutor ioExecutor = MetaClusterCurrent.wrapper(IOExecutor.class);
return ioExecutor.executeBlocking(promise -> {
try {
this.stat.plusThread();
newMycatConnection.insert(sql, params).onComplete(promise);
} catch (Exception e) {
promise.tryFail(e);
} finally {
this.stat.decThread();
}
});
}
use of io.mycat.IOExecutor in project Mycat2 by MyCATApache.
the class ThreadMycatConnectionImplWrapper method update.
@Override
public Future<SqlResult> update(String sql, List<Object> params) {
IOExecutor ioExecutor = MetaClusterCurrent.wrapper(IOExecutor.class);
return ioExecutor.executeBlocking(promise -> {
try {
this.stat.plusThread();
newMycatConnection.update(sql, params).onComplete(promise);
} catch (Exception e) {
promise.tryFail(e);
} finally {
this.stat.decThread();
}
});
}
use of io.mycat.IOExecutor in project Mycat2 by MyCATApache.
the class MycatSQLLogMonitorImpl method initBaseMonitor.
private void initBaseMonitor(Vertx vertx) {
{
TimerConfig instanceMonitorConfig = this.monitorConfig.getInstanceMonitor();
TimeUnit timeUnit = TimeUnit.valueOf(instanceMonitorConfig.getTimeUnit());
vertx.setTimer(timeUnit.toMillis(instanceMonitorConfig.getInitialDelay()), event -> vertx.setPeriodic(timeUnit.toMillis(instanceMonitorConfig.getPeriod()), event1 -> {
IOExecutor ioExecutor = MetaClusterCurrent.wrapper(IOExecutor.class);
ioExecutor.executeBlocking((Handler<Promise<Void>>) promise -> {
try {
instanceSnapshot = InstanceEntry.snapshot();
InstanceEntry.reset();
} finally {
promise.tryComplete();
}
});
}));
}
{
TimerConfig clusterConfig = this.monitorConfig.getClusterMonitor();
TimeUnit timeUnit = TimeUnit.valueOf(clusterConfig.getTimeUnit());
long readWriteRatioMillis = timeUnit.toMillis(clusterConfig.getPeriod());
vertx.setTimer(timeUnit.toMillis(clusterConfig.getInitialDelay()), event -> vertx.setPeriodic(readWriteRatioMillis, event12 -> {
IOExecutor ioExecutor = MetaClusterCurrent.wrapper(IOExecutor.class);
ioExecutor.executeBlocking((Handler<Promise<Void>>) promise -> {
try {
rwEntryMapSnapshot = RWEntry.snapshot();
RWEntry.reset();
} finally {
promise.tryComplete();
}
});
}));
}
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////
{
TimerConfig databaseInstanceMonitor = this.monitorConfig.getDatabaseInstanceMonitor();
TimeUnit timeUnit = TimeUnit.valueOf(databaseInstanceMonitor.getTimeUnit());
long databaseInstanceMonitorMillis = timeUnit.toMillis(databaseInstanceMonitor.getPeriod());
vertx.setTimer(timeUnit.toMillis(databaseInstanceMonitor.getInitialDelay()), event -> vertx.setPeriodic(databaseInstanceMonitorMillis, event12 -> {
IOExecutor ioExecutor = MetaClusterCurrent.wrapper(IOExecutor.class);
ioExecutor.executeBlocking((Handler<Promise<Void>>) promise -> {
try {
databaseInstanceMapSnapshot = DatabaseInstanceEntry.snapshot();
DatabaseInstanceEntry.reset();
} finally {
promise.tryComplete();
}
});
}));
}
}
Aggregations