forked from zstackio/zstack
-
Notifications
You must be signed in to change notification settings - Fork 0
[5.5.22][core] Bound JDBC waits on VIP failover #3993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zstack-robot-1
wants to merge
1
commit into
5.5.22
Choose a base branch
from
sync/ye.zou/fix/5.5.22-jdbc-vip-timeouts
base: 5.5.22
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,12 @@ public class DatabaseGlobalProperty { | |
| public static String DbIdleConnectionTestPeriod; | ||
| @GlobalProperty(name="DB.maxIdleTime", defaultValue = "60") | ||
| public static String DbMaxIdleTime; | ||
| @GlobalProperty(name="DB.connectTimeout", defaultValue = "5000") | ||
| public static String DbConnectTimeout; | ||
| @GlobalProperty(name="DB.socketTimeout", defaultValue = "60000") | ||
| public static String DbSocketTimeout; | ||
| @GlobalProperty(name="DB.tcpKeepAlive", defaultValue = "true") | ||
| public static String DbTcpKeepAlive; | ||
|
Comment on lines
+25
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为新增 JDBC 参数增加格式校验,避免错误配置延迟到运行期暴露。 Line 25-30 的新属性当前无格式约束。建议在属性层直接限制:超时必须为数字, 建议修改- `@GlobalProperty`(name="DB.connectTimeout", defaultValue = "5000")
+ `@GlobalProperty`(name="DB.connectTimeout", defaultValue = "5000")
+ `@RegexValues`(value = "^[0-9]+$")
public static String DbConnectTimeout;
- `@GlobalProperty`(name="DB.socketTimeout", defaultValue = "60000")
+ `@GlobalProperty`(name="DB.socketTimeout", defaultValue = "60000")
+ `@RegexValues`(value = "^[0-9]+$")
public static String DbSocketTimeout;
- `@GlobalProperty`(name="DB.tcpKeepAlive", defaultValue = "true")
+ `@GlobalProperty`(name="DB.tcpKeepAlive", defaultValue = "true")
+ `@RegexValues`(value = "^(?i:true|false)$")
public static String DbTcpKeepAlive;🤖 Prompt for AI Agents |
||
| @GlobalProperty(name="DB.glock.waitTimeout", defaultValue = "28800") | ||
| public static Long GLockWaitTimeout; | ||
| @GlobalProperty(name="RESTFacade.hostname") | ||
|
|
||
116 changes: 116 additions & 0 deletions
116
test/src/test/java/org/zstack/test/core/TestDefaultDbJdbcUrl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package org.zstack.test.core; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.zstack.core.Platform; | ||
| import org.zstack.core.db.DatabaseGlobalProperty; | ||
|
|
||
| import java.lang.reflect.Method; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| public class TestDefaultDbJdbcUrl { | ||
| private String oldDbUrl; | ||
| private String oldConnectTimeout; | ||
| private String oldSocketTimeout; | ||
| private String oldTcpKeepAlive; | ||
| private String oldDbFacadeJdbcUrl; | ||
| private String oldRestApiJdbcUrl; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| oldDbUrl = DatabaseGlobalProperty.DbUrl; | ||
| oldConnectTimeout = DatabaseGlobalProperty.DbConnectTimeout; | ||
| oldSocketTimeout = DatabaseGlobalProperty.DbSocketTimeout; | ||
| oldTcpKeepAlive = DatabaseGlobalProperty.DbTcpKeepAlive; | ||
| oldDbFacadeJdbcUrl = System.getProperty("DbFacadeDataSource.jdbcUrl"); | ||
| oldRestApiJdbcUrl = System.getProperty("RESTApiDataSource.jdbcUrl"); | ||
|
|
||
| DatabaseGlobalProperty.DbConnectTimeout = "5000"; | ||
| DatabaseGlobalProperty.DbSocketTimeout = "60000"; | ||
| DatabaseGlobalProperty.DbTcpKeepAlive = "true"; | ||
| System.clearProperty("DbFacadeDataSource.jdbcUrl"); | ||
| System.clearProperty("RESTApiDataSource.jdbcUrl"); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() { | ||
| DatabaseGlobalProperty.DbUrl = oldDbUrl; | ||
| DatabaseGlobalProperty.DbConnectTimeout = oldConnectTimeout; | ||
| DatabaseGlobalProperty.DbSocketTimeout = oldSocketTimeout; | ||
| DatabaseGlobalProperty.DbTcpKeepAlive = oldTcpKeepAlive; | ||
| restoreProperty("DbFacadeDataSource.jdbcUrl", oldDbFacadeJdbcUrl); | ||
| restoreProperty("RESTApiDataSource.jdbcUrl", oldRestApiJdbcUrl); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAppendTimeoutsToDefaultDbUrl() throws Exception { | ||
| assertEquals( | ||
| "jdbc:mysql://172.20.0.37:3306/zstack?connectTimeout=5000&socketTimeout=60000&tcpKeepAlive=true", | ||
| buildDbJdbcUrl("jdbc:mysql://172.20.0.37:3306", "zstack") | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAppendTimeoutsAfterExistingQuery() throws Exception { | ||
| assertEquals( | ||
| "jdbc:mysql://172.20.0.37:3306/zstack?useSSL=false&connectTimeout=5000&socketTimeout=60000&tcpKeepAlive=true", | ||
| buildDbJdbcUrl("jdbc:mysql://172.20.0.37:3306?useSSL=false", "zstack") | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDoNotOverrideExplicitTimeouts() throws Exception { | ||
| assertEquals( | ||
| "jdbc:mysql://172.20.0.37:3306/zstack?socketTimeout=10000&connectTimeout=1000&tcpKeepAlive=false", | ||
| buildDbJdbcUrl("jdbc:mysql://172.20.0.37:3306?socketTimeout=10000&connectTimeout=1000&tcpKeepAlive=false", "zstack") | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTemplateDbUrlKeepsQueryInPlace() throws Exception { | ||
| assertEquals( | ||
| "jdbc:mysql://172.20.0.37:3306/zstack_rest?useSSL=false&connectTimeout=5000&socketTimeout=60000&tcpKeepAlive=true", | ||
| buildDbJdbcUrl("jdbc:mysql://172.20.0.37:3306/{database}?useSSL=false", "zstack_rest") | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAppendTimeoutsToExplicitDatasourceJdbcUrls() throws Exception { | ||
| DatabaseGlobalProperty.DbUrl = null; | ||
| System.setProperty("DbFacadeDataSource.jdbcUrl", "jdbc:mysql://172.20.0.37:3306/zstack"); | ||
| System.setProperty("RESTApiDataSource.jdbcUrl", "jdbc:mysql://172.20.0.37:3306/zstack_rest?useSSL=false"); | ||
|
|
||
| prepareDefaultDbProperties(); | ||
|
|
||
| assertEquals( | ||
| "jdbc:mysql://172.20.0.37:3306/zstack?connectTimeout=5000&socketTimeout=60000&tcpKeepAlive=true", | ||
| System.getProperty("DbFacadeDataSource.jdbcUrl") | ||
| ); | ||
| assertEquals( | ||
| "jdbc:mysql://172.20.0.37:3306/zstack_rest?useSSL=false&connectTimeout=5000&socketTimeout=60000&tcpKeepAlive=true", | ||
| System.getProperty("RESTApiDataSource.jdbcUrl") | ||
| ); | ||
| } | ||
|
|
||
| private String buildDbJdbcUrl(String dbUrl, String database) throws Exception { | ||
| Method method = Platform.class.getDeclaredMethod("buildDbJdbcUrl", String.class, String.class); | ||
| method.setAccessible(true); | ||
| return (String) method.invoke(null, dbUrl, database); | ||
| } | ||
|
|
||
| private void prepareDefaultDbProperties() throws Exception { | ||
| Method method = Platform.class.getDeclaredMethod("prepareDefaultDbProperties"); | ||
| method.setAccessible(true); | ||
| method.invoke(null); | ||
| } | ||
|
|
||
| private void restoreProperty(String key, String value) { | ||
| if (value == null) { | ||
| System.clearProperty(key); | ||
| } else { | ||
| System.setProperty(key, value); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
避免在日志中输出完整 JDBC URL(可能包含敏感参数)。
Line 390 直接打印
defaultedJdbcUrl,若 URL 携带凭据或其他敏感 query,会写入日志。建议只记录属性名,或先脱敏再打印。建议修改
🤖 Prompt for AI Agents