Herve
unread,Jan 27, 2015, 7:22:02 AM1/27/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to cpp-dri...@lists.datastax.com
Hi,
We're planning to move our application storage to Cassandra.
As our app is a server written in C, we naturally looked at the cpp-driver and it's C API, to understand a bit more how it works.
When doing so, we noticed the driver does not seem to handle the out of memory situation (nor other C++ exception situation).
Example,in session.cpp:
CassFuture cass_session_execute(CassSession session,
const CassStatement* statement) {
return CassFuture::to(session->execute(statement->from()));
}
Future Session::execute(const Request statement) {
RequestHandler* request_handler = new RequestHandler(statement);
Future* future = request_handler->future();
execute(request_handler);
return future;
}
Out of memory situation on RequestHandler allocation is not particularly handled, so the default behavior is a bad_alloc exception thrown, causing the above application to abort as exception in not caught in the C API cass_session_execute, nor in the C application itself.
Writing a wrapper around the driver calls to catch such exceptions, does not seem the solution neither as there's other cases requiring handling this at a lower level.
Example:
still session.cpp
Future* Session::prepare(const char* statement, size_t length) {
PrepareRequest* prepare = new PrepareRequest();
prepare->set_query(statement, length); // bad_alloc can be thrown here by
// std:string -> would require to
// delete 'prepare' to avoid memory
// leak
RequestHandler* request_handler = new RequestHandler(prepare); // same here
// bad_alloc can be also thrown
// would also require to also delete
// 'prepare' to avoid memory leak
ResponseFuture* future = request_handler->future();
future->statement.assign(statement, length);
execute(request_handler);
return future;
}
Those are simple cases, but I realize there's much more complex situations, including ones where if we can't allocate memory, we just can't complete the action or properly free some resources.
Example:
CassFuture* cass_session_close(CassSession* session) {
cass::SessionCloseFuture* close_future = new cass::SessionCloseFuture();
session->close_async(close_future);
return CassFuture::to(close_future);
}
Here, failure to allocate close_future will not allow to do proper calls to release resources allocated for the session in any ways ...
So as the API currently stands, exception handling can only be achieved by catching all exceptions thrown by the API, exit and restart the application...
Did I get anything wrong?
Is there a better way to handle this? What would be the plans to address this, allowing to write more robust applications?
Thanks