Skip to content

Commit

Permalink
Merge branch '2.x' into add_jdk21_02
Browse files Browse the repository at this point in the history
  • Loading branch information
lightClouds917 authored Jan 6, 2025
2 parents 13daa81 + 5b31862 commit 4b51b87
Show file tree
Hide file tree
Showing 26 changed files with 260 additions and 101 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ 2.x, develop, master ]

jobs:
# job 1: Test based on java 8 and 17. Do not checkstyle.
# job 1: Test based on java 8, 17 and 21. Do not checkstyle.
build:
name: "build"
services:
Expand All @@ -28,7 +28,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [ 8, 17 ]
java: [ 8, 17, 21 ]
steps:
# step 1
- name: "Checkout"
Expand Down
8 changes: 7 additions & 1 deletion changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Add changes here for all PR submitted to the 2.x branch.
### feature:

- [[#7073](https://github.com/apache/incubator-seata/pull/7073)] support virtual thread,replace the usages of synchronized with ReentrantLock
- [[#7037](https://github.com/apache/incubator-seata/pull/7037)] support fury undolog parser
- [[#7069](https://github.com/apache/incubator-seata/pull/7069)] Raft cluster mode supports address translation

### bugfix:
Expand All @@ -16,14 +17,16 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6828](https://github.com/apache/incubator-seata/pull/6828)] spring boot compatible with file.conf and registry.conf
- [[#7012](https://github.com/apache/incubator-seata/pull/7012)] When the number of primary keys exceeds 1000, use union to concatenate the SQL
- [[#7075](https://github.com/apache/incubator-seata/pull/7075)] fast fail when channel is null
- [[#7089](https://github.com/apache/incubator-seata/pull/7089)] support instance registration to the registry center
- [[#7093](https://github.com/apache/incubator-seata/pull/7093)] add a test workflow for JDK 21

### security:

- [[#PR_NO](https://github.com/apache/incubator-seata/pull/PR_NO)] upgrade XXX

### test:

- [[#PR_NO](https://github.com/apache/incubator-seata/pull/PR_NO)] test XXX
- [[#7092](https://github.com/apache/incubator-seata/pull/7092)] fix the issue of NacosMockTest failing to run

### refactor:

Expand All @@ -34,9 +37,12 @@ Thanks to these contributors for their code commits. Please report an unintended
<!-- Please make sure your Github ID is in the list below -->

- [slievrly](https://github.com/slievrly)
- [GoodBoyCoder](https://github.com/GoodBoyCoder)
- [lyl2008dsg](https://github.com/lyl2008dsg)
- [remind](https://github.com/remind)
- [lightClouds917](https://github.com/lightClouds917)
- [PeppaO](https://github.com/PeppaO)
- [funky-eyes](https://github.com/funky-eyes)


Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
7 changes: 6 additions & 1 deletion changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### feature:

- [[#7073](https://github.com/apache/incubator-seata/pull/7073)] 支持虚拟线程,用ReentrantLock替换synchronized的用法
- [[#7037](https://github.com/apache/incubator-seata/pull/7037)] 支持UndoLog的fury序列化方式
- [[#7069](https://github.com/apache/incubator-seata/pull/7069)] Raft集群模式支持地址转换

### bugfix:
Expand All @@ -16,14 +17,16 @@
- [[#6828](https://github.com/apache/incubator-seata/pull/6828)] seata-spring-boot-starter兼容file.conf和registry.conf
- [[#7012](https://github.com/apache/incubator-seata/pull/7012)] 当主键超过1000个时,使用union拼接sql,可以使用索引
- [[#7075](https://github.com/apache/incubator-seata/pull/7075)] 当channel为空时,快速失败,以便于减少不必要的等待
- [[#7089](https://github.com/apache/incubator-seata/pull/7089)] 新增instance注册到注册中心的接口
- [[#7093](https://github.com/apache/incubator-seata/pull/7093)] 增加jdk21的工作流测试

### security:

- [[#PR_NO](https://github.com/apache/incubator-seata/pull/PR_NO)] 升级XXX

### test:

- [[#PR_NO](https://github.com/apache/incubator-seata/pull/PR_NO)] 测试XXX
- [[#7092](https://github.com/apache/incubator-seata/pull/7092)] 修复NacosMockTest测试方法并行导致测试结果被干扰失败的问题

### refactor:

Expand All @@ -34,9 +37,11 @@
<!-- 请确保您的 GitHub ID 在以下列表中 -->

- [slievrly](https://github.com/slievrly)
- [GoodBoyCoder](https://github.com/GoodBoyCoder)
- [lyl2008dsg](https://github.com/lyl2008dsg)
- [remind](https://github.com/remind)
- [lightClouds917](https://github.com/lightClouds917)
- [PeppaO](https://github.com/PeppaO)
- [funky-eyes](https://github.com/funky-eyes)

同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.seata.common.metadata.namingserver;
package org.apache.seata.common.metadata;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.seata.common.metadata.ClusterRole;
import org.apache.seata.common.metadata.Node;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import static org.apache.seata.common.util.CollectionUtils.mapToJsonString;


public class Instance {
private String namespace;
private String clusterName;
private String unit;
private Node.Endpoint control = new Node.Endpoint();
private Node.Endpoint transaction = new Node.Endpoint();
private Node.Endpoint control;
private Node.Endpoint transaction;
private double weight = 1.0;
private boolean healthy = true;
private long term;
Expand Down Expand Up @@ -169,25 +164,6 @@ public String toJsonString(ObjectMapper objectMapper) {
}
}


public Map<String, String> toMap() {
Map<String, String> resultMap = new HashMap<>();


resultMap.put("namespace", namespace);
resultMap.put("clusterName", clusterName);
resultMap.put("unit", unit);
resultMap.put("control", control.toString());
resultMap.put("transaction", transaction.toString());
resultMap.put("weight", String.valueOf(weight));
resultMap.put("healthy", String.valueOf(healthy));
resultMap.put("term", String.valueOf(term));
resultMap.put("timestamp", String.valueOf(timestamp));
resultMap.put("metadata", mapToJsonString(metadata));

return resultMap;
}

private static class SingletonHolder {
private static final Instance SERVER_INSTANCE = new Instance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.seata.common.metadata.ClusterRole;
import org.apache.seata.common.metadata.Instance;
import org.apache.seata.common.metadata.Node;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class NacosMockTest {
private static ConfigService configService;
private static final String NACOS_ENDPOINT = "127.0.0.1:8848";
Expand Down Expand Up @@ -68,6 +71,7 @@ public static void setup() throws NacosException {

@Test
@EnabledOnOs(OS.LINUX)
@Order(1)
public void getInstance() {
Assertions.assertNotNull(configService);
Assertions.assertNotNull(NacosConfiguration.getInstance());
Expand All @@ -76,6 +80,7 @@ public void getInstance() {

@Test
@EnabledOnOs(OS.LINUX)
@Order(2)
public void getConfig() {
Configuration configuration = ConfigurationFactory.getInstance();
String configStrValue = configuration.getConfig(SUB_NACOS_DATAID);
Expand Down Expand Up @@ -141,6 +146,7 @@ public void getConfig() {

@Test
@EnabledOnOs(OS.LINUX)
@Order(3)
public void putConfigIfAbsent() {
Configuration configuration = ConfigurationFactory.getInstance();
Assertions.assertThrows(UndeclaredThrowableException.class, () -> {
Expand All @@ -150,6 +156,7 @@ public void putConfigIfAbsent() {

@Test
@EnabledOnOs(OS.LINUX)
@Order(4)
public void removeConfig() {
Configuration configuration = ConfigurationFactory.getInstance();
boolean removed = configuration.removeConfig(NACOS_DATAID);
Expand All @@ -158,6 +165,7 @@ public void removeConfig() {

@Test
@EnabledOnOs(OS.LINUX)
@Order(5)
public void putConfig() {
Configuration configuration = ConfigurationFactory.getInstance();
boolean added = configuration.putConfig(SUB_NACOS_DATAID, "TEST");
Expand All @@ -168,6 +176,7 @@ public void putConfig() {

@Test
@EnabledOnOs(OS.LINUX)
@Order(6)
public void testConfigListener() throws NacosException, InterruptedException {
Configuration configuration = ConfigurationFactory.getInstance();
configuration.putConfig(NACOS_DATAID, "KEY=TEST");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import io.netty.handler.timeout.IdleStateHandler;
import org.apache.seata.common.ConfigurationKeys;
import org.apache.seata.common.XID;
import org.apache.seata.common.metadata.Instance;
import org.apache.seata.common.metadata.Node;
import org.apache.seata.common.thread.NamedThreadFactory;
import org.apache.seata.config.ConfigurationFactory;
import org.apache.seata.core.rpc.RemotingBootstrap;
Expand Down Expand Up @@ -170,9 +172,13 @@ public void initChannel(SocketChannel ch) {
try {
this.serverBootstrap.bind(port).sync();
LOGGER.info("Server started, service listen port: {}", getListenPort());
InetSocketAddress address = new InetSocketAddress(XID.getIpAddress(), XID.getPort());
Instance instance = Instance.getInstance();
// Lines 177-180 are just for compatibility with test cases
if (instance.getTransaction() == null) {
Instance.getInstance().setTransaction(new Node.Endpoint(XID.getIpAddress(), XID.getPort(), "netty"));
}
for (RegistryService<?> registryService : MultiRegistryFactory.getInstances()) {
registryService.register(address);
registryService.register(Instance.getInstance());
}
initialized.set(true);
} catch (SocketException se) {
Expand All @@ -189,9 +195,8 @@ public void shutdown() {
LOGGER.info("Shutting server down, the listen port: {}", XID.getPort());
}
if (initialized.get()) {
InetSocketAddress address = new InetSocketAddress(XID.getIpAddress(), XID.getPort());
for (RegistryService registryService : MultiRegistryFactory.getInstances()) {
registryService.unregister(address);
registryService.unregister(Instance.getInstance());
registryService.close();
}
//wait a few seconds for server transport
Expand Down
9 changes: 9 additions & 0 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@
<janino-version>3.1.10</janino-version>
<mockwebserver-version>4.12.0</mockwebserver-version>
<native-lib-loader.version>2.4.0</native-lib-loader.version>

<!-- for fury -->
<fury.version>0.8.0</fury.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -879,6 +882,12 @@
<version>${rocketmq-version}</version>
</dependency>

<!-- Fury Serialize -->
<dependency>
<groupId>org.apache.fury</groupId>
<artifactId>fury-core</artifactId>
<version>${fury.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.seata.discovery.registry;

import org.apache.seata.common.metadata.Instance;
import org.apache.seata.common.util.CollectionUtils;
import org.apache.seata.config.ConfigurationFactory;

Expand Down Expand Up @@ -61,16 +62,42 @@ public interface RegistryService<T> {
* @param address the address
* @throws Exception the exception
*/
@Deprecated
void register(InetSocketAddress address) throws Exception;

/**
* Register.
*
* @param instance the address
* @throws Exception the exception
*/
default void register(Instance instance) throws Exception {
InetSocketAddress inetSocketAddress =
new InetSocketAddress(instance.getTransaction().getHost(), instance.getTransaction().getPort());
register(inetSocketAddress);
}

/**
* Unregister.
*
* @param address the address
* @throws Exception the exception
*/
@Deprecated
void unregister(InetSocketAddress address) throws Exception;

/**
* Unregister.
*
* @param instance the instance
* @throws Exception the exception
*/
default void unregister(Instance instance) throws Exception {
InetSocketAddress inetSocketAddress =
new InetSocketAddress(instance.getTransaction().getHost(), instance.getTransaction().getPort());
unregister(inetSocketAddress);
}

/**
* Subscribe.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
import org.apache.http.entity.ContentType;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.apache.seata.common.metadata.Node;
import org.apache.seata.common.metadata.namingserver.Instance;
import org.apache.seata.common.metadata.Instance;
import org.apache.seata.common.metadata.namingserver.MetaResponse;
import org.apache.seata.common.thread.NamedThreadFactory;
import org.apache.seata.common.util.CollectionUtils;
Expand Down Expand Up @@ -148,9 +147,11 @@ static NamingserverRegistryServiceImpl getInstance() {

@Override
public void register(InetSocketAddress address) throws Exception {
NetUtil.validAddress(address);
Instance instance = Instance.getInstance();
instance.setTransaction(new Node.Endpoint(address.getAddress().getHostAddress(), address.getPort(), "netty"));
register(Instance.getInstance());
}

@Override
public void register(Instance instance) throws Exception {
instance.setTimestamp(System.currentTimeMillis());
doRegister(instance, getNamingAddrs());
}
Expand Down Expand Up @@ -198,11 +199,15 @@ public boolean doHealthCheck(String url) {
}
}



@Override
public void unregister(InetSocketAddress inetSocketAddress) {
unregister(Instance.getInstance());
}

@Override
public void unregister(InetSocketAddress address) {
NetUtil.validAddress(address);
Instance instance = Instance.getInstance();
instance.setTransaction(new Node.Endpoint(address.getAddress().getHostAddress(), address.getPort(), "netty"));
public void unregister(Instance instance) {
for (String urlSuffix : getNamingAddrs()) {
String url = HTTP_PREFIX + urlSuffix + "/naming/v1/unregister?";
String unit = instance.getUnit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.concurrent.TimeUnit;

import org.apache.seata.common.XID;
import org.apache.seata.common.metadata.Instance;
import org.apache.seata.common.metadata.Node;
import org.apache.seata.common.thread.NamedThreadFactory;
import org.apache.seata.common.util.NetUtil;
import org.apache.seata.common.util.NumberUtils;
Expand Down Expand Up @@ -78,6 +80,7 @@ public static void start(int port) {
XID.setIpAddress(NetUtil.getLocalIp());
XID.setPort(port);
// init snowflake for transactionId, branchId
Instance.getInstance().setTransaction(new Node.Endpoint(XID.getIpAddress(),XID.getPort(),"netty"));
UUIDGenerator.init(1L);

MockCoordinator coordinator = MockCoordinator.getInstance();
Expand Down
Loading

0 comments on commit 4b51b87

Please sign in to comment.