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/20 06:18:58 UTC
[GitHub] [shardingsphere] RaigorJiang commented on a diff in pull request #22270: Add properties check when registering storage nodes
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