Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: seata namingserver #5800

Merged
merged 31 commits into from
Oct 26, 2023
Merged

Conversation

ggbocoder
Copy link
Contributor

@ggbocoder ggbocoder commented Aug 25, 2023

  • I have registered the PR [[changes](typora://app/changes)](../changes).

Ⅰ. Describe what this PR did

1.实现了注册中心的基本功能,包括服务注册,服务发现,心跳检测等
2.设计并实现了领域模型的数据结构,包括集群,节点等
3.添加了部分单元测试/集成测试,并在seata-samples上进行验证

namingserver提供的HTTP接口如下:

接口名称 接口类型 说明 参数
registerInstance Post server服务注册接口 namespace 节点所属命名空间
clusterName 节点所属集群名称
unitName 节点所属unit名称
node 节点实体类
unregisterInstance Post server服务下线接口 unitName 节点所属命名空间
node 节点实体类
discovery Get client服务发现接口 namespace 命名空间
vGroup 事务分组
changeGroup Post 控制台修改事务接口 namespace 命名空间
clusterName 集群名称
unitName unit名称
vGroup 事务分组
watch Get client服务订阅接口 clientTerm 客户端保存的订阅时间戳
vGroup 事务分组
timeout 超时时间
request 客户端HTTP请求
health Get namingserver健康检查接口
clusters Get 控制台监控所有集群状态接口 namespace 命名空间

接口详情请查看[namingserver (getpostman.com)](https://documenter.getpostman.com/view/26098677/2s9YC31uAW)

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

测试名称 测试功能 通过情况
testRegister1 测试server节点注册后能否被发现 通过
testRegister2 测试同一server节点注册两次,服务发现时是否只有唯一一条数据 通过
testRegister3 测试多个server节点注册后能否全部被发现 通过
testUnregister 测试server节点register后又unregister是否不会被发现 通过
testWatch 测试server节点注册信息改变能否在1s内通知到client 通过
testSubscribe 测试server节点注册信息改变是否被通知 通过
testUnsubscribe 测试取消订阅后server节点注册信息改变是否会通知client 通过

image

Ⅳ. Describe how to verify it

1.执行mvn clean install "-Dmaven.test.skip=true"打包项目

2.将seata-samples中的seata-all版本换成新打包的版本

3.在seata-samples中修改registry配置,修改成

  type = "namingserver"
  namingserver {
    serverAddr = "127.0.0.1:8080"  //namingserver节点地址
  }

4.启动NamingserverApplication

5.修改server端的配置

  registry:
    type: namingserver
    metadata:
      cluster-type: default
      weight: 1
    namingserver:
      server-addr:
        - 127.0.0.1:8080
      cluster: cluster2
      namespace: public

6.启动server端的ServerApplication

7.启动DubboStockServiceStarter,DubboAccountServiceStarter,DubboOrderServiceStarter,DubboBusinessTester

Ⅴ. Special notes for reviews

implement domain model data structure
provide register,unregister,discovery,watch restful api to client
add tests
Disables
disabled
disabled tests
@CLAassistant
Copy link

CLAassistant commented Aug 25, 2023

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Sep 17, 2023

Codecov Report

Merging #5800 (62785a3) into summer-code_namingServer (2626f24) will decrease coverage by 1.82%.
The diff coverage is 6.71%.

❗ Current head 62785a3 differs from pull request most recent head b880a9d. Consider uploading reports for the commit b880a9d to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@                      Coverage Diff                       @@
##             summer-code_namingServer    #5800      +/-   ##
==============================================================
- Coverage                       49.78%   47.96%   -1.82%     
+ Complexity                       4545     4476      -69     
==============================================================
  Files                             854      837      -17     
  Lines                           29883    29287     -596     
  Branches                         3660     3630      -30     
==============================================================
- Hits                            14877    14048     -829     
- Misses                          13516    13781     +265     
+ Partials                         1490     1458      -32     
Files Coverage Δ
...ta/spring/boot/autoconfigure/StarterConstants.java 100.00% <ø> (ø)
...a/server/storage/db/store/LogStoreDataBaseDAO.java 75.44% <83.33%> (ø)
...java/io/seata/discovery/registry/RegistryType.java 0.00% <0.00%> (ø)
...try/namingserver/NamingserverRegistryProvider.java 0.00% <0.00%> (ø)
.../server/spring/listener/SeataPropertiesLoader.java 90.69% <86.95%> (-4.76%) ⬇️
...registry/namingserver/NamingRegistryException.java 0.00% <0.00%> (ø)
.../seata/server/store/VGroupMappingStoreManager.java 0.00% <0.00%> (ø)
...rc/main/java/io/seata/common/metadata/Cluster.java 0.00% <0.00%> (ø)
...in/java/io/seata/common/metadata/MetaResponse.java 0.00% <0.00%> (ø)
...e/src/main/java/io/seata/core/store/MappingDO.java 0.00% <0.00%> (ø)
... and 10 more

... and 65 files with indirect coverage changes

@slievrly slievrly added this to the Summer Code 2023 milestone Oct 19, 2023
@funky-eyes funky-eyes added type: feature Category issues or prs related to feature request. module/discovery discovery module module/server server module labels Oct 21, 2023
@funky-eyes funky-eyes changed the base branch from 2.x to summer-code_namingServer October 21, 2023 14:49
private List<Unit> unitData;

public Cluster() {
unitData = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest deleting this line of code and assigning the value in line 24.


private Map<String, Object> metadata = new HashMap<>();

private static Instance instance;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing to a singleton pattern for static inner classes

}

public void addMetadata(String key, Object value) {
if (this.metadata == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value is already assigned when the instance is created, so why is it necessary to make a judgment here?

&& Objects.equals(unit, instance.unit);
}

public String mapToJsonString(Map<String, Object> map) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be reused in CollectionUtils.



// convert String to Object
public static Node fromJsonString(String jsonString) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete useless code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this file.

</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-core</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not rely on the seata-core module

public class NamingController {
private static final Logger LOGGER = LoggerFactory.getLogger(NamingController.class);

private static final String OK = "200";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define a status code enumeration

@ConfigurationProperties(prefix = REGISTRY_NAMINGSERVER_PREFIX)
public class RegistryNamingserverProperties {
private String namespace = "public";
private String serverAddr = "127.0.0.1:8500";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the port 8500?

@@ -75,6 +92,47 @@ public void initialize(ConfigurableApplicationContext applicationContext) {
// Load by priority
System.setProperty("sessionMode", StoreConfig.getSessionMode().getName());
System.setProperty("lockMode", StoreConfig.getLockMode().getName());

// load node properties
Instance instance = Instance.getInstance();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't have too much content in one method. Separate methods by role type.

}

// load vgroup mapping relationship
String storeType = ConfigurationFactory.getInstance().getConfig("store.mode", "db");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read from SessionMode

}

@Override
public HashMap<String, Object> load() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change method name to loadVGroups

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class has not been modified, please roll it back.

HashMap<String, Object> vGroupMapping = new HashMap<>();
try {
File fileToLoad = new File(path);
if (!fileToLoad.exists()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the file exist when you first started it?

public boolean addVGroup(MappingDO mappingDO) {
String vGroup = mappingDO.getVGroup();
try (Jedis jedis = JedisPooledFactory.getJedisInstance(); Pipeline pipelined = jedis.pipelined()) {
pipelined.hmset(vGroup, BeanUtils.objectToMap(mappingDO));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a thread safety issue?

# support: nacos 、 eureka 、 redis 、 zk 、 consul 、 etcd3 、 sofa
type: file
# support: nacos 、 eureka 、 redis 、 zk 、 consul 、 etcd3 、 sofa 、 namingserver
type: namingserver
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to file


namingserver:
server-addr:
- 127.0.0.1:8889
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use a string, but a list?

store:
# support: file 、 db 、 redis
mode: file
# db:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these test codes

console/pom.xml Outdated
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-common</artifactId>
<version>2.0.0-SNAPSHOT</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to write the version number, do you?

core/pom.xml Outdated
@@ -67,6 +67,10 @@
<artifactId>fastjson</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the core module depend on httpclient?

<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-common</artifactId>
<version>2.0.0-SNAPSHOT</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to write the version number

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you remove all the original configurations here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other databases should also be supplemented with relevant table structures

server/pom.xml Outdated
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No version number should be added, all version dependencies should be handled in the dependencies module.

server/pom.xml Outdated
@@ -344,11 +337,6 @@
</ports>
<labels>
<name>seata-server</name>
<git.commit.message.full>${git.commit.message.full}</git.commit.message.full>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove?

@@ -40,6 +53,60 @@
* @author slievrly
*/
public class Server {

private static final String SEATA_ROOT_KEY = "seata";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is he a static variable and not a local variable?

weight: 1
namingserver:
server-addr: 127.0.0.1:8080,127.0.0.1:8081
cluster: cluster1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cluster1 change to default

metadata:
weight: 1
namingserver:
server-addr: 127.0.0.1:8080,127.0.0.1:8081
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why port is 8080?It is possible to write only one address here, because it is only an example.

Copy link
Contributor

@funky-eyes funky-eyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@funky-eyes funky-eyes merged commit 8fd1df4 into apache:summer-code_namingServer Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/discovery discovery module module/server server module summer2023 type: feature Category issues or prs related to feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants