List:Maria Storage Engine« Previous MessageNext Message »
From:Michael Widenius Date:December 15 2008 6:40pm
Subject:Re: bzr commit into MySQL/Maria:mysql-maria branch (monty:2701) WL#3262
View as plain text  
Hi!

>>>>> "Guilhem" == Guilhem Bichot <guilhem@stripped> writes:

Guilhem> Hello Monty,
Guilhem> just noticed something while playing with 
Guilhem> my_pthread_mutex_lock(NO_DETECTION):

Guilhem> Michael Widenius a écrit, Le 12/02/2008 11:03 PM:
>> #At bzr+ssh://bk-internal.mysql.com/bzrroot/server/mysql-maria/
>> 
>> 2701 Michael Widenius	2008-12-03
>> WL#3262 add mutex lock order checking to safemutex (also called
> safe_mutex_deadlock_detector)
>> This writes a warning on stderr if one uses mutex in different order,
>> like if one in one case would lock mutex in the order A,B and in another case
>> would lock mutex in the order B,A
>> This is inspired by and loosely based on the LOCKDEP patch by Jonas
>> Wrong mutex order is either fixed or mutex are marked with
> MYF_NO_DEADLOCK_DETECTION
>> if used inconsistently (need to be fixed by server team)


>> -int safe_mutex_lock(safe_mutex_t *mp, my_bool try_lock, const char *file, uint
> line)
>> +int safe_mutex_lock(safe_mutex_t *mp, myf my_flags, const char *file,
>> +                    uint line)
>> {
>> int error;
>> DBUG_PRINT("mutex", ("%s (0x%lx) locking", mp->name ? mp->name : "Null",
>> @@ -110,12 +182,13 @@ int safe_mutex_lock(safe_mutex_t *mp, my
>> pthread_mutex_lock(&mp->global);
>> if (mp->count > 0)
>> {
>> -    if (try_lock)
>> -    {
>> -      pthread_mutex_unlock(&mp->global);
>> -      return EBUSY;
>> -    }
>> -    else if (pthread_equal(pthread_self(),mp->thread))
>> +    /*
>> +      Check that we are not trying to lock mutex twice. This is an error
>> +      even if we are using 'try_lock' as it's not portably what happens
>> +      if you lock the mutex many times and this is in any case bad
>> +      behaviour that should not be encouraged
>> +    */
>> +    if (pthread_equal(pthread_self(),mp->thread))
>> {
>> fprintf(stderr,
>> "safe_mutex: Trying to lock mutex at %s, line %d, when the"
>> @@ -143,7 +216,7 @@ int safe_mutex_lock(safe_mutex_t *mp, my
>> instead just return EBUSY, since this is the expected behaviour
>> of trylock().
>> */
>> -  if (try_lock)
>> +  if (my_flags & MYF_TRY_LOCK)
>> {
>> error= pthread_mutex_trylock(&mp->mutex);
>> if (error == EBUSY)
>> @@ -169,7 +242,93 @@ int safe_mutex_lock(safe_mutex_t *mp, my
>> }
mp-> file= file;
mp-> line= line;
>> +  mp->active_flags= mp->create_flags | my_flags;

Guilhem> So if caller passes my_flags = MYF_NO_DEADLOCK_DETECTION (like in 
Guilhem> ha_ndbcluster_binlog.cc, where we want to disable detection just for one 
Guilhem> lock call), this changes mp->active_flags. But as far as I can see, this 
Guilhem> change is not undone at safe_mutex_unlock(). Does the detection become 
Guilhem> disabled forever?

mp->active_flags is set for that mutex for the duration of the lock.
mp->create_flags is the flag for lifetime changes.

As can bee seen in the above patch, next call to safe_mutex_lock()
will set active_flags to a new value independent of it's previous
value.

Regards,
Monty


Thread
bzr commit into MySQL/Maria:mysql-maria branch (monty:2701) WL#3262Michael Widenius2 Dec
  • Re: bzr commit into MySQL/Maria:mysql-maria branch (monty:2701) WL#3262Guilhem Bichot12 Dec
    • Re: bzr commit into MySQL/Maria:mysql-maria branch (monty:2701) WL#3262Michael Widenius15 Dec