-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#20422] xCluster: Checkpoint table for xCluster on create
Summary: As part of creating a new table, also create xCluster stream if the table belongs to a namespace that is part of an xClusterOutboundReplicationGroup. As part of table creation we create `AddTableToXClusterSourceTask` for each ReplicationGroup that we want to add the table to. The task invokes `XClusterOutboundReplicationGroup::AddTable` to create a xcluster stream checkpointed to `OpId().Min()` (0,0) so that replication will start from the beginning of the WAL. We currently skip extending WAL retention of the table since this requires an ALTER Table operation which cannot be performed unless the table creation has completed. #20769 tracks the task which will remove the need for performing ALTER Table in the first place. #20938 tracks the race conditions when tables are created concurrently with xcluster replication groups #16971 tracks delete of tables that are under replication **Upgrade/Rollback safety:** All the changes are guarded under flag `TEST_enable_xcluster_api_v2` Fixes #20422 Jira: DB-9415 Test Plan: TEST_F(XClusterOutboundReplicationGroupMockedTest, AddTable) TEST_F(XClusterOutboundReplicationGroupTest, AddTable) Reviewers: mlillibridge, jhe, slingam, xCluster Reviewed By: mlillibridge Subscribers: yql, xCluster, ybase, bogdan Differential Revision: https://phorge.dev.yugabyte.com/D31935
- Loading branch information
Showing
12 changed files
with
331 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/yb/master/xcluster/add_table_to_xcluster_source_task.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) YugabyteDB, Inc. | ||
// | ||
// Licensed 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. | ||
// | ||
|
||
#include "yb/master/xcluster/add_table_to_xcluster_source_task.h" | ||
|
||
#include "yb/master/catalog_manager.h" | ||
#include "yb/master/xcluster/xcluster_outbound_replication_group.h" | ||
|
||
namespace yb::master { | ||
|
||
using namespace std::placeholders; | ||
|
||
AddTableToXClusterSourceTask::AddTableToXClusterSourceTask( | ||
std::shared_ptr<XClusterOutboundReplicationGroup> outbound_replication_group, | ||
CatalogManager& catalog_manager, rpc::Messenger& messenger, TableInfoPtr table_info, | ||
const LeaderEpoch& epoch) | ||
: PostTabletCreateTaskBase( | ||
catalog_manager, *catalog_manager.AsyncTaskPool(), messenger, std::move(table_info), | ||
epoch), | ||
outbound_replication_group_(std::move(outbound_replication_group)) {} | ||
|
||
std::string AddTableToXClusterSourceTask::description() const { | ||
return Format("AddTableToXClusterSourceTask [$0]", table_info_->id()); | ||
} | ||
|
||
Status AddTableToXClusterSourceTask::FirstStep() { | ||
outbound_replication_group_->AddTable( | ||
table_info_, epoch_, std::bind(&AddTableToXClusterSourceTask::CompletionCallback, this, _1)); | ||
|
||
return Status::OK(); | ||
} | ||
|
||
void AddTableToXClusterSourceTask::CompletionCallback(const Status& status) { | ||
if (status.ok()) { | ||
Complete(); | ||
return; | ||
} | ||
|
||
AbortAndReturnPrevState(status); | ||
} | ||
|
||
} // namespace yb::master |
47 changes: 47 additions & 0 deletions
47
src/yb/master/xcluster/add_table_to_xcluster_source_task.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) YugabyteDB, Inc. | ||
// | ||
// Licensed 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. | ||
// | ||
|
||
#pragma once | ||
|
||
#include "yb/client/client_fwd.h" | ||
|
||
#include "yb/master/post_tablet_create_task_base.h" | ||
|
||
namespace yb::master { | ||
|
||
class XClusterOutboundReplicationGroup; | ||
|
||
class AddTableToXClusterSourceTask : public PostTabletCreateTaskBase { | ||
public: | ||
explicit AddTableToXClusterSourceTask( | ||
std::shared_ptr<XClusterOutboundReplicationGroup> outbound_replication_group, | ||
CatalogManager& catalog_manager, rpc::Messenger& messenger, TableInfoPtr table_info, | ||
const LeaderEpoch& epoch); | ||
|
||
server::MonitoredTaskType type() const override { | ||
return server::MonitoredTaskType::kAddTableToXClusterSource; | ||
} | ||
|
||
std::string type_name() const override { return "Add table to xCluster source replication"; } | ||
|
||
std::string description() const override; | ||
|
||
private: | ||
Status FirstStep() override; | ||
|
||
void CompletionCallback(const Status& status); | ||
|
||
const std::shared_ptr<XClusterOutboundReplicationGroup> outbound_replication_group_; | ||
}; | ||
|
||
} // namespace yb::master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.