From 2923cc6259e949b84d0379abcb7c13ef50a53388 Mon Sep 17 00:00:00 2001 From: ayuanzhang Date: Wed, 30 Oct 2024 20:38:30 +0800 Subject: [PATCH] fix testcase --- be/src/olap/snapshot_manager.cpp | 8 +- .../test_backup_with_ddl.groovy | 109 +++++++++++++++--- 2 files changed, 103 insertions(+), 14 deletions(-) diff --git a/be/src/olap/snapshot_manager.cpp b/be/src/olap/snapshot_manager.cpp index a3d363b1308826..20ca7bbb8ebcf6 100644 --- a/be/src/olap/snapshot_manager.cpp +++ b/be/src/olap/snapshot_manager.cpp @@ -86,7 +86,13 @@ Status SnapshotManager::make_snapshot(const TSnapshotRequest& request, string* s auto tablet_id = dp->param("tablet_id", -1); if (tablet_id != -1 && tablet_id == request.tablet_id) { LOG(INFO) << "Debug: SnapshotManager::make_snapshot.wait"; - sleep(20); + for (int i = 0; i < 1000; i++) { + if (_engine.tablet_manager()->get_tablet(request.tablet_id) == nullptr) { + sleep(3); + break; + } + sleep(1); + } } }); diff --git a/regression-test/suites/backup_restore/test_backup_with_ddl.groovy b/regression-test/suites/backup_restore/test_backup_with_ddl.groovy index b547f54b9ef4aa..7e86bdf67d08c6 100644 --- a/regression-test/suites/backup_restore/test_backup_with_ddl.groovy +++ b/regression-test/suites/backup_restore/test_backup_with_ddl.groovy @@ -22,6 +22,7 @@ suite("test_backup_with_ddl") { def insert_num = 5 + sql "DROP DATABASE IF EXISTS ${dbName}" sql "CREATE DATABASE IF NOT EXISTS ${dbName}" sql "DROP TABLE IF EXISTS ${dbName}.${tableName}" sql """ @@ -40,13 +41,16 @@ suite("test_backup_with_ddl") { for (int i = 0; i < insert_num; ++i) { sql """ - INSERT INTO ${dbName}.${tableName} VALUES (${i}, ${i}) + INSERT INTO ${dbName}.${tableName} VALUES (1, ${i}) """ } sql " sync " def res = sql "SELECT * FROM ${dbName}.${tableName}" assertEquals(res.size(), insert_num) + GetDebugPoint().clearDebugPointsForAllFEs() + GetDebugPoint().clearDebugPointsForAllBEs() + result = sql_return_maparray """show tablets from ${dbName}.${tableName}""" assertNotNull(result) def tabletId = null @@ -55,8 +59,7 @@ suite("test_backup_with_ddl") { break } - - logger.info("=== Test 1: drop table ===") + logger.info("========= Test 1: ignore checkBuckupRunning when truncate table ===") def snapshotName1 = "snapshot_test_1" GetDebugPoint().enableDebugPointForAllBEs("SnapshotManager::make_snapshot.wait", [tablet_id:"${tabletId}"]); @@ -68,18 +71,46 @@ suite("test_backup_with_ddl") { PROPERTIES ("type" = "full") """ - //GetDebugPoint().enableDebugPointForAllFEs('FE.checkBuckupRunning.ignore', null) + GetDebugPoint().enableDebugPointForAllFEs('FE.checkBuckupRunning.ignore', null) // wait backup snapshoting - count = 10 // 20s + count = 200 // 20s for (int i = 0; i < count; ++i) { def records = sql_return_maparray "SHOW BACKUP FROM ${dbName}" int found = 0 for (def res2 : records) { - //logger.info("row is ${res2}") + if (res2.State.equals("SNAPSHOTING")) { + found = 1 + break + } + } + if (found == 1) { + break + } + Thread.sleep(100) + } + + // truncate ok + sql """ + truncate table ${dbName}.${tableName}; + """ + + sql "sync" + // assert truncate success + res = sql "SELECT * FROM ${dbName}.${tableName}" + assertEquals(res.size(), 0) + + // wait backup canceled, failed to get tablet + count = 30 // 60s + def found = 0 + for (int i = 0; i < count; ++i) { + def records = sql_return_maparray "SHOW BACKUP FROM ${dbName}" + found = 0 + for (def res2 : records) { logger.info("row.State is ${res2.State}") + logger.info("row.TaskErrMsg is ${res2.TaskErrMsg}") - if (res2.State .equals("SNAPSHOTING")) { + if (res2.State.equals("CANCELLED") && (res2.TaskErrMsg as String).contains("failed to get tablet")) { found = 1 break } @@ -89,23 +120,75 @@ suite("test_backup_with_ddl") { } Thread.sleep(2000) } + + assertEquals(found, 1) + + syncer.waitSnapshotFinish(dbName) + + GetDebugPoint().disableDebugPointForAllBEs("SnapshotManager::make_snapshot.wait") + GetDebugPoint().disableDebugPointForAllFEs('FE.checkBuckupRunning.ignore') + + + + logger.info("========= Test 2: checkBuckupRunning when truncate table ===") + def snapshotName2 = "snapshot_test_2" + + for (int i = 0; i < insert_num; ++i) { + sql """ + INSERT INTO ${dbName}.${tableName} VALUES (${i}, ${i}) + """ + } + sql " sync " + + result = sql_return_maparray """show tablets from ${dbName}.${tableName}""" + assertNotNull(result) + tabletId = null + for (def res1 : result) { + tabletId = res1.TabletId + break + } + logger.info("========= show tablet ${tabletId} ===") + + sql """ + BACKUP SNAPSHOT ${dbName}.${snapshotName2} + TO `__keep_on_local__` + ON (${tableName}) + PROPERTIES ("type" = "full") + """ + + // wait backup snapshoting + count = 200 // 20s + found = 0 + for (int i = 0; i < count; ++i) { + def records = sql_return_maparray "SHOW BACKUP FROM ${dbName}" + found = 0 + for (def res2 : records) { + if (res2.State .equals("SNAPSHOTING")) { + found = 1 + break + } + } + if (found == 1) { + break + } + Thread.sleep(100) + } + + assertEquals(found, 1) + // truncate fail errCode = 2, detailMessage = Backup is running on this db: test_backup_with_ddl_db try_sql """ truncate table ${dbName}.${tableName}; """ - def res = sql "SELECT * FROM ${dbName}.${tableName}" + // assert truncate fail + res = sql "SELECT * FROM ${dbName}.${tableName}" assertEquals(res.size(), insert_num) syncer.waitSnapshotFinish(dbName) - GetDebugPoint().disableDebugPointForAllBEs("SnapshotManager::make_snapshot.wait") - GetDebugPoint().disableDebugPointForAllFEs('FE.checkBuckupRunning.ignore') sql "DROP TABLE IF EXISTS ${dbName}.${tableName}" sql "DROP DATABASE ${dbName} FORCE" } - -//test_create_table_exception.groovy -//disableDebugPointForAllFEs