|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +suite("test_backup_restore_with_view", "backup_restore") { |
| 19 | + String suiteName = "backup_restore_with_view" |
| 20 | + String dbName = "${suiteName}_db" |
| 21 | + String dbName1 = "${suiteName}_db_1" |
| 22 | + String repoName = "repo_" + UUID.randomUUID().toString().replace("-", "") |
| 23 | + String snapshotName = "${suiteName}_snapshot" |
| 24 | + String tableName = "${suiteName}_table" |
| 25 | + String viewName = "${suiteName}_view" |
| 26 | + |
| 27 | + def syncer = getSyncer() |
| 28 | + syncer.createS3Repository(repoName) |
| 29 | + sql "CREATE DATABASE IF NOT EXISTS ${dbName}" |
| 30 | + sql "CREATE DATABASE IF NOT EXISTS ${dbName1}" |
| 31 | + |
| 32 | + int numRows = 10; |
| 33 | + sql "DROP TABLE IF EXISTS ${dbName}.${tableName} FORCE" |
| 34 | + sql "DROP VIEW IF EXISTS ${dbName}.${viewName}" |
| 35 | + sql """ |
| 36 | + CREATE TABLE ${dbName}.${tableName} ( |
| 37 | + `id` LARGEINT NOT NULL, |
| 38 | + `count` LARGEINT SUM DEFAULT "0" |
| 39 | + ) |
| 40 | + AGGREGATE KEY(`id`) |
| 41 | + DISTRIBUTED BY HASH(`id`) BUCKETS 2 |
| 42 | + PROPERTIES |
| 43 | + ( |
| 44 | + "replication_num" = "1" |
| 45 | + ) |
| 46 | + """ |
| 47 | + List<String> values = [] |
| 48 | + for (int j = 1; j <= numRows; ++j) { |
| 49 | + values.add("(${j}, ${j})") |
| 50 | + } |
| 51 | + sql "INSERT INTO ${dbName}.${tableName} VALUES ${values.join(",")}" |
| 52 | + |
| 53 | + sql """CREATE VIEW ${dbName}.${viewName} (id, count) |
| 54 | + AS |
| 55 | + SELECT * FROM ${dbName}.${tableName} WHERE count > 5 |
| 56 | + """ |
| 57 | + |
| 58 | + qt_sql "SELECT * FROM ${dbName}.${tableName} ORDER BY id ASC" |
| 59 | + qt_sql "SELECT * FROM ${dbName}.${viewName} ORDER BY id ASC" |
| 60 | + |
| 61 | + sql """ |
| 62 | + BACKUP SNAPSHOT ${dbName}.${snapshotName} |
| 63 | + TO `${repoName}` |
| 64 | + """ |
| 65 | + |
| 66 | + syncer.waitSnapshotFinish(dbName) |
| 67 | + |
| 68 | + def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) |
| 69 | + assertTrue(snapshot != null) |
| 70 | + |
| 71 | + sql "DROP TABLE IF EXISTS ${dbName1}.${tableName} FORCE" |
| 72 | + sql "DROP VIEW IF EXISTS ${dbName1}.${viewName}" |
| 73 | + |
| 74 | + sql """ |
| 75 | + RESTORE SNAPSHOT ${dbName1}.${snapshotName} |
| 76 | + FROM `${repoName}` |
| 77 | + PROPERTIES |
| 78 | + ( |
| 79 | + "backup_timestamp" = "${snapshot}", |
| 80 | + "reserve_replica" = "true" |
| 81 | + ) |
| 82 | + """ |
| 83 | + |
| 84 | + syncer.waitAllRestoreFinish(dbName1) |
| 85 | + |
| 86 | + qt_sql "SELECT * FROM ${dbName1}.${tableName} ORDER BY id ASC" |
| 87 | + qt_sql "SELECT * FROM ${dbName1}.${viewName} ORDER BY id ASC" |
| 88 | + def show_view_result = sql_return_maparray "SHOW VIEW FROM ${tableName} FROM ${dbName1}" |
| 89 | + logger.info("show view result: ${show_view_result}") |
| 90 | + assertTrue(show_view_result.size() == 1); |
| 91 | + def show_view = show_view_result[0]['Create View'] |
| 92 | + assertTrue(show_view.contains("${dbName1}")) |
| 93 | + assertTrue(show_view.contains("${tableName}")) |
| 94 | + |
| 95 | + // restore to db, test the view signature. |
| 96 | + sql """ |
| 97 | + RESTORE SNAPSHOT ${dbName}.${snapshotName} |
| 98 | + FROM `${repoName}` |
| 99 | + PROPERTIES |
| 100 | + ( |
| 101 | + "backup_timestamp" = "${snapshot}", |
| 102 | + "reserve_replica" = "true" |
| 103 | + ) |
| 104 | + """ |
| 105 | + |
| 106 | + syncer.waitAllRestoreFinish(dbName) |
| 107 | + def restore_result = sql_return_maparray """ SHOW RESTORE FROM ${dbName} WHERE Label ="${snapshotName}" """ |
| 108 | + restore_result.last() |
| 109 | + logger.info("show restore result: ${restore_result}") |
| 110 | + assertTrue(restore_result.last().State == "FINISHED") |
| 111 | + |
| 112 | + // restore to db1, test the view signature. |
| 113 | + sql """ |
| 114 | + RESTORE SNAPSHOT ${dbName1}.${snapshotName} |
| 115 | + FROM `${repoName}` |
| 116 | + PROPERTIES |
| 117 | + ( |
| 118 | + "backup_timestamp" = "${snapshot}", |
| 119 | + "reserve_replica" = "true" |
| 120 | + ) |
| 121 | + """ |
| 122 | + |
| 123 | + syncer.waitAllRestoreFinish(dbName1) |
| 124 | + restore_result = sql_return_maparray """ SHOW RESTORE FROM ${dbName1} WHERE Label ="${snapshotName}" """ |
| 125 | + restore_result.last() |
| 126 | + logger.info("show restore result: ${restore_result}") |
| 127 | + assertTrue(restore_result.last().State == "FINISHED") |
| 128 | + |
| 129 | + sql "DROP TABLE ${dbName}.${tableName} FORCE" |
| 130 | + sql "DROP VIEW ${dbName}.${viewName}" |
| 131 | + sql "DROP DATABASE ${dbName} FORCE" |
| 132 | + sql "DROP TABLE ${dbName1}.${tableName} FORCE" |
| 133 | + sql "DROP VIEW ${dbName1}.${viewName}" |
| 134 | + sql "DROP DATABASE ${dbName1} FORCE" |
| 135 | + sql "DROP REPOSITORY `${repoName}`" |
| 136 | +} |
| 137 | + |
0 commit comments