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/08/15 11:10:29 UTC
[GitHub] [shardingsphere] wuwen5 opened a new pull request, #20197: Improve DriverDataSourceCache
wuwen5 opened a new pull request, #20197:
URL: https://github.com/apache/shardingsphere/pull/20197
Use ```computeIfAbsent``` avoid duplicate creation of data sources.
--
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] TeslaCN commented on a diff in pull request #20197: Improve DriverDataSourceCache
Posted by GitBox <gi...@apache.org>.
TeslaCN commented on code in PR #20197:
URL: https://github.com/apache/shardingsphere/pull/20197#discussion_r946460712
##########
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/DriverDataSourceCache.java:
##########
@@ -44,23 +43,17 @@ public DataSource get(final String url) throws SQLException {
if (dataSourceMap.containsKey(url)) {
return dataSourceMap.get(url);
}
- DataSource dataSource;
+ return dataSourceMap.computeIfAbsent(url, DriverDataSourceCache::createDataSource);
+ }
+
+ @SuppressWarnings("unchecked")
+ static <T extends Throwable> DataSource createDataSource(final String url) throws T {
Review Comment:
Consider adding `private` to 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
[GitHub] [shardingsphere] wuwen5 commented on a diff in pull request #20197: Improve DriverDataSourceCache
Posted by GitBox <gi...@apache.org>.
wuwen5 commented on code in PR #20197:
URL: https://github.com/apache/shardingsphere/pull/20197#discussion_r946451301
##########
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/DriverDataSourceCache.java:
##########
@@ -44,23 +43,17 @@ public DataSource get(final String url) throws SQLException {
if (dataSourceMap.containsKey(url)) {
return dataSourceMap.get(url);
}
- DataSource dataSource;
+ return dataSourceMap.computeIfAbsent(url, DriverDataSourceCache::createDataSource);
Review Comment:
Yep, this problem is that when the key present,Therefore, keeping the above code can avoid this problem。
```
if (dataSourceMap.containsKey(url)) {
return dataSourceMap.get(url);
}
```
Similar solutions
https://github.com/mybatis/mybatis-3/pull/1934/commits/beee143f72b0c396591aa0c59739a1e64fd41867
--
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] TeslaCN commented on a diff in pull request #20197: Improve DriverDataSourceCache
Posted by GitBox <gi...@apache.org>.
TeslaCN commented on code in PR #20197:
URL: https://github.com/apache/shardingsphere/pull/20197#discussion_r946458089
##########
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/DriverDataSourceCache.java:
##########
@@ -44,23 +43,17 @@ public DataSource get(final String url) throws SQLException {
if (dataSourceMap.containsKey(url)) {
return dataSourceMap.get(url);
}
- DataSource dataSource;
+ return dataSourceMap.computeIfAbsent(url, DriverDataSourceCache::createDataSource);
Review Comment:
Got it. I didn't saw the logic above.
--
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] TeslaCN commented on a diff in pull request #20197: Improve DriverDataSourceCache
Posted by GitBox <gi...@apache.org>.
TeslaCN commented on code in PR #20197:
URL: https://github.com/apache/shardingsphere/pull/20197#discussion_r946430888
##########
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/DriverDataSourceCache.java:
##########
@@ -44,23 +43,17 @@ public DataSource get(final String url) throws SQLException {
if (dataSourceMap.containsKey(url)) {
return dataSourceMap.get(url);
}
- DataSource dataSource;
+ return dataSourceMap.computeIfAbsent(url, DriverDataSourceCache::createDataSource);
Review Comment:
This may impact concurrent performance in Java 8. https://bugs.openjdk.org/browse/JDK-8161372
--
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] TeslaCN merged pull request #20197: Improve DriverDataSourceCache
Posted by GitBox <gi...@apache.org>.
TeslaCN merged PR #20197:
URL: https://github.com/apache/shardingsphere/pull/20197
--
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] wuwen5 commented on a diff in pull request #20197: Improve DriverDataSourceCache
Posted by GitBox <gi...@apache.org>.
wuwen5 commented on code in PR #20197:
URL: https://github.com/apache/shardingsphere/pull/20197#discussion_r946455780
##########
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/DriverDataSourceCache.java:
##########
@@ -44,23 +43,17 @@ public DataSource get(final String url) throws SQLException {
if (dataSourceMap.containsKey(url)) {
return dataSourceMap.get(url);
}
- DataSource dataSource;
+ return dataSourceMap.computeIfAbsent(url, DriverDataSourceCache::createDataSource);
Review Comment:
Generally, we don't need this code ``` if (dataSourceMap.containsKey(url)) ```, but because of this problem [JDK-8161372](https://bugs.openjdk.org/browse/JDK-8161372), we keep it.
--
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