Skip to content

Commit

Permalink
Bug#32169848 THD_NDB TRANSACTION FUNCTIONALITY [#5]
Browse files Browse the repository at this point in the history
Rename "lock_count" to "external_lock_count", increment the variable
only when transaction has been registered sucessfully and thus
remove two unneccessary decrement calls. Improve description of the
"external_lock_count" variable.

Change-Id: I5bfa91fdca8fa2d377b170696b6086293d8cb743
  • Loading branch information
blaudden committed May 19, 2021
1 parent 62af1b4 commit f7c43cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
22 changes: 11 additions & 11 deletions storage/ndb/plugin/ha_ndbcluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,6 @@ Thd_ndb::Thd_ndb(THD *thd)
connection = ndb_get_cluster_connection();
m_connect_count = connection->get_connect_count();
ndb = new Ndb(connection, "");
lock_count = 0;
save_point_count = 0;
trans = NULL;
m_handler = NULL;
Expand Down Expand Up @@ -7360,29 +7359,30 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) {

DBUG_PRINT("enter", ("lock_type != F_UNLCK "
"this: %p thd: %p thd_ndb: %p "
"thd_ndb->lock_count: %d",
this, thd, thd_ndb, thd_ndb->lock_count));
"thd_ndb->external_lock_count: %d",
this, thd, thd_ndb, thd_ndb->external_lock_count));

if ((error = start_statement(thd, thd_ndb, thd_ndb->lock_count++))) {
thd_ndb->lock_count--;
if ((error = start_statement(thd, thd_ndb, thd_ndb->external_lock_count))) {
return error;
}
if ((error = init_handler_for_statement(thd))) {
thd_ndb->lock_count--;
return error;
}
thd_ndb->external_lock_count++;
return 0;
} else {
Thd_ndb *thd_ndb = m_thd_ndb;
assert(thd_ndb);

DBUG_PRINT("enter", ("lock_type == F_UNLCK "
"this: %p thd: %p thd_ndb: %p "
"thd_ndb->lock_count: %d",
this, thd, thd_ndb, thd_ndb->lock_count));
"thd_ndb->external_lock_count: %d",
this, thd, thd_ndb, thd_ndb->external_lock_count));

thd_ndb->external_lock_count--;
if (thd_ndb->external_lock_count == 0) {
DBUG_PRINT("trans", ("Last external_lock() unlock"));

if (!--thd_ndb->lock_count) {
DBUG_PRINT("trans", ("Last external_lock"));
const bool autocommit_enabled =
!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN);
// Only the 'CREATE TABLE ... SELECT' variant of the
Expand All @@ -7392,7 +7392,7 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) {

if (thd_ndb->trans && (autocommit_enabled || is_create_table_select)) {
/*
Unlock is done without a transaction commit / rollback.
Unlock is done without transaction commit / rollback.
This happens if the thread didn't update any rows as a part of normal
DMLs or `CREATE TABLE ... SELECT` DDL .
We must in this case close the transaction to release resources
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 @@ -54,7 +54,14 @@ class Thd_ndb {
class Ndb_cluster_connection *connection;
class Ndb *ndb;
class ha_ndbcluster *m_handler;
uint lock_count;

// Reference counter for external_lock() calls. The counter controls that
// the handlerton is registered as being part of the MySQL transaction only at
// the first external_lock() call (when the counter is zero). Also the counter
// controls that any started NDB transaction is closed when external_lock(..,
// F_UNLOCK) is called for the last time (i.e when the counter is back to zero
// again).
uint external_lock_count{0};

// Reference counter for start_stmt() calls. The counter controls that the
// handlerton is registered as being part of the MySQL transaction at the
Expand Down

0 comments on commit f7c43cb

Please sign in to comment.