Skip to content

Commit

Permalink
osd/: add helpers to add remaining info dirtiers into PeeringState
Browse files Browse the repository at this point in the history
  • Loading branch information
athanatos committed May 1, 2019
1 parent 8319c0f commit dfbe5e0
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 102 deletions.
11 changes: 2 additions & 9 deletions src/osd/PG.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ PG::PG(OSDService *o, OSDMapRef curmap,
upset(recovery_state.upset),
actingset(recovery_state.actingset),
acting_recovery_backfill(recovery_state.acting_recovery_backfill),
dirty_info(recovery_state.dirty_info),
dirty_big_info(recovery_state.dirty_big_info),
info(recovery_state.info),
past_intervals(recovery_state.past_intervals),
pg_log(recovery_state.pg_log),
Expand Down Expand Up @@ -262,8 +260,7 @@ void PG::lock(bool no_lockdep) const
{
_lock.Lock(no_lockdep);
// if we have unrecorded dirty state with the lock dropped, there is a bug
ceph_assert(!dirty_info);
ceph_assert(!dirty_big_info);
ceph_assert(!recovery_state.debug_has_dirty_state());

dout(30) << "lock" << dendl;
}
Expand Down Expand Up @@ -925,9 +922,7 @@ void PG::upgrade(ObjectStore *store)
t.omap_setkeys(coll, pgmeta_oid, v);
}

dirty_info = true;
dirty_big_info = true;
write_if_dirty(t);
recovery_state.force_write_state(t);

