cherry pick from #39601
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user