From e0b65d0ff42b4b5a322869d5f0be47b983c19c31 Mon Sep 17 00:00:00 2001 From: walter Date: Fri, 23 Aug 2024 16:15:19 +0800 Subject: [PATCH] [fix](regression) Fix creating db for downstream url #39601 (#39818) cherry pick from #39601 --- .../org/apache/doris/regression/Config.groovy | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/regression-test/framework/src/main/groovy/org/apache/doris/regression/Config.groovy b/regression-test/framework/src/main/groovy/org/apache/doris/regression/Config.groovy index c624fccf83..007d0d48f3 100644 --- a/regression-test/framework/src/main/groovy/org/apache/doris/regression/Config.groovy +++ b/regression-test/framework/src/main/groovy/org/apache/doris/regression/Config.groovy @@ -642,6 +642,21 @@ class Config { } } + void tryCreateDownstreamDbIfNotExist(String dbName = defaultDb) { + // connect without specify default db + try { + String sql = "CREATE DATABASE IF NOT EXISTS ${dbName}" + log.info("Try to create db, sql: ${sql}".toString()) + if (!dryRun) { + getDownstreamConnection().withCloseable { conn -> + JdbcUtils.executeToList(conn, sql) + } + } + } catch (Throwable t) { + throw new IllegalStateException("Create database failed, ccrDownstreamUrl: ${ccrDownstreamUrl}", t) + } + } + boolean fetchRunMode() { if (isCloudMode == RunMode.UNKNOWN) { try { @@ -685,9 +700,13 @@ class Config { return DriverManager.getConnection(dbUrl, arrowFlightSqlJdbcUser, arrowFlightSqlJdbcPassword) } + Connection getDownstreamConnection() { + return DriverManager.getConnection(ccrDownstreamUrl, ccrDownstreamUser, ccrDownstreamPassword) + } + Connection getDownstreamConnectionByDbName(String dbName) { String dbUrl = buildUrlWithDb(ccrDownstreamUrl, dbName) - tryCreateDbIfNotExist(dbName) + tryCreateDownstreamDbIfNotExist(dbName) log.info("connect to ${dbUrl}".toString()) return DriverManager.getConnection(dbUrl, ccrDownstreamUser, ccrDownstreamPassword) }