Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,8 @@ private void checkAndPrepareMeta() {
return;
}
} else {
remoteView.resetIdsForRestore(env);
String srcDbName = jobInfo.dbName;
remoteView.resetIdsForRestore(env, srcDbName, db.getFullName());
restoredTbls.add(remoteView);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,13 @@ public View clone() {
return copied;
}

public void resetIdsForRestore(Env env) {
public void resetIdsForRestore(Env env, String srcDbName, String dbName) {
id = env.getNextId();

// the source db name is not setted in old BackupMeta, keep compatible with the old one.
if (srcDbName != null) {
inlineViewDef = inlineViewDef.replaceAll(srcDbName, dbName);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
suite("test_backup_restore_with_view", "backup_restore") {
String suiteName = "backup_restore_with_view"
String dbName = "${suiteName}_db"
String dbName1 = "${suiteName}_db_1"
String repoName = "repo_" + UUID.randomUUID().toString().replace("-", "")
String snapshotName = "${suiteName}_snapshot"
String tableName = "${suiteName}_table"
Expand All @@ -26,6 +27,7 @@ suite("test_backup_restore_with_view", "backup_restore") {
def syncer = getSyncer()
syncer.createS3Repository(repoName)
sql "CREATE DATABASE IF NOT EXISTS ${dbName}"
sql "CREATE DATABASE IF NOT EXISTS ${dbName1}"

int numRows = 10;
sql "DROP TABLE IF EXISTS ${dbName}.${tableName} FORCE"
Expand Down Expand Up @@ -66,11 +68,11 @@ suite("test_backup_restore_with_view", "backup_restore") {
def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
assertTrue(snapshot != null)

sql "DROP TABLE ${dbName}.${tableName} FORCE"
sql "DROP VIEW ${dbName}.${viewName}"
sql "DROP TABLE IF EXISTS ${dbName1}.${tableName} FORCE"
sql "DROP VIEW IF EXISTS ${dbName1}.${viewName}"

sql """
RESTORE SNAPSHOT ${dbName}.${snapshotName}
RESTORE SNAPSHOT ${dbName1}.${snapshotName}
FROM `${repoName}`
PROPERTIES
(
Expand All @@ -79,14 +81,24 @@ suite("test_backup_restore_with_view", "backup_restore") {
)
"""

syncer.waitAllRestoreFinish(dbName)
syncer.waitAllRestoreFinish(dbName1)

qt_sql "SELECT * FROM ${dbName1}.${tableName} ORDER BY id ASC"
qt_sql "SELECT * FROM ${dbName1}.${viewName} ORDER BY id ASC"
def show_view_result = sql_return_maparray "SHOW VIEW FROM ${tableName} FROM ${dbName1}"
logger.info("show view result: ${show_view_result}")
assertTrue(show_view_result.size() == 1);
def show_view = show_view_result[0]['Create View']
assertTrue(show_view.contains("${dbName1}"))
assertTrue(show_view.contains("${tableName}"))

qt_sql "SELECT * FROM ${dbName}.${tableName} ORDER BY id ASC"
qt_sql "SELECT * FROM ${dbName}.${viewName} ORDER BY id ASC"

sql "DROP TABLE ${dbName}.${tableName} FORCE"
sql "DROP VIEW ${dbName}.${viewName}"
sql "DROP DATABASE ${dbName} FORCE"
sql "DROP TABLE ${dbName1}.${tableName} FORCE"
sql "DROP VIEW ${dbName1}.${viewName}"
sql "DROP DATABASE ${dbName1} FORCE"
sql "DROP REPOSITORY `${repoName}`"
}