[fix](regression) Fix creating db for downstream url #39601 (#39818)

cherry pick from #39601
This commit is contained in:
walter
2024-08-23 16:15:19 +08:00
committed by GitHub
parent 0eadfbefc6
commit e0b65d0ff4

View File

@ -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)
}