gosonzhang commented on code in PR #9927:
URL: https://github.com/apache/inlong/pull/9927#discussion_r1554855940


##########
inlong-audit/audit-service/src/main/java/elector/task/DBMonitorTask.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package elector.task;
+
+import elector.api.SelectorConfig;
+import elector.impl.DBDataSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * DB monitor task
+ */
+public class DBMonitorTask implements Runnable {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(DBMonitorTask.class);
+    private SelectorConfig electorConfig;
+    private DBDataSource dbDataSource;
+    private int dbClosedTimes = 0;
+    private boolean replaced = true;
+
+    public DBMonitorTask(SelectorConfig electorConfig, DBDataSource 
dbDataSource) {
+        this.electorConfig = electorConfig;
+        this.dbDataSource = dbDataSource;
+    }
+
+    public void run() {
+        try {
+            while (true) {
+                logger.info("DB monitor task run once");
+                
TimeUnit.SECONDS.sleep(electorConfig.getDbMonitorRunInterval());
+
+                if (!(electorConfig.isUseDefaultLeader()))
+                    break;
+            }
+            if (dbDataSource.isDBDataSourceClosed()) {
+                dbClosedTimes += 1;
+                logger.info("DB closed times :{}", dbClosedTimes);
+            } else {
+                dbClosedTimes = 0;
+            }
+
+            if (dbClosedTimes >= 3) {

Review Comment:
   Does the maximum number of checks need to be extracted from the macro 
definition?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to