funky-eyes commented on code in PR #6538: URL: https://github.com/apache/incubator-seata/pull/6538#discussion_r1685869749
########## server/src/main/java/org/apache/seata/server/storage/db/store/VGroupMappingDataBaseDAO.java: ########## @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seata.server.storage.db.store; + +import org.apache.seata.common.metadata.namingserver.Instance; +import org.apache.seata.common.util.IOUtil; +import org.apache.seata.config.Configuration; +import org.apache.seata.config.ConfigurationFactory; +import org.apache.seata.core.store.MappingDO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import static org.apache.seata.common.NamingServerConstants.DEFAULT_VGROUP_MAPPING; +import static org.apache.seata.common.NamingServerConstants.MAPPING_TABLE_NAME; +import static org.apache.seata.common.NamingServerConstants.REGISTRY_NAMINGSERVER_CLUSTER; + + +public class VGroupMappingDataBaseDAO { + private static final Logger LOGGER = LoggerFactory.getLogger(VGroupMappingDataBaseDAO.class); + + protected DataSource vGroupMappingDataSource = null; + + protected final String vMapping; + + protected static final Configuration CONFIG = ConfigurationFactory.getInstance(); + + public VGroupMappingDataBaseDAO(DataSource vGroupMappingDataSource) { + this.vGroupMappingDataSource = vGroupMappingDataSource; + this.vMapping = CONFIG.getConfig(MAPPING_TABLE_NAME, DEFAULT_VGROUP_MAPPING); + } + + public boolean insertMappingDO(MappingDO mappingDO) { + clearMappingDOByVGroup(mappingDO.getVGroup()); + String sql = "INSERT INTO " + vMapping + " (vgroup,namespace, cluster) VALUES (?, ?, ?)"; + Connection conn = null; + PreparedStatement ps = null; + try { + int index = 1; + conn = vGroupMappingDataSource.getConnection(); + conn.setAutoCommit(true); + ps = conn.prepareStatement(sql); + ps.setString(index++, mappingDO.getVGroup()); + ps.setString(index++, mappingDO.getNamespace()); + ps.setString(index++, mappingDO.getCluster()); + + return ps.executeUpdate() > 0; + } catch (SQLException e) { + e.printStackTrace(); + } finally { + IOUtil.close(ps, conn); + } + return false; + } + + public boolean clearMappingDOByVGroup(String vGroup) { + String sql = "DELETE FROM " + vMapping + " WHERE vGroup = ?"; + Connection conn = null; + PreparedStatement ps = null; + try { + conn = vGroupMappingDataSource.getConnection(); + conn.setAutoCommit(true); + ps = conn.prepareStatement(sql); + ps.setString(1, vGroup); + return ps.executeUpdate() > 0; + } catch (SQLException e) { + e.printStackTrace(); + } finally { + IOUtil.close(ps, conn); + } + return false; + } + + public boolean deleteMappingDOByVGroup(String vGroup) { + String sql = "DELETE FROM " + vMapping + " WHERE vGroup = ? and cluster = ?"; + Instance instance = Instance.getInstance(); + Connection conn = null; + PreparedStatement ps = null; + try { + conn = vGroupMappingDataSource.getConnection(); + conn.setAutoCommit(true); + ps = conn.prepareStatement(sql); + ps.setString(1, vGroup); + ps.setString(2, instance.getClusterName()); + return ps.executeUpdate() > 0; + } catch (SQLException e) { + e.printStackTrace(); Review Comment: Throwing an exception through SeataRuntimeException wrapper ########## server/src/main/java/org/apache/seata/server/Server.java: ########## @@ -31,20 +36,71 @@ import org.apache.seata.server.lock.LockerManagerFactory; import org.apache.seata.server.metrics.MetricsManager; import org.apache.seata.server.session.SessionHolder; +import org.apache.seata.server.store.StoreConfig; +import org.apache.seata.server.store.VGroupMappingStoreManager; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.ApplicationListener; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.EnumerablePropertySource; +import org.springframework.core.env.PropertySource; import org.springframework.web.context.support.GenericWebApplicationContext; import static org.apache.seata.common.Constants.OBJECT_KEY_SPRING_APPLICATION_CONTEXT; +import static org.apache.seata.common.Constants.OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT; import static org.apache.seata.spring.boot.autoconfigure.StarterConstants.REGEX_SPLIT_CHAR; import static org.apache.seata.spring.boot.autoconfigure.StarterConstants.REGISTRY_PREFERED_NETWORKS; /** * The type Server. - * */ public class Server { + + public static void metadataInit() { + + ConfigurableEnvironment environment = (ConfigurableEnvironment) ObjectHolder.INSTANCE.getObject(OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT); + + // load node properties + Instance instance = Instance.getInstance(); + // load namespace + String namespaceKey = "seata.registry.namingserver.namespace"; + String namespace = environment.getProperty(namespaceKey, "public"); + instance.setNamespace(namespace); + // load cluster name + String clusterNameKey = "seata.registry.namingserver.cluster"; Review Comment: 同上 ditto ########## common/src/main/java/org/apache/seata/common/NamingServerConstants.java: ########## @@ -46,4 +46,19 @@ public interface NamingServerConstants { * The constant IP_PORT_SPLIT_CHAR */ String IP_PORT_SPLIT_CHAR = ":"; + + /** + * The constant DEFAULT_VGROUP_MAPPING + */ + String DEFAULT_VGROUP_MAPPING = "vgroup_table"; + + /** + * The constant REGISTRY_NAMINGSERVER_CLUSTER + */ + String REGISTRY_NAMINGSERVER_CLUSTER = "registry.namingserver.cluster"; Review Comment: 放到commonkeys那个类中,那里面有registry的所有配置,统一存放 Put it in the commonkeys class, which has all the configurations of store.db, and store it uniformly. ########## server/src/test/java/org/apache/seata/server/controller/NamingControllerTest.java: ########## @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seata.server.controller; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + + +@Disabled Review Comment: why Disabled? ########## server/src/main/java/org/apache/seata/server/storage/db/store/VGroupMappingDataBaseDAO.java: ########## @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seata.server.storage.db.store; + +import org.apache.seata.common.metadata.namingserver.Instance; +import org.apache.seata.common.util.IOUtil; +import org.apache.seata.config.Configuration; +import org.apache.seata.config.ConfigurationFactory; +import org.apache.seata.core.store.MappingDO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import static org.apache.seata.common.NamingServerConstants.DEFAULT_VGROUP_MAPPING; +import static org.apache.seata.common.NamingServerConstants.MAPPING_TABLE_NAME; +import static org.apache.seata.common.NamingServerConstants.REGISTRY_NAMINGSERVER_CLUSTER; + + +public class VGroupMappingDataBaseDAO { + private static final Logger LOGGER = LoggerFactory.getLogger(VGroupMappingDataBaseDAO.class); + + protected DataSource vGroupMappingDataSource = null; + + protected final String vMapping; + + protected static final Configuration CONFIG = ConfigurationFactory.getInstance(); + + public VGroupMappingDataBaseDAO(DataSource vGroupMappingDataSource) { + this.vGroupMappingDataSource = vGroupMappingDataSource; + this.vMapping = CONFIG.getConfig(MAPPING_TABLE_NAME, DEFAULT_VGROUP_MAPPING); + } + + public boolean insertMappingDO(MappingDO mappingDO) { + clearMappingDOByVGroup(mappingDO.getVGroup()); + String sql = "INSERT INTO " + vMapping + " (vgroup,namespace, cluster) VALUES (?, ?, ?)"; + Connection conn = null; + PreparedStatement ps = null; + try { + int index = 1; + conn = vGroupMappingDataSource.getConnection(); + conn.setAutoCommit(true); + ps = conn.prepareStatement(sql); + ps.setString(index++, mappingDO.getVGroup()); + ps.setString(index++, mappingDO.getNamespace()); + ps.setString(index++, mappingDO.getCluster()); + + return ps.executeUpdate() > 0; + } catch (SQLException e) { + e.printStackTrace(); + } finally { + IOUtil.close(ps, conn); + } + return false; + } + + public boolean clearMappingDOByVGroup(String vGroup) { + String sql = "DELETE FROM " + vMapping + " WHERE vGroup = ?"; + Connection conn = null; + PreparedStatement ps = null; + try { + conn = vGroupMappingDataSource.getConnection(); + conn.setAutoCommit(true); + ps = conn.prepareStatement(sql); + ps.setString(1, vGroup); + return ps.executeUpdate() > 0; + } catch (SQLException e) { + e.printStackTrace(); Review Comment: Throwing an exception through SeataRuntimeException wrapper ########## core/src/main/java/org/apache/seata/core/store/MappingDO.java: ########## @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seata.core.store; Review Comment: 为什么放到core模块? Why put it in the core module? ########## server/src/main/java/org/apache/seata/server/storage/db/store/VGroupMappingDataBaseDAO.java: ########## @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seata.server.storage.db.store; + +import org.apache.seata.common.metadata.namingserver.Instance; +import org.apache.seata.common.util.IOUtil; +import org.apache.seata.config.Configuration; +import org.apache.seata.config.ConfigurationFactory; +import org.apache.seata.core.store.MappingDO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import static org.apache.seata.common.NamingServerConstants.DEFAULT_VGROUP_MAPPING; +import static org.apache.seata.common.NamingServerConstants.MAPPING_TABLE_NAME; +import static org.apache.seata.common.NamingServerConstants.REGISTRY_NAMINGSERVER_CLUSTER; + + +public class VGroupMappingDataBaseDAO { + private static final Logger LOGGER = LoggerFactory.getLogger(VGroupMappingDataBaseDAO.class); + + protected DataSource vGroupMappingDataSource = null; + + protected final String vMapping; + + protected static final Configuration CONFIG = ConfigurationFactory.getInstance(); + + public VGroupMappingDataBaseDAO(DataSource vGroupMappingDataSource) { + this.vGroupMappingDataSource = vGroupMappingDataSource; + this.vMapping = CONFIG.getConfig(MAPPING_TABLE_NAME, DEFAULT_VGROUP_MAPPING); + } + + public boolean insertMappingDO(MappingDO mappingDO) { + clearMappingDOByVGroup(mappingDO.getVGroup()); + String sql = "INSERT INTO " + vMapping + " (vgroup,namespace, cluster) VALUES (?, ?, ?)"; + Connection conn = null; + PreparedStatement ps = null; + try { + int index = 1; + conn = vGroupMappingDataSource.getConnection(); + conn.setAutoCommit(true); + ps = conn.prepareStatement(sql); + ps.setString(index++, mappingDO.getVGroup()); + ps.setString(index++, mappingDO.getNamespace()); + ps.setString(index++, mappingDO.getCluster()); + + return ps.executeUpdate() > 0; + } catch (SQLException e) { + e.printStackTrace(); + } finally { + IOUtil.close(ps, conn); + } + return false; + } + + public boolean clearMappingDOByVGroup(String vGroup) { + String sql = "DELETE FROM " + vMapping + " WHERE vGroup = ?"; + Connection conn = null; + PreparedStatement ps = null; + try { + conn = vGroupMappingDataSource.getConnection(); + conn.setAutoCommit(true); + ps = conn.prepareStatement(sql); + ps.setString(1, vGroup); + return ps.executeUpdate() > 0; + } catch (SQLException e) { + e.printStackTrace(); + } finally { + IOUtil.close(ps, conn); + } + return false; + } + + public boolean deleteMappingDOByVGroup(String vGroup) { + String sql = "DELETE FROM " + vMapping + " WHERE vGroup = ? and cluster = ?"; + Instance instance = Instance.getInstance(); + Connection conn = null; + PreparedStatement ps = null; + try { + conn = vGroupMappingDataSource.getConnection(); + conn.setAutoCommit(true); + ps = conn.prepareStatement(sql); + ps.setString(1, vGroup); + ps.setString(2, instance.getClusterName()); + return ps.executeUpdate() > 0; + } catch (SQLException e) { + e.printStackTrace(); + } finally { + IOUtil.close(ps, conn); + } + return false; + } + + public List<MappingDO> queryMappingDO() { + String sql = "SELECT vgroup,namespace, cluster FROM " + vMapping + + " WHERE cluster = ?"; + Connection conn = null; + PreparedStatement ps = null; + ResultSet rs = null; + List<MappingDO> result = new ArrayList<>(); + + try { + conn = vGroupMappingDataSource.getConnection(); + ps = conn.prepareStatement(sql); + ps.setString(1, CONFIG.getConfig(REGISTRY_NAMINGSERVER_CLUSTER)); + rs = ps.executeQuery(); + + while (rs.next()) { + MappingDO mappingDO = new MappingDO(); + mappingDO.setNamespace(rs.getString("namespace")); + mappingDO.setCluster(rs.getString("cluster")); + mappingDO.setVGroup(rs.getString("vGroup")); + result.add(mappingDO); + } + } catch (SQLException e) { + e.printStackTrace(); Review Comment: 将异常通过SeataRuntimeException包装后抛出 Throwing an exception through SeataRuntimeException wrapper ########## server/src/main/java/org/apache/seata/server/session/SessionHolder.java: ########## @@ -277,6 +301,22 @@ private static void lockBranchSessions(List<BranchSession> branchSessions) { } + //region get group mapping manager + + /** + * Gets root session manager. + * + * @return the root session manager + */ + public static VGroupMappingStoreManager getRootVGroupMappingManager() { + if (ROOT_VGROUP_MAPPING_MANAGER == null) { Review Comment: 应该判断,如果注册中心为namingserver才需要加载。 It should be judged if the registry is namingserver before it needs to be loaded. ########## server/src/main/java/org/apache/seata/server/storage/db/store/DataBaseVGroupMappingStoreManager.java: ########## @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seata.server.storage.db.store; + +import org.apache.seata.common.loader.EnhancedServiceLoader; +import org.apache.seata.common.loader.LoadLevel; +import org.apache.seata.common.metadata.namingserver.Instance; +import org.apache.seata.config.Configuration; +import org.apache.seata.config.ConfigurationFactory; +import org.apache.seata.core.constants.ConfigurationKeys; +import org.apache.seata.core.store.MappingDO; +import org.apache.seata.core.store.db.DataSourceProvider; +import org.apache.seata.server.store.VGroupMappingStoreManager; + +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.List; + +@LoadLevel(name = "db") +public class DataBaseVGroupMappingStoreManager implements VGroupMappingStoreManager { + protected VGroupMappingDataBaseDAO vGroupMappingDataBaseDAO; + + protected static final Configuration CONFIG = ConfigurationFactory.getInstance(); + + public DataBaseVGroupMappingStoreManager() { + String datasourceType = CONFIG.getConfig(ConfigurationKeys.STORE_DB_DATASOURCE_TYPE); + //init dataSource + DataSource vGroupMappingDataSource = EnhancedServiceLoader.load(DataSourceProvider.class, datasourceType).provide(); + vGroupMappingDataBaseDAO = new VGroupMappingDataBaseDAO(vGroupMappingDataSource); + } + + @Override + public boolean addVGroup(MappingDO mappingDO) { + return vGroupMappingDataBaseDAO.insertMappingDO(mappingDO); + } + + @Override + public boolean removeVGroup(String vGroup) { + return vGroupMappingDataBaseDAO.deleteMappingDOByVGroup(vGroup); + } + + @Override + public HashMap<String, Object> loadVGroups() { + List<MappingDO> mappingDOS = vGroupMappingDataBaseDAO.queryMappingDO(); + Instance instance = Instance.getInstance(); + HashMap<String, Object> mappings = new HashMap<>(); + for (MappingDO mappingDO : mappingDOS) { + if (mappingDO.getCluster() != null && mappingDO.getCluster().equals(instance.getClusterName())) { + mappings.put(mappingDO.getVGroup(), null); Review Comment: 为什么value是null? why value is null ########## server/src/main/java/org/apache/seata/server/storage/db/store/VGroupMappingDataBaseDAO.java: ########## @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seata.server.storage.db.store; + +import org.apache.seata.common.metadata.namingserver.Instance; +import org.apache.seata.common.util.IOUtil; +import org.apache.seata.config.Configuration; +import org.apache.seata.config.ConfigurationFactory; +import org.apache.seata.core.store.MappingDO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import static org.apache.seata.common.NamingServerConstants.DEFAULT_VGROUP_MAPPING; +import static org.apache.seata.common.NamingServerConstants.MAPPING_TABLE_NAME; +import static org.apache.seata.common.NamingServerConstants.REGISTRY_NAMINGSERVER_CLUSTER; + + +public class VGroupMappingDataBaseDAO { + private static final Logger LOGGER = LoggerFactory.getLogger(VGroupMappingDataBaseDAO.class); + + protected DataSource vGroupMappingDataSource = null; + + protected final String vMapping; + + protected static final Configuration CONFIG = ConfigurationFactory.getInstance(); + + public VGroupMappingDataBaseDAO(DataSource vGroupMappingDataSource) { + this.vGroupMappingDataSource = vGroupMappingDataSource; + this.vMapping = CONFIG.getConfig(MAPPING_TABLE_NAME, DEFAULT_VGROUP_MAPPING); + } + + public boolean insertMappingDO(MappingDO mappingDO) { + clearMappingDOByVGroup(mappingDO.getVGroup()); + String sql = "INSERT INTO " + vMapping + " (vgroup,namespace, cluster) VALUES (?, ?, ?)"; + Connection conn = null; + PreparedStatement ps = null; + try { + int index = 1; + conn = vGroupMappingDataSource.getConnection(); + conn.setAutoCommit(true); + ps = conn.prepareStatement(sql); + ps.setString(index++, mappingDO.getVGroup()); + ps.setString(index++, mappingDO.getNamespace()); + ps.setString(index++, mappingDO.getCluster()); + + return ps.executeUpdate() > 0; + } catch (SQLException e) { + e.printStackTrace(); Review Comment: Throwing an exception through SeataRuntimeException wrapper ########## common/src/main/java/org/apache/seata/common/NamingServerConstants.java: ########## @@ -46,4 +46,19 @@ public interface NamingServerConstants { * The constant IP_PORT_SPLIT_CHAR */ String IP_PORT_SPLIT_CHAR = ":"; + + /** + * The constant DEFAULT_VGROUP_MAPPING + */ + String DEFAULT_VGROUP_MAPPING = "vgroup_table"; + + /** + * The constant REGISTRY_NAMINGSERVER_CLUSTER + */ + String REGISTRY_NAMINGSERVER_CLUSTER = "registry.namingserver.cluster"; + + /** + * The constant MAPPING_TABLE_NAME + */ + String MAPPING_TABLE_NAME = "store.db.mapping-table"; Review Comment: 放到commonkeys那个类中,那里面有store.db的所有配置,统一存放 Put it in the commonkeys class, which has all the configurations of store.db, and store it uniformly. ########## server/src/main/java/org/apache/seata/server/storage/db/store/VGroupMappingDataBaseDAO.java: ########## @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seata.server.storage.db.store; + +import org.apache.seata.common.metadata.namingserver.Instance; +import org.apache.seata.common.util.IOUtil; +import org.apache.seata.config.Configuration; +import org.apache.seata.config.ConfigurationFactory; +import org.apache.seata.core.store.MappingDO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import static org.apache.seata.common.NamingServerConstants.DEFAULT_VGROUP_MAPPING; +import static org.apache.seata.common.NamingServerConstants.MAPPING_TABLE_NAME; +import static org.apache.seata.common.NamingServerConstants.REGISTRY_NAMINGSERVER_CLUSTER; + + +public class VGroupMappingDataBaseDAO { + private static final Logger LOGGER = LoggerFactory.getLogger(VGroupMappingDataBaseDAO.class); + + protected DataSource vGroupMappingDataSource = null; + + protected final String vMapping; + + protected static final Configuration CONFIG = ConfigurationFactory.getInstance(); + + public VGroupMappingDataBaseDAO(DataSource vGroupMappingDataSource) { + this.vGroupMappingDataSource = vGroupMappingDataSource; + this.vMapping = CONFIG.getConfig(MAPPING_TABLE_NAME, DEFAULT_VGROUP_MAPPING); + } + + public boolean insertMappingDO(MappingDO mappingDO) { + clearMappingDOByVGroup(mappingDO.getVGroup()); Review Comment: 为什么不将clearMappingDOByVGroup所使用的connection跟insertMappingDO保持一致? Why not make the connection used by clearMappingDOByVGroup the same as insertMappingDO? ########## server/src/main/java/org/apache/seata/server/Server.java: ########## @@ -31,20 +36,71 @@ import org.apache.seata.server.lock.LockerManagerFactory; import org.apache.seata.server.metrics.MetricsManager; import org.apache.seata.server.session.SessionHolder; +import org.apache.seata.server.store.StoreConfig; +import org.apache.seata.server.store.VGroupMappingStoreManager; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.ApplicationListener; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.EnumerablePropertySource; +import org.springframework.core.env.PropertySource; import org.springframework.web.context.support.GenericWebApplicationContext; import static org.apache.seata.common.Constants.OBJECT_KEY_SPRING_APPLICATION_CONTEXT; +import static org.apache.seata.common.Constants.OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT; import static org.apache.seata.spring.boot.autoconfigure.StarterConstants.REGEX_SPLIT_CHAR; import static org.apache.seata.spring.boot.autoconfigure.StarterConstants.REGISTRY_PREFERED_NETWORKS; /** * The type Server. - * */ public class Server { + + public static void metadataInit() { + + ConfigurableEnvironment environment = (ConfigurableEnvironment) ObjectHolder.INSTANCE.getObject(OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT); + + // load node properties + Instance instance = Instance.getInstance(); + // load namespace + String namespaceKey = "seata.registry.namingserver.namespace"; Review Comment: 弄成常量 change to constant ########## server/src/main/java/org/apache/seata/server/Server.java: ########## @@ -31,20 +36,71 @@ import org.apache.seata.server.lock.LockerManagerFactory; import org.apache.seata.server.metrics.MetricsManager; import org.apache.seata.server.session.SessionHolder; +import org.apache.seata.server.store.StoreConfig; +import org.apache.seata.server.store.VGroupMappingStoreManager; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.ApplicationListener; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.EnumerablePropertySource; +import org.springframework.core.env.PropertySource; import org.springframework.web.context.support.GenericWebApplicationContext; import static org.apache.seata.common.Constants.OBJECT_KEY_SPRING_APPLICATION_CONTEXT; +import static org.apache.seata.common.Constants.OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT; import static org.apache.seata.spring.boot.autoconfigure.StarterConstants.REGEX_SPLIT_CHAR; import static org.apache.seata.spring.boot.autoconfigure.StarterConstants.REGISTRY_PREFERED_NETWORKS; /** * The type Server. - * */ public class Server { + + public static void metadataInit() { Review Comment: 不是namingserver为注册中心,默认先不需要加载元数据 It is not namingserver as the registry, and there is no need to load metadata by default. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
