Skip to content

Commit

Permalink
1.repair front end connection leaks
Browse files Browse the repository at this point in the history
2.improve monitor
  • Loading branch information
junwen12221 committed Aug 27, 2021
1 parent 50e5fd7 commit 87af0fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
37 changes: 31 additions & 6 deletions mycat2/src/main/java/io/mycat/monitor/MycatSQLLogMonitorImpl.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.mycat.monitor;

import io.mycat.IOExecutor;
import io.mycat.MetaClusterCurrent;
import io.mycat.config.MonitorConfig;
import io.mycat.config.SqlLogConfig;
import io.mycat.config.TimerConfig;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerRequest;
Expand All @@ -24,6 +27,7 @@ public class MycatSQLLogMonitorImpl extends MycatSQLLogMonitor {
public static final String SHOW_DB_MONITOR_URL = "/ShowDbMonitor";
public static final String SHOW_RW_MONITOR_URL = "/ShowRwMonitor";
public static final String QUERY_SQL_LOG = "/QuerySqlLog";

@SneakyThrows
public MycatSQLLogMonitorImpl(long workerId, MonitorConfig monitorConfig, Vertx vertx) {
super(workerId);
Expand Down Expand Up @@ -71,8 +75,15 @@ private void initBaseMonitor(Vertx vertx) {
TimeUnit timeUnit = TimeUnit.valueOf(instanceMonitorConfig.getTimeUnit());

vertx.setTimer(timeUnit.toMillis(instanceMonitorConfig.getInitialDelay()), event -> vertx.setPeriodic(timeUnit.toMillis(instanceMonitorConfig.getPeriod()), event1 -> {
instanceSnapshot = InstanceEntry.snapshot();
InstanceEntry.reset();
IOExecutor ioExecutor = MetaClusterCurrent.wrapper(IOExecutor.class);
ioExecutor.executeBlocking((Handler<Promise<Void>>) promise -> {
try {
instanceSnapshot = InstanceEntry.snapshot();
InstanceEntry.reset();
}finally {
promise.tryComplete();
}
});
}));
}

Expand All @@ -83,8 +94,15 @@ private void initBaseMonitor(Vertx vertx) {
long readWriteRatioMillis = timeUnit.toMillis(clusterConfig.getPeriod());

vertx.setTimer(timeUnit.toMillis(clusterConfig.getInitialDelay()), event -> vertx.setPeriodic(readWriteRatioMillis, event12 -> {
rwEntryMapSnapshot = RWEntry.snapshot();
RWEntry.reset();
IOExecutor ioExecutor = MetaClusterCurrent.wrapper(IOExecutor.class);
ioExecutor.executeBlocking((Handler<Promise<Void>>) promise -> {
try {
rwEntryMapSnapshot = RWEntry.snapshot();
RWEntry.reset();
}finally {
promise.tryComplete();
}
});
}));
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -93,8 +111,15 @@ private void initBaseMonitor(Vertx vertx) {
TimeUnit timeUnit = TimeUnit.valueOf(databaseInstanceMonitor.getTimeUnit());
long databaseInstanceMonitorMillis = timeUnit.toMillis(databaseInstanceMonitor.getPeriod());
vertx.setTimer(timeUnit.toMillis(databaseInstanceMonitor.getInitialDelay()), event -> vertx.setPeriodic(databaseInstanceMonitorMillis, event12 -> {
databaseInstanceMapSnapshot = DatabaseInstanceEntry.snapshot();
DatabaseInstanceEntry.reset();
IOExecutor ioExecutor = MetaClusterCurrent.wrapper(IOExecutor.class);
ioExecutor.executeBlocking((Handler<Promise<Void>>) promise -> {
try {
databaseInstanceMapSnapshot = DatabaseInstanceEntry.snapshot();
DatabaseInstanceEntry.reset();
}finally {
promise.tryComplete();
}
});
}));
}
}
Expand Down
1 change: 1 addition & 0 deletions mycat2/src/main/java/io/mycat/vertx/VertxMycatServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public void addSession(VertxSession vertxSession) {
socket.closeHandler(event -> {
String message = "session:{} is closing:{}";
LOGGER.info(message, vertxSession);
sessions.remove(vertxSession);
});
sessions.add(vertxSession);
}
Expand Down

0 comments on commit 87af0fe

Please sign in to comment.