osd/: add sync/async read methods to PGBackend

Signed-off-by: Samuel Just <sam.just@inktank.com>
This commit is contained in:
Samuel Just 2013-12-06 11:44:02 -08:00
parent 66bc91cf0a
commit 2fe5e1f2d2
5 changed files with 63 additions and 0 deletions

View File

@ -185,6 +185,7 @@ OSDService::OSDService(OSD *osd) :
scrub_finalize_wq(osd->scrub_finalize_wq),
rep_scrub_wq(osd->rep_scrub_wq),
push_wq("push_wq", cct->_conf->osd_recovery_thread_timeout, &osd->recovery_tp),
gen_wq("gen_wq", cct->_conf->osd_recovery_thread_timeout, &osd->recovery_tp),
class_handler(osd->class_handler),
publish_lock("OSDService::publish_lock"),
pre_publish_lock("OSDService::pre_publish_lock"),

View File

@ -312,6 +312,7 @@ public:
ThreadPool::WorkQueue<PG> &scrub_finalize_wq;
ThreadPool::WorkQueue<MOSDRepScrub> &rep_scrub_wq;
GenContextWQ push_wq;
GenContextWQ gen_wq;
ClassHandler *&class_handler;
void dequeue_pg(PG *pg, list<OpRequestRef> *dequeued);

View File

@ -416,6 +416,19 @@
virtual int objects_get_attrs(
const hobject_t &hoid,
map<string, bufferlist> *out) = 0;
virtual int objects_read_sync(
const hobject_t &hoid,
uint64_t off,
uint64_t len,
bufferlist *bl) = 0;
virtual void objects_read_async(
const hobject_t &hoid,
uint64_t off,
uint64_t len,
bufferlist *bl,
Context *on_complete) = 0;
};
#endif

View File

@ -324,6 +324,41 @@ int ReplicatedBackend::objects_get_attrs(
*out);
}
int ReplicatedBackend::objects_read_sync(
const hobject_t &hoid,
uint64_t off,
uint64_t len,
bufferlist *bl)
{
return osd->store->read(coll, hoid, off, len, *bl);
}
struct AsyncReadCallback : public GenContext<ThreadPool::TPHandle&> {
int r;
Context *c;
AsyncReadCallback(int r, Context *c) : r(r), c(c) {}
void finish(ThreadPool::TPHandle&) {
c->complete(r);
c = NULL;
}
~AsyncReadCallback() {
delete c;
}
};
void ReplicatedBackend::objects_read_async(
const hobject_t &hoid,
uint64_t off,
uint64_t len,
bufferlist *bl,
Context *on_complete)
{
int r = osd->store->read(coll, hoid, off, len, *bl);
osd->gen_wq.queue(
get_parent()->bless_gencontext(
new AsyncReadCallback(r, on_complete)));
}
class RPGTransaction : public PGBackend::PGTransaction {
coll_t coll;
coll_t temp_coll;

View File

@ -176,6 +176,19 @@ public:
const hobject_t &hoid,
map<string, bufferlist> *out);
int objects_read_sync(
const hobject_t &hoid,
uint64_t off,
uint64_t len,
bufferlist *bl);
void objects_read_async(
const hobject_t &hoid,
uint64_t off,
uint64_t len,
bufferlist *bl,
Context *on_complete);
private:
// push
struct PushInfo {