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/11/19 02:13:32 UTC

[GitHub] [shardingsphere] jiangML opened a new pull request, #22270: Add properties check when registering storage nodes

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

   Fixes #22260.
   
   Changes proposed in this pull request:
     -  Add properties check when registering storage nodes
   
   ---
   
   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 (or in comment I request) added corresponding labels for the pull request.
   - [ ] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -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] RaigorJiang commented on a diff in pull request #22270: Add properties check when registering storage nodes

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


##########
infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/DefaultDataSourcePoolPropertiesValidator.java:
##########
@@ -0,0 +1,31 @@
+/*
+ * 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.infra.datasource.pool.metadata;
+
+import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
+
+/**
+ * Default data source pool properties validator.
+ */
+public class DefaultDataSourcePoolPropertiesValidator implements DataSourcePoolPropertiesValidator {
+    
+    @Override
+    public void validateProperties(final DataSourceProperties dataSourceProps) {
+        

Review Comment:
   Unnecessary blank line.



-- 
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] RaigorJiang commented on a diff in pull request #22270: Add properties check when registering storage nodes

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


##########
infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/DefaultDataSourcePoolPropertiesValidator.java:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.infra.datasource.pool.metadata;
+
+import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
+
+/**
+ * Default data source pool properties validator.
+ */
+public class DefaultDataSourcePoolPropertiesValidator implements DataSourcePoolPropertiesValidator {

Review Comment:
   Can this class be final?



-- 
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 #22270: Add properties check when registering storage nodes

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

   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/22270?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 [#22270](https://codecov.io/gh/apache/shardingsphere/pull/22270?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (e22332b) into [master](https://codecov.io/gh/apache/shardingsphere/commit/988d8f122b22a07bcb7e58dd05a608016fd41304?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (988d8f1) will **decrease** coverage by `0.02%`.
   > The diff coverage is `38.18%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #22270      +/-   ##
   ============================================
   - Coverage     59.37%   59.35%   -0.03%     
   - Complexity     2269     2270       +1     
   ============================================
     Files          4163     4165       +2     
     Lines         57686    57740      +54     
     Branches       9787     9799      +12     
   ============================================
   + Hits          34249    34269      +20     
   - Misses        20588    20615      +27     
   - Partials       2849     2856       +7     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/22270?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...data/DefaultDataSourcePoolPropertiesValidator.java](https://codecov.io/gh/apache/shardingsphere/pull/22270/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-aW5mcmEvY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9kYXRhc291cmNlL3Bvb2wvbWV0YWRhdGEvRGVmYXVsdERhdGFTb3VyY2VQb29sUHJvcGVydGllc1ZhbGlkYXRvci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...metadata/type/c3p0/C3P0DataSourcePoolMetaData.java](https://codecov.io/gh/apache/shardingsphere/pull/22270/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-aW5mcmEvY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9kYXRhc291cmNlL3Bvb2wvbWV0YWRhdGEvdHlwZS9jM3AwL0MzUDBEYXRhU291cmNlUG9vbE1ldGFEYXRhLmphdmE=) | `83.33% <0.00%> (-2.39%)` | :arrow_down: |
   | [...metadata/type/dbcp/DBCPDataSourcePoolMetaData.java](https://codecov.io/gh/apache/shardingsphere/pull/22270/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-aW5mcmEvY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9kYXRhc291cmNlL3Bvb2wvbWV0YWRhdGEvdHlwZS9kYmNwL0RCQ1BEYXRhU291cmNlUG9vbE1ldGFEYXRhLmphdmE=) | `92.85% <0.00%> (-7.15%)` | :arrow_down: |
   | [...ikari/HikariDataSourcePoolPropertiesValidator.java](https://codecov.io/gh/apache/shardingsphere/pull/22270/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-aW5mcmEvY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9kYXRhc291cmNlL3Bvb2wvbWV0YWRhdGEvdHlwZS9oaWthcmkvSGlrYXJpRGF0YVNvdXJjZVBvb2xQcm9wZXJ0aWVzVmFsaWRhdG9yLmphdmE=) | `33.33% <33.33%> (ø)` | |
   | [...atasource/props/DataSourcePropertiesValidator.java](https://codecov.io/gh/apache/shardingsphere/pull/22270/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-aW5mcmEvY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9kYXRhc291cmNlL3Byb3BzL0RhdGFTb3VyY2VQcm9wZXJ0aWVzVmFsaWRhdG9yLmphdmE=) | `84.37% <63.63%> (-11.08%)` | :arrow_down: |
   | [...data/type/hikari/HikariDataSourcePoolMetaData.java](https://codecov.io/gh/apache/shardingsphere/pull/22270/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-aW5mcmEvY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9kYXRhc291cmNlL3Bvb2wvbWV0YWRhdGEvdHlwZS9oaWthcmkvSGlrYXJpRGF0YVNvdXJjZVBvb2xNZXRhRGF0YS5qYXZh) | `100.00% <100.00%> (ø)` | |
   
   :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] RaigorJiang commented on a diff in pull request #22270: Add properties check when registering storage nodes

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


##########
infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/metadata/type/hikari/HikariDataSourcePoolPropertiesValidator.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.infra.datasource.pool.metadata.type.hikari;
+
+import org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolPropertiesValidator;
+import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
+
+import java.util.Objects;
+
+/**
+ * Hikari data source pool properties validator.
+ */
+public final class HikariDataSourcePoolPropertiesValidator implements DataSourcePoolPropertiesValidator {
+    
+    private static final long SOFT_TIMEOUT_FLOOR = Long.getLong("com.zaxxer.hikari.timeoutMs.floor", 250L);
+    
+    @Override
+    public void validateProperties(final DataSourceProperties dataSourceProps) throws IllegalArgumentException {
+        validateConnectionTimeout(dataSourceProps);
+        validateIdleTimeout(dataSourceProps);
+        validateMaximumPoolSize(dataSourceProps);
+        validateMinimumIdle(dataSourceProps);
+        validateValidationTimeout(dataSourceProps);
+    }
+    
+    private void validateConnectionTimeout(final DataSourceProperties dataSourceProps) {
+        if (!checkValueExist(dataSourceProps, "connectionTimeout")) {
+            return;
+        }
+        long connectionTimeout = Long.parseLong(dataSourceProps.getAllLocalProperties().get("connectionTimeout").toString());
+        if (connectionTimeout < SOFT_TIMEOUT_FLOOR) {
+            throw new IllegalArgumentException("connectionTimeout cannot be less than " + SOFT_TIMEOUT_FLOOR + "ms");
+        }
+    }
+    
+    private void validateIdleTimeout(final DataSourceProperties dataSourceProps) {
+        if (!checkValueExist(dataSourceProps, "idleTimeout")) {
+            return;
+        }
+        long idleTimeout = Long.parseLong(dataSourceProps.getAllLocalProperties().get("idleTimeout").toString());
+        if (idleTimeout < 0) {
+            throw new IllegalArgumentException("idleTimeout cannot be negative");
+        }
+    }
+    
+    private void validateMaximumPoolSize(final DataSourceProperties dataSourceProps) {
+        if (!checkValueExist(dataSourceProps, "maximumPoolSize")) {
+            return;
+        }
+        int maximumPoolSize = Integer.parseInt(dataSourceProps.getAllLocalProperties().get("maximumPoolSize").toString());
+        if (maximumPoolSize < 1) {
+            throw new IllegalArgumentException("maxPoolSize cannot be less than 1");
+        }
+    }
+    
+    private void validateMinimumIdle(final DataSourceProperties dataSourceProps) {
+        if (!checkValueExist(dataSourceProps, "minimumIdle")) {
+            return;
+        }
+        int minimumIdle = Integer.parseInt(dataSourceProps.getAllLocalProperties().get("minimumIdle").toString());
+        if (minimumIdle < 0) {
+            throw new IllegalArgumentException("minimumIdle cannot be negative");
+        }
+    }
+    
+    private void validateValidationTimeout(final DataSourceProperties dataSourceProps) {
+        if (!checkValueExist(dataSourceProps, "validationTimeout")) {
+            return;
+        }
+        long validationTimeout = Long.parseLong(dataSourceProps.getAllLocalProperties().get("validationTimeout").toString());
+        if (validationTimeout < SOFT_TIMEOUT_FLOOR) {

Review Comment:
   Hi @jiangML , can we use ShardingSpherePreconditions to check state?



-- 
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] RaigorJiang merged pull request #22270: Add properties check when registering storage nodes

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


-- 
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