You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/10/09 11:07:36 UTC

[GitHub] [shardingsphere] tuichenchuxin opened a new pull request, #21424: collect sharding sphere data.

tuichenchuxin opened a new pull request, #21424:
URL: https://github.com/apache/shardingsphere/pull/21424

   For #21268.
   
   Changes proposed in this pull request:
     - collect sharding sphere data.
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [ ] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [ ] I have self-reviewed the commit code.
   - [ ] I have passed maven check: `mvn clean install -B -T2C -DskipTests -Dmaven.javadoc.skip=true -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [ ] I have added corresponding unit tests for my changes.
   


-- 
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@shardingsphere.apache.org

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


[GitHub] [shardingsphere] codecov-commenter commented on pull request #21424: collect sharding sphere data.

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #21424:
URL: https://github.com/apache/shardingsphere/pull/21424#issuecomment-1272524725

   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/21424?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#21424](https://codecov.io/gh/apache/shardingsphere/pull/21424?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (4864547) into [master](https://codecov.io/gh/apache/shardingsphere/commit/24dfec3cd1a5be4f11224c61232359a20c60891e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (24dfec3) will **decrease** coverage by `0.12%`.
   > The diff coverage is `0.00%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #21424      +/-   ##
   ============================================
   - Coverage     61.50%   61.37%   -0.13%     
     Complexity     2508     2508              
   ============================================
     Files          4097     4102       +5     
     Lines         56766    56876     +110     
     Branches       7498     7515      +17     
   ============================================
   - Hits          34913    34910       -3     
   - Misses        18928    19041     +113     
     Partials       2925     2925              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/21424?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...etadata/data/ShardingStatisticsTableCollector.java](https://codecov.io/gh/apache/shardingsphere/pull/21424/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZmVhdHVyZXMvc2hhcmRpbmcvY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvbWV0YWRhdGEvZGF0YS9TaGFyZGluZ1N0YXRpc3RpY3NUYWJsZUNvbGxlY3Rvci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [.../collector/ShardingSphereDataCollectorFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/21424/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a2VybmVsL2RhdGEtcGlwZWxpbmUvYXBpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9kYXRhL3BpcGVsaW5lL3NwaS9kYXRhL2NvbGxlY3Rvci9TaGFyZGluZ1NwaGVyZURhdGFDb2xsZWN0b3JGYWN0b3J5LmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...line/core/execute/ShardingSphereDataJobWorker.java](https://codecov.io/gh/apache/shardingsphere/pull/21424/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a2VybmVsL2RhdGEtcGlwZWxpbmUvY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZGF0YS9waXBlbGluZS9jb3JlL2V4ZWN1dGUvU2hhcmRpbmdTcGhlcmVEYXRhSm9iV29ya2VyLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...e/execute/ShardingSphereDataScheduleCollector.java](https://codecov.io/gh/apache/shardingsphere/pull/21424/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a2VybmVsL2RhdGEtcGlwZWxpbmUvY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZGF0YS9waXBlbGluZS9jb3JlL2V4ZWN1dGUvU2hhcmRpbmdTcGhlcmVEYXRhU2NoZWR1bGVDb2xsZWN0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...dingSphereDataContextManagerLifecycleListener.java](https://codecov.io/gh/apache/shardingsphere/pull/21424/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a2VybmVsL2RhdGEtcGlwZWxpbmUvY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZGF0YS9waXBlbGluZS9jb3JlL2xpc3RlbmVyL1NoYXJkaW5nU3BoZXJlRGF0YUNvbnRleHRNYW5hZ2VyTGlmZWN5Y2xlTGlzdGVuZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...handler/distsql/ral/hint/enums/HintSourceType.java](https://codecov.io/gh/apache/shardingsphere/pull/21424/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHJveHkvYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC9oYW5kbGVyL2Rpc3RzcWwvcmFsL2hpbnQvZW51bXMvSGludFNvdXJjZVR5cGUuamF2YQ==) | `0.00% <0.00%> (-42.86%)` | :arrow_down: |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
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@shardingsphere.apache.org

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


[GitHub] [shardingsphere] strongduanmu merged pull request #21424: collect sharding sphere data.

Posted by GitBox <gi...@apache.org>.
strongduanmu merged PR #21424:
URL: https://github.com/apache/shardingsphere/pull/21424


-- 
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@shardingsphere.apache.org

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


[GitHub] [shardingsphere] strongduanmu commented on a diff in pull request #21424: collect sharding sphere data.

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on code in PR #21424:
URL: https://github.com/apache/shardingsphere/pull/21424#discussion_r990865462


##########
features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.shardingsphere.sharding.metadata.data;
+
+import org.apache.shardingsphere.data.pipeline.spi.data.collector.ShardingSphereDataCollector;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereRowData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sharding.rule.TableRule;
+
+import javax.sql.DataSource;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Sharding statistics table data collector.
+ */
+public class ShardingStatisticsTableCollector implements ShardingSphereDataCollector {
+    
+    private static final String SHARDING_STATISTICS_TABLE = "sharding_statistics_table";
+    
+    private static final String SHARDING_SPHERE = "shardingsphere";
+    
+    private static final String MYSQL_TABLE_ROWS_AND_DATA_LENGTH = "SELECT TABLE_ROWS, DATA_LENGTH FROM information_schema.TABLES WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'";
+    
+    @Override
+    public void collectShardingSphereData(final ShardingSphereData shardingSphereData, final String databaseName, final Collection<ShardingSphereRule> rules,

Review Comment:
   Do you think rename this method to collect is better?



##########
features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.shardingsphere.sharding.metadata.data;
+
+import org.apache.shardingsphere.data.pipeline.spi.data.collector.ShardingSphereDataCollector;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereRowData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sharding.rule.TableRule;
+
+import javax.sql.DataSource;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Sharding statistics table data collector.
+ */
+public class ShardingStatisticsTableCollector implements ShardingSphereDataCollector {
+    
+    private static final String SHARDING_STATISTICS_TABLE = "sharding_statistics_table";
+    
+    private static final String SHARDING_SPHERE = "shardingsphere";
+    
+    private static final String MYSQL_TABLE_ROWS_AND_DATA_LENGTH = "SELECT TABLE_ROWS, DATA_LENGTH FROM information_schema.TABLES WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'";
+    
+    @Override
+    public void collectShardingSphereData(final ShardingSphereData shardingSphereData, final String databaseName, final Collection<ShardingSphereRule> rules,
+                                          final Map<String, DataSource> dataSources, final DatabaseType databaseType) throws SQLException {
+        ShardingRule shardingRule = null;
+        for (ShardingSphereRule each : rules) {

Review Comment:
   Can we use common findSingleRule method?



##########
features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.shardingsphere.sharding.metadata.data;
+
+import org.apache.shardingsphere.data.pipeline.spi.data.collector.ShardingSphereDataCollector;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereRowData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sharding.rule.TableRule;
+
+import javax.sql.DataSource;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Sharding statistics table data collector.
+ */
+public class ShardingStatisticsTableCollector implements ShardingSphereDataCollector {
+    
+    private static final String SHARDING_STATISTICS_TABLE = "sharding_statistics_table";
+    
+    private static final String SHARDING_SPHERE = "shardingsphere";
+    
+    private static final String MYSQL_TABLE_ROWS_AND_DATA_LENGTH = "SELECT TABLE_ROWS, DATA_LENGTH FROM information_schema.TABLES WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'";
+    
+    @Override
+    public void collectShardingSphereData(final ShardingSphereData shardingSphereData, final String databaseName, final Collection<ShardingSphereRule> rules,
+                                          final Map<String, DataSource> dataSources, final DatabaseType databaseType) throws SQLException {
+        ShardingRule shardingRule = null;
+        for (ShardingSphereRule each : rules) {
+            if (each instanceof ShardingRule) {
+                shardingRule = (ShardingRule) each;
+                break;
+            }
+        }
+        if (null == shardingRule) {
+            return;
+        }
+        ShardingSphereTableData tableData = new ShardingSphereTableData(SHARDING_STATISTICS_TABLE);

Review Comment:
   Please extract this logic to a private method.



-- 
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@shardingsphere.apache.org

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