This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push: new 3f250e55ce6 branch-2.1: [Enhancement](regression-test)Add regression test for database properties backup and restore #41925 (#47643) 3f250e55ce6 is described below commit 3f250e55ce6d7f8b9b2e7086db4bb425675671f3 Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> AuthorDate: Sun Feb 9 04:24:05 2025 +0800 branch-2.1: [Enhancement](regression-test)Add regression test for database properties backup and restore #41925 (#47643) Cherry-picked from #41925 Co-authored-by: Uniqueyou <wangyix...@selectdb.com> --- .../test_backup_store_with_db_properties.groovy | 106 ++++++++++++++++++++ .../test_backup_store_with_db_properties_kv.groovy | 111 +++++++++++++++++++++ 2 files changed, 217 insertions(+) diff --git a/regression-test/suites/backup_restore/test_backup_store_with_db_properties.groovy b/regression-test/suites/backup_restore/test_backup_store_with_db_properties.groovy new file mode 100644 index 00000000000..83cd32dd33d --- /dev/null +++ b/regression-test/suites/backup_restore/test_backup_store_with_db_properties.groovy @@ -0,0 +1,106 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_backup_store_with_db_properties","backup_restore") { + String dbName = "test_backup_store_with_db_properties_db" + String suiteName = "test_backup_store_with_db_properties" + String repoName = "repo_" + UUID.randomUUID().toString().replace("-", "") + String snapshotName = "${suiteName}_snapshot" + String tableNamePrefix = "${suiteName}" + + def forceReplicaNum = getFeConfig('force_olap_table_replication_num') as int + def replicaNum = forceReplicaNum > 0 ? forceReplicaNum : 1 + def syncer = getSyncer() + syncer.createS3Repository(repoName) + + sql "DROP DATABASE IF EXISTS ${dbName} FORCE" + + sql """ + CREATE DATABASE IF NOT EXISTS ${dbName} + PROPERTIES ("replication_allocation" = "tag.location.default:${replicaNum}") + """ + + def result_kv_origin = sql "SHOW CREATE DATABASE ${dbName}" + assertTrue(result_kv_origin.toString().containsIgnoreCase("tag.location.default:${replicaNum}")) + + int numTables = 10; + int numRows = 10; + List<String> tables = [] + + for (int i = 0; i < numTables; ++i) { + String tableName = "${tableNamePrefix}_t${i}" + tables.add(tableName) + sql "DROP TABLE IF EXISTS ${dbName}.${tableName} FORCE" + sql """ + CREATE TABLE ${dbName}.${tableName} ( + `id` LARGEINT NOT NULL + ) + AGGREGATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 2 + PROPERTIES + ( + "replication_allocation" = "tag.location.default:${replicaNum}" + ) + """ + List<String> values = [] + for (int j = 1; j <= numRows; ++j) { + values.add("(${j})") + } + sql "INSERT INTO ${dbName}.${tableName} VALUES ${values.join(",")}" + def result = sql "SELECT * FROM ${dbName}.${tableName}" + assertEquals(result.size(), numRows); + } + + def backupTables = tables[0..numTables - 1] + sql """ + BACKUP SNAPSHOT ${dbName}.${snapshotName} + TO `${repoName}` + """ + + syncer.waitSnapshotFinish(dbName) + + def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) + assertTrue(snapshot != null) + + for (def tableName in backupTables) { + sql "TRUNCATE TABLE ${dbName}.${tableName}" + } + + sql """ + RESTORE SNAPSHOT ${dbName}.${snapshotName} + FROM `${repoName}` + PROPERTIES + ( + "backup_timestamp" = "${snapshot}", + "reserve_replica" = "true" + ) + """ + + syncer.waitAllRestoreFinish(dbName) + + def result_kv_restore = sql "SHOW CREATE DATABASE ${dbName}" + assertEquals(result_kv_restore, result_kv_origin); + + for (def tableName in tables) { + result = sql "SELECT * FROM ${dbName}.${tableName}" + assertEquals(result.size(), numRows); + sql "DROP TABLE ${dbName}.${tableName} FORCE" + } + + sql "DROP REPOSITORY `${repoName}`" +} + diff --git a/regression-test/suites/backup_restore/test_backup_store_with_db_properties_kv.groovy b/regression-test/suites/backup_restore/test_backup_store_with_db_properties_kv.groovy new file mode 100644 index 00000000000..5c57819c73a --- /dev/null +++ b/regression-test/suites/backup_restore/test_backup_store_with_db_properties_kv.groovy @@ -0,0 +1,111 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_backup_store_with_db_properties_kv","backup_restore") { + String dbName = "test_backup_store_with_db_properties_kv_db" + String suiteName = "test_backup_store_with_db_properties_kv" + String repoName = "repo_" + UUID.randomUUID().toString().replace("-", "") + String snapshotName = "${suiteName}_snapshot" + String tableNamePrefix = "${suiteName}" + + def forceReplicaNum = getFeConfig('force_olap_table_replication_num') as int + def replicaNum = forceReplicaNum > 0 ? forceReplicaNum : 1 + def syncer = getSyncer() + syncer.createS3Repository(repoName) + + sql "DROP DATABASE IF EXISTS ${dbName} FORCE" + + sql """ + CREATE DATABASE IF NOT EXISTS ${dbName} + PROPERTIES + ( + "replication_allocation" = "tag.location.default:${replicaNum}", + "test_key" = "test_value" + ) + """ + + def result_origin = sql "SHOW CREATE DATABASE ${dbName}" + assertTrue(result_origin.toString().containsIgnoreCase("tag.location.default:${replicaNum}")) + assertTrue(result_origin.toString().containsIgnoreCase('"test_key" = "test_value"')) + + int numTables = 10; + int numRows = 10; + List<String> tables = [] + + for (int i = 0; i < numTables; ++i) { + String tableName = "${tableNamePrefix}_t${i}" + tables.add(tableName) + sql "DROP TABLE IF EXISTS ${dbName}.${tableName} FORCE" + sql """ + CREATE TABLE ${dbName}.${tableName} ( + `id` LARGEINT NOT NULL + ) + AGGREGATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 2 + PROPERTIES + ( + "replication_allocation" = "tag.location.default:${replicaNum}" + ) + """ + List<String> values = [] + for (int j = 1; j <= numRows; ++j) { + values.add("(${j})") + } + sql "INSERT INTO ${dbName}.${tableName} VALUES ${values.join(",")}" + def result = sql "SELECT * FROM ${dbName}.${tableName}" + assertEquals(result.size(), numRows); + } + + def backupTables = tables[0..numTables - 1] + sql """ + BACKUP SNAPSHOT ${dbName}.${snapshotName} + TO `${repoName}` + """ + + syncer.waitSnapshotFinish(dbName) + + def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) + assertTrue(snapshot != null) + + for (def tableName in backupTables) { + sql "TRUNCATE TABLE ${dbName}.${tableName}" + } + + sql """ + RESTORE SNAPSHOT ${dbName}.${snapshotName} + FROM `${repoName}` + PROPERTIES + ( + "backup_timestamp" = "${snapshot}", + "reserve_replica" = "true" + ) + """ + + syncer.waitAllRestoreFinish(dbName) + + def result_restore = sql "SHOW CREATE DATABASE ${dbName}" + assertEquals(result_restore, result_origin); + + for (def tableName in tables) { + result = sql "SELECT * FROM ${dbName}.${tableName}" + assertEquals(result.size(), numRows); + sql "DROP TABLE ${dbName}.${tableName} FORCE" + } + + sql "DROP REPOSITORY `${repoName}`" +} + --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org