Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osd/PGLog: add roll_forward_to(to update crt) to PGLog update_missing #38906

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/osd/PGLog.cc
Expand Up @@ -358,7 +358,7 @@ void PGLog::rewind_divergent_log(eversion_t newhead,

void PGLog::merge_log(pg_info_t &oinfo, pg_log_t&& olog, pg_shard_t fromosd,
pg_info_t &info, LogEntryHandler *rollbacker,
bool &dirty_info, bool &dirty_big_info)
bool &dirty_info, bool &dirty_big_info, bool *rollforwarded)
{
dout(10) << "merge_log " << olog << " from osd." << fromosd
<< " into " << log << dendl;
Expand All @@ -377,6 +377,7 @@ void PGLog::merge_log(pg_info_t &oinfo, pg_log_t&& olog, pg_shard_t fromosd,
}

bool changed = false;
bool should_rollforward = false;

// extend on tail?
// this is just filling in history. it does not affect our
Expand Down Expand Up @@ -453,7 +454,6 @@ void PGLog::merge_log(pg_info_t &oinfo, pg_log_t&& olog, pg_shard_t fromosd,
for (auto &&oe: divergent) {
dout(10) << "merge_log divergent " << oe << dendl;
}
log.roll_forward_to(log.head, rollbacker);
Copy link
Member

@neha-ojha neha-ojha Mar 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR can be simplified and made more unit-testable by only doing a roll_forward_to() if new_entries is not empty, which is essentially what is used for doing log->add() and setting should_rollforward.


mempool::osd_pglog::list<pg_log_entry_t> new_entries;
new_entries.splice(new_entries.end(), olog.log, from, to);
Expand All @@ -463,6 +463,7 @@ void PGLog::merge_log(pg_info_t &oinfo, pg_log_t&& olog, pg_shard_t fromosd,
false,
&log,
missing,
&should_rollforward,
rollbacker,
this);

Expand All @@ -476,6 +477,11 @@ void PGLog::merge_log(pg_info_t &oinfo, pg_log_t&& olog, pg_shard_t fromosd,
this);

info.last_update = log.head = olog.head;
if (should_rollforward && log.get_can_rollback_to() > original_crt) {
log.roll_forward_to(log.head, rollbacker);
dout(10) << "crt updated after new entries merged to " << log.head << dendl;
if (rollforwarded) { *rollforwarded = true; }
}

// We cannot rollback into the new log entries
log.skip_can_rollback_to_to_head();
Expand Down
11 changes: 8 additions & 3 deletions src/osd/PGLog.h
Expand Up @@ -1248,7 +1248,7 @@ struct PGLog : DoutPrefixProvider {
pg_log_t&& olog,
pg_shard_t from,
pg_info_t &info, LogEntryHandler *rollbacker,
bool &dirty_info, bool &dirty_big_info);
bool &dirty_info, bool &dirty_big_info, bool *rollforwarded=nullptr);

template <typename missing_type>
static bool append_log_entries_update_missing(
Expand All @@ -1257,6 +1257,7 @@ struct PGLog : DoutPrefixProvider {
bool maintain_rollback,
IndexedLog *log,
missing_type &missing,
bool *should_rollforward,
LogEntryHandler *rollbacker,
const DoutPrefixProvider *dpp) {
bool invalidate_stats = false;
Expand All @@ -1266,8 +1267,11 @@ struct PGLog : DoutPrefixProvider {
for (auto p = entries.begin(); p != entries.end(); ++p) {
invalidate_stats = invalidate_stats || !p->is_error();
if (log) {
ldpp_dout(dpp, 20) << "update missing, append " << *p << dendl;
log->add(*p);
log->add(*p);
ldpp_dout(dpp, 20) << "update missing, appended " << *p << dendl;
if (should_rollforward) {
*should_rollforward = true;
}
}
if (p->soid <= last_backfill &&
!p->is_error()) {
Expand Down Expand Up @@ -1302,6 +1306,7 @@ struct PGLog : DoutPrefixProvider {
true,
&log,
missing,
nullptr,
rollbacker,
this);
if (!entries.empty()) {
Expand Down
1 change: 1 addition & 0 deletions src/osd/PeeringState.cc
Expand Up @@ -4114,6 +4114,7 @@ void PeeringState::merge_new_log_entries(
NULL,
pmissing,
NULL,
nullptr,
dpp);
pinfo.last_update = info.last_update;
pinfo.stats.stats_invalid = pinfo.stats.stats_invalid || invalidate_stats;
Expand Down
36 changes: 32 additions & 4 deletions src/test/osd/TestPGLog.cc
Expand Up @@ -252,10 +252,13 @@ class PGLogTest : virtual public ::testing::Test, protected PGLog, public PGLogT

void verify_sideeffects(
const TestCase &tcase,
const LogHandler &handler) {
const LogHandler &handler,
bool rollforwarded) {

auto original_log = tcase.get_fulldiv();

ASSERT_EQ(tcase.toremove.size(), handler.removed.size());
ASSERT_EQ(tcase.torollback.size(), handler.rolledback.size());

{
list<pg_log_entry_t>::const_iterator titer = tcase.torollback.begin();
list<pg_log_entry_t>::const_iterator hiter = handler.rolledback.begin();
Expand All @@ -271,6 +274,12 @@ class PGLogTest : virtual public ::testing::Test, protected PGLog, public PGLogT
EXPECT_EQ(*titer, *hiter);
}
}

CephContext *cct = g_ceph_context;
lgeneric_subdout(g_ceph_context, osd, 10) << "prior PG size " << original_log.log.size() << dendl;
if(log.log.size() > original_log.log.size()) {
ASSERT_TRUE(rollforwarded);
}
}

void test_merge_log(const TestCase &tcase) {
Expand All @@ -288,13 +297,14 @@ class PGLogTest : virtual public ::testing::Test, protected PGLog, public PGLogT
LogHandler h;
bool dirty_info = false;
bool dirty_big_info = false;
bool rollforwarded = false;
merge_log(
oinfo, std::move(olog), pg_shard_t(1, shard_id_t(0)), info,
&h, dirty_info, dirty_big_info);
&h, dirty_info, dirty_big_info, &rollforwarded);

ASSERT_EQ(info.last_update, oinfo.last_update);
verify_missing(tcase, missing);
verify_sideeffects(tcase, h);
verify_sideeffects(tcase, h, rollforwarded);
}

void test_proc_replica_log(const TestCase &tcase) {
Expand Down Expand Up @@ -567,6 +577,7 @@ TEST_F(PGLogTest, merge_old_entry) {
EXPECT_TRUE(t.empty());
EXPECT_FALSE(missing.have_missing());
EXPECT_TRUE(log.empty());
EXPECT_EQ(log.get_can_rollback_to(), eversion_t(0,0));
}

// the new entry (from the logs) has a version that is higher than
Expand Down Expand Up @@ -881,6 +892,7 @@ TEST_F(PGLogTest, merge_log) {

EXPECT_FALSE(missing.have_missing());
EXPECT_EQ(0U, log.log.size());
EXPECT_EQ(log.get_can_rollback_to(), eversion_t(0,0));
EXPECT_EQ(stat_version, info.stats.version);
EXPECT_TRUE(remove_snap.empty());
EXPECT_EQ(last_backfill, info.last_backfill);
Expand All @@ -895,6 +907,7 @@ TEST_F(PGLogTest, merge_log) {

EXPECT_FALSE(missing.have_missing());
EXPECT_EQ(0U, log.log.size());
EXPECT_EQ(log.get_can_rollback_to(), eversion_t(0,0));
EXPECT_EQ(stat_version, info.stats.version);
EXPECT_TRUE(remove_snap.empty());
EXPECT_TRUE(info.purged_snaps.empty());
Expand All @@ -907,6 +920,7 @@ TEST_F(PGLogTest, merge_log) {
// copied from oinfo.stats but info.stats.reported_* is guaranteed to
// never be replaced by a lower version
{
//case: 1
clear();

pg_log_t olog;
Expand All @@ -930,6 +944,7 @@ TEST_F(PGLogTest, merge_log) {
EXPECT_FALSE(missing.have_missing());
EXPECT_EQ(0U, log.log.size());
EXPECT_EQ(eversion_t(), info.stats.version);
EXPECT_EQ(log.get_can_rollback_to(), eversion_t(0,0));
EXPECT_EQ(1ull, info.stats.reported_seq);
EXPECT_EQ(10u, info.stats.reported_epoch);
EXPECT_TRUE(remove_snap.empty());
Expand All @@ -945,6 +960,7 @@ TEST_F(PGLogTest, merge_log) {

EXPECT_FALSE(missing.have_missing());
EXPECT_EQ(0U, log.log.size());
EXPECT_EQ(log.get_can_rollback_to(), eversion_t(0,0));
EXPECT_EQ(stat_version, info.stats.version);
EXPECT_EQ(1ull, info.stats.reported_seq);
EXPECT_EQ(10u, info.stats.reported_epoch);
Expand Down Expand Up @@ -992,6 +1008,7 @@ TEST_F(PGLogTest, merge_log) {
+--------+-------+
*/
{
//case: 2
clear();

pg_log_t olog;
Expand Down Expand Up @@ -1036,6 +1053,7 @@ TEST_F(PGLogTest, merge_log) {

EXPECT_FALSE(missing.have_missing());
EXPECT_EQ(2U, log.log.size());
EXPECT_EQ(log.get_can_rollback_to(), eversion_t(0,0));
EXPECT_EQ(stat_version, info.stats.version);
EXPECT_TRUE(remove_snap.empty());
EXPECT_EQ(last_backfill, info.last_backfill);
Expand All @@ -1050,6 +1068,7 @@ TEST_F(PGLogTest, merge_log) {

EXPECT_FALSE(missing.have_missing());
EXPECT_EQ(3U, log.log.size());
EXPECT_EQ(log.get_can_rollback_to(), eversion_t(0,0));
EXPECT_EQ(stat_version, info.stats.version);
EXPECT_TRUE(remove_snap.empty());
EXPECT_TRUE(info.purged_snaps.empty());
Expand Down Expand Up @@ -1085,6 +1104,7 @@ TEST_F(PGLogTest, merge_log) {

*/
{
//case: 3
clear();

pg_log_t olog;
Expand Down Expand Up @@ -1175,6 +1195,7 @@ TEST_F(PGLogTest, merge_log) {
EXPECT_TRUE(is_dirty());
EXPECT_TRUE(dirty_info);
EXPECT_TRUE(dirty_big_info);
EXPECT_EQ(log.get_can_rollback_to(), log.head);
}

/* +--------------------------+
Expand Down Expand Up @@ -1204,6 +1225,7 @@ TEST_F(PGLogTest, merge_log) {

*/
{
//case: 4
clear();

pg_log_t olog;
Expand Down Expand Up @@ -1264,6 +1286,7 @@ TEST_F(PGLogTest, merge_log) {
EXPECT_FALSE(missing.have_missing());
EXPECT_EQ(1U, log.objects.count(divergent_object));
EXPECT_EQ(3U, log.log.size());
EXPECT_EQ(log.get_can_rollback_to(), eversion_t(0,0));
EXPECT_TRUE(remove_snap.empty());
EXPECT_EQ(log.head, info.last_update);
EXPECT_TRUE(info.purged_snaps.empty());
Expand All @@ -1284,6 +1307,7 @@ TEST_F(PGLogTest, merge_log) {
EXPECT_TRUE(missing.is_missing(divergent_object));
EXPECT_EQ(1U, log.objects.count(divergent_object));
EXPECT_EQ(4U, log.log.size());
EXPECT_EQ(log.get_can_rollback_to(), olog.head);
/* DELETE entries from olog that are appended to the hed of the
log, and the divergent version of the object is removed (added
to remove_snap). When peering handles deletes, it is the earlier
Expand Down Expand Up @@ -1319,6 +1343,7 @@ TEST_F(PGLogTest, merge_log) {

*/
{
//case: 5
clear();

pg_log_t olog;
Expand Down Expand Up @@ -1365,6 +1390,7 @@ TEST_F(PGLogTest, merge_log) {

EXPECT_FALSE(missing.have_missing());
EXPECT_EQ(3U, log.log.size());
EXPECT_EQ(log.get_can_rollback_to(), eversion_t(0,0));
EXPECT_EQ(stat_version, info.stats.version);
EXPECT_TRUE(remove_snap.empty());
EXPECT_EQ(last_backfill, info.last_backfill);
Expand All @@ -1380,6 +1406,7 @@ TEST_F(PGLogTest, merge_log) {

EXPECT_FALSE(missing.have_missing());
EXPECT_EQ(2U, log.log.size());
EXPECT_EQ(log.get_can_rollback_to(), eversion_t(0,0));
EXPECT_EQ(stat_version, info.stats.version);
EXPECT_EQ(0x9U, remove_snap.front().get_hash());
EXPECT_TRUE(info.purged_snaps.empty());
Expand Down Expand Up @@ -1487,6 +1514,7 @@ TEST_F(PGLogTest, proc_replica_log) {
proc_replica_log(oinfo, olog, omissing, from);

EXPECT_FALSE(omissing.have_missing());
EXPECT_EQ(log.get_can_rollback_to(), eversion_t(0,0));
}

{
Expand Down