|
| 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_cancelled", "backup_cancelled") { |
| 19 | + String suiteName = "test_backup_cancelled" |
| 20 | + String repoName = "${suiteName}_repo" |
| 21 | + String dbName = "${suiteName}_db" |
| 22 | + String tableName = "${suiteName}_table" |
| 23 | + String snapshotName = "${suiteName}_snapshot" |
| 24 | + String snapshotName_1 = "${suiteName}_snapshot1" |
| 25 | + |
| 26 | + def syncer = getSyncer() |
| 27 | + syncer.createS3Repository(repoName) |
| 28 | + |
| 29 | + sql "CREATE DATABASE IF NOT EXISTS ${dbName}" |
| 30 | + sql "DROP TABLE IF EXISTS ${dbName}.${tableName}" |
| 31 | + sql """ |
| 32 | + CREATE TABLE ${dbName}.${tableName} ( |
| 33 | + `id` LARGEINT NOT NULL, |
| 34 | + `count` LARGEINT SUM DEFAULT "0") |
| 35 | + AGGREGATE KEY(`id`) |
| 36 | + DISTRIBUTED BY HASH(`id`) BUCKETS 2 |
| 37 | + PROPERTIES |
| 38 | + ( |
| 39 | + "replication_num" = "1" |
| 40 | + ) |
| 41 | + """ |
| 42 | + |
| 43 | + List<String> values = [] |
| 44 | + for (int i = 1; i <= 10; ++i) { |
| 45 | + values.add("(${i}, ${i})") |
| 46 | + } |
| 47 | + sql "INSERT INTO ${dbName}.${tableName} VALUES ${values.join(",")}" |
| 48 | + def result = sql "SELECT * FROM ${dbName}.${tableName}" |
| 49 | + assertEquals(result.size(), values.size()); |
| 50 | + |
| 51 | + result = sql_return_maparray """show tablets from ${dbName}.${tableName}""" |
| 52 | + assertNotNull(result) |
| 53 | + def tabletId = null |
| 54 | + for (def res : result) { |
| 55 | + tabletId = res.TabletId |
| 56 | + break |
| 57 | + } |
| 58 | + |
| 59 | + // test failed to get tablet when truncate or drop table |
| 60 | + |
| 61 | + GetDebugPoint().enableDebugPointForAllBEs("SnapshotManager::make_snapshot.inject_failure", [tablet_id:"${tabletId}", execute:3]); |
| 62 | + |
| 63 | + |
| 64 | + sql """ |
| 65 | + BACKUP SNAPSHOT ${dbName}.${snapshotName} |
| 66 | + TO `${repoName}` |
| 67 | + ON (${tableName}) |
| 68 | + """ |
| 69 | + |
| 70 | + syncer.waitSnapshotFinish(dbName) |
| 71 | + |
| 72 | + |
| 73 | + GetDebugPoint().disableDebugPointForAllBEs("SnapshotManager::make_snapshot.inject_failure") |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + // test missing versions when compaction or balance |
| 79 | + |
| 80 | + GetDebugPoint().enableDebugPointForAllBEs("Tablet::capture_consistent_versions.inject_failure", [tablet_id:"${tabletId}", execute:1]); |
| 81 | + |
| 82 | + sql """ |
| 83 | + BACKUP SNAPSHOT ${dbName}.${snapshotName_1} |
| 84 | + TO `${repoName}` |
| 85 | + ON (${tableName}) |
| 86 | + """ |
| 87 | + |
| 88 | + syncer.waitSnapshotFinish(dbName) |
| 89 | + |
| 90 | + GetDebugPoint().disableDebugPointForAllBEs("Tablet::capture_consistent_versions.inject_failure"); |
| 91 | + |
| 92 | + |
| 93 | + def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) |
| 94 | + assertTrue(snapshot != null) |
| 95 | + |
| 96 | + sql "TRUNCATE TABLE ${dbName}.${tableName}" |
| 97 | + |
| 98 | + sql """ |
| 99 | + RESTORE SNAPSHOT ${dbName}.${snapshotName} |
| 100 | + FROM `${repoName}` |
| 101 | + ON ( `${tableName}`) |
| 102 | + PROPERTIES |
| 103 | + ( |
| 104 | + "backup_timestamp" = "${snapshot}", |
| 105 | + "reserve_replica" = "true" |
| 106 | + ) |
| 107 | + """ |
| 108 | + |
| 109 | + syncer.waitAllRestoreFinish(dbName) |
| 110 | + |
| 111 | + result = sql "SELECT * FROM ${dbName}.${tableName}" |
| 112 | + assertEquals(result.size(), values.size()); |
| 113 | + |
| 114 | + sql "DROP TABLE ${dbName}.${tableName} FORCE" |
| 115 | + sql "DROP DATABASE ${dbName} FORCE" |
| 116 | + sql "DROP REPOSITORY `${repoName}`" |
| 117 | +} |
| 118 | + |
| 119 | + |
| 120 | +suite("test_backup_cooldown_cancelled", "backup_cooldown_cancelled") { |
| 121 | + |
| 122 | + String suiteName = "test_backup_cooldown_cancelled" |
| 123 | + String resource_name = "resource_${suiteName}" |
| 124 | + String policy_name= "policy_${suiteName}" |
| 125 | + String dbName = "${suiteName}_db" |
| 126 | + String tableName = "${suiteName}_table" |
| 127 | + String snapshotName = "${suiteName}_snapshot" |
| 128 | + String repoName = "${suiteName}_repo" |
| 129 | + |
| 130 | + def syncer = getSyncer() |
| 131 | + syncer.createS3Repository(repoName) |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + sql """ |
| 136 | + CREATE RESOURCE IF NOT EXISTS "${resource_name}" |
| 137 | + PROPERTIES( |
| 138 | + "type"="s3", |
| 139 | + "AWS_ENDPOINT" = "${getS3Endpoint()}", |
| 140 | + "AWS_REGION" = "${getS3Region()}", |
| 141 | + "AWS_ROOT_PATH" = "regression/cooldown", |
| 142 | + "AWS_ACCESS_KEY" = "${getS3AK()}", |
| 143 | + "AWS_SECRET_KEY" = "${getS3SK()}", |
| 144 | + "AWS_MAX_CONNECTIONS" = "50", |
| 145 | + "AWS_REQUEST_TIMEOUT_MS" = "3000", |
| 146 | + "AWS_CONNECTION_TIMEOUT_MS" = "1000", |
| 147 | + "AWS_BUCKET" = "${getS3BucketName()}", |
| 148 | + "s3_validity_check" = "true" |
| 149 | + ); |
| 150 | + """ |
| 151 | + |
| 152 | + sql """ |
| 153 | + CREATE STORAGE POLICY IF NOT EXISTS ${policy_name} |
| 154 | + PROPERTIES( |
| 155 | + "storage_resource" = "${resource_name}", |
| 156 | + "cooldown_ttl" = "300" |
| 157 | + ) |
| 158 | + """ |
| 159 | + |
| 160 | + sql "CREATE DATABASE IF NOT EXISTS ${dbName}" |
| 161 | + sql "DROP TABLE IF EXISTS ${dbName}.${tableName}" |
| 162 | + |
| 163 | + sql """ |
| 164 | + CREATE TABLE ${dbName}.${tableName} |
| 165 | + ( |
| 166 | + k1 BIGINT, |
| 167 | + v1 VARCHAR(48) |
| 168 | + ) |
| 169 | + DUPLICATE KEY(k1) |
| 170 | + DISTRIBUTED BY HASH (k1) BUCKETS 3 |
| 171 | + PROPERTIES( |
| 172 | + "storage_policy" = "${policy_name}", |
| 173 | + "replication_allocation" = "tag.location.default: 1" |
| 174 | + ); |
| 175 | + """ |
| 176 | + |
| 177 | + |
| 178 | + // test backup cooldown table and should be cancelled |
| 179 | + sql """ |
| 180 | + BACKUP SNAPSHOT ${dbName}.${snapshotName} |
| 181 | + TO `${repoName}` |
| 182 | + ON (${tableName}) |
| 183 | + """ |
| 184 | + |
| 185 | + syncer.waitSnapshotFinish(dbName) |
| 186 | + |
| 187 | + //cleanup |
| 188 | + sql "DROP TABLE ${dbName}.${tableName} FORCE" |
| 189 | + sql "DROP DATABASE ${dbName} FORCE" |
| 190 | + sql "DROP REPOSITORY `${repoName}`" |
| 191 | + |
| 192 | + sql """ |
| 193 | + drop storage policy ${policy_name}; |
| 194 | + """ |
| 195 | + |
| 196 | + sql """ |
| 197 | + drop resource ${resource_name}; |
| 198 | + """ |
| 199 | +} |
0 commit comments