Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cases](regression-test) Add backup & restore with multi tables test #26040

Merged
merged 1 commit into from
Oct 31, 2023
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 @@ -350,8 +350,11 @@ class Syncer {
return isCheckedOK
}

Boolean checkSnapshotFinish() {
String checkSQL = "SHOW BACKUP FROM " + context.db
Boolean checkSnapshotFinish(String dbName = null) {
if (dbName == null) {
dbName = context.db
}
String checkSQL = "SHOW BACKUP FROM ${dbName}"
def records = suite.sql(checkSQL)
for (row in records) {
logger.info("BACKUP row is ${row}")
Expand Down Expand Up @@ -385,8 +388,11 @@ class Syncer {
null
}

Boolean checkAllRestoreFinish() {
String checkSQL = "SHOW RESTORE FROM ${context.db}"
Boolean checkAllRestoreFinish(String dbName = null) {
if (dbName == null) {
dbName = context.db
}
String checkSQL = "SHOW RESTORE FROM ${dbName}"
def records = suite.sql(checkSQL)
for (row in records) {
logger.info("Restore row is ${row}")
Expand Down
29 changes: 16 additions & 13 deletions regression-test/suites/backup_restore/test_backup_restore.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

suite("test_backup_restore", "backup_restore") {
String repoName = "test_backup_restore_repo"
String dbName = "backup_restore_db"
String tableName = "test_backup_restore_table"

def syncer = getSyncer()
syncer.createS3Repository(repoName)

String tableName = "test_backup_restore_table"
sql "DROP TABLE IF EXISTS ${tableName}"
sql "CREATE DATABASE IF NOT EXISTS ${dbName}"
sql "DROP TABLE IF EXISTS ${dbName}.${tableName}"
sql """
CREATE TABLE ${tableName} (
CREATE TABLE ${dbName}.${tableName} (
`id` LARGEINT NOT NULL,
`count` LARGEINT SUM DEFAULT "0")
AGGREGATE KEY(`id`)
Expand All @@ -36,31 +38,31 @@ suite("test_backup_restore", "backup_restore") {
"""

List<String> values = []
for (i = 1; i <= 10; ++i) {
for (int i = 1; i <= 10; ++i) {
values.add("(${i}, ${i})")
}
sql "INSERT INTO ${tableName} VALUES ${values.join(",")}"
def result = sql "SELECT * FROM ${tableName}"
sql "INSERT INTO ${dbName}.${tableName} VALUES ${values.join(",")}"
def result = sql "SELECT * FROM ${dbName}.${tableName}"
assertEquals(result.size(), values.size());

String snapshotName = "test_backup_restore_snapshot"
sql """
BACKUP SNAPSHOT ${snapshotName}
BACKUP SNAPSHOT ${dbName}.${snapshotName}
TO `${repoName}`
ON (${tableName})
"""

while (!syncer.checkSnapshotFinish()) {
while (!syncer.checkSnapshotFinish(dbName)) {
Thread.sleep(3000)
}

snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
assertTrue(snapshot != null)

sql "TRUNCATE TABLE ${tableName}"
sql "TRUNCATE TABLE ${dbName}.${tableName}"

sql """
RESTORE SNAPSHOT ${snapshotName}
RESTORE SNAPSHOT ${dbName}.${snapshotName}
FROM `${repoName}`
ON ( `${tableName}`)
PROPERTIES
Expand All @@ -70,14 +72,15 @@ suite("test_backup_restore", "backup_restore") {
)
"""

while (!syncer.checkAllRestoreFinish()) {
while (!syncer.checkAllRestoreFinish(dbName)) {
Thread.sleep(3000)
}

result = sql "SELECT * FROM ${tableName}"
result = sql "SELECT * FROM ${dbName}.${tableName}"
assertEquals(result.size(), values.size());

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// 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_restore_multi_tables", "backup_restore") {
String dbName = "backup_restore_multi_tables_db"
String suiteName = "test_backup_restore_multi_tables"
String repoName = "${suiteName}_repo"
String snapshotName = "${suiteName}_snapshot"
String tableNamePrefix = "${suiteName}_tables"

def syncer = getSyncer()
syncer.createS3Repository(repoName)
sql "CREATE DATABASE IF NOT EXISTS ${dbName}"

int numTables = 10;
int numRows = 10;
List<String> tables = []
for (int i = 0; i < numTables; ++i) {
String tableName = "${tableNamePrefix}_${i}"
tables.add(tableName)
sql "DROP TABLE IF EXISTS ${dbName}.${tableName}"
sql """
CREATE TABLE ${dbName}.${tableName} (
`id` LARGEINT NOT NULL,
`count` LARGEINT SUM DEFAULT "0"
)
AGGREGATE KEY(`id`)
DISTRIBUTED BY HASH(`id`) BUCKETS 2
PROPERTIES
(
"replication_num" = "1"
)
"""
List<String> values = []
for (int j = 1; j <= numRows; ++j) {
values.add("(${j}, ${j})")
}
sql "INSERT INTO ${dbName}.${tableName} VALUES ${values.join(",")}"
def result = sql "SELECT * FROM ${dbName}.${tableName}"
assertEquals(result.size(), numRows);
}

def backupTables = tables[0..5]
sql """
BACKUP SNAPSHOT ${dbName}.${snapshotName}
TO `${repoName}`
ON (${backupTables.join(",")})
"""

while (!syncer.checkSnapshotFinish(dbName)) {
Thread.sleep(3000)
}

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}`
ON (${backupTables.join(",")})
PROPERTIES
(
"backup_timestamp" = "${snapshot}",
"replication_num" = "1"
)
"""

while (!syncer.checkAllRestoreFinish(dbName)) {
Thread.sleep(3000)
}

for (def tableName in tables) {
result = sql "SELECT * FROM ${dbName}.${tableName}"
assertEquals(result.size(), numRows);
sql "DROP TABLE ${dbName}.${tableName} FORCE"
}

sql "DROP DATABASE ${dbName} FORCE"
sql "DROP REPOSITORY `${repoName}`"
}