From 50c77dc44764c591ced04f1fe3d9fd1ea4ca06d7 Mon Sep 17 00:00:00 2001
From: ggbocoder <1832877748@qq.com>
Date: Tue, 2 Jan 2024 10:47:26 +0800
Subject: [PATCH 01/14] add signature
---
changes/en-us/2.x.md | 1 +
changes/zh-cn/2.x.md | 1 +
2 files changed, 2 insertions(+)
diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index fb0f41b9e4d..7feac090302 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -45,6 +45,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6200](/~https://github.com/apache/incubator-seata/pull/6200)] cancel required_status_checks
- [[#6201](/~https://github.com/apache/incubator-seata/pull/6201)] restore required_status_checks kept to remove context validation
- [[#6218](/~https://github.com/apache/incubator-seata/pull/6218)] remove Seata-Docker link
+- [[#6227](/~https://github.com/apache/incubator-seata/pull/6227)] validate that the primary key is free of illegal characters
### security:
- [[#6069](/~https://github.com/apache/incubator-seata/pull/6069)] Upgrade Guava dependencies to fix security vulnerabilities
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index e87037d13e4..62f52558f91 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -45,6 +45,7 @@
- [[#6200](/~https://github.com/apache/incubator-seata/pull/6200)] 去除required_status_checks检查
- [[#6201](/~https://github.com/apache/incubator-seata/pull/6201)] 恢复required_status_checks但去除context校验
- [[#6218](/~https://github.com/apache/incubator-seata/pull/6218)] 移除Seata-Docker链接
+- [[#6227](/~https://github.com/apache/incubator-seata/pull/6227)] 校验pk中不含逗号
### security:
- [[#6069](/~https://github.com/apache/incubator-seata/pull/6069)] 升级Guava依赖版本,修复安全漏洞
From cf974364ef66a412e50186c186fa90fd41f947aa Mon Sep 17 00:00:00 2001
From: ggbocoder <1832877748@qq.com>
Date: Tue, 20 Aug 2024 07:56:33 +0800
Subject: [PATCH 02/14] fix
---
.../namingserver/NamingServerNode.java | 9 ++
dependencies/pom.xml | 6 +
.../NamingserverRegistryServiceImpl.java | 12 +-
namingserver/pom.xml | 5 +
.../namingserver/manager/NamingManager.java | 126 ++++++++++--------
.../java/org/apache/seata/server/Server.java | 27 +++-
.../db/store/VGroupMappingDataBaseDAO.java | 3 +-
7 files changed, 116 insertions(+), 72 deletions(-)
diff --git a/common/src/main/java/org/apache/seata/common/metadata/namingserver/NamingServerNode.java b/common/src/main/java/org/apache/seata/common/metadata/namingserver/NamingServerNode.java
index 5645ac0e3ed..459dd66b944 100644
--- a/common/src/main/java/org/apache/seata/common/metadata/namingserver/NamingServerNode.java
+++ b/common/src/main/java/org/apache/seata/common/metadata/namingserver/NamingServerNode.java
@@ -27,6 +27,15 @@ public class NamingServerNode extends Node {
private double weight = 1.0;
private boolean healthy = true;
private long term;
+ private String unit;
+
+ public String getUnit() {
+ return unit;
+ }
+
+ public void setUnit(String unit) {
+ this.unit = unit;
+ }
public double getWeight() {
return weight;
diff --git a/dependencies/pom.xml b/dependencies/pom.xml
index e4887f5ca42..bb063aaf73c 100644
--- a/dependencies/pom.xml
+++ b/dependencies/pom.xml
@@ -111,6 +111,7 @@
1.2.20
2.9.0
3.4.3
+ 3.1.8
4.8
@@ -395,6 +396,11 @@
+
+ com.github.ben-manes.caffeine
+ caffeine
+ ${caffeine.version}
+
com.alibaba.spring
spring-context-support
diff --git a/discovery/seata-discovery-namingserver/src/main/java/org/apache/seata/discovery/registry/namingserver/NamingserverRegistryServiceImpl.java b/discovery/seata-discovery-namingserver/src/main/java/org/apache/seata/discovery/registry/namingserver/NamingserverRegistryServiceImpl.java
index b8c988eb310..719336283d3 100644
--- a/discovery/seata-discovery-namingserver/src/main/java/org/apache/seata/discovery/registry/namingserver/NamingserverRegistryServiceImpl.java
+++ b/discovery/seata-discovery-namingserver/src/main/java/org/apache/seata/discovery/registry/namingserver/NamingserverRegistryServiceImpl.java
@@ -62,7 +62,6 @@
import org.slf4j.LoggerFactory;
-
public class NamingserverRegistryServiceImpl implements RegistryService {
private static final Logger LOGGER = LoggerFactory.getLogger(NamingserverRegistryServiceImpl.class);
@@ -163,15 +162,6 @@ public void register(InetSocketAddress address) throws Exception {
heartBeatScheduledFuture.cancel(false);
}
- heartBeatScheduledFuture = this.executorService.scheduleAtFixedRate(() -> {
- try {
- instance.setTimestamp(System.currentTimeMillis());
- doRegister(instance, getNamingAddrs());
- } catch (Exception e) {
- LOGGER.error("Naming server register Exception", e);
- }
- }, HEARTBEAT_PERIOD, HEARTBEAT_PERIOD, TimeUnit.MILLISECONDS);
-
}
public void doRegister(Instance instance, List urlList) {
@@ -232,7 +222,7 @@ public void unregister(InetSocketAddress address) {
String unit = instance.getUnit();
String jsonBody = instance.toJsonString();
String params = "unit=" + unit;
- params = params + "&cluster=" + instance.getClusterName();
+ params = params + "&clusterName=" + instance.getClusterName();
params = params + "&namespace=" + instance.getNamespace();
url += params;
Map header = new HashMap<>();
diff --git a/namingserver/pom.xml b/namingserver/pom.xml
index 61e5b0bd8a6..4ed5764fa82 100644
--- a/namingserver/pom.xml
+++ b/namingserver/pom.xml
@@ -82,6 +82,11 @@
spring-boot-starter
+
+ com.github.ben-manes.caffeine
+ caffeine
+
+
org.springframework.boot
spring-boot-starter-test
diff --git a/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java b/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java
index 5e892674b43..7849346a803 100644
--- a/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java
+++ b/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java
@@ -33,6 +33,10 @@
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.PostConstruct;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.LoadingCache;
+import com.github.benmanes.caffeine.cache.RemovalCause;
+import com.github.benmanes.caffeine.cache.RemovalListener;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.entity.ContentType;
import org.apache.http.protocol.HTTP;
@@ -47,6 +51,8 @@
import org.apache.seata.namingserver.listener.ClusterChangeEvent;
import org.apache.seata.namingserver.entity.pojo.ClusterData;
import org.apache.seata.namingserver.entity.vo.monitor.ClusterVO;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -63,10 +69,10 @@
public class NamingManager {
private static final Logger LOGGER = LoggerFactory.getLogger(NamingManager.class);
private final ConcurrentMap instanceLiveTable;
- private final ConcurrentMap/* unitName */>>> vGroupMap;
+ private volatile LoadingCache/* unitName */>>> vGroupMap;
private final ConcurrentMap> namespaceClusterDataMap;
+ ConcurrentMap> namespaceClusterDataMap;
@Value("${heartbeat.threshold:90000}")
private int heartbeatTimeThreshold;
@@ -75,19 +81,29 @@ public class NamingManager {
private int heartbeatCheckTimePeriod;
protected final ScheduledExecutorService heartBeatCheckService =
- new ScheduledThreadPoolExecutor(1, new CustomizableThreadFactory("heartBeatCheckExcuter"));
+ new ScheduledThreadPoolExecutor(1, new CustomizableThreadFactory("heartBeatCheckExcuter"));
@Autowired
private ApplicationContext applicationContext;
public NamingManager() {
this.instanceLiveTable = new ConcurrentHashMap<>();
- this.vGroupMap = new ConcurrentHashMap<>();
this.namespaceClusterDataMap = new ConcurrentHashMap<>();
}
@PostConstruct
public void init() {
+ this.vGroupMap = Caffeine.newBuilder()
+ .expireAfterAccess(10000, TimeUnit.MILLISECONDS) // 设置过期时间
+ .maximumSize(Integer.MAX_VALUE) // 设置最大缓存条目数
+ .removalListener(new RemovalListener