瀏覽代碼

优化逻辑

穿云 3 月之前
父節點
當前提交
72e328e5dd

+ 18 - 6
dbsyncer-biz/src/main/java/org/dbsyncer/biz/impl/PluginServiceImpl.java

@@ -8,6 +8,7 @@ import org.dbsyncer.biz.PluginService;
 import org.dbsyncer.biz.vo.PluginVo;
 import org.dbsyncer.common.util.CollectionUtils;
 import org.dbsyncer.common.util.StringUtil;
+import org.dbsyncer.parser.ParserException;
 import org.dbsyncer.parser.ProfileComponent;
 import org.dbsyncer.parser.LogService;
 import org.dbsyncer.parser.LogType;
@@ -22,9 +23,9 @@ import org.springframework.util.Assert;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
 /**
@@ -90,7 +91,7 @@ public class PluginServiceImpl implements PluginService {
     }
 
     private Map<String, List<String>> getPluginClassNameMap() {
-        Map<String, List<String>> map = new HashMap<>();
+        Map<String, List<String>> map = new ConcurrentHashMap<>();
         List<Mapping> mappingAll = profileComponent.getMappingAll();
         if (CollectionUtils.isEmpty(mappingAll)) {
             return map;
@@ -99,8 +100,7 @@ public class PluginServiceImpl implements PluginService {
         for (Mapping m : mappingAll) {
             Plugin plugin = m.getPlugin();
             if (null != plugin) {
-                map.putIfAbsent(plugin.getClassName(), new ArrayList<>());
-                map.get(plugin.getClassName()).add(m.getName());
+                putPluginMap(map, plugin.getClassName(), m.getName());
                 continue;
             }
 
@@ -111,8 +111,7 @@ public class PluginServiceImpl implements PluginService {
             for (TableGroup t : tableGroupAll) {
                 Plugin p = t.getPlugin();
                 if (null != p) {
-                    map.putIfAbsent(p.getClassName(), new ArrayList<>());
-                    map.get(p.getClassName()).add(m.getName());
+                    putPluginMap(map, p.getClassName(), m.getName());
                     break;
                 }
             }
@@ -120,4 +119,17 @@ public class PluginServiceImpl implements PluginService {
 
         return map;
     }
+
+    private void putPluginMap(Map<String, List<String>> map, String className, String name) {
+        map.compute(className, (k,v) -> {
+            if (v == null) {
+                try {
+                    return new ArrayList<>();
+                } catch (Exception e) {
+                    throw new ParserException(e);
+                }
+            }
+            return v;
+        }).add(name);
+    }
 }

+ 6 - 1
dbsyncer-common/src/main/java/org/dbsyncer/common/scheduled/impl/ScheduledTaskServiceImpl.java

@@ -73,7 +73,12 @@ public class ScheduledTaskServiceImpl implements ScheduledTaskService, Disposabl
             logger.error(msg);
             throw new CommonException(msg);
         }
-        map.putIfAbsent(key, scheduledFutureMapper.apply());
+        map.compute(key, (k,v) -> {
+            if (v == null) {
+                return scheduledFutureMapper.apply();
+            }
+            return v;
+        });
     }
 
     @Override

+ 1 - 1
dbsyncer-parser/src/main/java/org/dbsyncer/parser/impl/CacheServiceImpl.java

@@ -15,7 +15,7 @@ import java.util.concurrent.ConcurrentHashMap;
 @Component
 public class CacheServiceImpl implements CacheService {
 
-    private Map<String, Object> cache = new ConcurrentHashMap<>();
+    private final Map<String, Object> cache = new ConcurrentHashMap<>();
 
     @Override
     public Object put(String key, Object value) {

+ 7 - 4
dbsyncer-sdk/src/main/java/org/dbsyncer/sdk/listener/AbstractDatabaseListener.java

@@ -127,10 +127,13 @@ public abstract class AbstractDatabaseListener extends AbstractListener<Database
             querySql.append(notContainsWhere ? " WHERE " : StringUtil.EMPTY);
             PrimaryKeyUtil.buildSql(querySql, primaryKeys, quotation, " AND ", " = ? ", notContainsWhere);
             DqlMapper dqlMapper = new DqlMapper(instance, sqlName, querySql.toString(), sqlColumns, tablePKIndex, sqlPKIndexMap);
-            if (!dqlMap.containsKey(tableName)) {
-                dqlMap.putIfAbsent(tableName, new ArrayList<>());
-            }
-            dqlMap.get(tableName).add(dqlMapper);
+            dqlMap.compute(tableName, (k, v)-> {
+                if(v == null) {
+                    return new ArrayList<>();
+                }
+                return v;
+            }).add(dqlMapper);
+
             // 注册监听表名
             filterTable.add(tableName);
         }

+ 2 - 2
dbsyncer-web/src/main/resources/application.properties

@@ -27,7 +27,7 @@ dbsyncer.parser.general.buffer-writer-count=1000
 # [GeneralBufferActuator]每次消费缓存队列的任务数
 dbsyncer.parser.general.buffer-pull-count=20000
 # [GeneralBufferActuator]缓存队列容量
-dbsyncer.parser.general.buffer-queue-capacity=100000
+dbsyncer.parser.general.buffer-queue-capacity=50000
 # [GeneralBufferActuator]定时消费缓存队列间隔(毫秒)
 dbsyncer.parser.general.buffer-period-millisecond=300
 # *********************** 表执行器配置 ***********************
@@ -66,7 +66,7 @@ dbsyncer.storage.buffer-writer-count=1000
 # [StorageBufferActuator]每次消费缓存队列的任务数
 dbsyncer.storage.buffer-pull-count=20000
 # [StorageBufferActuator]缓存队列容量
-dbsyncer.storage.buffer-queue-capacity=100000
+dbsyncer.storage.buffer-queue-capacity=50000
 # [StorageBufferActuator]定时消费缓存队列间隔(毫秒)
 dbsyncer.storage.buffer-period-millisecond=300