Skip to content

Commit

Permalink
Bug#32169848 THD_NDB TRANSACTION FUNCTIONALITY [#4]
Browse files Browse the repository at this point in the history
Increment the "start_stmt_count" variable only when handler
has been registered sucessfully and thus remove two unneccessary
decrement calls. Improve description of the "start_stmt_count"
variable.

Change-Id: I50f269fb024002a122cf898c84fb578c50007980
  • Loading branch information
blaudden committed May 19, 2021
1 parent a1aef87 commit 62af1b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 7 additions & 4 deletions storage/ndb/plugin/ha_ndbcluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,6 @@ Thd_ndb::Thd_ndb(THD *thd)
m_connect_count = connection->get_connect_count();
ndb = new Ndb(connection, "");
lock_count = 0;
start_stmt_count = 0;
save_point_count = 0;
trans = NULL;
m_handler = NULL;
Expand Down Expand Up @@ -7473,14 +7472,14 @@ int ha_ndbcluster::start_stmt(THD *thd, thr_lock_type) {

int error;
Thd_ndb *thd_ndb = get_thd_ndb(thd);
if ((error = start_statement(thd, thd_ndb, thd_ndb->start_stmt_count++))) {
thd_ndb->start_stmt_count--;
if ((error = start_statement(thd, thd_ndb, thd_ndb->start_stmt_count))) {
return error;
}
if ((error = init_handler_for_statement(thd))) {
thd_ndb->start_stmt_count--;
return error;
}
thd_ndb->start_stmt_count++;

return 0;
}

Expand Down Expand Up @@ -7648,7 +7647,9 @@ int ndbcluster_commit(handlerton *, THD *thd, bool all) {
ddl_ctx->commit();
}

// Reset reference counter for start_stmt()
thd_ndb->start_stmt_count = 0;

if (trans == NULL) {
DBUG_PRINT("info", ("trans == NULL"));
return 0;
Expand Down Expand Up @@ -7828,7 +7829,9 @@ static int ndbcluster_rollback(handlerton *, THD *thd, bool all) {
thd_ndb->save_point_count));
assert(ndb);

// Reset reference counter for start_stmt()
thd_ndb->start_stmt_count = 0;

if (trans == nullptr) {
// NdbTransaction was never started
DBUG_PRINT("info", ("trans == NULL"));
Expand Down
9 changes: 8 additions & 1 deletion storage/ndb/plugin/ndb_thd_ndb.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ class Thd_ndb {
class Ndb *ndb;
class ha_ndbcluster *m_handler;
uint lock_count;
uint start_stmt_count;

// Reference counter for start_stmt() calls. The counter controls that the
// handlerton is registered as being part of the MySQL transaction at the
// first start_stmt() call (when the counter is zero). When MySQL
// ends the transaction by calling either ndbcluster_commit() or
// ndbcluster_rollback(), the counter is then reset back to zero.
uint start_stmt_count{0};

uint save_point_count;
class NdbTransaction *trans;
bool m_error;
Expand Down

0 comments on commit 62af1b4

Please sign in to comment.