Commit d62f99f8 authored by unknown's avatar unknown

Bug #28992: trigger fails in pushbuild

 - fixed wrong test case for bug 20903
 - closed the dangling connections in trigger.test
 - GET_LOCK() and RELEASE_LOCK() now produce more detailed log
 - fixed an omission in GET_LOCK() : assign the thread_id when
    acquiring the lock.


mysql-test/r/trigger.result:
  Bug #28992: test case updated
mysql-test/t/trigger.test:
  Bug #28992: test case updated. dangling connections closed.
sql/item_func.cc:
  Bug #28992: 
   - GET_LOCK() and RELEASE_LOCK() now produce more detailed log
   - fixed an omission in GET_LOCK() : assign the thread_id when
      acquiring the lock.
parent 66866ba3
...@@ -1454,19 +1454,22 @@ CREATE TABLE t2 (id INTEGER); ...@@ -1454,19 +1454,22 @@ CREATE TABLE t2 (id INTEGER);
INSERT INTO t2 VALUES (1),(2); INSERT INTO t2 VALUES (1),(2);
CREATE TRIGGER t1_test AFTER INSERT ON t1 FOR EACH ROW CREATE TRIGGER t1_test AFTER INSERT ON t1 FOR EACH ROW
INSERT INTO t2 VALUES (new.id); INSERT INTO t2 VALUES (new.id);
SELECT GET_LOCK('B26162',20); SELECT GET_LOCK('B26162',120);
GET_LOCK('B26162',20) GET_LOCK('B26162',120)
1 1
SELECT 'rl_acquirer', GET_LOCK('B26162',5), id FROM t2 WHERE id = 1; SELECT 'rl_acquirer', GET_LOCK('B26162',120), id FROM t2 WHERE id = 1;
SET SESSION LOW_PRIORITY_UPDATES=1; SET SESSION LOW_PRIORITY_UPDATES=1;
SET GLOBAL LOW_PRIORITY_UPDATES=1; SET GLOBAL LOW_PRIORITY_UPDATES=1;
INSERT INTO t1 VALUES (5); INSERT INTO t1 VALUES (5);
SELECT 'rl_contender', id FROM t2 WHERE id > 1; SELECT 'rl_contender', id FROM t2 WHERE id > 1;
SELECT RELEASE_LOCK('B26162'); SELECT RELEASE_LOCK('B26162');
RELEASE_LOCK('B26162') RELEASE_LOCK('B26162')
0 1
rl_acquirer GET_LOCK('B26162',5) id rl_acquirer GET_LOCK('B26162',120) id
rl_acquirer 0 1 rl_acquirer 1 1
SELECT RELEASE_LOCK('B26162');
RELEASE_LOCK('B26162')
1
rl_contender id rl_contender id
rl_contender 2 rl_contender 2
DROP TRIGGER t1_test; DROP TRIGGER t1_test;
......
...@@ -1763,6 +1763,9 @@ select * from t1; ...@@ -1763,6 +1763,9 @@ select * from t1;
select * from t3; select * from t3;
drop table t1, t2, t3; drop table t1, t2, t3;
disconnect addconroot1;
disconnect addconroot2;
disconnect addconwithoutdb;
# #
# Bug #26162: Trigger DML ignores low_priority_updates setting # Bug #26162: Trigger DML ignores low_priority_updates setting
# #
...@@ -1776,19 +1779,23 @@ INSERT INTO t2 VALUES (1),(2); ...@@ -1776,19 +1779,23 @@ INSERT INTO t2 VALUES (1),(2);
CREATE TRIGGER t1_test AFTER INSERT ON t1 FOR EACH ROW CREATE TRIGGER t1_test AFTER INSERT ON t1 FOR EACH ROW
INSERT INTO t2 VALUES (new.id); INSERT INTO t2 VALUES (new.id);
CONNECT (rl_holder, localhost, root,,);
CONNECT (rl_acquirer, localhost, root,,); CONNECT (rl_acquirer, localhost, root,,);
CONNECT (wl_acquirer, localhost, root,,); CONNECT (wl_acquirer, localhost, root,,);
CONNECT (rl_contender, localhost, root,,); CONNECT (rl_contender, localhost, root,,);
SELECT GET_LOCK('B26162',20); CONNECTION rl_holder;
SELECT GET_LOCK('B26162',120);
CONNECTION rl_acquirer; CONNECTION rl_acquirer;
--send --send
SELECT 'rl_acquirer', GET_LOCK('B26162',5), id FROM t2 WHERE id = 1; SELECT 'rl_acquirer', GET_LOCK('B26162',120), id FROM t2 WHERE id = 1;
CONNECTION wl_acquirer; CONNECTION wl_acquirer;
SET SESSION LOW_PRIORITY_UPDATES=1; SET SESSION LOW_PRIORITY_UPDATES=1;
SET GLOBAL LOW_PRIORITY_UPDATES=1; SET GLOBAL LOW_PRIORITY_UPDATES=1;
#need to wait for rl_acquirer to lock on the B26162 lock
sleep 2;
--send --send
INSERT INTO t1 VALUES (5); INSERT INTO t1 VALUES (5);
...@@ -1798,13 +1805,16 @@ CONNECTION rl_contender; ...@@ -1798,13 +1805,16 @@ CONNECTION rl_contender;
--send --send
SELECT 'rl_contender', id FROM t2 WHERE id > 1; SELECT 'rl_contender', id FROM t2 WHERE id > 1;
CONNECTION default; CONNECTION rl_holder;
#need to wait for wl_acquirer and rl_contender to lock on t2
sleep 2;
SELECT RELEASE_LOCK('B26162'); SELECT RELEASE_LOCK('B26162');
CONNECTION wl_acquirer;
--reap
CONNECTION rl_acquirer; CONNECTION rl_acquirer;
--reap --reap
SELECT RELEASE_LOCK('B26162');
CONNECTION wl_acquirer;
--reap
CONNECTION rl_contender; CONNECTION rl_contender;
--reap --reap
...@@ -1812,6 +1822,7 @@ CONNECTION default; ...@@ -1812,6 +1822,7 @@ CONNECTION default;
DISCONNECT rl_acquirer; DISCONNECT rl_acquirer;
DISCONNECT wl_acquirer; DISCONNECT wl_acquirer;
DISCONNECT rl_contender; DISCONNECT rl_contender;
DISCONNECT rl_holder;
DROP TRIGGER t1_test; DROP TRIGGER t1_test;
DROP TABLE t1,t2; DROP TABLE t1,t2;
......
...@@ -3449,6 +3449,7 @@ longlong Item_func_get_lock::val_int() ...@@ -3449,6 +3449,7 @@ longlong Item_func_get_lock::val_int()
THD *thd=current_thd; THD *thd=current_thd;
User_level_lock *ull; User_level_lock *ull;
int error; int error;
DBUG_ENTER("Item_func_get_lock::val_int");
/* /*
In slave thread no need to get locks, everything is serialized. Anyway In slave thread no need to get locks, everything is serialized. Anyway
...@@ -3458,7 +3459,7 @@ longlong Item_func_get_lock::val_int() ...@@ -3458,7 +3459,7 @@ longlong Item_func_get_lock::val_int()
it's not guaranteed to be same as on master. it's not guaranteed to be same as on master.
*/ */
if (thd->slave_thread) if (thd->slave_thread)
return 1; DBUG_RETURN(1);
pthread_mutex_lock(&LOCK_user_locks); pthread_mutex_lock(&LOCK_user_locks);
...@@ -3466,8 +3467,10 @@ longlong Item_func_get_lock::val_int() ...@@ -3466,8 +3467,10 @@ longlong Item_func_get_lock::val_int()
{ {
pthread_mutex_unlock(&LOCK_user_locks); pthread_mutex_unlock(&LOCK_user_locks);
null_value=1; null_value=1;
return 0; DBUG_RETURN(0);
} }
DBUG_PRINT("info", ("lock %.*s, thd=%ld", res->length(), res->ptr(),
(long) thd->real_id));
null_value=0; null_value=0;
if (thd->ull) if (thd->ull)
...@@ -3486,14 +3489,17 @@ longlong Item_func_get_lock::val_int() ...@@ -3486,14 +3489,17 @@ longlong Item_func_get_lock::val_int()
delete ull; delete ull;
pthread_mutex_unlock(&LOCK_user_locks); pthread_mutex_unlock(&LOCK_user_locks);
null_value=1; // Probably out of memory null_value=1; // Probably out of memory
return 0; DBUG_RETURN(0);
} }
ull->thread=thd->real_id; ull->thread=thd->real_id;
ull->thread_id=thd->thread_id;
thd->ull=ull; thd->ull=ull;
pthread_mutex_unlock(&LOCK_user_locks); pthread_mutex_unlock(&LOCK_user_locks);
return 1; // Got new lock DBUG_PRINT("info", ("made new lock"));
DBUG_RETURN(1); // Got new lock
} }
ull->count++; ull->count++;
DBUG_PRINT("info", ("ull->count=%d", ull->count));
/* /*
Structure is now initialized. Try to get the lock. Structure is now initialized. Try to get the lock.
...@@ -3507,9 +3513,13 @@ longlong Item_func_get_lock::val_int() ...@@ -3507,9 +3513,13 @@ longlong Item_func_get_lock::val_int()
error= 0; error= 0;
while (ull->locked && !thd->killed) while (ull->locked && !thd->killed)
{ {
DBUG_PRINT("info", ("waiting on lock"));
error= pthread_cond_timedwait(&ull->cond,&LOCK_user_locks,&abstime); error= pthread_cond_timedwait(&ull->cond,&LOCK_user_locks,&abstime);
if (error == ETIMEDOUT || error == ETIME) if (error == ETIMEDOUT || error == ETIME)
{
DBUG_PRINT("info", ("lock wait timeout"));
break; break;
}
error= 0; error= 0;
} }
...@@ -3533,6 +3543,7 @@ longlong Item_func_get_lock::val_int() ...@@ -3533,6 +3543,7 @@ longlong Item_func_get_lock::val_int()
ull->thread_id= thd->thread_id; ull->thread_id= thd->thread_id;
thd->ull=ull; thd->ull=ull;
error=0; error=0;
DBUG_PRINT("info", ("got the lock"));
} }
pthread_mutex_unlock(&LOCK_user_locks); pthread_mutex_unlock(&LOCK_user_locks);
...@@ -3542,7 +3553,7 @@ longlong Item_func_get_lock::val_int() ...@@ -3542,7 +3553,7 @@ longlong Item_func_get_lock::val_int()
thd->mysys_var->current_cond= 0; thd->mysys_var->current_cond= 0;
pthread_mutex_unlock(&thd->mysys_var->mutex); pthread_mutex_unlock(&thd->mysys_var->mutex);
return !error ? 1 : 0; DBUG_RETURN(!error ? 1 : 0);
} }
...@@ -3560,11 +3571,14 @@ longlong Item_func_release_lock::val_int() ...@@ -3560,11 +3571,14 @@ longlong Item_func_release_lock::val_int()
String *res=args[0]->val_str(&value); String *res=args[0]->val_str(&value);
User_level_lock *ull; User_level_lock *ull;
longlong result; longlong result;
THD *thd=current_thd;
DBUG_ENTER("Item_func_release_lock::val_int");
if (!res || !res->length()) if (!res || !res->length())
{ {
null_value=1; null_value=1;
return 0; DBUG_RETURN(0);
} }
DBUG_PRINT("info", ("lock %.*s", res->length(), res->ptr()));
null_value=0; null_value=0;
result=0; result=0;
...@@ -3577,19 +3591,20 @@ longlong Item_func_release_lock::val_int() ...@@ -3577,19 +3591,20 @@ longlong Item_func_release_lock::val_int()
} }
else else
{ {
#ifdef EMBEDDED_LIBRARY DBUG_PRINT("info", ("ull->locked=%d ull->thread=%ld thd=%ld",
if (ull->locked && pthread_equal(current_thd->real_id,ull->thread)) (int) ull->locked,
#else (long)ull->thread,
if (ull->locked && pthread_equal(pthread_self(),ull->thread)) (long)thd->real_id));
#endif if (ull->locked && pthread_equal(thd->real_id,ull->thread))
{ {
DBUG_PRINT("info", ("release lock"));
result=1; // Release is ok result=1; // Release is ok
item_user_lock_release(ull); item_user_lock_release(ull);
current_thd->ull=0; thd->ull=0;
} }
} }
pthread_mutex_unlock(&LOCK_user_locks); pthread_mutex_unlock(&LOCK_user_locks);
return result; DBUG_RETURN(result);
} }
......
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