(libradosstriper::RadosStriperImpl* striper,
const std::string& soid,
const std::string& lockCookie,
- librados::AioCompletionImpl *userCompletion) :
+ librados::AioCompletionImpl *userCompletion,
+ int n) :
+ RefCountedObject(striper->cct(), n),
m_striper(striper), m_soid(soid), m_lockCookie(lockCookie), m_ack(0) {
m_striper->get();
if (userCompletion) m_ack = new librados::IoCtxImpl::C_aio_Ack(userCompletion);
librados::AioCompletionImpl *userCompletion,
bufferlist* bl,
std::vector<ObjectExtent>* extents,
- std::vector<bufferlist>* resultbl) :
- CompletionData(striper, soid, lockCookie, userCompletion),
+ std::vector<bufferlist>* resultbl,
+ int n) :
+ CompletionData(striper, soid, lockCookie, userCompletion, n),
m_bl(bl), m_extents(extents), m_resultbl(resultbl) {}
libradosstriper::RadosStriperImpl::ReadCompletionData::~ReadCompletionData() {
(libradosstriper::RadosStriperImpl* striper,
const std::string& soid,
const std::string& lockCookie,
- librados::AioCompletionImpl *userCompletion) :
- CompletionData(striper, soid, lockCookie, userCompletion), m_safe(0) {
+ librados::AioCompletionImpl *userCompletion,
+ int n) :
+ CompletionData(striper, soid, lockCookie, userCompletion, n), m_safe(0) {
if (userCompletion) m_safe = new librados::IoCtxImpl::C_aio_Safe(userCompletion);
}
libradosstriper::MultiAioCompletionImpl *comp =
reinterpret_cast<libradosstriper::MultiAioCompletionImpl*>(c);
cdata->complete(comp->rval);
- delete cdata;
+ cdata->put();
}
static void rados_req_read_safe(rados_completion_t c, void *arg)
libradosstriper::RadosStriperImpl::WriteCompletionData *cdata =
reinterpret_cast<libradosstriper::RadosStriperImpl::WriteCompletionData*>(arg);
cdata->m_striper->closeForWrite(cdata->m_soid, cdata->m_lockCookie);
+ cdata->put();
}
int libradosstriper::RadosStriperImpl::write_in_open_object(const std::string& soid,
uint64_t off) {
// create a completion object
WriteCompletionData *cdata = new WriteCompletionData(this, soid, lockCookie);
+ cdata->get();
libradosstriper::MultiAioCompletionImpl *c = new libradosstriper::MultiAioCompletionImpl;
c->set_complete_callback(cdata, striper_write_req_complete);
// call the asynchronous API
// return result
rc = c->get_return_value();
}
- delete cdata;
c->put();
+ cdata->put();
return rc;
}
libradosstriper::MultiAioCompletionImpl *comp =
reinterpret_cast<libradosstriper::MultiAioCompletionImpl*>(c);
cdata->complete(comp->rval);
- if (0 == comp->pending_safe) {
- delete cdata;
- }
+ cdata->put();
}
static void striper_write_aio_req_safe(rados_striper_multi_completion_t c, void *arg)
libradosstriper::MultiAioCompletionImpl *comp =
reinterpret_cast<libradosstriper::MultiAioCompletionImpl*>(c);
cdata->safe(comp->rval);
- if (0 == comp->pending_complete) {
- delete cdata;
- }
+ cdata->put();
}
int libradosstriper::RadosStriperImpl::aio_write_in_open_object(const std::string& soid,
uint64_t off) {
// create a completion object
m_ioCtxImpl->get();
- WriteCompletionData *cdata = new WriteCompletionData(this, soid, lockCookie, c);
+ // we need 2 references as both striper_write_aio_req_complete and
+ // striper_write_aio_req_safe will release one
+ WriteCompletionData *cdata = new WriteCompletionData(this, soid, lockCookie, c, 2);
c->io = m_ioCtxImpl;
libradosstriper::MultiAioCompletionImpl *nc = new libradosstriper::MultiAioCompletionImpl;
nc->set_complete_callback(cdata, striper_write_aio_req_complete);
* struct handling the data needed to pass to the call back
* function in asynchronous operations
*/
- struct CompletionData {
- /// striper to be used to handle the write completion
- libradosstriper::RadosStriperImpl *m_striper;
- /// striped object concerned by the write operation
- std::string m_soid;
- /// shared lock to be released at completion
- std::string m_lockCookie;
- /// completion handler
- librados::IoCtxImpl::C_aio_Ack *m_ack;
+ struct CompletionData : RefCountedObject {
/// constructor
CompletionData(libradosstriper::RadosStriperImpl * striper,
const std::string& soid,
const std::string& lockCookie,
- librados::AioCompletionImpl *userCompletion = 0);
+ librados::AioCompletionImpl *userCompletion = 0,
+ int n = 1);
/// destructor
virtual ~CompletionData();
/// complete method
void complete(int r);
+ /// striper to be used to handle the write completion
+ libradosstriper::RadosStriperImpl *m_striper;
+ /// striped object concerned by the write operation
+ std::string m_soid;
+ /// shared lock to be released at completion
+ std::string m_lockCookie;
+ /// completion handler
+ librados::IoCtxImpl::C_aio_Ack *m_ack;
};
/**
librados::AioCompletionImpl *userCompletion,
bufferlist* bl,
std::vector<ObjectExtent>* extents,
- std::vector<bufferlist>* resultbl);
+ std::vector<bufferlist>* resultbl,
+ int n = 1);
/// destructor
virtual ~ReadCompletionData();
/// complete method
WriteCompletionData(libradosstriper::RadosStriperImpl * striper,
const std::string& soid,
const std::string& lockCookie,
- librados::AioCompletionImpl *userCompletion = 0);
+ librados::AioCompletionImpl *userCompletion = 0,
+ int n = 1);
/// destructor
virtual ~WriteCompletionData();
/// safe method