ObjectStore::CollectionHandle ch = store->open_collection(coll);
int r = store->queue_transaction(ch, std::move(t));
Expand Down Expand Up @@ -3885,8 +3880,6 @@ void PG::do_delete_work(ObjectStore::Transaction *t)
info.pgid.get_split_bits(pool.info.get_pg_num()));
_init(*t, info.pgid, &pool.info);
recovery_state.reset_last_persisted();
dirty_info = true;
dirty_big_info = true;
} else {
recovery_state.set_delete_complete();

Expand Down
5 changes: 1 addition & 4 deletions src/osd/PG.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ class PG : public DoutPrefixProvider, public PeeringState::PeeringListener {
set<pg_shard_t> &upset;
set<pg_shard_t> &actingset;
set<pg_shard_t> &acting_recovery_backfill;
bool &dirty_info;
bool &dirty_big_info;
pg_info_t &info;
PastIntervals &past_intervals;
PGLog &pg_log;
Expand Down Expand Up @@ -250,8 +248,7 @@ class PG : public DoutPrefixProvider, public PeeringState::PeeringListener {
void lock(bool no_lockdep = false) const;
void unlock() const {
//generic_dout(0) << this << " " << info.pgid << " unlock" << dendl;
ceph_assert(!dirty_info);
ceph_assert(!dirty_big_info);
ceph_assert(!recovery_state.debug_has_dirty_state());
_lock.Unlock();
}
bool is_locked() const {
Expand Down
2 changes: 1 addition & 1 deletion src/osd/PGLog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ void PGLog::write_log_and_missing(
const ghobject_t &log_oid,
bool require_rollback)
{
if (is_dirty()) {
if (needs_write()) {
dout(6) << "write_log_and_missing with: "
<< "dirty_to: " << dirty_to
<< ", dirty_from: " << dirty_from
Expand Down
8 changes: 6 additions & 2 deletions src/osd/PGLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,12 @@ struct PGLog : DoutPrefixProvider {
dirty_from_dups = from;
}
public:
bool needs_write() const {
return !touched_log || is_dirty();
}

bool is_dirty() const {
return !touched_log ||
(dirty_to != eversion_t()) ||
return (dirty_to != eversion_t()) ||
(dirty_from != eversion_t::max()) ||
(writeout_from != eversion_t::max()) ||
!(trimmed.empty()) ||
Expand All @@ -601,6 +604,7 @@ struct PGLog : DoutPrefixProvider {
(write_from_dups != eversion_t::max()) ||
rebuilt_missing_with_deletes;
}

void mark_log_for_rewrite() {
mark_dirty_to(eversion_t::max());
mark_dirty_from(eversion_t());
Expand Down
78 changes: 78 additions & 0 deletions src/osd/PeeringState.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3589,6 +3589,74 @@ void PeeringState::append_log(
write_if_dirty(t);
}

void PeeringState::recover_got(
const hobject_t &oid, eversion_t v,
bool is_delete,
ObjectStore::Transaction &t)
{
if (v > pg_log.get_can_rollback_to()) {
/* This can only happen during a repair, and even then, it would
* be one heck of a race. If we are repairing the object, the
* write in question must be fully committed, so it's not valid
* to roll it back anyway (and we'll be rolled forward shortly
* anyway) */
PGLog::LogEntryHandlerRef handler{pl->get_log_handler(&t)};
pg_log.roll_forward_to(v, handler.get());
}

psdout(10) << "got missing " << oid << " v " << v << dendl;
pg_log.recover_got(oid, v, info);
if (pg_log.get_log().complete_to != pg_log.get_log().log.end()) {
psdout(10) << "last_complete now " << info.last_complete
<< " log.complete_to " << pg_log.get_log().complete_to->version
<< dendl;
} else {
psdout(10) << "last_complete now " << info.last_complete
<< " log.complete_to at end" << dendl;
//below is not true in the repair case.
//assert(missing.num_missing() == 0); // otherwise, complete_to was wrong.
ceph_assert(info.last_complete == info.last_update);
}

if (is_primary()) {
ceph_assert(missing_loc.needs_recovery(oid));
if (!is_delete)
missing_loc.add_location(oid, pg_whoami);
}

// update pg
dirty_info = true;
write_if_dirty(t);
}

void PeeringState::update_backfill_progress(
const hobject_t &updated_backfill,
const pg_stat_t &updated_stats,
bool preserve_local_num_bytes,
ObjectStore::Transaction &t) {
info.set_last_backfill(updated_backfill);
if (preserve_local_num_bytes) {
psdout(25) << __func__ << " primary " << updated_stats.stats.sum.num_bytes
<< " local " << info.stats.stats.sum.num_bytes << dendl;
int64_t bytes = info.stats.stats.sum.num_bytes;
info.stats = updated_stats;
info.stats.stats.sum.num_bytes = bytes;
} else {
psdout(20) << __func__ << " final " << updated_stats.stats.sum.num_bytes
<< " replaces local " << info.stats.stats.sum.num_bytes << dendl;
info.stats = updated_stats;
}

dirty_info = true;
write_if_dirty(t);
}

void PeeringState::adjust_purged_snaps(
std::function<void(interval_set<snapid_t> &snaps)> f) {
f(info.purged_snaps);
dirty_info = true;
dirty_big_info = true;
}

/*------------ Peering State Machine----------------*/
#undef dout_prefix
Expand Down Expand Up @@ -5554,6 +5622,16 @@ PeeringState::Deleting::Deleting(my_context ctx)
DECLARE_LOCALS
ps->deleting = true;
ObjectStore::Transaction* t = context<PeeringMachine>().get_cur_transaction();

// adjust info to backfill
ps->info.set_last_backfill(hobject_t());
ps->pg_log.reset_backfill();
ps->dirty_info = true;

// clear log
PGLog::LogEntryHandlerRef rollbacker{pl->get_log_handler(t)};
ps->pg_log.roll_forward(rollbacker.get());

pl->on_removal(t);
}

Expand Down
62 changes: 42 additions & 20 deletions src/osd/PeeringState.h
Original file line number Diff line number Diff line change
Expand Up @@ -1419,24 +1419,8 @@ class PeeringState : public MissingLoc::MappingInfo {
boost::optional<eversion_t> trim_to,
boost::optional<eversion_t> roll_forward_to);

/**
* Merge entries updating missing as necessary on all
* acting_recovery_backfill logs and missings (also missing_loc)
*/
void merge_new_log_entries(
const mempool::osd_pglog::list<pg_log_entry_t> &entries,
ObjectStore::Transaction &t,
boost::optional<eversion_t> trim_to,
boost::optional<eversion_t> roll_forward_to);

void add_log_entry(const pg_log_entry_t& e, bool applied);
void append_log(
const vector<pg_log_entry_t>& logv,
eversion_t trim_to,
eversion_t roll_forward_to,
ObjectStore::Transaction &t,
bool transaction_applied,
bool async);

public:
PeeringState(
CephContext *cct,
Expand Down Expand Up @@ -1522,6 +1506,35 @@ class PeeringState : public MissingLoc::MappingInfo {
const pg_stat_t &pg_stats_publish,
const object_stat_collection_t &unstable_stats);

/**
* Merge entries updating missing as necessary on all
* acting_recovery_backfill logs and missings (also missing_loc)
*/
void merge_new_log_entries(
const mempool::osd_pglog::list<pg_log_entry_t> &entries,
ObjectStore::Transaction &t,
boost::optional<eversion_t> trim_to,
boost::optional<eversion_t> roll_forward_to);

void append_log(
const vector<pg_log_entry_t>& logv,
eversion_t trim_to,
eversion_t roll_forward_to,
ObjectStore::Transaction &t,
bool transaction_applied,
bool async);

void recover_got(
const hobject_t &oid, eversion_t v,
bool is_delete,
ObjectStore::Transaction &t);

void update_backfill_progress(
const hobject_t &updated_backfill,
const pg_stat_t &updated_stats,
bool preserve_local_num_bytes,
ObjectStore::Transaction &t);

void dump_history(Formatter *f) const {
state_history.dump(f);
}
Expand Down Expand Up @@ -1569,6 +1582,8 @@ class PeeringState : public MissingLoc::MappingInfo {
/// resets last_persisted_osdmap
void reset_last_persisted() {
last_persisted_osdmap = 0;
dirty_info = true;
dirty_big_info = true;
}

void shutdown() {
Expand All @@ -1579,11 +1594,14 @@ class PeeringState : public MissingLoc::MappingInfo {
deleted = true;
}

template <typename Func>
void adjust_purged_snaps(Func f) {
f(info.purged_snaps);
void adjust_purged_snaps(
std::function<void(interval_set<snapid_t> &snaps)> f);


void force_write_state(ObjectStore::Transaction &t) {
dirty_info = true;
dirty_big_info = true;
write_if_dirty(t);
}

bool is_deleting() const {
Expand Down Expand Up @@ -1743,6 +1761,10 @@ class PeeringState : public MissingLoc::MappingInfo {
return min_last_complete_ondisk;
}

bool debug_has_dirty_state() const {
return dirty_info || dirty_big_info;
}

std::string get_pg_state_string() const {
return pg_state_string(state);
}
Expand Down
Loading

0 comments on commit dfbe5e0

Please sign in to comment.