Skip to content

Commit 149581a

Browse files
committed
Remove unnecessary changes. Apply changes to XtraDB.
1 parent 04f241a commit 149581a

File tree

5 files changed

+91
-36
lines changed

5 files changed

+91
-36
lines changed

sql/rpl_parallel.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,7 @@ handle_rpl_parallel_thread(void *arg)
14101410
mysql_mutex_unlock(&rpt->LOCK_rpl_thread);
14111411

14121412
my_thread_end();
1413+
14131414
return NULL;
14141415
}
14151416

storage/innobase/lock/lock0lock.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,6 @@ lock_grant(
9494
lock_t* lock, /*!< in/out: waiting lock request */
9595
bool owns_trx_mutex); /*!< in: whether lock->trx->mutex is owned */
9696

97-
98-
/* Buffer to collect THDs to report waits for. */
99-
struct thd_wait_reports {
100-
struct thd_wait_reports *next; /*!< List link */
101-
ulint used; /*!< How many elements in waitees[] */
102-
trx_t *waitees[64]; /*!< Trxs for thd_report_wait_for() */
103-
};
104-
10597
extern "C" void thd_rpl_deadlock_check(MYSQL_THD thd, MYSQL_THD other_thd);
10698
extern "C" int thd_need_wait_reports(const MYSQL_THD thd);
10799
extern "C" int thd_need_ordering_with(const MYSQL_THD thd, const MYSQL_THD other_thd);

