Bug #59309 Cleanup MDL - THD interface
Submitted: 5 Jan 2011 13:56 Modified: 30 Jan 2011 18:15
Reporter: Tor Didriksen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Tests Severity:S3 (Non-critical)
Version:5.6 OS:Any
Assigned to: Tor Didriksen CPU Architecture:Any

[5 Jan 2011 13:56] Tor Didriksen
Description:
The interface between MDL and THD currently consists of a small set of free functions:
thd_enter_cond
thd_exit_cond
mysql_notify_thread_having_shared_lock

Replace these with an interface, for better unit testing.
Currently the unit test has a single global mutex for mocking away
the notification functions above.

Using an interface instead, we can have an arbitrary number of test threads.

How to repeat:
Read the code.

Suggested fix:
class MDL_context_owner
{
public:
  virtual ~MDL_context_owner() {}

  /**
     @see THD::enter_cond() and THD::exit_cond()
   */
  virtual const char* enter_cond(mysql_cond_t *cond, mysql_mutex_t* mutex,
                                 const char* msg) = 0;
  virtual void exit_cond(const char* old_msg) = 0;
  /**
     Has the owner thread been killed?
   */
  virtual int  is_killed() = 0;

  virtual THD* get_thd() = 0;

  /**
     @see mysql_notify_thread_having_shared_lock()
   */
  virtual bool notify_shared_lock(MDL_context_owner *in_use,
                                  bool needs_thr_lock_abort) = 0;
};
[5 Jan 2011 14:51] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/127982

3462 Tor Didriksen	2011-01-05
      Bug #59309  Cleanup MDL - THD interface 
      
      Define an abstract interface MDL_context_owner
      which is implemented by THD and the unit test classes.
     @ sql/mdl.cc
        Use m_owner rather than thd when notifying about waiting events.
     @ sql/mdl.h
        Introduce a new interface (abstract class) MDL_context_owner.
        Remove declaration of the free functions used previously.
     @ sql/sql_base.cc
        Remove note about broken interface.
     @ sql/sql_class.h
        THD now implements the MDL_context_owner interface.
     @ unittest/gunit/mdl-t.cc
        Remove mock free-functions.
        Let the test fixture class and the test thread class implement MDL_context_owner
     @ unittest/gunit/mdl_mytap-t.cc
        Remove mock free-functions.
        Let the test fixture class and the test thread class implement MDL_context_owner
     @ unittest/gunit/test_mdl_context_owner.h
        Common implementation of MDL_context_owner for the two MDL unit tests.
[6 Jan 2011 13:03] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/128076

3465 Tor Didriksen	2011-01-06
      Bug #59309  Cleanup MDL - THD interface 
      
      Define an abstract interface MDL_context_owner
      which is implemented by THD and the unit test classes.
     @ sql/mdl.cc
        Use m_owner rather than thd when notifying about waiting events.
     @ sql/mdl.h
        Introduce a new interface (abstract class) MDL_context_owner.
        Remove declaration of the free functions used previously.
     @ sql/sql_base.cc
        Rename mysql_notify_thread_having_shared_lock to THD::notify_shared_lock
        and move it to sql_class.cc
     @ sql/sql_class.cc
        Rename mysql_notify_thread_having_shared_lock to THD::notify_shared_lock
        and move it here.
     @ sql/sql_class.h
        THD now implements the MDL_context_owner interface.
     @ sql/sql_insert.cc
        Update comment about notify_shared_lock
     @ unittest/gunit/mdl-t.cc
        Remove mock free-functions.
        Let the test fixture class and the test thread class implement MDL_context_owner
     @ unittest/gunit/mdl_mytap-t.cc
        Remove mock free-functions.
        Let the test fixture class and the test thread class implement MDL_context_owner
     @ unittest/gunit/test_mdl_context_owner.h
        Common implementation of MDL_context_owner for the two MDL unit tests.
[6 Jan 2011 14:21] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/128081

3465 Tor Didriksen	2011-01-06
      Bug #59309  Cleanup MDL - THD interface 
      
      Define an abstract interface MDL_context_owner
      which is implemented by THD and the unit test classes.
     @ sql/mdl.cc
        Use m_owner rather than thd when notifying about waiting events.
     @ sql/mdl.h
        Introduce a new interface (abstract class) MDL_context_owner.
        Remove declaration of the free functions used previously.
     @ sql/sql_base.cc
        Rename mysql_notify_thread_having_shared_lock to THD::notify_shared_lock
        and move it to sql_class.cc
     @ sql/sql_class.cc
        Rename mysql_notify_thread_having_shared_lock to THD::notify_shared_lock
        and move it here.
     @ sql/sql_class.h
        THD now implements the MDL_context_owner interface.
     @ sql/sql_insert.cc
        Update comment about notify_shared_lock
     @ unittest/gunit/mdl-t.cc
        Remove mock free-functions.
        Let the test fixture class and the test thread class implement MDL_context_owner
     @ unittest/gunit/mdl_mytap-t.cc
        Remove mock free-functions.
        Let the test fixture class and the test thread class implement MDL_context_owner
     @ unittest/gunit/test_mdl_context_owner.h
        Common implementation of MDL_context_owner for the two MDL unit tests.
[6 Jan 2011 14:30] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/128084

3465 Tor Didriksen	2011-01-06
      Bug #59309  Cleanup MDL - THD interface 
      
      Define an abstract interface MDL_context_owner
      which is implemented by THD and the unit test classes.
     @ sql/mdl.cc
        Use m_owner rather than thd when notifying about waiting events.
     @ sql/mdl.h
        Introduce a new interface (abstract class) MDL_context_owner.
        Remove declaration of the free functions used previously.
     @ sql/sql_base.cc
        Rename mysql_notify_thread_having_shared_lock to THD::notify_shared_lock
        and move it to sql_class.cc
     @ sql/sql_class.cc
        Rename mysql_notify_thread_having_shared_lock to THD::notify_shared_lock
        and move it here.
     @ sql/sql_class.h
        THD now implements the MDL_context_owner interface.
     @ sql/sql_insert.cc
        Update comment about notify_shared_lock
     @ unittest/gunit/mdl-t.cc
        Remove mock free-functions.
        Let the test fixture class and the test thread class implement MDL_context_owner
     @ unittest/gunit/mdl_mytap-t.cc
        Remove mock free-functions.
        Let the test fixture class and the test thread class implement MDL_context_owner
     @ unittest/gunit/test_mdl_context_owner.h
        Common implementation of MDL_context_owner for the two MDL unit tests.
[10 Jan 2011 8:42] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/128251

3471 Tor Didriksen	2011-01-06
      Bug #59309  Cleanup MDL - THD interface 
      
      Define an abstract interface MDL_context_owner
      which is implemented by THD and the unit test classes.
     @ sql/mdl.cc
        Use m_owner rather than thd when notifying about waiting events.
     @ sql/mdl.h
        Introduce a new interface (abstract class) MDL_context_owner.
        Remove declaration of the free functions used previously.
     @ sql/sql_base.cc
        Rename mysql_notify_thread_having_shared_lock to THD::notify_shared_lock
        and move it to sql_class.cc
     @ sql/sql_class.cc
        Rename mysql_notify_thread_having_shared_lock to THD::notify_shared_lock
        and move it here.
     @ sql/sql_class.h
        THD now implements the MDL_context_owner interface.
     @ sql/sql_insert.cc
        Update comment about notify_shared_lock
     @ unittest/gunit/mdl-t.cc
        Remove mock free-functions.
        Let the test fixture class and the test thread class implement MDL_context_owner
     @ unittest/gunit/mdl_mytap-t.cc
        Remove mock free-functions.
        Let the test fixture class and the test thread class implement MDL_context_owner
     @ unittest/gunit/test_mdl_context_owner.h
        Common implementation of MDL_context_owner for the two MDL unit tests.
[11 Jan 2011 6:59] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/128383

3482 Tor Didriksen	2011-01-06
      Bug #59309  Cleanup MDL - THD interface 
      
      Define an abstract interface MDL_context_owner
      which is implemented by THD and the unit test classes.
     @ sql/mdl.cc
        Use m_owner rather than thd when notifying about waiting events.
     @ sql/mdl.h
        Introduce a new interface (abstract class) MDL_context_owner.
        Remove declaration of the free functions used previously.
     @ sql/sql_base.cc
        Rename mysql_notify_thread_having_shared_lock to THD::notify_shared_lock
        and move it to sql_class.cc
     @ sql/sql_class.cc
        Rename mysql_notify_thread_having_shared_lock to THD::notify_shared_lock
        and move it here.
     @ sql/sql_class.h
        THD now implements the MDL_context_owner interface.
     @ sql/sql_insert.cc
        Update comment about notify_shared_lock
     @ unittest/gunit/mdl-t.cc
        Remove mock free-functions.
        Let the test fixture class and the test thread class implement MDL_context_owner
     @ unittest/gunit/mdl_mytap-t.cc
        Remove mock free-functions.
        Let the test fixture class and the test thread class implement MDL_context_owner
     @ unittest/gunit/test_mdl_context_owner.h
        Common implementation of MDL_context_owner for the two MDL unit tests.
[27 Jan 2011 15:31] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/129785

3562 Tor Didriksen	2011-01-27
      Bug #59309  Cleanup MDL - THD interface 
      
      Define an abstract interface MDL_context_owner
      which is implemented by THD and the unit test classes.
      
      This allows us to separate MDL from the THD and the rest of the server code,
      and do standalone unit testing of the MDL module.
     @ sql/mdl.cc
        Use m_owner rather than thd when notifying about waiting events.
     @ sql/mdl.h
        Introduce a new interface (abstract class) MDL_context_owner.
        Remove declaration of the free functions used previously.
     @ sql/sql_base.cc
        Rename mysql_notify_thread_having_shared_lock to THD::notify_shared_lock
        and move it to sql_class.cc
     @ sql/sql_class.cc
        Rename mysql_notify_thread_having_shared_lock to THD::notify_shared_lock
        and move it here.
     @ sql/sql_class.h
        THD now implements the MDL_context_owner interface.
     @ sql/sql_insert.cc
        Update comment about notify_shared_lock
     @ unittest/gunit/mdl-t.cc
        Remove mock free-functions.
        Let the test fixture class and the test thread class implement MDL_context_owner
     @ unittest/gunit/mdl_mytap-t.cc
        Remove mock free-functions.
        Let the test fixture class and the test thread class implement MDL_context_owner
     @ unittest/gunit/test_mdl_context_owner.h
        Common implementation of MDL_context_owner for the two MDL unit tests.
[27 Jan 2011 15:32] Bugs System
Pushed into mysql-trunk 5.6.2 (revid:tor.didriksen@oracle.com-20110127153118-qo3gyazm32xcwsw8) (version source revid:tor.didriksen@oracle.com-20110127153118-qo3gyazm32xcwsw8) (merge vers: 5.6.2) (pib:24)
[30 Jan 2011 18:15] Paul DuBois
No user implications. No changelog entry needed.