ReplicatedPG: replace map iterators with SharedPtrRegistry::get_next

SharedPtrRegistry does not provide an iterator equivalent to

    map<hobject_t, ObjectContext*>::iterator i

It is replaced with a thread safe get_next method roughly used
as follows:

    pair<hobject_t, ObjectContextRef> i;
    while (object_contexts.get_next(i.first, &i))

All occurences of the iterator are replaced with get_next style
traversal.

http://tracker.ceph.com/issues/5510 refs #5510

Signed-off-by: Loic Dachary <loic@dachary.org>
This commit is contained in:
Loic Dachary 2013-08-13 16:40:06 +02:00
parent 8c745944c9
commit 833a225008

View File

@ -4329,11 +4329,10 @@ void ReplicatedPG::repop_ack(RepGather *repop, int result, int ack_type,
void ReplicatedPG::get_watchers(list<obj_watch_item_t> &pg_watchers)
{
for (map<hobject_t, ObjectContext*>::iterator i = object_contexts.begin();
i != object_contexts.end();
++i) {
i->second->get();
get_obc_watchers(i->second, pg_watchers);
pair<hobject_t, ObjectContextRef> i;
while (object_contexts.get_next(i.first, &i)) {
ObjectContextRef obc(i.second);
get_obc_watchers(obc, pg_watchers);
}
}
@ -4361,12 +4360,9 @@ void ReplicatedPG::get_obc_watchers(ObjectContextRef obc, list<obj_watch_item_t>
void ReplicatedPG::check_blacklisted_watchers()
{
dout(20) << "ReplicatedPG::check_blacklisted_watchers for pg " << get_pgid() << dendl;
for (map<hobject_t, ObjectContext*>::iterator i = object_contexts.begin();
i != object_contexts.end();
++i) {
i->second->get();
check_blacklisted_obc_watchers(i->second);
}
pair<hobject_t, ObjectContextRef> i;
while (object_contexts.get_next(i.first, &i))
check_blacklisted_obc_watchers(i.second);
}
void ReplicatedPG::check_blacklisted_obc_watchers(ObjectContextRef obc)
@ -4546,23 +4542,18 @@ ObjectContextRef ReplicatedPG::get_object_context(const hobject_t& soid,
void ReplicatedPG::context_registry_on_change()
{
list<ObjectContext *> contexts;
for (map<hobject_t, ObjectContext*>::iterator i = object_contexts.begin();
i != object_contexts.end();
++i) {
i->second->get();
contexts.push_back(i->second);
for (map<pair<uint64_t, entity_name_t>, WatchRef>::iterator j =
i->second->watchers.begin();
j != i->second->watchers.end();
i->second->watchers.erase(j++)) {
j->second->discard();
pair<hobject_t, ObjectContextRef> i;
while (object_contexts.get_next(i.first, &i)) {
ObjectContextRef obc(i.second);
if (obc) {
for (map<pair<uint64_t, entity_name_t>, WatchRef>::iterator j =
obc->watchers.begin();
j != obc->watchers.end();
obc->watchers.erase(j++)) {
j->second->discard();
}
}
}
for (list<ObjectContext *>::iterator i = contexts.begin();
i != contexts.end();
contexts.erase(i++)) {
}
}