Commit a336cb20 authored by Will DeVries's avatar Will DeVries Committed by Sergei Petrunia

Fix some transaction handling errors.

parent ea5b6a6c
...@@ -189,6 +189,7 @@ int clustrix_connection::rollback_trans() ...@@ -189,6 +189,7 @@ int clustrix_connection::rollback_trans()
int clustrix_connection::begin_stmt_trans() int clustrix_connection::begin_stmt_trans()
{ {
assert(has_transaction);
if (has_statement_trans) if (has_statement_trans)
return 0; return 0;
...@@ -202,6 +203,7 @@ int clustrix_connection::begin_stmt_trans() ...@@ -202,6 +203,7 @@ int clustrix_connection::begin_stmt_trans()
int clustrix_connection::commit_stmt_trans() int clustrix_connection::commit_stmt_trans()
{ {
assert(has_transaction);
const char *stmt = "RELEASE SAVEPOINT STMT_TRANS"; const char *stmt = "RELEASE SAVEPOINT STMT_TRANS";
int error_code = mysql_real_query(&clustrix_net, stmt, strlen(stmt)); int error_code = mysql_real_query(&clustrix_net, stmt, strlen(stmt));
if (error_code) if (error_code)
...@@ -212,6 +214,7 @@ int clustrix_connection::commit_stmt_trans() ...@@ -212,6 +214,7 @@ int clustrix_connection::commit_stmt_trans()
int clustrix_connection::rollback_stmt_trans() int clustrix_connection::rollback_stmt_trans()
{ {
assert(has_transaction);
const char *stmt = "ROLLBACK TO STMT_TRANS"; const char *stmt = "ROLLBACK TO STMT_TRANS";
int error_code = mysql_real_query(&clustrix_net, stmt, strlen(stmt)); int error_code = mysql_real_query(&clustrix_net, stmt, strlen(stmt));
if (error_code) if (error_code)
......
...@@ -825,16 +825,17 @@ int ha_clustrixdb::external_lock(THD *thd, int lock_type) ...@@ -825,16 +825,17 @@ int ha_clustrixdb::external_lock(THD *thd, int lock_type)
int error_code; int error_code;
clustrix_connection *trx = get_trx(thd, &error_code); clustrix_connection *trx = get_trx(thd, &error_code);
if (lock_type != F_UNLCK) { if (lock_type != F_UNLCK) {
trx->begin_trans(); if ((error_code = trx->begin_trans()))
trx->begin_stmt_trans(); return error_code;
if ((error_code = trx->begin_stmt_trans()))
return error_code;
trans_register_ha(thd, FALSE, clustrixdb_hton); trans_register_ha(thd, FALSE, clustrixdb_hton);
if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
trans_register_ha(thd, TRUE, clustrixdb_hton); trans_register_ha(thd, TRUE, clustrixdb_hton);
} }
//if (lock_type != F_UNLCK)
//DBUG_ASSERT(trx && trx == get_trx(thd, &error_code));
return 0; return 0;
} }
...@@ -931,11 +932,13 @@ static int clustrixdb_commit(handlerton *hton, THD *thd, bool all) ...@@ -931,11 +932,13 @@ static int clustrixdb_commit(handlerton *hton, THD *thd, bool all)
clustrix_connection* trx = (clustrix_connection *) thd_get_ha_data(thd, hton); clustrix_connection* trx = (clustrix_connection *) thd_get_ha_data(thd, hton);
assert(trx); assert(trx);
if (trx->has_stmt_trans() && ((error_code = trx->commit_stmt_trans()))) if (all || !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
return error_code; if (trx->has_trans())
if (all && trx->has_trans())
error_code = trx->commit_trans(); error_code = trx->commit_trans();
} else {
if (trx->has_stmt_trans())
error_code = trx->commit_stmt_trans();
}
return error_code; return error_code;
} }
...@@ -946,11 +949,13 @@ static int clustrixdb_rollback(handlerton *hton, THD *thd, bool all) ...@@ -946,11 +949,13 @@ static int clustrixdb_rollback(handlerton *hton, THD *thd, bool all)
clustrix_connection* trx = (clustrix_connection *) thd_get_ha_data(thd, hton); clustrix_connection* trx = (clustrix_connection *) thd_get_ha_data(thd, hton);
assert(trx); assert(trx);
if (trx->has_stmt_trans() && ((error_code = trx->rollback_stmt_trans()))) if (all || !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
return error_code; if (trx->has_trans())
if (all || trx->has_trans())
error_code = trx->rollback_trans(); error_code = trx->rollback_trans();
} else {
if (trx->has_stmt_trans())
error_code = trx->rollback_stmt_trans();
}
return error_code; return error_code;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment