Skip to content

Commit 4495f8f

Browse files
committed
[yugabyte#27532] xCluster: Suport major YSQL upgrade with xCluster
Summary: Major YSQL upgrade involves a soft delete and recreate of the databases during pg_upgrade. Normally drop database is blocker if the database is under xCluster. This only affects the `yugabyte` and internal dbs created during the initdb phase. Relaxing this check for the major upgrade since no real database is dropped. Jira: DB-17092 Test Plan: TEST_P(XClusterUpgradeTest, UpgradeHashPartitionedTable) { Reviewers: slingam Reviewed By: slingam Subscribers: ybase Differential Revision: https://phorge.dev.yugabyte.com/D44673
1 parent abf33ba commit 4495f8f

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

src/yb/integration-tests/upgrade-tests/xcluster_upgrade-itest.cc

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,39 +42,45 @@ const auto kCountIdxRowsStmt = Format("SELECT COUNT(1) FROM $0 WHERE $1 IN (0,1,
4242

4343
YB_STRONGLY_TYPED_BOOL(RangePartitioned);
4444

45-
class XClusterUpgradeTest : public UpgradeTestBase {
45+
class XClusterUpgradeTestBase : public UpgradeTestBase {
4646
public:
47-
XClusterUpgradeTest() : UpgradeTestBase(kBuild_2_25_0_0) {}
47+
explicit XClusterUpgradeTestBase(const std::string& from_version)
48+
: UpgradeTestBase(from_version) {}
4849

49-
void TearDown() override {
50-
SwitchToConsumerCluster();
51-
TearDownCluster();
50+
void SetUp() override {
51+
TEST_SETUP_SUPER(UpgradeTestBase);
5252

53-
SwitchToProducerCluster();
54-
UpgradeTestBase::TearDown();
55-
}
56-
57-
Status StartClustersInOldVersion(RangePartitioned ranged_partitioned = RangePartitioned::kFalse) {
5853
ExternalMiniClusterOptions opts;
5954
opts.num_masters = 3;
6055
opts.num_tablet_servers = 3;
6156

6257
opts.cluster_id = "producer_cluster";
6358
opts.cluster_short_name = "P";
64-
RETURN_NOT_OK(StartClusterInOldVersion(opts));
59+
ASSERT_OK(StartClusterInOldVersion(opts));
6560
producer_cluster_ = cluster_.get();
6661
producer_client_ = client_.get();
6762

63+
#if !defined(NDEBUG)
64+
if (IsYsqlMajorVersionUpgrade()) {
65+
GTEST_SKIP() << "xCluster major YSQL Upgrade testing not supported in debug mode";
66+
}
67+
#endif
68+
6869
SwitchToConsumerCluster();
6970
opts.cluster_id = "consumer_cluster";
7071
opts.cluster_short_name = "C";
71-
RETURN_NOT_OK(StartClusterInOldVersion(opts));
72+
ASSERT_OK(StartClusterInOldVersion(opts));
7273
consumer_cluster_ = cluster_.get();
7374
consumer_client_ = client_.get();
7475
SwitchToProducerCluster();
76+
}
7577

76-
RETURN_NOT_OK(CreateTablesAndSetupXCluster(ranged_partitioned));
77-
return Status::OK();
78+
void TearDown() override {
79+
SwitchToConsumerCluster();
80+
TearDownCluster();
81+
82+
SwitchToProducerCluster();
83+
UpgradeTestBase::TearDown();
7884
}
7985

8086
Status RunOnBothClusters(const std::function<Status(ExternalMiniCluster*)>& run_on_cluster) {
@@ -245,7 +251,7 @@ class XClusterUpgradeTest : public UpgradeTestBase {
245251
}
246252

247253
void SimpleReplicationTest(RangePartitioned ranged_partitioned) {
248-
ASSERT_OK(StartClustersInOldVersion());
254+
ASSERT_OK(CreateTablesAndSetupXCluster(ranged_partitioned));
249255

250256
TestThreadHolder thread_holder;
251257
std::atomic<int64_t> rows_inserted = 0;
@@ -307,13 +313,24 @@ class XClusterUpgradeTest : public UpgradeTestBase {
307313
client::YBClient *producer_client_, *consumer_client_;
308314
};
309315

310-
TEST_F(XClusterUpgradeTest, UpgradeHashPartitionedTable) {
316+
class XClusterUpgradeTest : public XClusterUpgradeTestBase,
317+
public ::testing::WithParamInterface<std::string> {
318+
public:
319+
XClusterUpgradeTest() : XClusterUpgradeTestBase(GetParam()) {}
320+
};
321+
322+
INSTANTIATE_TEST_SUITE_P(
323+
UpgradeFrom_2024_2_4_0, XClusterUpgradeTest, ::testing::Values(kBuild_2024_2_4_0));
324+
INSTANTIATE_TEST_SUITE_P(
325+
UpgradeFrom_2_25_0_0, XClusterUpgradeTest, ::testing::Values(kBuild_2_25_0_0));
326+
327+
TEST_P(XClusterUpgradeTest, UpgradeHashPartitionedTable) {
311328
ASSERT_NO_FATAL_FAILURE(SimpleReplicationTest(RangePartitioned::kFalse));
312329
}
313330

314331
// #27380 added support for range partitioned tables in xCluster replication.
315332
// Enable this test once the from build with the fix is available.
316-
TEST_F(XClusterUpgradeTest, YB_DISABLE_TEST(UpgradeRangePartitionedTable)) {
333+
TEST_P(XClusterUpgradeTest, YB_DISABLE_TEST(UpgradeRangePartitionedTable)) {
317334
ASSERT_NO_FATAL_FAILURE(SimpleReplicationTest(RangePartitioned::kTrue));
318335
}
319336

src/yb/master/catalog_manager.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9247,7 +9247,10 @@ Status CatalogManager::DeleteYsqlDatabase(const DeleteNamespaceRequestPB* req,
92479247
// Only allow YSQL database deletion if it does not contain any replicated tables. No need to
92489248
// check this for YCQL keyspaces, as YCQL does not allow drops of non-empty keyspaces, regardless
92499249
// of their replication status.
9250-
RETURN_NOT_OK(CheckIfDatabaseHasReplication(database));
9250+
// Skip this check during major YSQL upgrade since we are not actually dropping the database.
9251+
if (!ysql_manager_->IsMajorUpgradeInProgress()) {
9252+
RETURN_NOT_OK(CheckIfDatabaseHasReplication(database));
9253+
}
92519254

92529255
// Set the Namespace to DELETING.
92539256
TRACE("Locking database");

0 commit comments

Comments
 (0)