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/03/28 07:39:22 UTC
[GitHub] [shardingsphere] TeslaCN opened a new pull request #16429: Add reference count in JDBCBackendConnection
TeslaCN opened a new pull request #16429:
URL: https://github.com/apache/shardingsphere/pull/16429
Fixes #16294.
--
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 change in pull request #16429: Add reference count in JDBCBackendConnection
Posted by GitBox <gi...@apache.org>.
TeslaCN commented on a change in pull request #16429:
URL: https://github.com/apache/shardingsphere/pull/16429#discussion_r836258932
##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java
##########
@@ -176,43 +176,48 @@ public void unmarkResourceInUse(final JDBCDatabaseCommunicationEngine databaseCo
@Override
public Void prepareForTaskExecution() throws BackendConnectionException {
- if (!connectionSession.getTransactionStatus().isInConnectionHeldTransaction()) {
- connectionStatus.waitUntilConnectionRelease();
- connectionStatus.switchToUsing();
- }
- if (!connectionSession.isAutoCommit() && !connectionSession.getTransactionStatus().isInTransaction()) {
- JDBCBackendTransactionManager transactionManager = new JDBCBackendTransactionManager(this);
- try {
- transactionManager.begin();
- } catch (SQLException ex) {
- throw new BackendConnectionException(ex);
+ synchronized (this) {
+ connectionReferenceCount++;
+ if (!connectionSession.isAutoCommit() && !connectionSession.getTransactionStatus().isInTransaction()) {
+ JDBCBackendTransactionManager transactionManager = new JDBCBackendTransactionManager(this);
+ try {
+ transactionManager.begin();
+ } catch (SQLException ex) {
+ throw new BackendConnectionException(ex);
+ }
}
+ return null;
}
- return null;
}
@Override
public Void closeExecutionResources() throws BackendConnectionException {
- Collection<Exception> result = new LinkedList<>();
- result.addAll(closeDatabaseCommunicationEngines(false));
- result.addAll(closeFederationExecutor());
- if (!connectionSession.getTransactionStatus().isInConnectionHeldTransaction()) {
- result.addAll(closeDatabaseCommunicationEngines(true));
- result.addAll(closeConnections(false));
- connectionStatus.switchToReleased();
- }
- if (result.isEmpty()) {
- return null;
+ synchronized (this) {
+ if (connectionReferenceCount > 0 && connectionReferenceCount-- > 1) {
Review comment:
> Maybe `--connectionReferenceCount` ? or why not use `connectionReferenceCount > 1`?
Count may not be increased before decrease.
--
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] totalo commented on a change in pull request #16429: Add reference count in JDBCBackendConnection
Posted by GitBox <gi...@apache.org>.
totalo commented on a change in pull request #16429:
URL: https://github.com/apache/shardingsphere/pull/16429#discussion_r836249953
##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java
##########
@@ -176,43 +176,48 @@ public void unmarkResourceInUse(final JDBCDatabaseCommunicationEngine databaseCo
@Override
public Void prepareForTaskExecution() throws BackendConnectionException {
- if (!connectionSession.getTransactionStatus().isInConnectionHeldTransaction()) {
- connectionStatus.waitUntilConnectionRelease();
- connectionStatus.switchToUsing();
- }
- if (!connectionSession.isAutoCommit() && !connectionSession.getTransactionStatus().isInTransaction()) {
- JDBCBackendTransactionManager transactionManager = new JDBCBackendTransactionManager(this);
- try {
- transactionManager.begin();
- } catch (SQLException ex) {
- throw new BackendConnectionException(ex);
+ synchronized (this) {
+ connectionReferenceCount++;
+ if (!connectionSession.isAutoCommit() && !connectionSession.getTransactionStatus().isInTransaction()) {
+ JDBCBackendTransactionManager transactionManager = new JDBCBackendTransactionManager(this);
+ try {
+ transactionManager.begin();
+ } catch (SQLException ex) {
+ throw new BackendConnectionException(ex);
+ }
}
+ return null;
}
- return null;
}
@Override
public Void closeExecutionResources() throws BackendConnectionException {
- Collection<Exception> result = new LinkedList<>();
- result.addAll(closeDatabaseCommunicationEngines(false));
- result.addAll(closeFederationExecutor());
- if (!connectionSession.getTransactionStatus().isInConnectionHeldTransaction()) {
- result.addAll(closeDatabaseCommunicationEngines(true));
- result.addAll(closeConnections(false));
- connectionStatus.switchToReleased();
- }
- if (result.isEmpty()) {
- return null;
+ synchronized (this) {
+ if (connectionReferenceCount > 0 && connectionReferenceCount-- > 1) {
Review comment:
Maybe `--connectionReferenceCount` ? or why not use `connectionReferenceCount > 1`?
--
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] terrymanu merged pull request #16429: Add reference count in JDBCBackendConnection
Posted by GitBox <gi...@apache.org>.
terrymanu merged pull request #16429:
URL: https://github.com/apache/shardingsphere/pull/16429
--
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] totalo commented on a change in pull request #16429: Add reference count in JDBCBackendConnection
Posted by GitBox <gi...@apache.org>.
totalo commented on a change in pull request #16429:
URL: https://github.com/apache/shardingsphere/pull/16429#discussion_r836279008
##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java
##########
@@ -176,43 +176,48 @@ public void unmarkResourceInUse(final JDBCDatabaseCommunicationEngine databaseCo
@Override
public Void prepareForTaskExecution() throws BackendConnectionException {
- if (!connectionSession.getTransactionStatus().isInConnectionHeldTransaction()) {
- connectionStatus.waitUntilConnectionRelease();
- connectionStatus.switchToUsing();
- }
- if (!connectionSession.isAutoCommit() && !connectionSession.getTransactionStatus().isInTransaction()) {
- JDBCBackendTransactionManager transactionManager = new JDBCBackendTransactionManager(this);
- try {
- transactionManager.begin();
- } catch (SQLException ex) {
- throw new BackendConnectionException(ex);
+ synchronized (this) {
+ connectionReferenceCount++;
+ if (!connectionSession.isAutoCommit() && !connectionSession.getTransactionStatus().isInTransaction()) {
+ JDBCBackendTransactionManager transactionManager = new JDBCBackendTransactionManager(this);
+ try {
+ transactionManager.begin();
+ } catch (SQLException ex) {
+ throw new BackendConnectionException(ex);
+ }
}
+ return null;
}
- return null;
}
@Override
public Void closeExecutionResources() throws BackendConnectionException {
- Collection<Exception> result = new LinkedList<>();
- result.addAll(closeDatabaseCommunicationEngines(false));
- result.addAll(closeFederationExecutor());
- if (!connectionSession.getTransactionStatus().isInConnectionHeldTransaction()) {
- result.addAll(closeDatabaseCommunicationEngines(true));
- result.addAll(closeConnections(false));
- connectionStatus.switchToReleased();
- }
- if (result.isEmpty()) {
- return null;
+ synchronized (this) {
+ if (connectionReferenceCount > 0 && connectionReferenceCount-- > 1) {
Review comment:
Got it.thanks
--
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