From df127e042ffa0409857c8a7e5e35dd9144805af8 Mon Sep 17 00:00:00 2001 From: Minghui Yang Date: Thu, 16 May 2024 23:03:18 +0000 Subject: [PATCH] [#13358] YSQL: YBDdlAtomicityBackupTest::RunDdlAtomicityTest test change Summary: The way the test YBDdlAtomicityBackupTest::RunDdlAtomicityTest is written, all the DDLs will be inflight during the backup - so backup will fail. It's better to test the case where backup fails if any single DDL is inflight. This diff changes the test to randomly pick one DDL to be inflight and verify the backup fails. Jira: DB-2996 Test Plan: ./yb_build.sh release --cxx-test yb-backup-cross-feature-test --gtest_filter YBDdlAtomicityBackupTest.DdlRollbackAtomicityTest -n 20 Reviewers: fizaa Reviewed By: fizaa Subscribers: ybase, yql Differential Revision: https://phorge.dev.yugabyte.com/D35140 --- src/yb/tools/yb-backup/yb-backup-cross-feature-test.cc | 5 +++-- src/yb/yql/pgwrapper/pg_ddl_atomicity_test_base.cc | 9 +++++++++ src/yb/yql/pgwrapper/pg_ddl_atomicity_test_base.h | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/yb/tools/yb-backup/yb-backup-cross-feature-test.cc b/src/yb/tools/yb-backup/yb-backup-cross-feature-test.cc index e180b9369586..d94748b09247 100644 --- a/src/yb/tools/yb-backup/yb-backup-cross-feature-test.cc +++ b/src/yb/tools/yb-backup/yb-backup-cross-feature-test.cc @@ -1917,12 +1917,13 @@ Status YBDdlAtomicityBackupTest::RunDdlAtomicityTest(pgwrapper::DdlErrorInjectio auto client = VERIFY_RESULT(cluster_->CreateClient()); - // Run all DDLs after pausing DDL rollback. RETURN_NOT_OK(cluster_->SetFlagOnMasters("TEST_pause_ddl_rollback", "true")); if (inject_error) { - RETURN_NOT_OK(RunAllDdlsWithErrorInjection(&conn)); + // Run one failed DDL after pausing DDL rollback. + RETURN_NOT_OK(RunOneDdlWithErrorInjection(&conn)); } else { + // Run all DDLs after pausing DDL rollback. RETURN_NOT_OK(RunAllDdls(&conn)); } diff --git a/src/yb/yql/pgwrapper/pg_ddl_atomicity_test_base.cc b/src/yb/yql/pgwrapper/pg_ddl_atomicity_test_base.cc index 924e705ae2bb..a1301b74ea00 100644 --- a/src/yb/yql/pgwrapper/pg_ddl_atomicity_test_base.cc +++ b/src/yb/yql/pgwrapper/pg_ddl_atomicity_test_base.cc @@ -90,6 +90,15 @@ Status PgDdlAtomicityTestBase::RunAllDdlsWithErrorInjection(PGConn* conn) { return Status::OK(); } +Status PgDdlAtomicityTestBase::RunOneDdlWithErrorInjection(PGConn* conn) { + const auto& ddls = GetAllDDLs(); + const auto selected = RandomUniformInt(0UL, ddls.size() - 1); + const auto& ddl = ddls[selected]; + LOG(INFO) << "selected ddl to fail: " << ddl; + RETURN_NOT_OK(conn->TestFailDdl(ddl)); + return Status::OK(); +} + Status PgDdlAtomicityTestBase::VerifyAllSuccessfulDdls(PGConn *conn, client::YBClient* client, const string& database) { diff --git a/src/yb/yql/pgwrapper/pg_ddl_atomicity_test_base.h b/src/yb/yql/pgwrapper/pg_ddl_atomicity_test_base.h index 959cabc29280..5ed0a51a1ae7 100644 --- a/src/yb/yql/pgwrapper/pg_ddl_atomicity_test_base.h +++ b/src/yb/yql/pgwrapper/pg_ddl_atomicity_test_base.h @@ -135,6 +135,10 @@ class PgDdlAtomicityTestBase : public LibPqTestBase { // initiate rollback on the YB-Master. Status RunAllDdlsWithErrorInjection(PGConn* conn); + // From all possible DDLs supported by this test, randomly select one DDL and run with + // error injection. The selected DDL will fail and initiate rollback on the YB-Master. + Status RunOneDdlWithErrorInjection(PGConn* conn); + // API that can be used after 'RunAllDdls' above to wait for all the DDL verification to // complete. Status WaitForDdlVerificationAfterSuccessfulDdl(