You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ch...@apache.org on 2023/12/22 06:17:27 UTC

(shardingsphere) branch master updated: Restore original databaseName in connectionSession after unicast (#29501)

This is an automated email from the ASF dual-hosted git repository.

chenjiahao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 835b0554bc5 Restore original databaseName in connectionSession after unicast (#29501)
835b0554bc5 is described below

commit 835b0554bc599114d237884d32a9073932b70589
Author: Raigor <ra...@gmail.com>
AuthorDate: Fri Dec 22 14:17:20 2023 +0800

    Restore original databaseName in connectionSession after unicast (#29501)
---
 .../handler/data/impl/UnicastDatabaseBackendHandler.java       | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java
index e992f4481e4..6bcec191e2f 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java
@@ -53,15 +53,15 @@ public final class UnicastDatabaseBackendHandler implements DatabaseBackendHandl
     
     @Override
     public ResponseHeader execute() throws SQLException {
-        String originDatabase = connectionSession.getDefaultDatabaseName();
-        String databaseName = null == originDatabase ? getFirstDatabaseName() : originDatabase;
-        ShardingSpherePreconditions.checkState(ProxyContext.getInstance().getDatabase(databaseName).containsDataSource(), () -> new StorageUnitNotExistedException(databaseName));
+        String originalDatabaseName = connectionSession.getDefaultDatabaseName();
+        String unicastDatabaseName = null == originalDatabaseName ? getFirstDatabaseName() : originalDatabaseName;
+        ShardingSpherePreconditions.checkState(ProxyContext.getInstance().getDatabase(unicastDatabaseName).containsDataSource(), () -> new StorageUnitNotExistedException(unicastDatabaseName));
         try {
-            connectionSession.setCurrentDatabase(databaseName);
+            connectionSession.setCurrentDatabase(unicastDatabaseName);
             databaseConnector = databaseConnectorFactory.newInstance(queryContext, connectionSession.getDatabaseConnectionManager(), false);
             return databaseConnector.execute();
         } finally {
-            connectionSession.setCurrentDatabase(databaseName);
+            connectionSession.setCurrentDatabase(originalDatabaseName);
         }
     }