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

Fix transaction assertions and rename some methods.

parent 62b8d3d4
......@@ -213,18 +213,18 @@ int clustrix_connection::send_transaction_cmd()
DBUG_RETURN(error_code);
}
bool clustrix_connection::begin_trans()
bool clustrix_connection::begin_transaction()
{
DBUG_ENTER("clustrix_connection::begin_trans");
DBUG_ENTER("clustrix_connection::begin_transaction");
assert(!has_transaction);
commit_flag_next |= CLUSTRIX_TRANS_BEGIN;
has_transaction = TRUE;
DBUG_RETURN(TRUE);
}
bool clustrix_connection::commit_trans()
bool clustrix_connection::commit_transaction()
{
DBUG_ENTER("clustrix_connection::commit_trans");
DBUG_ENTER("clustrix_connection::commit_transaction");
assert(has_transaction);
if (commit_flag_next & CLUSTRIX_TRANS_BEGIN) {
......@@ -234,13 +234,13 @@ bool clustrix_connection::commit_trans()
commit_flag_next |= CLUSTRIX_TRANS_COMMIT;
has_transaction = FALSE;
has_statement_trans = FALSE;
has_anonymous_savepoint = FALSE;
DBUG_RETURN(TRUE);
}
bool clustrix_connection::rollback_trans()
bool clustrix_connection::rollback_transaction()
{
DBUG_ENTER("clustrix_connection::rollback_trans");
DBUG_ENTER("clustrix_connection::rollback_transaction");
assert(has_transaction);
if (commit_flag_next & CLUSTRIX_TRANS_BEGIN) {
......@@ -250,7 +250,7 @@ bool clustrix_connection::rollback_trans()
commit_flag_next |= CLUSTRIX_TRANS_ROLLBACK;
has_transaction = FALSE;
has_statement_trans = FALSE;
has_anonymous_savepoint = FALSE;
DBUG_RETURN(TRUE);
}
......@@ -264,42 +264,42 @@ void clustrix_connection::auto_commit_closed()
assert(has_transaction);
if (commit_flag_next & CLUSTRIX_TRANS_COMMIT_ON_FINISH) {
has_transaction = FALSE;
has_statement_trans = FALSE;
has_anonymous_savepoint = FALSE;
commit_flag_next &= ~CLUSTRIX_TRANS_COMMIT_ON_FINISH;
}
}
bool clustrix_connection::begin_stmt_trans()
bool clustrix_connection::set_anonymous_savepoint()
{
DBUG_ENTER("clustrix_connection::begin_stmt_trans");
DBUG_ENTER("clustrix_connection::set_anonymous_savepoint");
assert(has_transaction);
assert(!has_statement_trans);
assert(!has_anonymous_savepoint);
commit_flag_next |= CLUSTRIX_STMT_NEW;
has_statement_trans = TRUE;
has_anonymous_savepoint = TRUE;
DBUG_RETURN(TRUE);
}
bool clustrix_connection::commit_stmt_trans()
bool clustrix_connection::release_anonymous_savepoint()
{
DBUG_ENTER("clustrix_connection::commit_stmt_trans");
DBUG_ENTER("clustrix_connection::release_anonymous_savepoint");
assert(has_transaction);
assert(has_statement_trans);
assert(has_anonymous_savepoint);
if (commit_flag_next & CLUSTRIX_STMT_NEW) {
commit_flag_next &= ~CLUSTRIX_STMT_NEW;
DBUG_RETURN(FALSE);
}
has_statement_trans = FALSE;
has_anonymous_savepoint = FALSE;
DBUG_RETURN(TRUE);
}
bool clustrix_connection::rollback_stmt_trans()
bool clustrix_connection::rollback_to_anonymous_savepoint()
{
DBUG_ENTER("clustrix_connection::rollback_stmt_trans");
DBUG_ENTER("clustrix_connection::rollback_to_anonymous_savepoint");
assert(has_transaction);
assert(has_statement_trans);
assert(has_anonymous_savepoint);
if (commit_flag_next & CLUSTRIX_STMT_NEW) {
commit_flag_next &= ~CLUSTRIX_STMT_NEW;
......@@ -307,7 +307,7 @@ bool clustrix_connection::rollback_stmt_trans()
}
commit_flag_next |= CLUSTRIX_STMT_ROLLBACK;
has_statement_trans = FALSE;
has_anonymous_savepoint = FALSE;
DBUG_RETURN(TRUE);
}
......
......@@ -37,7 +37,7 @@ class clustrix_connection
size_t reply_length;
bool has_transaction;
bool has_statement_trans;
bool has_anonymous_savepoint;
int commit_flag_next;
public:
......@@ -46,7 +46,7 @@ class clustrix_connection
{
DBUG_ENTER("clustrix_connection::clustrix_connection");
memset(&clustrix_net, 0, sizeof(MYSQL));
has_statement_trans = FALSE;
has_anonymous_savepoint = FALSE;
has_transaction = FALSE;
commit_flag_next = 0;
DBUG_VOID_RETURN;
......@@ -73,22 +73,21 @@ class clustrix_connection
void disconnect(bool is_destructor = FALSE);
int send_transaction_cmd();
bool begin_trans();
bool commit_trans();
bool rollback_trans();
bool begin_transaction();
bool commit_transaction();
bool rollback_transaction();
void auto_commit_next();
void auto_commit_closed();
inline bool has_trans()
inline bool has_open_transaction()
{
return has_transaction;
}
bool begin_stmt_trans();
bool commit_stmt_trans();
bool rollback_stmt_trans();
inline bool has_stmt_trans()
bool set_anonymous_savepoint();
bool release_anonymous_savepoint();
bool rollback_to_anonymous_savepoint();
inline bool has_open_anonymous_savepoint()
{
return has_statement_trans;
return has_anonymous_savepoint;
}
int run_query(String &stmt);
......@@ -151,5 +150,6 @@ class clustrix_connection
int begin_command(uchar command);
int send_command();
int read_query_response();
void auto_commit_closed();
};
#endif // _clustrix_connection_h
......@@ -409,7 +409,7 @@ int ha_clustrixdb::write_row(const uchar *buf)
if (!trx)
return error_code;
assert(trx->has_stmt_trans());
assert(trx->has_open_transaction());
/* Convert the row format to binlog (packed) format */
uchar *packed_new_row = (uchar*) my_alloca(estimate_row_size(table));
......@@ -442,7 +442,7 @@ int ha_clustrixdb::update_row(const uchar *old_data, const uchar *new_data)
if (!trx)
DBUG_RETURN(error_code);
assert(trx->has_stmt_trans());
assert(trx->has_open_transaction());
size_t row_size = estimate_row_size(table);
size_t packed_key_len;
......@@ -502,7 +502,7 @@ int ha_clustrixdb::delete_row(const uchar *buf)
if (!trx)
return error_code;
assert(trx->has_stmt_trans());
assert(trx->has_open_transaction());
// The estimate should consider only key fields widths.
size_t packed_key_len;
......@@ -932,11 +932,11 @@ int ha_clustrixdb::external_lock(THD *thd, int lock_type)
int error_code;
clustrix_connection *trx = get_trx(thd, &error_code);
if (lock_type != F_UNLCK) {
trx->begin_trans();
trx->begin_transaction();
trans_register_ha(thd, FALSE, clustrixdb_hton);
if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
trx->begin_stmt_trans();
trx->set_anonymous_savepoint();
trans_register_ha(thd, TRUE, clustrixdb_hton);
}
}
......@@ -1039,11 +1039,11 @@ static int clustrixdb_commit(handlerton *hton, THD *thd, bool all)
bool send_cmd;
if (all || !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
if (trx->has_trans())
send_cmd = trx->commit_trans();
if (trx->has_open_transaction())
send_cmd = trx->commit_transaction();
} else {
if (trx->has_stmt_trans())
send_cmd = trx->commit_stmt_trans();
if (trx->has_open_anonymous_savepoint())
send_cmd = trx->release_anonymous_savepoint();
}
if (send_cmd)
......@@ -1059,11 +1059,11 @@ static int clustrixdb_rollback(handlerton *hton, THD *thd, bool all)
bool send_cmd;
if (all || !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
if (trx->has_trans())
send_cmd = trx->rollback_trans();
if (trx->has_open_transaction())
send_cmd = trx->rollback_transaction();
} else {
if (trx->has_stmt_trans())
send_cmd = trx->rollback_stmt_trans();
if (trx->has_open_anonymous_savepoint())
send_cmd = trx->rollback_to_anonymous_savepoint();
}
if (send_cmd)
......
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