Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lock position bug in PMGDQueryHandler #5

Merged
merged 1 commit into from
Mar 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions src/PMGDQueryHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,10 @@ std::vector<PMGDCmdResponses>
std::vector<PMGDCmdResponses> responses(num_groups);

assert(_tx == NULL);
_dblock->lock();
for (const auto cmd : cmds) {
PMGDCmdResponse *response = new PMGDCmdResponse();
try {
if (process_query(cmd, response) < 0) {
error_cleanup(responses, response);
break; // Goto cleanup site.
}
}
catch (Exception e) {
if (process_query(cmd, response) < 0) {
error_cleanup(responses, response);
break; // Goto cleanup site.
}
Expand All @@ -90,6 +85,7 @@ std::vector<PMGDCmdResponses>
_tx = NULL;
}

_dblock->unlock();
return responses;
}

Expand Down Expand Up @@ -125,7 +121,6 @@ int PMGDQueryHandler::process_query(const PMGDCmd *cmd,
switch (code) {
case PMGDCmd::TxBegin:
{
_dblock->lock();

// TODO: Needs to distinguish transaction parameters like RO/RW
_tx = new Transaction(*_db, Transaction::ReadWrite);
Expand All @@ -135,15 +130,11 @@ int PMGDQueryHandler::process_query(const PMGDCmd *cmd,
case PMGDCmd::TxCommit:
{
_tx->commit();
_dblock->unlock();
set_response(response, protobufs::TX, PMGDCmdResponse::Success);
break;
}
case PMGDCmd::TxAbort:
{
delete _tx;
_tx = NULL;
_dblock->unlock();
set_response(response, protobufs::TX, PMGDCmdResponse::Abort,
"Abort called");
retval = -1;
Expand All @@ -161,12 +152,9 @@ int PMGDQueryHandler::process_query(const PMGDCmd *cmd,
}
}
catch (Exception e) {
delete _tx;
_tx = NULL;
_dblock->unlock();
set_response(response, PMGDCmdResponse::Exception,
e.name + std::string(": ") + e.msg);
throw e;
retval = -1;
}

return retval;
Expand Down