You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "ggbocoder (via GitHub)" <gi...@apache.org> on 2024/08/29 00:36:16 UTC

[PR] Optimize: optimize the initialization logic for server meta [incubator-seata]

ggbocoder opened a new pull request, #6795:
URL: https://github.com/apache/incubator-seata/pull/6795

   <!-- Please make sure you have read and understood the contributing guidelines -->
   
   - [ ] I have registered the PR [changes](../changes).
   
   ### Ⅰ. Describe what this PR did
   1.optimize the initialization logic for server meta
   2.use jackson to serialize node
   3.remove the logic of replacing node-weight using metadata
   
   
   ### Ⅱ. Does this pull request fix one issue?
   <!-- If that, add "fixes #xxx" below in the next line, for example, fixes #97. -->
   
   
   ### Ⅲ. Why don't you add test cases (unit test/integration test)? 
   
   
   ### Ⅳ. Describe how to verify it
   
   
   ### Ⅴ. Special notes for reviews
   
   


-- 
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: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] optimize: optimize the initialization logic for server meta [incubator-seata]

Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #6795:
URL: https://github.com/apache/incubator-seata/pull/6795#discussion_r1738126299


##########
common/src/main/java/org/apache/seata/common/metadata/Node.java:
##########
@@ -40,6 +43,8 @@ public class Node {
 
     private Map<String, Object> metadata = new HashMap<>();
 
+    private ObjectMapper objectMapper = new ObjectMapper();

Review Comment:
   不要在node里创建这东西



##########
common/src/main/java/org/apache/seata/common/metadata/namingserver/Instance.java:
##########
@@ -41,7 +41,7 @@ public class Instance {
     private long timestamp;
     private ClusterRole role = ClusterRole.MEMBER;
     private Map<String, Object> metadata = new HashMap<>();
-
+    private final ObjectMapper objectMapper = new ObjectMapper();

Review Comment:
   不要在这个里面构建ObjectMapper



-- 
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: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] optimize: optimize the initialization logic for server meta [incubator-seata]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #6795:
URL: https://github.com/apache/incubator-seata/pull/6795#issuecomment-2319600401

   ## [Codecov](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: Patch coverage is `23.07692%` with `30 lines` in your changes missing coverage. Please review.
   > Project coverage is 52.21%. Comparing base [(`3bb8f73`)](https://app.codecov.io/gh/apache/incubator-seata/commit/3bb8f73a41a50c7424cc93fa79261e20d53cb96d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`f5a4fd2`)](https://app.codecov.io/gh/apache/incubator-seata/commit/f5a4fd2a346da221ef260f35eb7b7a11fb52d5b1?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...g/apache/seata/server/instance/ServerInstance.java](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?src=pr&el=tree&filepath=server%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fserver%2Finstance%2FServerInstance.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9zZXJ2ZXIvaW5zdGFuY2UvU2VydmVySW5zdGFuY2UuamF2YQ==) | 12.50% | [27 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...in/java/org/apache/seata/common/metadata/Node.java](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?src=pr&el=tree&filepath=common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcommon%2Fmetadata%2FNode.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9jb21tb24vbWV0YWRhdGEvTm9kZS5qYXZh) | 50.00% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/incubator-seata/pull/6795/graphs/tree.svg?width=650&height=150&src=pr&token=tbmHt2ZfxO&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@             Coverage Diff              @@
   ##                2.x    #6795      +/-   ##
   ============================================
   + Coverage     52.18%   52.21%   +0.02%     
   - Complexity     6311     6312       +1     
   ============================================
     Files          1067     1068       +1     
     Lines         37278    37259      -19     
     Branches       4427     4426       -1     
   ============================================
   + Hits          19455    19456       +1     
   + Misses        15890    15873      -17     
   + Partials       1933     1930       -3     
   ```
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...e/seata/common/metadata/namingserver/Instance.java](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?src=pr&el=tree&filepath=common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcommon%2Fmetadata%2Fnamingserver%2FInstance.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9jb21tb24vbWV0YWRhdGEvbmFtaW5nc2VydmVyL0luc3RhbmNlLmphdmE=) | `42.64% <100.00%> (ø)` | |
   | [...common/metadata/namingserver/NamingServerNode.java](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?src=pr&el=tree&filepath=common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcommon%2Fmetadata%2Fnamingserver%2FNamingServerNode.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9jb21tb24vbWV0YWRhdGEvbmFtaW5nc2VydmVyL05hbWluZ1NlcnZlck5vZGUuamF2YQ==) | `34.61% <ø> (-2.06%)` | :arrow_down: |
   | [...he/seata/namingserver/entity/pojo/ClusterData.java](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?src=pr&el=tree&filepath=namingserver%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fnamingserver%2Fentity%2Fpojo%2FClusterData.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bmFtaW5nc2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9uYW1pbmdzZXJ2ZXIvZW50aXR5L3Bvam8vQ2x1c3RlckRhdGEuamF2YQ==) | `70.90% <ø> (+3.11%)` | :arrow_up: |
   | [...ache/seata/namingserver/manager/NamingManager.java](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?src=pr&el=tree&filepath=namingserver%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fnamingserver%2Fmanager%2FNamingManager.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bmFtaW5nc2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9uYW1pbmdzZXJ2ZXIvbWFuYWdlci9OYW1pbmdNYW5hZ2VyLmphdmE=) | `68.42% <100.00%> (ø)` | |
   | [.../src/main/java/org/apache/seata/server/Server.java](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?src=pr&el=tree&filepath=server%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fserver%2FServer.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9zZXJ2ZXIvU2VydmVyLmphdmE=) | `72.72% <100.00%> (+31.45%)` | :arrow_up: |
   | [...in/java/org/apache/seata/common/metadata/Node.java](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?src=pr&el=tree&filepath=common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcommon%2Fmetadata%2FNode.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9jb21tb24vbWV0YWRhdGEvTm9kZS5qYXZh) | `63.07% <50.00%> (+13.07%)` | :arrow_up: |
   | [...g/apache/seata/server/instance/ServerInstance.java](https://app.codecov.io/gh/apache/incubator-seata/pull/6795?src=pr&el=tree&filepath=server%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fserver%2Finstance%2FServerInstance.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9zZXJ2ZXIvaW5zdGFuY2UvU2VydmVySW5zdGFuY2UuamF2YQ==) | `12.50% <12.50%> (ø)` | |
   
   </details>


-- 
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: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] optimize: optimize the initialization logic for server meta [incubator-seata]

Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes merged PR #6795:
URL: https://github.com/apache/incubator-seata/pull/6795


-- 
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: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] optimize: optimize the initialization logic for server meta [incubator-seata]

Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #6795:
URL: https://github.com/apache/incubator-seata/pull/6795#discussion_r1735823784


##########
server/src/main/java/org/apache/seata/server/Server.java:
##########
@@ -69,66 +56,14 @@
 public class Server {
     private static final Logger LOGGER = LoggerFactory.getLogger(Server.class);
 
-    protected static volatile ScheduledExecutorService EXECUTOR_SERVICE;
-
     @Resource
     RegistryNamingServerProperties registryNamingServerProperties;
 
     @Resource
     RegistryProperties registryProperties;
 
-    public void metadataInit() {
-        VGroupMappingStoreManager vGroupMappingStoreManager = SessionHolder.getRootVGroupMappingManager();
-        if (StringUtils.equals(registryProperties.getType(), NAMING_SERVER)) {
-            EXECUTOR_SERVICE = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("scheduledExcuter", 1, true));
-            ConfigurableEnvironment environment = (ConfigurableEnvironment) ObjectHolder.INSTANCE.getObject(OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT);
-
-            // load node properties
-            Instance instance = Instance.getInstance();
-            // load namespace
-            String namespace = registryNamingServerProperties.getNamespace();
-            instance.setNamespace(namespace);
-            // load cluster name
-            String clusterName = registryNamingServerProperties.getCluster();
-            instance.setClusterName(clusterName);
-
-            // load cluster type
-            String clusterType = String.valueOf(StoreConfig.getSessionMode());
-            instance.addMetadata("cluster-type", "raft".equals(clusterType) ? clusterType : "default");
-
-            // load unit name
-            instance.setUnit(String.valueOf(UUID.randomUUID()));
-
-            instance.setTerm(System.currentTimeMillis());
-
-            // load node Endpoint
-            instance.setControl(new Node.Endpoint(NetUtil.getLocalIp(), Integer.parseInt(Objects.requireNonNull(environment.getProperty("server.port"))), "http"));
-
-            // load metadata
-            for (PropertySource<?> propertySource : environment.getPropertySources()) {
-                if (propertySource instanceof EnumerablePropertySource) {
-                    EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) propertySource;
-                    for (String propertyName : enumerablePropertySource.getPropertyNames()) {
-                        if (propertyName.startsWith(META_PREFIX)) {
-                            instance.addMetadata(propertyName.substring(META_PREFIX.length()), enumerablePropertySource.getProperty(propertyName));
-                        }
-                    }
-                }
-            }
-            // load vgroup mapping relationship
-            instance.addMetadata("vGroup", vGroupMappingStoreManager.loadVGroups());
-
-            EXECUTOR_SERVICE.scheduleAtFixedRate(() -> {
-                try {
-                    vGroupMappingStoreManager.notifyMapping();
-                } catch (Exception e) {
-                    LOGGER.error("Naming server register Exception", e);
-                }
-            }, registryNamingServerProperties.getHeartbeatPeriod(),  registryNamingServerProperties.getHeartbeatPeriod(), TimeUnit.MILLISECONDS);
-            ServerRunner.addDisposable(EXECUTOR_SERVICE::shutdown);
-        }
-    }
-
+    @Resource
+    ServerInstance serverInstance;

Review Comment:
   registryNamingServerProperties 和 registryProperties在server里就不需要了吧?
   registryNamingServerProperties and registryProperties are not needed in the server, right?



##########
common/src/main/java/org/apache/seata/common/metadata/Node.java:
##########
@@ -122,27 +125,12 @@ public boolean equals(Object o) {
 
     // convert to String
     public String toJsonString() {
-        StringBuilder sb = new StringBuilder();
-        sb.append("{");
-        sb.append("\"controlEndpoint\": ").append(control.toString()).append(", ");
-        sb.append("\"transactionEndpoint\": ").append(transaction.toString()).append(", ");
-        sb.append("\"weight\": ").append(weight).append(", ");
-        sb.append("\"healthy\": ").append(healthy).append(", ");
-        sb.append("\"timeStamp\": ").append(timeStamp).append(", ");
-        sb.append("\"metadata\": {");
-
-        // handle metadata k-v map
-        int i = 0;
-        for (Map.Entry<String, Object> entry : metadata.entrySet()) {
-            if (i > 0) {
-                sb.append(", ");
-            }
-            sb.append("\"").append(entry.getKey()).append("\": \"").append(entry.getValue()).append("\"");
-            i++;
+        ObjectMapper objectMapper = new ObjectMapper();

Review Comment:
   将objectMapper构建在NamingserverRegistryServiceImpl里,通过传入进来的objectMapper进行toJsonString,包括instance内的toJsonString之类的转行,全部改成这样
   Build objectMapper in NamingserverRegistryServiceImpl, toJsonString is performed through the incoming objectMapper, including the row transition of toJsonString in instance, all changed to this



-- 
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: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org