Skip to content

Commit

Permalink
MDEV-12837: WSREP: BF lock wait long
Browse files Browse the repository at this point in the history
Problem was a merge error from MySQL wsrep i.e. Galera.

wsrep_on_check
	New check function. Galera can't be enabled
	if innodb-lock-schedule-algorithm=VATS.

innobase_kill_query
	In Galera async kill we could own lock mutex.

innobase_init
	If Variance-Aware-Transaction-Sheduling Algorithm (VATS) is
	used on Galera we fall back to First-Come-First-Served (FCFS)
	with notice to user.

Changed innodb-lock-schedule-algorithm as read-only parameter
as it was designed to be.

lock_reset_lock_and_trx_wait
	Use ib::hex() to print out transaction ID.

lock_rec_other_has_expl_req,
lock_rec_other_has_conflicting,
RecLock::add_to_waitq
lock_rec_lock_slow
lock_table_other_has_incompatible
lock_rec_insert_check_and_lock
lock_prdt_other_has_conflicting

	Change pointer to conflicting lock to normal pointer as this
	pointer contents could be changed later.

RecLock::create
	Conclicting lock pointer is moved to last parameter with
	default value NULL. This conflicting transaction could
	be selected as victim in Galera if requesting transaction
	is BF (brute force) transaction. In this case contents
	of conflicting lock pointer will be changed. Use ib::hex() to print
	transaction ids.
  • Loading branch information
Jan Lindström committed Dec 7, 2017
1 parent 3eaca00 commit da3a3a6
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 86 deletions.
3 changes: 2 additions & 1 deletion sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5005,7 +5005,8 @@ static Sys_var_mybool Sys_wsrep_on (
"wsrep_on", "To enable wsrep replication ",
SESSION_VAR(wsrep_on),
CMD_LINE(OPT_ARG), DEFAULT(FALSE),
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
NO_MUTEX_GUARD, NOT_IN_BINLOG,
ON_CHECK(wsrep_on_check),
ON_UPDATE(wsrep_on_update));

static Sys_var_charptr Sys_wsrep_start_position (
Expand Down
16 changes: 16 additions & 0 deletions sql/wsrep_var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,28 @@ int wsrep_init_vars()
return 0;
}

extern ulong innodb_lock_schedule_algorithm;

bool wsrep_on_update (sys_var *self, THD* thd, enum_var_type var_type)
{
if (var_type == OPT_GLOBAL) {
// FIXME: this variable probably should be changed only per session
thd->variables.wsrep_on = global_system_variables.wsrep_on;
}

return false;
}

bool wsrep_on_check(sys_var *self, THD* thd, set_var* var)
{
bool new_wsrep_on= (bool)var->save_result.ulonglong_value;

if (new_wsrep_on && innodb_lock_schedule_algorithm != 0) {
my_message(ER_WRONG_ARGUMENTS, " WSREP (galera) can't be enabled "
"if innodb_lock_schedule_algorithm=VATS. Please configure"
" innodb_lock_schedule_algorithm=FCFS and restart.", MYF(0));
return true;
}
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion sql/wsrep_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ int wsrep_init_vars();
#define DEFAULT_ARGS (THD* thd, enum_var_type var_type)
#define INIT_ARGS (const char* opt)

extern bool wsrep_causal_reads_update UPDATE_ARGS;
extern bool wsrep_causal_reads_update UPDATE_ARGS;
extern bool wsrep_on_check CHECK_ARGS;
extern bool wsrep_on_update UPDATE_ARGS;
extern bool wsrep_sync_wait_update UPDATE_ARGS;
extern bool wsrep_start_position_check CHECK_ARGS;
Expand Down
14 changes: 12 additions & 2 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3862,6 +3862,16 @@ innobase_init(
goto error;
}

#ifdef WITH_WSREP
/* Currently, Galera does not support VATS lock schedule algorithm. */
if (innodb_lock_schedule_algorithm == INNODB_LOCK_SCHEDULE_ALGORITHM_VATS
&& global_system_variables.wsrep_on) {
ib::info() << "In Galera environment Variance-Aware-Transaction-Sheduling Algorithm"
" is not supported. Falling back to First-Come-First-Served order. ";
innodb_lock_schedule_algorithm = INNODB_LOCK_SCHEDULE_ALGORITHM_FCFS;
}
#endif /* WITH_WSREP */

#ifndef HAVE_LZ4
if (innodb_compression_algorithm == PAGE_LZ4_ALGORITHM) {
sql_print_error("InnoDB: innodb_compression_algorithm = %lu unsupported.\n"
Expand Down Expand Up @@ -5351,7 +5361,7 @@ innobase_kill_query(
wsrep_thd_is_BF(current_thd, FALSE));
}

if (!wsrep_thd_is_BF(trx->mysql_thd, FALSE)) {
if (!wsrep_thd_is_BF(trx->mysql_thd, FALSE) && trx->abort_type != TRX_WSREP_ABORT) {
lock_mutex_enter();
lock_mutex_taken = true;
}
Expand Down Expand Up @@ -20863,7 +20873,7 @@ static MYSQL_SYSVAR_ULONG(doublewrite_batch_size, srv_doublewrite_batch_size,
#endif /* defined UNIV_DEBUG || defined UNIV_PERF_DEBUG */

static MYSQL_SYSVAR_ENUM(lock_schedule_algorithm, innodb_lock_schedule_algorithm,
PLUGIN_VAR_RQCMDARG,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"The algorithm Innodb uses for deciding which locks to grant next when"
" a lock is released. Possible values are"
" FCFS"
Expand Down
19 changes: 10 additions & 9 deletions storage/innobase/include/lock0priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ class RecLock {
as a victim, and we got the lock immediately: no need to
wait then */
dberr_t add_to_waitq(
const lock_t* wait_for,
lock_t* wait_for,
const lock_prdt_t*
prdt = NULL);

Expand All @@ -731,21 +731,22 @@ class RecLock {
@param[in] owns_trx_mutex true if caller owns the trx_t::mutex
@param[in] add_to_hash add the lock to hash table
@param[in] prdt Predicate lock (optional)
@param[in,out] c_lock Conflicting lock request or NULL
in Galera conflicting lock is selected
as deadlock victim if requester
is BF transaction.
@return new lock instance */
lock_t* create(
trx_t* trx,
bool owns_trx_mutex,
bool add_to_hash,
const lock_prdt_t*
prdt = NULL);
prdt = NULL
#ifdef WITH_WSREP
,lock_t* c_lock = NULL
#endif /* WITH_WSREP */
);

lock_t* create(
lock_t* const c_lock,
trx_t* trx,
bool owns_trx_mutex,
bool add_to_hash,
const lock_prdt_t*
prdt = NULL);
/**
Check of the lock is on m_rec_id.
@param[in] lock Lock to compare with
Expand Down
Loading

0 comments on commit da3a3a6

Please sign in to comment.