storage/xtradb/include/trx0trx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,8 @@ struct trx_t{
876876

877877
time_t start_time; /*!< time the trx state last time became
878878
TRX_STATE_ACTIVE */
879+
clock_t start_time_micro; /*!< start time of the transaction
880+
in microseconds. */
879881
trx_id_t id; /*!< transaction id */
880882
XID xid; /*!< X/Open XA transaction
881883
identification to identify a

storage/xtradb/lock/lock0lock.cc

Lines changed: 86 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,8 @@ wsrep_print_wait_locks(
20312031

20322032
/*********************************************************************//**
20332033
Check if lock1 has higher priority than lock2.
2034-
NULL has lowest priority..
2034+
NULL has lowest priority.
2035+
If either is a high priority transaction, the lock has higher priority.
20352036
If neither of them is wait lock, the first one has higher priority.
20362037
If only one of them is a wait lock, it has lower priority.
20372038
Otherwise, the one with an older transaction has higher priority.
@@ -2055,13 +2056,19 @@ has_higher_priority(
20552056
// lock2 is preferred as a victim, so lock1 has higher priority
20562057
return true;
20572058
}
2059+
if (trx_is_high_priority(lock1->trx)) {
2060+
return true;
2061+
}
2062+
if (trx_is_high_priority(lock2->trx)) {
2063+
return false;
2064+
}
20582065
// No preference. Compre them by wait mode and trx age.
20592066
if (!lock_get_wait(lock1)) {
20602067
return true;
20612068
} else if (!lock_get_wait(lock2)) {
20622069
return false;
20632070
}
2064-
return lock1->trx->start_time < lock2->trx->start_time;
2071+
return lock1->trx->start_time_micro <= lock2->trx->start_time_micro;
20652072
}
20662073

20672074
/*********************************************************************//**
@@ -2071,7 +2078,7 @@ If the lock is not a wait lock, insert it to the head of the hash list.
20712078
Otherwise, insert it to the middle of the wait locks according to the age of
20722079
the transaciton. */
20732080
static
2074-
void
2081+
dberr_t
20752082
lock_rec_insert_by_trx_age(
20762083
lock_t *in_lock) /*!< in: lock to be insert */{
20772084
ulint space;
@@ -2085,7 +2092,7 @@ lock_rec_insert_by_trx_age(
20852092
space = in_lock->un_member.rec_lock.space;
20862093
page_no = in_lock->un_member.rec_lock.page_no;
20872094
rec_fold = lock_rec_fold(space, page_no);
2088-
hash = lock_sys->rec_hash;
2095+
hash = lock_hash_get(in_lock->type_mode);
20892096
cell = hash_get_nth_cell(hash,
20902097
hash_calc_hash(rec_fold, hash));
20912098

@@ -2094,7 +2101,11 @@ lock_rec_insert_by_trx_age(
20942101
if (node == NULL || !lock_get_wait(in_lock) || has_higher_priority(in_lock, node)) {
20952102
cell->node = in_lock;
20962103
in_lock->hash = node;
2097-
return;
2104+
if (lock_get_wait(in_lock)) {
2105+
lock_grant(in_lock, true);
2106+
return DB_SUCCESS_LOCKED_REC;
2107+
}
2108+
return DB_SUCCESS;
20982109
}
20992110
while (node != NULL && has_higher_priority((lock_t *) node->hash,
21002111
in_lock)) {
@@ -2103,6 +2114,20 @@ lock_rec_insert_by_trx_age(
21032114
next = (lock_t *) node->hash;
21042115
node->hash = in_lock;
21052116
in_lock->hash = next;
2117+
2118+
if (lock_get_wait(in_lock) && !lock_rec_has_to_wait_in_queue(in_lock)) {
2119+
lock_grant(in_lock, true);
2120+
if (cell->node != in_lock) {
2121+
// Move it to the front of the queue
2122+
node->hash = in_lock->hash;
2123+
next = (lock_t *) cell->node;
2124+
cell->node = in_lock;
2125+
in_lock->hash = next;
2126+
}
2127+
return DB_SUCCESS_LOCKED_REC;
2128+
}
2129+
2130+
return DB_SUCCESS;
21062131
}
21072132

21082133
static
@@ -2327,7 +2352,7 @@ lock_rec_create(
23272352
trx_mutex_exit(c_lock->trx);
23282353
} else {
23292354
if (innodb_lock_schedule_algorithm == INNODB_LOCK_SCHEDULE_ALGORITHM_VATS
2330-
&& !is_slave_replication) {
2355+
&& !thd_is_replication_slave_thread(trx->mysql_thd)) {
23312356
if (type_mode & LOCK_WAIT) {
23322357
HASH_INSERT(lock_t, hash, lock_sys->rec_hash, rec_fold, lock);
23332358
} else {
@@ -2339,7 +2364,7 @@ lock_rec_create(
23392364
}
23402365
#else
23412366
if (innodb_lock_schedule_algorithm == INNODB_LOCK_SCHEDULE_ALGORITHM_VATS
2342-
&& !is_slave_replication) {
2367+
&& !thd_is_replication_slave_thread(trx->mysql_thd)) {
23432368
if (type_mode & LOCK_WAIT) {
23442369
HASH_INSERT(lock_t, hash, lock_sys->rec_hash, rec_fold, lock);
23452370
} else {
@@ -2512,18 +2537,19 @@ lock_rec_enqueue_waiting(
25122537
result = DB_LOCK_WAIT;
25132538
}
25142539

2540+
25152541
// Move it only when it does not cause a deadlock.
2516-
if (innodb_lock_schedule_algorithm
2542+
if (err != DB_DEADLOCK
2543+
&& innodb_lock_schedule_algorithm
25172544
== INNODB_LOCK_SCHEDULE_ALGORITHM_VATS
2518-
&& !is_slave_replication) {
2545+
&& !thd_is_replication_slave_thread(lock->trx->mysql_thd)
2546+
&& !trx_is_high_priority(lock->trx)) {
25192547

2520-
HASH_DELETE(lock_t, hash, lock_sys->rec_hash,
2521-
lock_rec_fold(lock->un_member.rec_lock.space,
2522-
lock->un_member.rec_lock.page_noo), lock);
2523-
lock_rec_insert_by_trx_age(lock);
2524-
if (lock_get_wait(lock) && !lock_rec_has_to_wait_in_queue(lock)) {
2525-
lock_grant(lock, true);
2526-
result = DB_SUCCESS_LOCKED_REC;
2548+
HASH_DELETE(lock_t, hash, lock_hash_get(lock->type_mode),
2549+
m_rec_id.fold(), lock);
2550+
dberr_t res = lock_rec_insert_by_trx_age(lock);
2551+
if (res != DB_SUCCESS) {
2552+
return res;
25272553
}
25282554
}
25292555

@@ -2963,6 +2989,7 @@ lock_grant(
29632989
bool owns_trx_mutex) /*!< in: whether lock->trx->mutex is owned */
29642990
{
29652991
ut_ad(lock_mutex_own());
2992+
ut_ad(trx_mutex_own(lock->trx) == owns_trx_mutex);
29662993

29672994
lock_reset_lock_and_trx_wait(lock);
29682995

@@ -3060,29 +3087,45 @@ lock_rec_cancel(
30603087
static
30613088
void
30623089
lock_grant_and_move_on_page(
3090+
hash_table_t *lock_hash,
30633091
ulint space,
30643092
ulint page_no)
30653093
{
30663094
lock_t* lock;
30673095
lock_t* previous;
30683096
ulint rec_fold = lock_rec_fold(space, page_no);
30693097

3070-
previous = (lock_t *) hash_get_nth_cell(lock_sys->rec_hash,
3071-
hash_calc_hash(rec_fold, lock_sys->rec_hash))->node;
3098+
previous = (lock_t *) hash_get_nth_cell(lock_hash,
3099+
hash_calc_hash(rec_fold, lock_hash))->node;
3100+
if (previous == NULL) {
3101+
return;
3102+
}
3103+
if (previous->un_member.rec_lock.space == space &&
3104+
previous->un_member.rec_lock.page_no == page_no) {
3105+
lock = previous;
3106+
}
3107+
else {
3108+
while (previous->hash &&
3109+
(previous->hash->un_member.rec_lock.space != space ||
3110+
previous->hash->un_member.rec_lock.page_no != page_no)) {
3111+
previous = previous->hash;
3112+
}
3113+
lock = previous->hash;
3114+
}
3115+
3116+
ut_ad(previous->hash == lock || previous == lock);
30723117
/* Grant locks if there are no conflicting locks ahead.
30733118
Move granted locks to the head of the list. */
3074-
for (lock = lock_rec_get_first_on_page_addr(lock_sys->rec_hash, space,
3075-
page_no);
3076-
lock != NULL;) {
3119+
for (;lock != NULL;) {
30773120

30783121
/* If the lock is a wait lock on this page, and it does not need to wait. */
30793122
if ((lock->un_member.rec_lock.space == space)
30803123
&& (lock->un_member.rec_lock.page_no == page_no)
30813124
&& lock_get_wait(lock)
30823125
&& !lock_rec_has_to_wait_in_queue(lock)) {
3083-
3126+
30843127
lock_grant(lock, false);
3085-
3128+
30863129
if (previous != NULL) {
30873130
/* Move the lock to the head of the list. */
30883131
HASH_GET_NEXT(hash, previous) = HASH_GET_NEXT(hash, lock);
@@ -3144,7 +3187,8 @@ lock_rec_dequeue_from_page(
31443187
MONITOR_DEC(MONITOR_NUM_RECLOCK);
31453188

31463189
if (innodb_lock_schedule_algorithm
3147-
== INNODB_LOCK_SCHEDULE_ALGORITHM_FCFS || is_slave_replication) {
3190+
== INNODB_LOCK_SCHEDULE_ALGORITHM_FCFS ||
3191+
thd_is_replication_slave_thread(in_lock->trx->mysql_thd)) {
31483192

31493193
/* Check if waiting locks in the queue can now be granted:
31503194
grant locks if there are no conflicting locks ahead. Stop at
@@ -5479,6 +5523,7 @@ lock_table_dequeue(
54795523
static
54805524
void
54815525
lock_grant_and_move_on_rec(
5526+
hash_table_t *lock_hash,
54825527
lock_t *first_lock,
54835528
ulint heap_no)
54845529
{
@@ -5492,11 +5537,23 @@ lock_grant_and_move_on_rec(
54925537
page_no = first_lock->un_member.rec_lock.page_no;
54935538
rec_fold = lock_rec_fold(space, page_no);
54945539

5495-
previous = (lock_t *) hash_get_nth_cell(lock_sys->rec_hash,
5496-
hash_calc_hash(rec_fold, lock_sys->rec_hash))->node;
5540+
previous = (lock_t *) hash_get_nth_cell(lock_hash,
5541+
hash_calc_hash(rec_fold, lock_hash))->node;
5542+
if (previous == NULL) {
5543+
return;
5544+
}
5545+
if (previous == first_lock) {
5546+
lock = previous;
5547+
} else {
5548+
while (previous->hash &&
5549+
previous->hash != first_lock) {
5550+
previous = previous->hash;
5551+
}
5552+
lock = previous->hash;
5553+
}
54975554
/* Grant locks if there are no conflicting locks ahead.
54985555
Move granted locks to the head of the list. */
5499-
for (lock = first_lock; lock != NULL;) {
5556+
for (;lock != NULL;) {
55005557

55015558
/* If the lock is a wait lock on this page, and it does not need to wait. */
55025559
if (lock->un_member.rec_lock.space == space
@@ -5587,7 +5644,8 @@ lock_rec_unlock(
55875644
lock_rec_reset_nth_bit(lock, heap_no);
55885645

55895646
if (innodb_lock_schedule_algorithm
5590-
== INNODB_LOCK_SCHEDULE_ALGORITHM_FCFS || is_slave_replication) {
5647+
== INNODB_LOCK_SCHEDULE_ALGORITHM_FCFS ||
5648+
thd_is_replication_slave_thread(lock->trx->mysql_thd)) {
55915649

55925650
/* Check if we can now grant waiting lock requests */
55935651

storage/xtradb/trx/trx0trx.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,8 @@ trx_start_low(
11171117

11181118
trx->start_time = ut_time();
11191119

1120+
trx->start_time_micro = clock();
1121+
11201122
MONITOR_INC(MONITOR_TRX_ACTIVE);
11211123
}
11221124

0 commit comments

Comments
 (0)