From 16ed0b9af8bc08c7dabead1c1a7c1a22b1fb02fb Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 13 Aug 2013 12:52:41 -0700 Subject: [PATCH] librados: fix async aio completion wakeup For aio flush, we register a wait on the most recent write. The write completion code, however, was *only* waking the waiter if they were waiting on that write, without regard to previous writes (completed or not). For example, we might have 6 and 7 outstanding and wait on 7. If they finish in order all is well, but if 7 finishes first we do the flush completion early. Similarly, if we - start 6 - start 7 - finish 7 - flush; wait on 7 - finish 6 we can hang forever. Fix by doing any completions that are prior to the oldest pending write in the aio write completion handler. Refs: #5919 Signed-off-by: Sage Weil Reviewed-by: Josh Durgin Tested-by: Oliver Francke --- src/librados/IoCtxImpl.cc | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/librados/IoCtxImpl.cc b/src/librados/IoCtxImpl.cc index b5da027e8f6..ce9743a54b3 100644 --- a/src/librados/IoCtxImpl.cc +++ b/src/librados/IoCtxImpl.cc @@ -82,22 +82,25 @@ void librados::IoCtxImpl::complete_aio_write(AioCompletionImpl *c) aio_write_list_lock.Lock(); assert(c->io == this); c->aio_write_list_item.remove_myself(); - // queue async flush waiters - map >::iterator waiters = - aio_write_waiters.find(c->aio_write_seq); - if (waiters != aio_write_waiters.end()) { - ldout(client->cct, 20) << "found " << waiters->second.size() - << " waiters" << dendl; + + map >::iterator waiters = aio_write_waiters.begin(); + while (waiters != aio_write_waiters.end()) { + if (!aio_write_list.empty() && + aio_write_list.front()->aio_write_seq <= waiters->first) { + ldout(client->cct, 20) << " next outstanding write is " << aio_write_list.front()->aio_write_seq + << " <= waiter " << waiters->first + << ", stopping" << dendl; + break; + } + ldout(client->cct, 20) << " waking waiters on seq " << waiters->first << dendl; for (std::list::iterator it = waiters->second.begin(); it != waiters->second.end(); ++it) { client->finisher.queue(new C_AioCompleteAndSafe(*it)); (*it)->put(); } - aio_write_waiters.erase(waiters); - } else { - ldout(client->cct, 20) << "found no waiters for tid " - << c->aio_write_seq << dendl; + aio_write_waiters.erase(waiters++); } + aio_write_cond.Signal(); aio_write_list_lock.Unlock(); put(); @@ -109,11 +112,13 @@ void librados::IoCtxImpl::flush_aio_writes_async(AioCompletionImpl *c) << " completion " << c << dendl; Mutex::Locker l(aio_write_list_lock); tid_t seq = aio_write_seq; - ldout(client->cct, 20) << "flush_aio_writes_async waiting on tid " - << seq << dendl; if (aio_write_list.empty()) { + ldout(client->cct, 20) << "flush_aio_writes_async no writes. (tid " + << seq << ")" << dendl; client->finisher.queue(new C_AioCompleteAndSafe(c)); } else { + ldout(client->cct, 20) << "flush_aio_writes_async " << aio_write_list.size() + << " writes in flight; waiting on tid " << seq << dendl; c->get(); aio_write_waiters[seq].push_back(c); }