Skip to content

Commit

Permalink
Merge pull request ceph#550 from ceph/wip-6040
Browse files Browse the repository at this point in the history
Wip 6040

Reviewed-by: Sage Weil <[email protected]>
Reviewed-by: Loic Dachary <[email protected]>
  • Loading branch information
athanatos committed Aug 28, 2013
2 parents fd3fd59 + f808c20 commit 3e63c1a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 28 deletions.
53 changes: 36 additions & 17 deletions src/osd/PGLog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void PGLog::IndexedLog::split_into(
index();
}

void PGLog::IndexedLog::trim(eversion_t s)
void PGLog::IndexedLog::trim(eversion_t s, set<eversion_t> *trimmed)
{
if (complete_to != log.end() &&
complete_to->version <= s) {
Expand All @@ -77,6 +77,8 @@ void PGLog::IndexedLog::trim(eversion_t s)
if (e.version > s)
break;
generic_dout(20) << "trim " << e << dendl;
if (trimmed)
trimmed->insert(e.version);
unindex(e); // remove from index,
log.pop_front(); // from log
}
Expand Down Expand Up @@ -142,14 +144,8 @@ void PGLog::trim(eversion_t trim_to, pg_info_t &info)
assert(trim_to <= info.last_complete);

dout(10) << "trim " << log << " to " << trim_to << dendl;
log.trim(trim_to);
log.trim(trim_to, &trimmed);
info.log_tail = log.tail;

if (log.log.empty()) {
mark_dirty_to(eversion_t::max());
} else {
mark_dirty_to(log.log.front().version);
}
}
}

