Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
wyxxxcat committed Feb 10, 2025
1 parent b1e7432 commit 34adc13
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ public void setBeingSyncedProperties() {
TableProperty tableProperty = getOrCreatTableProperty();
tableProperty.setIsBeingSynced();
tableProperty.removeInvalidProperties();
partitionInfo.refreshTableStoragePolicy("");
if (isAutoBucket()) {
markAutoBucket();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// 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_storage_policy", "backup_restore") {
String suiteName = "test_backup_restore_storage_policy"
String dbName = "${suiteName}_db"
String repoName = "repo_" + UUID.randomUUID().toString().replace("-", "")
String snapshotName = "${suiteName}_snapshot"
String tableName = "${suiteName}_table"
def resource_name = "test_backup_restore_storage_policy_resource"
def policy_name= "test_backup_restore_storage_policy"

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

sql "CREATE DATABASE IF NOT EXISTS ${dbName}"
sql "DROP TABLE IF EXISTS ${dbName}.${tableName}"

def check_storage_policy_exist = { name->
def polices = sql"""
show storage policy;
"""
for (p in polices) {
if (name == p[0]) {
return true;
}
}
return false;
}

if (check_storage_policy_exist(policy_name)) {
sql """
DROP STORAGE POLICY ${policy_name}
"""
}

def has_resouce = sql """
SHOW RESOURCES WHERE NAME = "${resource_name}";
"""

if (has_resouce.size() > 0) {
sql """
DROP RESOURCE ${resource_name}
"""
}

sql """
CREATE RESOURCE IF NOT EXISTS "${resource_name}"
PROPERTIES(
"type"="s3",
"AWS_ENDPOINT" = "${getS3Endpoint()}",
"AWS_REGION" = "${getS3Region()}",
"AWS_ROOT_PATH" = "regression/cooldown",
"AWS_ACCESS_KEY" = "${getS3AK()}",
"AWS_SECRET_KEY" = "${getS3SK()}",
"AWS_MAX_CONNECTIONS" = "50",
"AWS_REQUEST_TIMEOUT_MS" = "3000",
"AWS_CONNECTION_TIMEOUT_MS" = "1000",
"AWS_BUCKET" = "${getS3BucketName()}",
"s3_validity_check" = "true"
);
"""

sql """
CREATE STORAGE POLICY IF NOT EXISTS ${policy_name}
PROPERTIES(
"storage_resource" = "${resource_name}",
"cooldown_ttl" = "300"
)
"""

sql """
CREATE TABLE ${dbName}.${tableName} (
`id` LARGEINT NOT NULL,
`count` LARGEINT SUM DEFAULT "0"
)
AGGREGATE KEY(`id`)
PARTITION BY RANGE(`id`)
(
PARTITION p1 VALUES LESS THAN ("10") ("storage_policy" = \"${policy_name}\"),
PARTITION p2 VALUES LESS THAN ("20") ("storage_policy" = \"${policy_name}\")
)
DISTRIBUTED BY HASH(`id`) BUCKETS 2
PROPERTIES
(
"replication_num" = "1"
)
"""

sql """
BACKUP SNAPSHOT ${dbName}.${snapshotName}
TO `${repoName}`
"""

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

sql "DROP TABLE ${dbName}.${tableName} FORCE"

sql """
RESTORE SNAPSHOT ${dbName}.${snapshotName}
FROM `${repoName}`
ON (`${tableName}`)
PROPERTIES
(
"backup_timestamp" = "${snapshot}",
"reserve_replica" = "true",
"is_being_synced" = "true"
)
"""


syncer.waitAllRestoreFinish(dbName)

def res = sql "SHOW CREATE TABLE ${dbName}.${tableName}"

logger.info(res[0][1])

assertTrue(!res[0][1].contains("(\"storage_policy\" = \"${policy_name}\")"))

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

0 comments on commit 34adc13

Please sign in to comment.