This is an automated email from the ASF dual-hosted git repository. kxiao pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 1842c7db9c77ba7aadc05b5c61fd863df267c907 Author: Jibing-Li <[email protected]> AuthorDate: Tue Sep 12 14:12:18 2023 +0800 [fix](forward master op)Set default catalog and db only when they exist in master FE while executing forwarded stmt (#24212) In this case, forward to master will throw catalog or db not found exception: Connect to a follower: 1. create database test 2. use test 3. drop database test 4. create database test This is because after step 2, the default db in follower has been set to `test`, drop database will not change the default db. In step 4, the default db `test` is set and forwarded to master, and master will fail to find it because it is already dropped. This pr is to set the default catalog and db only when they exist. The actual reason is that, when Follower handle the `drop db` stmt, it will forward to master to execute it, but can not unset its own "current db" --- .../main/java/org/apache/doris/qe/ConnectProcessor.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java index 4c2549d22a..833e185d6f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java @@ -747,11 +747,19 @@ public class ConnectProcessor { int idx = request.isSetStmtIdx() ? request.getStmtIdx() : 0; executor = new StmtExecutor(ctx, new OriginStatement(request.getSql(), idx), true); ctx.setExecutor(executor); + // Set default catalog only if the catalog exists. if (request.isSetDefaultCatalog()) { - ctx.getEnv().changeCatalog(ctx, request.getDefaultCatalog()); - } - if (request.isSetDefaultDatabase() && !request.getDefaultDatabase().isEmpty()) { - ctx.getEnv().changeDb(ctx, request.getDefaultDatabase()); + CatalogIf catalog = ctx.getEnv().getCatalogMgr().getCatalog(request.getDefaultCatalog()); + if (catalog != null) { + ctx.getEnv().changeCatalog(ctx, request.getDefaultCatalog()); + // Set default db only when the default catalog is set and the dbname exists in default catalog. + if (request.isSetDefaultDatabase()) { + DatabaseIf db = ctx.getCurrentCatalog().getDbNullable(request.getDefaultDatabase()); + if (db != null) { + ctx.getEnv().changeDb(ctx, request.getDefaultDatabase()); + } + } + } } TUniqueId queryId; // This query id will be set in ctx if (request.isSetQueryId()) { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