Expand Down Expand Up @@ -542,13 +538,18 @@ void PGLog::write_log(
<< "dirty_to: " << dirty_to
<< ", dirty_from: " << dirty_from
<< ", dirty_divergent_priors: " << dirty_divergent_priors
<< ", writeout_from: " << writeout_from
<< ", trimmed: " << trimmed
<< dendl;
_write_log(t, log, log_oid, divergent_priors,
dirty_to,
dirty_from,
dirty_divergent_priors,
!touched_log,
&log_keys_debug);
_write_log(
t, log, log_oid, divergent_priors,
dirty_to,
dirty_from,
writeout_from,
trimmed,
dirty_divergent_priors,
!touched_log,
(pg_log_debug ? &log_keys_debug : 0));
undirty();
} else {
dout(10) << "log is not dirty" << dendl;
Expand All @@ -558,20 +559,36 @@ void PGLog::write_log(
void PGLog::write_log(ObjectStore::Transaction& t, pg_log_t &log,
const hobject_t &log_oid, map<eversion_t, hobject_t> &divergent_priors)
{
_write_log(t, log, log_oid, divergent_priors, eversion_t::max(), eversion_t(),
true, true, 0);
_write_log(
t, log, log_oid,
divergent_priors, eversion_t::max(), eversion_t(), eversion_t(),
set<eversion_t>(),
true, true, 0);
}

void PGLog::_write_log(
ObjectStore::Transaction& t, pg_log_t &log,
const hobject_t &log_oid, map<eversion_t, hobject_t> &divergent_priors,
eversion_t dirty_to,
eversion_t dirty_from,
eversion_t writeout_from,
const set<eversion_t> &trimmed,
bool dirty_divergent_priors,
bool touch_log,
set<string> *log_keys_debug
)
{
set<string> to_remove;
for (set<eversion_t>::const_iterator i = trimmed.begin();
i != trimmed.end();
++i) {
to_remove.insert(i->get_key_name());
if (log_keys_debug) {
assert(log_keys_debug->count(i->get_key_name()));
log_keys_debug->erase(i->get_key_name());
}
}

//dout(10) << "write_log, clearing up to " << dirty_to << dendl;
if (touch_log)
t.touch(coll_t(), log_oid);
Expand Down Expand Up @@ -599,7 +616,8 @@ void PGLog::_write_log(
}

for (list<pg_log_entry_t>::reverse_iterator p = log.log.rbegin();
p != log.log.rend() && p->version >= dirty_from &&
p != log.log.rend() &&
(p->version >= dirty_from || p->version >= writeout_from) &&
p->version >= dirty_to;
++p) {
bufferlist bl(sizeof(*p) * 2);
Expand All @@ -621,6 +639,7 @@ void PGLog::_write_log(
::encode(divergent_priors, keys["divergent_priors"]);
}

t.omap_rmkeys(coll_t::META_COLL, log_oid, to_remove);
t.omap_setkeys(coll_t::META_COLL, log_oid, keys);
}

Expand Down
36 changes: 25 additions & 11 deletions src/osd/PGLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,31 +142,36 @@ struct PGLog {
caller_ops[e.reqid] = &(log.back());
}

void trim(eversion_t s);
void trim(eversion_t s, set<eversion_t> *trimmed);

ostream& print(ostream& out) const;
};


protected:
//////////////////// data members ////////////////////
bool pg_log_debug;

map<eversion_t, hobject_t> divergent_priors;
pg_missing_t missing;
IndexedLog log;

/// Log is clean on [dirty_to, dirty_from)
bool touched_log;
eversion_t dirty_to;
eversion_t dirty_from;
eversion_t dirty_to; ///< must clear/writeout all keys up to dirty_to
eversion_t dirty_from; ///< must clear/writeout all keys past dirty_from
eversion_t writeout_from; ///< must writout keys past writeout_from
set<eversion_t> trimmed; ///< must clear keys in trimmed
bool dirty_divergent_priors;
CephContext *cct;

bool is_dirty() const {
return !touched_log ||
(dirty_to != eversion_t()) ||
(dirty_from != eversion_t::max()) ||
dirty_divergent_priors;
dirty_divergent_priors ||
(writeout_from != eversion_t::max()) ||
!(trimmed.empty());
}
void mark_dirty_to(eversion_t to) {
if (to > dirty_to)
Expand All @@ -176,6 +181,10 @@ struct PGLog {
if (from < dirty_from)
dirty_from = from;
}
void mark_writeout_from(eversion_t from) {
if (from < writeout_from)
writeout_from = from;
}
void add_divergent_prior(eversion_t version, hobject_t obj) {
divergent_priors.insert(make_pair(version, obj));
dirty_divergent_priors = true;
Expand Down Expand Up @@ -205,11 +214,9 @@ struct PGLog {
log_keys_debug->erase(i++));
}
void check() {
assert(log.log.size() == log_keys_debug.size());
if (cct &&
!(cct->_conf->osd_debug_pg_log_writeout)) {
if (!pg_log_debug)
return;
}
assert(log.log.size() == log_keys_debug.size());
for (list<pg_log_entry_t>::iterator i = log.log.begin();
i != log.log.end();
++i) {
Expand All @@ -222,10 +229,13 @@ struct PGLog {
dirty_from = eversion_t::max();
dirty_divergent_priors = false;
touched_log = true;
trimmed.clear();
writeout_from = eversion_t::max();
check();
}
public:
PGLog(CephContext *cct = 0) :
pg_log_debug(!(cct && !(cct->_conf->osd_debug_pg_log_writeout))),
touched_log(false), dirty_from(eversion_t::max()),
dirty_divergent_priors(false), cct(cct) {}

Expand Down Expand Up @@ -281,7 +291,7 @@ struct PGLog {
void unindex() { log.unindex(); }

void add(pg_log_entry_t& e) {
mark_dirty_from(e.version);
mark_writeout_from(e.version);
log.add(e);
}

Expand Down Expand Up @@ -374,15 +384,19 @@ struct PGLog {
const hobject_t &log_oid, map<eversion_t, hobject_t> &divergent_priors,
eversion_t dirty_to,
eversion_t dirty_from,
eversion_t writeout_from,
const set<eversion_t> &trimmed,
bool dirty_divergent_priors,
bool touch_log,
set<string> *log_keys_debug
);

bool read_log(ObjectStore *store, coll_t coll, hobject_t log_oid,
const pg_info_t &info, ostringstream &oss) {
return read_log(store, coll, log_oid, info, divergent_priors,
log, missing, oss, &log_keys_debug);
return read_log(
store, coll, log_oid, info, divergent_priors,
log, missing, oss,
(pg_log_debug ? &log_keys_debug : 0));
}

/// return true if the log should be rewritten
Expand Down

0 comments on commit 3e63c1a

Please sign in to comment.