Skip to content

Commit

Permalink
[#7126] PITR: Load snapshot schedules during bootstrap
Browse files Browse the repository at this point in the history
Summary:
This diff adds snapshot schedule loading during tablet bootstrap.
So schedules are loaded after master restart.

Test Plan: ybd --gtest_filter SnapshotScheduleTest.Restart

Reviewers: bogdan, amitanand, oleg

Reviewed By: oleg

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D10916
  • Loading branch information
spolitov committed Mar 16, 2021
1 parent 4fa24b7 commit b6d5b63
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
40 changes: 28 additions & 12 deletions src/yb/client/snapshot-schedule-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ class SnapshotScheduleTest : public SnapshotTestBase {
LOG(INFO) << "Schedules: " << resp.ShortDebugString();
return std::move(resp.schedules());
}

CHECKED_STATUS WaitScheduleSnapshot(const SnapshotScheduleId& schedule_id) {
return WaitFor([this, schedule_id]() -> Result<bool> {
auto snapshots = VERIFY_RESULT(ListSnapshots());
EXPECT_LE(snapshots.size(), 1);
LOG(INFO) << "Snapshots: " << AsString(snapshots);
for (const auto& snapshot : snapshots) {
EXPECT_EQ(TryFullyDecodeSnapshotScheduleId(snapshot.entry().schedule_id()), schedule_id);
if (snapshot.entry().state() == master::SysSnapshotEntryPB::COMPLETE) {
return true;
}
}
return false;
}, kSnapshotInterval / 2, "First snapshot");
}
};

TEST_F(SnapshotScheduleTest, Create) {
Expand Down Expand Up @@ -97,18 +112,7 @@ TEST_F(SnapshotScheduleTest, Create) {
TEST_F(SnapshotScheduleTest, Snapshot) {
ASSERT_NO_FATALS(WriteData());
auto schedule_id = ASSERT_RESULT(CreateSchedule());
ASSERT_OK(WaitFor([this, schedule_id]() -> Result<bool> {
auto snapshots = VERIFY_RESULT(ListSnapshots());
EXPECT_LE(snapshots.size(), 1);
LOG(INFO) << "Snapshots: " << AsString(snapshots);
for (const auto& snapshot : snapshots) {
EXPECT_EQ(TryFullyDecodeSnapshotScheduleId(snapshot.entry().schedule_id()), schedule_id);
if (snapshot.entry().state() == master::SysSnapshotEntryPB::COMPLETE) {
return true;
}
}
return false;
}, kSnapshotInterval / 2, "First snapshot"));
ASSERT_OK(WaitScheduleSnapshot(schedule_id));

auto schedules = ASSERT_RESULT(ListSchedules());
ASSERT_EQ(schedules.size(), 1);
Expand Down Expand Up @@ -141,5 +145,17 @@ TEST_F(SnapshotScheduleTest, GC) {
}
}

TEST_F(SnapshotScheduleTest, Restart) {
ASSERT_NO_FATALS(WriteData());
auto schedule_id = ASSERT_RESULT(CreateSchedule());
ASSERT_OK(WaitScheduleSnapshot(schedule_id));
ASSERT_OK(cluster_->RestartSync());

auto schedules = ASSERT_RESULT(ListSchedules());
ASSERT_EQ(schedules.size(), 1);
ASSERT_EQ(schedules[0].snapshots().size(), 1);
ASSERT_EQ(schedules[0].snapshots()[0].entry().state(), master::SysSnapshotEntryPB::COMPLETE);
}

} // namespace client
} // namespace yb
6 changes: 5 additions & 1 deletion src/yb/master/master_snapshot_coordinator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,13 @@ class MasterSnapshotCoordinator::Impl {

CHECKED_STATUS Load(tablet::Tablet* tablet) {
std::lock_guard<std::mutex> lock(mutex_);
return EnumerateSysCatalog(tablet, context_.schema(), SysRowEntry::SNAPSHOT,
RETURN_NOT_OK(EnumerateSysCatalog(tablet, context_.schema(), SysRowEntry::SNAPSHOT,
[this](const Slice& id, const Slice& data) NO_THREAD_SAFETY_ANALYSIS -> Status {
return LoadEntry<SysSnapshotEntryPB>(id, data, &snapshots_);
}));
return EnumerateSysCatalog(tablet, context_.schema(), SysRowEntry::SNAPSHOT_SCHEDULE,
[this](const Slice& id, const Slice& data) NO_THREAD_SAFETY_ANALYSIS -> Status {
return LoadEntry<SnapshotScheduleOptionsPB>(id, data, &schedules_);
});
}

Expand Down

0 comments on commit b6d5b63

Please sign in to comment.