Skip to content

Commit

Permalink
[cases](regression-test) Add backup restore operation test
Browse files Browse the repository at this point in the history
1. restore overwrites an exists table
2. backup & restore with exclude table
3. restore to a new table
4. restore mix exists and new tables
5. restore with alias
  • Loading branch information
w41ter committed Oct 31, 2023
1 parent 994db8b commit 210ac78
Show file tree
Hide file tree
Showing 8 changed files with 574 additions and 0 deletions.
41 changes: 41 additions & 0 deletions regression-test/data/backup_restore/test_backup_restore_alias.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select --
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
20 21
123 341

-- !select --
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
20 21
123 341

-- !select --
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select --
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
20 20
21 21

-- !select --
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
20 20
21 21

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select --
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
20 20
21 21

-- !select --
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 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_alias", "backup_restore") {
String repoName = "test_backup_restore_alias_repo"
String dbName = "backup_restore_alias_db"
String tableName = "test_backup_restore_alias_table"
String aliasName = "test_backup_restore_alias_table_alias"

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

sql "CREATE DATABASE IF NOT EXISTS ${dbName}"
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 i = 1; i <= 10; ++i) {
values.add("(${i}, ${i})")
}
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 ${dbName}.${snapshotName}
TO `${repoName}`
ON (${tableName})
"""

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

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

sql "INSERT INTO ${dbName}.${tableName} VALUES (20, 21), (123, 341)"
qt_select "SELECT * FROM ${dbName}.${tableName} ORDER BY id"

sql """
RESTORE SNAPSHOT ${dbName}.${snapshotName}
FROM `${repoName}`
ON ( `${tableName}` AS `${aliasName}` )
PROPERTIES
(
"backup_timestamp" = "${snapshot}",
"replication_num" = "1"
)
"""

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

qt_select "SELECT * FROM ${dbName}.${tableName} ORDER BY id"
qt_select "SELECT * FROM ${dbName}.${aliasName} ORDER BY id"

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,103 @@
// 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_exclude", "backup_restore") {
String dbName = "backup_restore_exclude"
String suiteName = "test_backup_restore_exclude"
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 backupExcludeTable = tables.removeLast();
sql """
BACKUP SNAPSHOT ${dbName}.${snapshotName}
TO `${repoName}`
EXCLUDE (${backupExcludeTable})
"""

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

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

// Overwrite exists table.
sql "INSERT INTO ${dbName}.${backupExcludeTable} VALUES (20, 20), (21, 21)"
qt_select "SELECT * FROM ${dbName}.${backupExcludeTable} ORDER BY id"

def restoreExcludeTable = tables.removeLast()
sql "DROP TABLE ${dbName}.${restoreExcludeTable} FORCE"

sql """
RESTORE SNAPSHOT ${dbName}.${snapshotName}
FROM `${repoName}`
EXCLUDE (${restoreExcludeTable})
PROPERTIES
(
"backup_timestamp" = "${snapshot}",
"replication_num" = "1"
)
"""

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

qt_select "SELECT * FROM ${dbName}.${backupExcludeTable} ORDER BY id"
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}`"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// 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_overwrite", "backup_restore") {
String dbName = "backup_restore_multi_tables_overwrite_db"
String suiteName = "test_backup_restore_multi_tables_overwrite"
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)

// Overwrite exists table.
def firstTableName = backupTables[0]
sql "INSERT INTO ${dbName}.${firstTableName} VALUES (20, 20), (21, 21)"
qt_select "SELECT * FROM ${dbName}.${firstTableName} ORDER BY id"

sql """
RESTORE SNAPSHOT ${dbName}.${snapshotName}
FROM `${repoName}`
ON (${backupTables.join(",")})
PROPERTIES
(
"backup_timestamp" = "${snapshot}",
"replication_num" = "1"
)
"""

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

qt_select "SELECT * FROM ${dbName}.${firstTableName} ORDER BY id"
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}`"
}

Loading

0 comments on commit 210ac78

Please sign in to comment.