1. 12 Feb, 2010 1 commit
    • Dmitry Lenev's avatar
      Fix for bug #50908 "Assertion `handler_tables_hash.records == 0' · 249be178
      Dmitry Lenev authored
      failed in enter_locked_tables_mode".
      
      Server was aborted due to assertion failure when one tried to 
      execute statement requiring prelocking (i.e. firing triggers
      or using stored functions) while having open HANDLERs.
      
      The problem was that THD::enter_locked_tables_mode() method
      which was called at the beginning of execution of prelocked 
      statement assumed there are no open HANDLERs. It had to do 
      so because corresponding THD::leave_locked_tables_mode()
      method was unable to properly restore MDL sentinel when
      leaving LOCK TABLES/prelocked mode in the presence of open 
      HANDLERs.
      
      This patch solves this problem by changing the latter method
      to properly restore MDL sentinel and thus removing need for 
      this assumption. As a side-effect, it lifts unjustified
      limitation by allowing to keep HANDLERs open when entering 
      LOCK TABLES mode.
      
      mysql-test/include/handler.inc:
        Adjusted tests after making LOCK TABLES not to close
        open HANDLERs. Added coverage for bug #50908
        "Assertion `handler_tables_hash.records == 0' failed
        in enter_locked_tables_mode".
      mysql-test/r/handler_innodb.result:
        Updated test results (see include/handler.inc).
      mysql-test/r/handler_myisam.result:
        Updated test results (see include/handler.inc).
      sql/mysql_priv.h:
        Introduced mysql_ha_move_tickets_after_trans_sentinel()
        routine which allows to move tickets for metadata locks
        corresponding to open HANDLERs after transaction sentinel.
      sql/sql_class.cc:
        Changed THD::leave_locked_tables_mode() to correctly restore 
        MDL sentinel value in the presence of open HANDLERs.
      sql/sql_class.h:
        Removed assert from THD::enter_locked_tables_mode() as we
        no longer have to close HANDLERs when entering LOCK TABLES 
        or prelocked modes. Instead we keep them open and correctly
        restore MDL sentinel value after leaving them.
        Removal of assert also fixes problem from the bug report.
      sql/sql_handler.cc:
        Introduced mysql_ha_move_tickets_after_trans_sentinel()
        routine which allows to move tickets for metadata locks
        corresponding to open HANDLERs after transaction sentinel.
      sql/sql_parse.cc:
        We no longer have to close HANDLERs when entering LOCK TABLES 
        mode. Instead we keep them open and simply correctly restore 
        MDL sentinel value after leaving this mode.
      249be178
  2. 08 Feb, 2010 1 commit
    • Dmitry Lenev's avatar
      Fix for bug #50913 "Deadlock between open_and_lock_tables_derived · e7d689f5
      Dmitry Lenev authored
      and MDL".
      
      Concurrent execution of a multi-DELETE statement and ALTER
      TABLE statement which affected one of the tables used in
      the multi-DELETE sometimes led to deadlock.
      Similar deadlocks might have occured when one performed
      INSERT/UPDATE/DELETE on a view and concurrently executed
      ALTER TABLE for the view's underlying table, or when one
      concurrently executed TRUNCATE TABLE for InnoDB table and
      ALTER TABLE for the same table.
      
      These deadlocks were caused by a discrepancy between types of
      metadata and thr_lock.cc locks acquired by those statements.
      
      What happened was that multi-DELETE/TRUNCATE/DML-through-the-
      view statement in the first connection acquired SR lock on a
      table, then ALTER TABLE would come in in the second connection
      and acquire SNW metadata lock and TL_WRITE_ALLOW_READ
      thr_lock.c lock and then would start waiting for the first
      connection during lock upgrade. After that the statement in
      the first connection would try to acquire TL_WRITE lock on
      table and would start waiting for the second connection,
      creating a deadlock.
      
      This patch solves this problem by ensuring that we acquire
      SW metadata lock in all cases in which we acquiring write
      thr_lock.c lock. This guarantees that deadlocks like the
      one described above won't occur since all lock conflicts
      in such situation are resolved within MDL subsystem.
      
      This patch also adds assert which should guarantee that
      such situations won't arise in future.
      
      mysql-test/r/lock_multi.result:
        Added main test for bug #50913 "Deadlock between
        open_and_lock_tables_derived and MDL".
      mysql-test/r/mdl_sync.result:
        Added additional coverage for bug #50913 "Deadlock
        between open_and_lock_tables_derived and MDL".
      mysql-test/t/lock_multi.test:
        Added main test for bug #50913 "Deadlock between
        open_and_lock_tables_derived and MDL".
      mysql-test/t/mdl_sync.test:
        Added additional coverage for bug #50913 "Deadlock
        between open_and_lock_tables_derived and MDL".
      sql/lock.cc:
        Added assert that enforces that when we are locking
        a non-temporary table we have an appropriate type of
        metadata lock on this table.
      sql/mysql_priv.h:
        Added separate flag for open_tables() to be able specify that
        SH metadata locks on table to be open should be acquired.
        We can no longer use MYSQL_LOCK_IGNORE_FLUSH flag for this
        as in addition to use in I_S implementation it is also used
        for opening system tables. Since in the latter case we also
        acquire thr_lock.c locks using SH metadata lock in it instead
        of SR or SW locks may lead to deadlock.
      sql/sql_base.cc:
        When opening tables don't interpret MYSQL_LOCK_IGNORE_FLUSH
        flag as request to acquire SH metadata locks. This flag is
        also used for opening system tables for which we also take
        thr_lock.c locks and thus proper metadata lock to take in
        this case is SR or SW lock (otherwise deadlocks can occur).
        In cases when SH lock is really required (e.g. when tables
        are open by I_S implementation) we rely on that newly
        introduced MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL flag is
        used.
      sql/sql_delete.cc:
        mysql_truncate_by_delete():
          Adjust type of metadata lock to be requested after changing
          type of thr_lock.c lock for table list element from one
          which was set in parser to TL_WRITE.
          This removes discrepancy between types of these locks which
          allowed deadlocks to creep in.
      sql/sql_handler.cc:
        When closing table which was open by HANDLER statement clear
        TABLE::open_by_handler flag. This allows to use this flag as
        a reliable indication that TABLE instance was open by HANDLER
        statement in assert which was added to mysql_lock_tables().
      sql/sql_parse.cc:
        multi_delete_set_locks_and_link_aux_tables():
          Adjust type of metadata lock to be requested after changing
          type of thr_lock.c lock for table list element from one
          which was set in parser to TL_WRITE.
          This removes discrepancy between types of these locks which
          allowed deadlocks to creep in.
      sql/sql_show.cc:
        Use newly introduced MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL
        flag in order to acquire SH metadata locks when opening tables
        in I_S implementation.
      sql/sql_update.cc:
        Added comment explaining why in multi-update after deciding
        that we need weaker thr_lock.c lock on a table we don't
        downgrade metadata lock on it.
      sql/sql_view.cc:
        When merging view into main statement adjust type of metadata
        lock to be requested after changing type of thr_lock.c lock
        for table. This removes discrepancy between types of these
        locks which allowed deadlocks to creep in.
      e7d689f5
  3. 04 Feb, 2010 1 commit
    • Konstantin Osipov's avatar
      Merge next-mr -> next-4284. · caa966cf
      Konstantin Osipov authored
      Cherry-pick a fix Bug#37148 from next-mr, to preserve
      file ids of the added files, and ensure that all the necessary
      changes have been pulled.
      
      Since initially Bug#37148 was null-merged into 6.0,
      the changeset that is now being cherry-picked was likewise
      null merged into next-4284.
      
      Now that Bug#37148 has been reapplied to 6.0, try to make
      it work with next-4284. This is also necessary to be able
      to pull other changes from 5.1-rep into next-4284.
      
      To resolve the merge issues use this changeset applied
      to 6.0:
      revid:jperkin@sun.com-20091216103628-ylhqf7s6yegui2t9
      revno: 3776.1.1
      committer: He Zhenxing <zhenxing.he@sun.com>
      branch nick: 6.0-codebase-bugfixing
      timestamp: Thu 2009-12-17 17:02:50 +0800
      message:
        Fix merge problem with Bug#37148
      
      
      
      caa966cf
  4. 01 Feb, 2010 1 commit
    • Dmitry Lenev's avatar
      Implement new type-of-operation-aware metadata locks. · ff6fd58d
      Dmitry Lenev authored
      Add a wait-for graph based deadlock detector to the
      MDL subsystem.
      
      Fixes bug #46272 "MySQL 5.4.4, new MDL: unnecessary deadlock" and
      bug #37346 "innodb does not detect deadlock between update and
      alter table".
      
      The first bug manifested itself as an unwarranted abort of a
      transaction with ER_LOCK_DEADLOCK error by a concurrent ALTER
      statement, when this transaction tried to repeat use of a
      table, which it has already used in a similar fashion before
      ALTER started.
      
      The second bug showed up as a deadlock between table-level
      locks and InnoDB row locks, which was "detected" only after
      innodb_lock_wait_timeout timeout.
      
      A transaction would start using the table and modify a few
      rows.
      Then ALTER TABLE would come in, and start copying rows
      into a temporary table. Eventually it would stumble on
      the modified records and get blocked on a row lock.
      The first transaction would try to do more updates, and get
      blocked on thr_lock.c lock.
      This situation of circular wait would only get resolved
      by a timeout.
      
      Both these bugs stemmed from inadequate solutions to the
      problem of deadlocks occurring between different
      locking subsystems.
      
      In the first case we tried to avoid deadlocks between metadata
      locking and table-level locking subsystems, when upgrading shared
      metadata lock to exclusive one.
      Transactions holding the shared lock on the table and waiting for
      some table-level lock used to be aborted too aggressively.
      
      We also allowed ALTER TABLE to start in presence of transactions
      that modify the subject table. ALTER TABLE acquires
      TL_WRITE_ALLOW_READ lock at start, and that block all writes
      against the table (naturally, we don't want any writes to be lost
      when switching the old and the new table). TL_WRITE_ALLOW_READ
      lock, in turn, would block the started transaction on thr_lock.c
      lock, should they do more updates. This, again, lead to the need
      to abort such transactions.
      
      The second bug occurred simply because we didn't have any
      mechanism to detect deadlocks between the table-level locks
      in thr_lock.c and row-level locks in InnoDB, other than
      innodb_lock_wait_timeout.
      
      This patch solves both these problems by moving lock conflicts
      which are causing these deadlocks into the metadata locking
      subsystem, thus making it possible to avoid or detect such
      deadlocks inside MDL.
      
      To do this we introduce new type-of-operation-aware metadata
      locks, which allow MDL subsystem to know not only the fact that
      transaction has used or is going to use some object but also what
      kind of operation it has carried out or going to carry out on the
      object.
      
      This, along with the addition of a special kind of upgradable
      metadata lock, allows ALTER TABLE to wait until all
      transactions which has updated the table to go away.
      This solves the second issue.
      Another special type of upgradable metadata lock is acquired
      by LOCK TABLE WRITE. This second lock type allows to solve the
      first issue, since abortion of table-level locks in event of
      DDL under LOCK TABLES becomes also unnecessary.
      
      Below follows the list of incompatible changes introduced by
      this patch:
      
      - From now on, ALTER TABLE and CREATE/DROP TRIGGER SQL (i.e. those
        statements that acquire TL_WRITE_ALLOW_READ lock)
        wait for all transactions which has *updated* the table to
        complete.
      
      - From now on, LOCK TABLES ... WRITE, REPAIR/OPTIMIZE TABLE
        (i.e. all statements which acquire TL_WRITE table-level lock) wait
        for all transaction which *updated or read* from the table
        to complete.
        As a consequence, innodb_table_locks=0 option no longer applies
        to LOCK TABLES ... WRITE.
      
      - DROP DATABASE, DROP TABLE, RENAME TABLE no longer abort
        statements or transactions which use tables being dropped or
        renamed, and instead wait for these transactions to complete.
      
      - Since LOCK TABLES WRITE now takes a special metadata lock,
        not compatible with with reads or writes against the subject table
        and transaction-wide, thr_lock.c deadlock avoidance algorithm
        that used to ensure absence of deadlocks between LOCK TABLES
        WRITE and other statements is no longer sufficient, even for
        MyISAM. The wait-for graph based deadlock detector of MDL
        subsystem may sometimes be necessary and is involved. This may
        lead to ER_LOCK_DEADLOCK error produced for multi-statement
        transactions even if these only use MyISAM:
      
        session 1:         session 2:
        begin;
      
        update t1 ...      lock table t2 write, t1 write;
                           -- gets a lock on t2, blocks on t1
      
        update t2 ...
        (ER_LOCK_DEADLOCK)
      
      - Finally,  support of LOW_PRIORITY option for LOCK TABLES ... WRITE
        was abandoned.
        LOCK TABLE ... LOW_PRIORITY WRITE from now on has the same
        priority as the usual LOCK TABLE ... WRITE.
        SELECT HIGH PRIORITY no longer trumps LOCK TABLE ... WRITE  in
        the wait queue.
      
      - We do not take upgradable metadata locks on implicitly
        locked tables. So if one has, say, a view v1 that uses
        table t1, and issues:
        LOCK TABLE v1 WRITE;
        FLUSH TABLE t1; -- (or just 'FLUSH TABLES'),
        an error is produced.
        In order to be able to perform DDL on a table under LOCK TABLES,
        the table must be locked explicitly in the LOCK TABLES list.
      
      mysql-test/include/handler.inc:
        Adjusted test case to trigger an execution path on which bug 41110
        "crash with handler command when used concurrently with alter
        table" and bug 41112 "crash in mysql_ha_close_table/get_lock_data
        with alter table" were originally discovered. Left old test case
        which no longer triggers this execution path for the sake of
        coverage.
        Added test coverage for HANDLER SQL statements and type-aware
        metadata locks.
        Added a test for the global shared lock and HANDLER SQL.
        Updated tests to take into account that the old simple deadlock
        detection heuristics was replaced with a graph-based deadlock
        detector.
      mysql-test/r/debug_sync.result:
        Updated results (see debug_sync.test).
      mysql-test/r/handler_innodb.result:
        Updated results (see handler.inc test).
      mysql-test/r/handler_myisam.result:
        Updated results (see handler.inc test).
      mysql-test/r/innodb-lock.result:
        Updated results (see innodb-lock.test).
      mysql-test/r/innodb_mysql_lock.result:
        Updated results (see innodb_mysql_lock.test).
      mysql-test/r/lock.result:
        Updated results (see lock.test).
      mysql-test/r/lock_multi.result:
        Updated results (see lock_multi.test).
      mysql-test/r/lock_sync.result:
        Updated results (see lock_sync.test).
      mysql-test/r/mdl_sync.result:
        Updated results (see mdl_sync.test).
      mysql-test/r/sp-threads.result:
        SHOW PROCESSLIST output has changed due to the fact that waiting
        for LOCK TABLES WRITE now happens within metadata locking
        subsystem.
      mysql-test/r/truncate_coverage.result:
        Updated results (see truncate_coverage.test).
      mysql-test/suite/funcs_1/datadict/processlist_val.inc:
        SELECT FROM I_S.PROCESSLIST output has changed due to fact that
        waiting for LOCK TABLES WRITE now happens within metadata locking
        subsystem.
      mysql-test/suite/funcs_1/r/processlist_val_no_prot.result:
        SELECT FROM I_S.PROCESSLIST output has changed due to fact that
        waiting for LOCK TABLES WRITE now happens within metadata locking
        subsystem.
      mysql-test/suite/rpl/t/rpl_sp.test:
        Updated to a new SHOW PROCESSLIST state name.
      mysql-test/t/debug_sync.test:
        Use LOCK TABLES READ instead of LOCK TABLES WRITE as the latter
        no longer allows to trigger execution path involving waiting on
        thr_lock.c lock and therefore reaching debug sync-point covered
        by this test.
      mysql-test/t/innodb-lock.test:
        Adjusted test case to the fact that innodb_table_locks=0 option is
        no longer supported, since LOCK TABLES WRITE handles all its
        conflicts within MDL subsystem.
      mysql-test/t/innodb_mysql_lock.test:
        Added test for bug #37346 "innodb does not detect deadlock between
        update and alter table".
      mysql-test/t/lock.test:
        Added test coverage which checks the fact that we no longer support
        DDL under LOCK TABLES on tables which were locked implicitly.
        Adjusted existing test cases accordingly.
      mysql-test/t/lock_multi.test:
        Added test for bug #46272 "MySQL 5.4.4, new MDL: unnecessary
        deadlock".  Adjusted other test cases to take into account the
        fact that waiting for LOCK TABLES ... WRITE now happens within MDL
        subsystem.
      mysql-test/t/lock_sync.test:
        Since LOCK TABLES ... WRITE now takes SNRW metadata lock for
        tables locked explicitly we have to implicitly lock InnoDB tables
        (through view) to trigger the table-level lock conflict between
        TL_WRITE and TL_WRITE_ALLOW_WRITE.
      mysql-test/t/mdl_sync.test:
        Added basic test coverage for type-of-operation-aware metadata
        locks. Also covered with tests some use cases involving HANDLER
        statements in which a deadlock could arise.
        Adjusted existing tests to take type-of-operation-aware MDL into
        account.
      mysql-test/t/multi_update.test:
        Update to a new SHOW PROCESSLIST state name.
      mysql-test/t/truncate_coverage.test:
        Adjusted test case after making LOCK TABLES WRITE to wait until
        transactions that use the table to be locked are completed.
        Updated to the changed name of DEBUG_SYNC point.
      sql/handler.cc:
        Global read lock functionality has been
        moved into a class.
      sql/lock.cc:
        Global read lock functionality has been
        moved into a class.
        Updated code to use the new MDL API.
      sql/mdl.cc:
        Introduced new type-of-operation aware metadata locks.
        To do this:
        - Changed MDL_lock to use one list for waiting requests and one
          list for granted requests. For each list, added a bitmap
          that holds information what lock types a list contains.
          Added a helper class MDL_lock::List to manipulate with granted
          and waited lists while keeping the bitmaps in sync
          with list contents.
        - Changed lock-compatibility functions to use bitmaps that
          define compatibility.
        - Introduced a graph based deadlock detector inspired by
          waiting_threads.c from Maria implementation.
        - Now that we have a deadlock detector, and no longer have
          a global lock to protect individual lock objects, but rather
          use an rw lock per object, removed redundant code for upgrade,
          and the global read lock. Changed the MDL API to
          no longer require the caller to acquire the global
          intention exclusive lock by means of a separate method.
          Removed a few more methods that became redundant.
        - Removed deadlock detection heuristic, it has been made
          obsolete by the deadlock detector.
        - With operation-type-aware metadata locks, MDL subsystem has
          become aware of potential conflicts between DDL and open
          transactions. This made it possible to remove calls to
          mysql_abort_transactions_with_shared_lock() from acquisition
          paths for exclusive lock and lock upgrade. Now we can simply
          wait for these transactions to complete without fear of
          deadlock. Function mysql_lock_abort() has also become
          unnecessary for all conflicting cases except when a DDL
          conflicts with a connection that has an open HANDLER.
      sql/mdl.h:
        Introduced new type-of-operation aware metadata locks.
        Introduced a graph based deadlock detector and supporting
        methods.
        Added comments.
        God rid of redundant API calls.
        Renamed m_lt_or_ha_sentinel to m_trans_sentinel,
        since now it guards the global read lock as well as
        LOCK TABLES and HANDLER locks.
      sql/mysql_priv.h:
        Moved the global read lock functionality into a
        class.
        Added MYSQL_OPEN_FORCE_SHARED_MDL flag which forces
        open_tables() to take MDL_SHARED on tables instead of
        metadata locks specified in the parser. We use this to
        allow PREPARE run concurrently in presence of
        LOCK TABLES ... WRITE.
        Added signature for find_table_for_mdl_ugprade().
      sql/set_var.cc:
        Global read lock functionality has been
        moved into a class.
      sql/sp_head.cc:
        When creating TABLE_LIST elements for prelocking or
        system tables set the type of request for metadata
        lock according to the operation that will be performed
        on the table.
      sql/sql_base.cc:
        - Updated code to use the new MDL API.
        - In order to avoid locks starvation we take upgradable
          locks all at once. As result implicitly locked tables no
          longer get an upgradable lock. Consequently DDL and FLUSH
          TABLES for such tables is prohibited.
          find_write_locked_table() was replaced by
          find_table_for_mdl_upgrade() function.
          open_table() was adjusted to return TABLE instance with
          upgradable ticket when necessary.
        - We no longer wait for all locks on OT_WAIT back off
          action -- only on the lock that caused the wait
          conflict. Moreover, now we distinguish cases when we
          have to wait due to conflict in MDL and old version
          of table in TDC.
        - Upate mysql_notify_threads_having_share_locks()
          to only abort thr_lock.c waits of threads that
          have open HANDLERs, since lock conflicts with only
          these threads now can lead to deadlocks not detectable
          by the MDL deadlock detector.
        - Remove mysql_abort_transactions_with_shared_locks()
          which is no longer needed.
      sql/sql_class.cc:
        Global read lock functionality has been moved into a class.
        Re-arranged code in THD::cleanup() to simplify assert.
      sql/sql_class.h:
        Introduced class to incapsulate global read lock
        functionality.
        Now sentinel in MDL subsystem guards the global read lock
        as well as LOCK TABLES and HANDLER locks. Adjusted code
        accordingly.
      sql/sql_db.cc:
        Global read lock functionality has been moved into a class.
      sql/sql_delete.cc:
        We no longer acquire upgradable metadata locks on tables
        which are locked by LOCK TABLES implicitly. As result
        TRUNCATE TABLE is no longer allowed for such tables.
        Updated code to use the new MDL API.
      sql/sql_handler.cc:
        Inform MDL_context about presence of open HANDLERs.
        Since HANLDERs break MDL protocol by acquiring table-level
        lock while holding only S metadata lock on a table MDL
        subsystem should take special care about such contexts (Now
        this is the only case when mysql_lock_abort() is used).
      sql/sql_parse.cc:
        Global read lock functionality has been moved into a class.
        Do not take upgradable metadata locks when opening tables
        for CREATE TABLE SELECT as it is not necessary and limits
        concurrency.
        When initializing TABLE_LIST objects before adding them
        to the table list set the type of request for metadata lock
        according to the operation that will be performed on the
        table.
        We no longer acquire upgradable metadata locks on tables
        which are locked by LOCK TABLES implicitly. As result FLUSH
        TABLES is no longer allowed for such tables.
      sql/sql_prepare.cc:
        Use MYSQL_OPEN_FORCE_SHARED_MDL flag when opening
        tables during PREPARE. This allows PREPARE to run
        concurrently in presence of LOCK TABLES ... WRITE.
      sql/sql_rename.cc:
        Global read lock functionality has been moved into a class.
      sql/sql_show.cc:
        Updated code to use the new MDL API.
      sql/sql_table.cc:
        Global read lock functionality has been moved into a class.
        We no longer acquire upgradable metadata locks on tables
        which are locked by LOCK TABLES implicitly. As result DROP
        TABLE is no longer allowed for such tables.
        Updated code to use the new MDL API.
      sql/sql_trigger.cc:
        Global read lock functionality has been moved into a class.
        We no longer acquire upgradable metadata locks on tables
        which are locked by LOCK TABLES implicitly. As result
        CREATE/DROP TRIGGER is no longer allowed for such tables.
        Updated code to use the new MDL API.
      sql/sql_view.cc:
        Global read lock functionality has been moved into a class.
        Fixed results of wrong merge that led to misuse of GLR API.
        CREATE VIEW statement is not a commit statement.
      sql/table.cc:
        When resetting TABLE_LIST objects for PS or SP re-execution
        set the type of request for metadata lock according to the
        operation that will be performed on the table. Do the same
        in auxiliary function initializing metadata lock requests
        in a table list.
      sql/table.h:
        When initializing TABLE_LIST objects set the type of request
        for metadata lock according to the operation that will be
        performed on the table.
      sql/transaction.cc:
        Global read lock functionality has been moved into a class.
      ff6fd58d
  5. 29 Jan, 2010 1 commit
  6. 28 Jan, 2010 1 commit
    • Davi Arnaut's avatar
      Fix for compiler warnings: · 47e52b90
      Davi Arnaut authored
      Rename method as to not hide a base.
      Reorder attributes initialization.
      Remove unused variable.
      Rework code to silence a warning due to assignment used as truth value.
      
      
      sql/item_strfunc.cc:
        Rename method as to not hide a base.
      sql/item_strfunc.h:
        Rename method as to not hide a base.
      sql/log_event.cc:
        Reorder attributes initialization.
      sql/rpl_injector.cc:
        Rework code to silence a warning due to assignment used as truth value.
      sql/rpl_record.cc:
        Remove unused variable.
      sql/sql_db.cc:
        Rework code to silence a warning due to assignment used as truth value.
      sql/sql_parse.cc:
        Rework code to silence a warning due to assignment used as truth value.
      sql/sql_table.cc:
        Rework code to silence a warning due to assignment used as truth value.
      47e52b90
  7. 24 Jan, 2010 1 commit
  8. 22 Jan, 2010 1 commit
    • Sergey Glukhov's avatar
      Bug#49501 Inefficient information_schema check (system collation), addon · 5f106ea2
      Sergey Glukhov authored
      removed wrongly introduced strlen calls
      
      
      sql/events.cc:
        removed wrongly introduced strlen calls
      sql/mysql_priv.h:
        removed wrongly introduced strlen calls
      sql/repl_failsafe.cc:
        removed wrongly introduced strlen calls
      sql/sql_db.cc:
        removed wrongly introduced strlen calls
      sql/sql_parse.cc:
        removed wrongly introduced strlen calls
      sql/sql_show.cc:
        removed wrongly introduced strlen calls
      5f106ea2
  9. 21 Jan, 2010 1 commit
    • Dmitry Lenev's avatar
      Patch that changes metadata locking subsystem to use mutex per lock and · b3f63454
      Dmitry Lenev authored
      condition variable per context instead of one mutex and one conditional
      variable for the whole subsystem.
      
      This should increase concurrency in this subsystem.
      
      It also opens the way for further changes which are necessary to solve
      such bugs as bug #46272 "MySQL 5.4.4, new MDL: unnecessary deadlock"
      and bug #37346 "innodb does not detect deadlock between update and alter
      table".
      
      Two other notable changes done by this patch:
      
      - MDL subsystem no longer implicitly acquires global intention exclusive
        metadata lock when per-object metadata lock is acquired. Now this has
        to be done by explicit calls outside of MDL subsystem.
      - Instead of using separate MDL_context for opening system tables/tables
        for purposes of I_S we now create MDL savepoint in the main context
        before opening tables and rollback to this savepoint after closing
        them. This means that it is now possible to get ER_LOCK_DEADLOCK error
        even not inside a transaction. This might happen in unlikely case when
        one runs DDL on one of system tables while also running DDL on some
        other tables. Cases when this ER_LOCK_DEADLOCK error is not justified
        will be addressed by advanced deadlock detector for MDL subsystem which
        we plan to implement.
      
      mysql-test/include/handler.inc:
        Adjusted handler_myisam.test and handler_innodb.test to the fact that
        exclusive metadata locks on tables are now acquired according to
        alphabetical order of fully qualified table names instead of order
        in which tables are mentioned in statement.
      mysql-test/r/handler_innodb.result:
        Adjusted handler_myisam.test and handler_innodb.test to the fact that
        exclusive metadata locks on tables are now acquired according to
        alphabetical order of fully qualified table names instead of order
        in which tables are mentioned in statement.
      mysql-test/r/handler_myisam.result:
        Adjusted handler_myisam.test and handler_innodb.test to the fact that
        exclusive metadata locks on tables are now acquired according to
        alphabetical order of fully qualified table names instead of order
        in which tables are mentioned in statement.
      mysql-test/r/mdl_sync.result:
        Adjusted mdl_sync.test to the fact that exclusive metadata locks on
        tables are now acquired according to alphabetical order of fully
        qualified table names instead of order in which tables are mentioned
        in statement.
      mysql-test/t/mdl_sync.test:
        Adjusted mdl_sync.test to the fact that exclusive metadata locks on
        tables are now acquired according to alphabetical order of fully
        qualified table names instead of order in which tables are mentioned
        in statement.
      sql/events.cc:
        Instead of using separate MDL_context for opening system tables we now
        create MDL savepoint in the main context before opening such tables
        and rollback to this savepoint after closing them. To support this
        change methods of THD responsible for saving/restoring open table
        state were changed to use Open_tables_backup class which in addition
        to Open_table_state has a member for this savepoint. As result code
        opening/closing system tables was changed to use Open_tables_backup
        instead of Open_table_state class as well.
      sql/ha_ndbcluster.cc:
        Since manipulations with open table state no longer install proxy
        MDL_context it does not make sense to perform them in order to
        satisfy assert in mysql_rm_tables_part2(). Removed them per agreement
        with Cluster team. This has not broken test suite since scenario in
        which deadlock can occur and assertion fails is not covered by tests.
      sql/lock.cc:
        MDL subsystem no longer implicitly acquires global intention exclusive
        metadata lock when per-object exclusive metadata lock is acquired.
        Now this has to be done by explicit calls outside of MDL subsystem.
      sql/log.cc:
        Instead of using separate MDL_context for opening system tables we now
        create MDL savepoint in the main context before opening such tables
        and rollback to this savepoint after closing them. To support this
        change methods of THD responsible for saving/restoring open table
        state were changed to use Open_tables_backup class which in addition
        to Open_table_state has a member for this savepoint. As result code
        opening/closing system tables was changed to use Open_tables_backup
        instead of Open_table_state class as well.
      sql/mdl.cc:
        Changed metadata locking subsystem to use mutex per lock and condition
        variable per context instead of one mutex and one conditional variable
        for the whole subsystem.
        Changed approach to handling of global metadata locks. Instead of
        implicitly acquiring intention exclusive locks when user requests
        per-object upgradeable or exclusive locks now we require them to be
        acquired explicitly in the same way as ordinary metadata locks.
        In fact global lock are now ordinary metadata locks in new GLOBAL
        namespace.
        
        To implement these changes:
        - Removed LOCK_mdl mutex and COND_mdl condition variable.
        - Introduced MDL_lock::m_mutex mutexes which protect individual lock
          objects.
        - Replaced mdl_locks hash with MDL_map class, which has hash for
          MDL_lock objects as a member and separate mutex which protects this
          hash. Methods of this class allow to find(), find_or_create() or
          remove() MDL_lock objects in concurrency-friendly fashion (i.e.
          for most common operation, find_or_create(), we don't acquire
          MDL_lock::m_mutex while holding MDL_map::m_mutex. Thanks to MikaelR
          for this idea and benchmarks!). Added three auxiliary members to
          MDL_lock class (m_is_destroyed, m_ref_usage, m_ref_release) to
          support this concurrency-friendly behavior.
        - Introduced MDL_context::m_ctx_wakeup_cond condition variable to be
          used for waiting until this context's pending request can be
          satisfied or its thread has to perform actions to resolve potential
          deadlock. Context which want to wait add ticket corresponding to the
          request to an appropriate queue of waiters in MDL_lock object so
          they can be noticed when other contexts change state of lock and be
          awaken by them by signalling on MDL_context::m_ctx_wakeup_cond.
          As consequence MDL_ticket objects has to be used for any waiting
          in metadata locking subsystem including one which happens in
          MDL_context::wait_for_locks() method.
          Another consequence is that MDL_context is no longer copyable and
          can't be saved/restored when working with system tables.
        - Made MDL_lock an abstract class, which delegates specifying exact
          compatibility matrix to its descendants. Added MDL_global_lock child
          class for global lock (The old is_lock_type_compatible() method
          became can_grant_lock() method of this class). Added MDL_object_lock
          class to represent per-object lock (The old MDL_lock::can_grant_lock()
          became its method). Choice between two classes happens based on MDL
          namespace in MDL_lock::create() method.
        - Got rid of MDL_lock::type member as its meaning became ambigous for
          global locks.
        - To simplify waking up of contexts waiting for lock split waiting queue
          in MDL_lock class in two queues. One for pending requests for exclusive
          (including intention exclusive) locks and another for requests for
          shared locks.
        - Added virtual wake_up_waiters() method to MDL_lock, MDL_global_lock and
          MDL_object_lock classes which allows to wake up waiting contexts after
          state of lock changes. Replaced old duplicated code with calls to this
          method.
        - Adjusted MDL_context::try_acquire_shared_lock()/exclusive_lock()/
          global_shared_lock(), MDL_ticket::upgrade_shared_lock_to_exclusive_lock()
          and MDL_context::release_ticket() methods to use MDL_map and
          MDL_lock::m_mutex instead of single LOCK_mdl mutex and wake up
          waiters according to the approach described above. The latter method
          also was renamed to MDL_context::release_lock().
        - Changed MDL_context::try_acquire_shared_lock()/exclusive_lock() and
          release_lock() not to handle global locks. They are now supposed to
          be taken explicitly like ordinary metadata locks.
        - Added helper MDL_context::try_acquire_global_intention_exclusive_lock()
          and acquire_global_intention_exclusive_lock() methods.
        - Moved common code from MDL_context::acquire_global_shared_lock() and
          acquire_global_intention_exclusive_lock() to new method -
          MDL_context::acquire_lock_impl().
        - Moved common code from MDL_context::try_acquire_shared_lock(),
          try_acquire_global_intention_exclusive_lock()/exclusive_lock()
          to MDL_context::try_acquire_lock_impl().
        - Since acquiring of several exclusive locks can no longer happen under
          single LOCK_mdl mutex the approach to it had to be changed. Now we do
          it in one by one fashion. This is done in alphabetical order to avoid
          deadlocks. Changed MDL_context::acquire_exclusive_locks() accordingly
          (as part of this change moved code responsible for acquiring single
          exclusive lock to new MDL_context::acquire_exclusive_lock_impl()
          method).
        - Since we no longer have single LOCK_mdl mutex which protects all
          MDL_context::m_is_waiting_in_mdl members using these members to
          determine if we have really awaken context holding conflicting
          shared lock became inconvinient. Got rid of this member and changed
          notify_shared_lock() helper function and process of acquiring
          of/upgrading to exclusive lock not to rely on such information.
          Now in MDL_context::acquire_exclusive_lock_impl() and
          MDL_ticket::upgrade_shared_lock_to_exclusive_lock() we simply
          re-try to wake up threads holding conflicting shared locks after
          small time out.
        - Adjusted MDL_context::can_wait_lead_to_deadlock() and
          MDL_ticket::has_pending_conflicting_lock() to use per-lock
          mutexes instead of LOCK_mdl. To do this introduced
          MDL_lock::has_pending_exclusive_lock() method.
      sql/mdl.h:
        Changed metadata locking subsystem to use mutex per lock and condition
        variable per context instead of one mutex and one conditional variable
        for the whole subsystem. In order to implement this change:
        
        - Added MDL_key::cmp() method to be able to sort MDL_key objects
          alphabetically. Changed length fields in MDL_key class to uint16
          as 16-bit is enough for length of any key.
        - Changed MDL_ticket::get_ctx() to return pointer to non-const
          object in order to be able to use MDL_context::awake() method
          for such contexts.
        - Got rid of unlocked versions of can_wait_lead_to_deadlock()/
          has_pending_conflicting_lock() methods in MDL_context and
          MDL_ticket. We no longer has single mutex which protects all
          locks. Thus one always has to use versions of these methods
          which acquire per-lock mutexes.
        - MDL_request_list type of list now counts its elements.
        - Added MDL_context::m_ctx_wakeup_cond condition variable to be used
          for waiting until this context's pending request can be satisfied
          or its thread has to perform actions to resolve potential deadlock.
          Added awake() method to wake up context from such wait.
          Addition of condition variable made MDL_context uncopyable.
          As result we no longer can save/restore MDL_context when working
          with system tables. Instead we create MDL savepoint before opening
          those tables and rollback to it once they are closed.
        - MDL_context::release_ticket() became release_lock() method.
        - Added auxiliary MDL_context::acquire_exclusive_lock_impl() method
          which does all necessary work to acquire exclusive lock on one object
          but should not be used directly as it does not enforce any asserts
          ensuring that no deadlocks are possible.
        - Since we no longer need to know if thread trying to acquire exclusive
          lock managed to wake up any threads having conflicting shared locks
          (as, anyway, we will try to wake up such threads again shortly)
        - MDL_context::m_is_waiting_in_mdl member became unnecessary and
          notify_shared_lock() no longer needs to be friend of MDL_context.
        
        Changed approach to handling of global metadata locks. Instead of
        implicitly acquiring intention exclusive locks when user requests
        per-object upgradeable or exclusive locks now we require them to be
        acquired explicitly in the same way as ordinary metadata locks.
        
        - Added new GLOBAL namespace for such locks.
        - Added new type of lock to be requested MDL_INTENTION_EXCLISIVE.
        - Added MDL_context::try_acquire_global_intention_exclusive_lock()
          and acquire_global_intention_exclusive_lock() methods.
        - Moved common code from MDL_context::acquire_global_shared_lock()
          and acquire_global_intention_exclusive_lock() to new method -
          MDL_context::acquire_lock_impl().
        - Moved common code from MDL_context::try_acquire_shared_lock(),
          try_acquire_global_intention_exclusive_lock()/exclusive_lock()
          to MDL_context::try_acquire_lock_impl().
        - Added helper MDL_context::is_global_lock_owner() method to be
          able easily to find what kind of global lock this context holds.
        - MDL_context::m_has_global_shared_lock became unnecessary as
          global read lock is now represented by ordinary ticket.
        - Removed assert in MDL_context::set_lt_or_ha_sentinel() which became
          false for cases when we execute LOCK TABLES under global read lock
          mode.
      sql/mysql_priv.h:
        Instead of using separate MDL_context for opening system tables we now
        create MDL savepoint in the main context before opening such tables
        and rollback to this savepoint after closing them. To support this
        change methods of THD responsible for saving/restoring open table
        state were changed to use Open_tables_backup class which in addition
        to Open_table_state has a member for this savepoint. As result calls
        opening/closing system tables were changed to use Open_tables_backup
        instead of Open_table_state class as well.
      sql/sp.cc:
        Instead of using separate MDL_context for opening system tables we now
        create MDL savepoint in the main context before opening such tables
        and rollback to this savepoint after closing them. To support this
        change methods of THD responsible for saving/restoring open table
        state were changed to use Open_tables_backup class which in addition
        to Open_table_state has a member for this savepoint. As result code
        opening/closing system tables was changed to use Open_tables_backup
        instead of Open_table_state class as well.
      sql/sp.h:
        Instead of using separate MDL_context for opening system tables we now
        create MDL savepoint in the main context before opening such tables
        and rollback to this savepoint after closing them. To support this
        change methods of THD responsible for saving/restoring open table
        state were changed to use Open_tables_backup class which in addition
        to Open_table_state has a member for this savepoint. As result code
        opening/closing system tables was changed to use Open_tables_backup
        instead of Open_table_state class as well.
      sql/sql_base.cc:
        close_thread_tables():
          Since we no longer use separate MDL_context for opening system
          tables we need to avoid releasing all transaction locks when
          closing system table. Releasing metadata lock on system table
          is now responsibility of THD::restore_backup_open_tables_state().
        open_table_get_mdl_lock(),
        Open_table_context::recover_from_failed_open():
          MDL subsystem no longer implicitly acquires global intention exclusive
          metadata lock when per-object upgradable or exclusive metadata lock is
          acquired. So this have to be done explicitly from these calls.
          Changed Open_table_context class to store MDL_request object for
          global intention exclusive lock acquired when opening tables.
        open_table():
          Do not release metadata lock if we have failed to open table as
          this lock might have been acquired by one of previous statements
          in transaction, and therefore should not be released.
        open_system_tables_for_read()/close_system_tables()/
        open_performance_schema_table():
          Instead of using separate MDL_context for opening system tables we now
          create MDL savepoint in the main context before opening such tables
          and rollback to this savepoint after closing them. To support this
          change methods of THD responsible for saving/restoring open table
          state were changed to use Open_tables_backup class which in addition
          to Open_table_state has a member for this savepoint. As result code
          opening/closing system tables was changed to use Open_tables_backup
          instead of Open_table_state class as well.
        close_performance_schema_table():
          Got rid of duplicated code.
      sql/sql_class.cc:
        Instead of using separate MDL_context for opening system tables we now
        create MDL savepoint in the main context before opening such tables
        and rollback to this savepoint after closing them. To support this
        change methods of THD responsible for saving/restoring open table
        state were changed to use Open_tables_backup class which in addition
        to Open_table_state has a member for this savepoint. Also releasing
        metadata lock on system table is now responsibility of
        THD::restore_backup_open_tables_state().
        Adjusted assert in THD::cleanup() to take into account fact that now
        we also use MDL sentinel for global read lock.
      sql/sql_class.h:
        Instead of using separate MDL_context for opening system tables we now
        create MDL savepoint in the main context before opening such tables
        and rollback to this savepoint after closing them. As result:
        - 'mdl_context' member was moved out of Open_tables_state to THD class.
          enter_locked_tables_mode()/leave_locked_tables_mode() had to follow.
        - Methods of THD responsible for saving/restoring open table state were
          changed to use Open_tables_backup class which in addition to
          Open_table_state has a member for this savepoint.
        Changed Open_table_context class to store MDL_request object for
        global intention exclusive lock acquired when opening tables.
      sql/sql_delete.cc:
        MDL subsystem no longer implicitly acquires global intention exclusive
        metadata lock when per-object exclusive metadata lock is acquired.
        Now this has to be done by explicit calls outside of MDL subsystem.
      sql/sql_help.cc:
        Instead of using separate MDL_context for opening system tables we now
        create MDL savepoint in the main context before opening such tables
        and rollback to this savepoint after closing them. To support this
        change methods of THD responsible for saving/restoring open table
        state were changed to use Open_tables_backup class which in addition
        to Open_table_state has a member for this savepoint. As result code
        opening/closing system tables was changed to use Open_tables_backup
        instead of Open_table_state class as well.
      sql/sql_parse.cc:
        Adjusted assert reload_acl_and_cache() to the fact that global read
        lock now takes full-blown metadata lock.
      sql/sql_plist.h:
        Added support for element counting to I_P_List list template.
        One can use policy classes to specify if such counting is needed
        or not needed for particular list.
      sql/sql_show.cc:
        Instead of using separate MDL_context for opening tables for I_S
        purposes we now create MDL savepoint in the main context before
        opening tables and rollback to this savepoint after closing them.
        To support this and similar change for system tables methods of
        THD responsible for saving/restoring open table state were changed
        to use Open_tables_backup class which in addition to Open_table_state
        has a member for this savepoint. As result code opening/closing tables
        for I_S purposes was changed to use Open_tables_backup instead of
        Open_table_state class as well.
      sql/sql_table.cc:
        mysql_rm_tables_part2():
          Since now global intention exclusive metadata lock is ordinary
          metadata lock we no longer can rely that by releasing MDL locks
          on all tables we will release all locks acquired by this routine.
          So in non-LOCK-TABLES mode we have to release all locks acquired
          explicitly.
        prepare_for_repair(), mysql_alter_table():
          MDL subsystem no longer implicitly acquires global intention
          exclusive metadata lock when per-object exclusive metadata lock
          is acquired. Now this has to be done by explicit calls outside of
          MDL subsystem.
      sql/tztime.cc:
        Instead of using separate MDL_context for opening system tables we now
        create MDL savepoint in the main context before opening such tables
        and rollback to this savepoint after closing them. To support this
        change methods of THD responsible for saving/restoring open table
        state were changed to use Open_tables_backup class which in addition
        to Open_table_state has a member for this savepoint. As result code
        opening/closing system tables was changed to use Open_tables_backup
        instead of Open_table_state class as well.
        Also changed code not to use special mechanism for open system tables
        when it is not really necessary.
      b3f63454
  10. 19 Jan, 2010 1 commit
    • Sergey Glukhov's avatar
      Bug#49501 Inefficient information_schema check (system collation) · 3a95b614
      Sergey Glukhov authored
      added check_length optimization for I_S_NAME comparison
      
      
      sql/event_data_objects.cc:
        added check_length optimization for I_S_NAME comparison
      sql/events.cc:
        added check_length optimization for I_S_NAME comparison
      sql/mysql_priv.h:
        added check_length optimization for I_S_NAME comparison
      sql/repl_failsafe.cc:
        added check_length optimization for I_S_NAME comparison
      sql/sql_db.cc:
        added check_length optimization for I_S_NAME comparison
      sql/sql_parse.cc:
        added check_length optimization for I_S_NAME comparison
      sql/sql_show.cc:
        added check_length optimization for I_S_NAME comparison
      sql/sql_view.cc:
        added check_length optimization for I_S_NAME comparison
      sql/table.cc:
        added check_length optimization for I_S_NAME comparison
      3a95b614
  11. 18 Jan, 2010 1 commit
    • Mattias Jonsson's avatar
      Bug#47343: InnoDB fails to clean-up after lock wait timeout on · b489ba04
      Mattias Jonsson authored
                 REORGANIZE PARTITION
      
      There were several problems which lead to this this,
      all related to bad error handling.
      
      1) There was several bugs preventing the ddl-log to be used for
         cleaning up created files on error.
      
      2) The error handling after the copy partition rows did not close
         and unlock the tables, resulting in deletion of partitions
         which were in use, which lead InnoDB to put the partition to
         drop in a background queue.
      
      sql/ha_partition.cc:
        Bug#47343: InnoDB fails to clean-up after lock wait timeout on
                   REORGANIZE PARTITION
        
        Better error handling, if partition has been created/opened/locked
        then make sure it is unlocked and closed before returning error.
        The delete of the newly created partition is handled by the ddl-log.
      sql/sql_parse.cc:
        Bug#47343: InnoDB fails to clean-up after lock wait timeout on
                   REORGANIZE PARTITION
        
        Fix a bug found when experimenting, thd could really be NULL here,
        as mentioned in the function header.
      sql/sql_partition.cc:
        Bug#47343: InnoDB fails to clean-up after lock wait timeout on
                   REORGANIZE PARTITION
        
        Used the correct .frm shadow name to put into the ddl-log.
        Really use the ddl-log to handle errors.
      sql/sql_table.cc:
        Bug#47343: InnoDB fails to clean-up after lock wait timeout on
                   REORGANIZE PARTITION
        
        Fixes of the ddl-log when used as error recovery (no crash).
        When executing an entry from memory (not read from disk)
        the name_len was not set correctly.
      b489ba04
  12. 16 Jan, 2010 1 commit
    • unknown's avatar
      BUG#47418 RBR fails, failure with mixup of base/temporary/view · 94343315
      unknown authored
      'CREATE TABLE IF NOT EXISTS ... SELECT' statement were causing 'CREATE
      TEMPORARY TABLE ...' to be written to the binary log in row-based 
      mode (a.k.a. RBR), when there was a temporary table with the same name.
      Because the 'CREATE TABLE ... SELECT' statement was executed as 
      'INSERT ... SELECT' into the temporary table. Since in RBR mode no 
      other statements related to temporary tables are written into binary log,
      this sometimes broke replication.
      
      This patch changes behavior of 'CREATE TABLE [IF NOT EXISTS] ... SELECT ...'.
      it ignores existence of temporary table with the 
      same name as table being created and is interpreted
      as attempt to create/insert into base table. This makes behavior of
      'CREATE TABLE [IF NOT EXISTS] ... SELECT' consistent with
      how ordinary 'CREATE TABLE' and 'CREATE TABLE ... LIKE' behave.
      94343315
  13. 15 Jan, 2010 2 commits
  14. 13 Jan, 2010 1 commit
    • Kristofer Pettersson's avatar
      Bug#33982 debug assertion and crash reloading grant tables after sighup or kill · 31f1566f
      Kristofer Pettersson authored
      In certain rare cases when a process was interrupted
      during a FLUSH PRIVILEGES operation the diagnostic
      area would be set to an error state but the function
      responsible for the operation would still signal
      success. This would lead to a debug assertion error
      later on when the server would attempt to reset the
      DA before sending the error message.
      
      This patch fixes the issue by assuring that
      reload_acl_and_cache() always fails if an error
      condition is raised.
      
      The second issue was that a KILL could cause
      a console error message which referred to a DA
      state without first making sure that such a
      state existed.
      
      This patch fixes this issue in two different
      palces by first checking DA state before
      fetching the error message.
      
       
      
      sql/sql_acl.cc:
        * Make sure that there is an error to print before attempting to do so.
        * Minor style change: change 1 to TRUE for clarity.
      sql/sql_parse.cc:
        * Always fail reload_acl_and_cache() if the query was killed.
      sql/sql_servers.cc:
        * Make sure that there is an error to print before attempting to do so.
      31f1566f
  15. 12 Jan, 2010 3 commits
    • Jon Olav Hauglid's avatar
      Bug #49988 MDL deadlocks with mysql_create_db, reload_acl_and_cache · a8577264
      Jon Olav Hauglid authored
      This was a deadlock between LOCK TABLES/CREATE DATABASE in one connection
      and DROP DATABASE in another. It only happened if the table locked by 
      LOCK TABLES was in the database to be dropped. The deadlock is similar
      to the one in Bug#48940, but with LOCK TABLES instead of an active
      transaction.
      
      The order of events needed to trigger the deadlock was:
      1) Connection 1 locks table db1.t1 using LOCK TABLES. It will now
      have a metadata lock on the table name.
      2) Connection 2 issues DROP DATABASE db1. This will wait inside
      the MDL subsystem for the lock on db1.t1 to go away. While waiting, it
      will hold the LOCK_mysql_create_db mutex.
      3) Connection 1 issues CREATE DATABASE (database name irrelevant).
      This will hang trying to lock the same mutex. Since this is the connection
      holding the metadata lock blocking Connection 2, we have a deadlock.
      
      This deadlock would also happen for earlier trees without MDL, but 
      there DROP DATABASE would wait for a table to be removed from the
      table definition cache.
      
      This patch fixes the problem by prohibiting CREATE DATABASE in LOCK TABLES
      mode. In the example above, this prevents Connection 1 from hanging trying
      to get the LOCK_mysql_create_db mutex. Note that other commands that use
      LOCK_mysql_create_db (ALTER/DROP DATABASE) are already prohibited in 
      LOCK TABLES mode.
      
      Incompatible change: CREATE DATABASE is now disallowed in LOCK TABLES mode.
      
      Test case added to schema.test.
      
      
      mysql-test/t/drop.test:
        Updates the test for Bug#21216 by swapping the order of CREATE DATABASE
        and LOCK TABLES. This is now needed as CREATE DATABASE is prohibited in
        LOCK TABLES mode.
      mysql-test/t/schema.test:
        Test case for Bug#49988 added.
        Also fixes a problem with the test for Bug#48940 where the result 
        would differ for embedded server.
      a8577264
    • Martin Hansson's avatar
      Bug#48157: crash in Item_field::used_tables · 2c369f6b
      Martin Hansson authored
      MySQL handles the join syntax "JOIN ... USING( field1,
      ... )" and natural joins by building the same parse tree as
      a corresponding join with an "ON t1.field1 = t2.field1 ..."
      expression would produce. This parse tree was not cleaned up
      properly in the following scenario. If a thread tries to
      lock some tables and finds that the tables were dropped and
      re-created while waiting for the lock, it cleans up column
      references in the statement by means a per-statement free
      list. But if the statement was part of a stored procedure,
      column references on the stored procedure's free list weren't
      cleaned up and thus contained pointers to freed objects.
      
      Fixed by adding a call to clean up the current prepared
      statement's free list.
      
      
      mysql-test/r/sp_sync.result:
        Bug#48157: Test case
      mysql-test/t/sp_sync.test:
        Bug#48157: Test result
      sql/item.h:
        Bug#48157: Commented field.
      sql/sql_parse.cc:
        Bug#48157: Commented function.
      sql/sql_update.cc:
        Bug#48157: fix
      2c369f6b
    • Marc Alff's avatar
      WL#2360 Performance schema · 6b3d5248
      Marc Alff authored
      Part V: performance schema implementation
      6b3d5248
  16. 07 Jan, 2010 1 commit
  17. 31 Dec, 2009 1 commit
    • unknown's avatar
      Bug #49137 Replication failure on SBR/MBR + multi-table DROP TEMPORARY TABLE · 28baa532
      unknown authored
            
      In statement-based or mixed-mode replication, use DROP TEMPORARY TABLE
      to drop multiple tables causes different errors on master and slave, 
      when one or more of these tables do not exist. Because when executed
      on slave, it would automatically add IF EXISTS to the query to ignore
      all ER_BAD_TABLE_ERROR errors.
      
      To fix the problem, do not add IF EXISTS when executing DROP TEMPORARY
      TABLE on the slave, and clear the ER_BAD_TABLE_ERROR error after
      execution if the query does not expect any errors.
      
      
      mysql-test/r/rpl_drop_temp.result:
        Updated for the patch of bug#49137.
      mysql-test/t/rpl_drop_temp.test:
        Added the test file to verify if DROP MULTI TEMPORARY TABLE
        will cause different errors on master and slave, when one or
        more of these tables do not exist.
      sql/log_event.cc:
        Added code to handle above cases which are
        removed from sql_parse.cc
      sql/sql_parse.cc:
        Remove the code to issue the 'Unknown table' error,
        if the temporary table does not exist when dropping
        it on slave. The above cases decribed in comments
        will be handled later in log_event.cc.
      28baa532
  18. 29 Dec, 2009 1 commit
    • Konstantin Osipov's avatar
      Apply and review: · d7a3acdc
      Konstantin Osipov authored
      3655 Jon Olav Hauglid   2009-10-19
      Bug #30977 Concurrent statement using stored function and DROP FUNCTION 
                 breaks SBR
      Bug #48246 assert in close_thread_table
      
      Implement a fix for:
      Bug #41804 purge stored procedure cache causes mysterious hang for many
                 minutes
      Bug #49972 Crash in prepared statements
      
      The problem was that concurrent execution of DML statements that
      use stored functions and DDL statements that drop/modify the same
      function might result in incorrect binary log in statement (and
      mixed) mode and therefore break replication.
      
      This patch fixes the problem by introducing metadata locking for
      stored procedures and functions. This is similar to what is done
      in Bug#25144 for views. Procedures and functions now are
      locked using metadata locks until the transaction is either
      committed or rolled back. This prevents other statements from
      modifying the procedure/function while it is being executed. This
      provides commit ordering - guaranteeing serializability across
      multiple transactions and thus fixes the reported binlog problem.
      
      Note that we do not take locks for top-level CALLs. This means
      that procedures called directly are not protected from changes by
      simultaneous DDL operations so they are executed at the state they
      had at the time of the CALL. By not taking locks for top-level
      CALLs, we still allow transactions to be started inside
      procedures.
      
      This patch also changes stored procedure cache invalidation.
      Upon a change of cache version, we no longer invalidate the entire
      cache, but only those routines which we use, only when a statement
      is executed that uses them.
      
      This patch also changes the logic of prepared statement validation.
      A stored procedure used by a prepared statement is now validated
      only once a metadata lock has been acquired. A version mismatch
      causes a flush of the obsolete routine from the cache and
      statement reprepare.
      Incompatible changes:
      1) ER_LOCK_DEADLOCK is reported for a transaction trying to access
         a procedure/function that is locked by a DDL operation in
         another connection.
      
      2) Procedure/function DDL operations are now prohibited in LOCK
         TABLES mode as exclusive locks must be taken all at once and
         LOCK TABLES provides no way to specifiy procedures/functions to
         be locked.
      
      Test cases have been added to sp-lock.test and rpl_sp.test.
      
      Work on this bug has very much been a team effort and this patch
      includes and is based on contributions from Davi Arnaut, Dmitry
      Lenev, Magne Mæhre and Konstantin Osipov.
      
      
      mysql-test/r/ps_ddl.result:
        Update results (Bug#30977).
      mysql-test/r/ps_ddl1.result:
        Update results (Bug#30977).
      mysql-test/r/sp-error.result:
        Update results (Bug#30977).
      mysql-test/r/sp-lock.result:
        Update results (Bug#30977).
      mysql-test/suite/rpl/r/rpl_sp.result:
        Update results (Bug#30977).
      mysql-test/suite/rpl/t/rpl_sp.test:
        Add a test case for Bug#30977.
      mysql-test/t/ps_ddl.test:
        Update comments. We no longer re-prepare a prepared statement
        when a stored procedure used in top-level CALL is changed.
      mysql-test/t/ps_ddl1.test:
        Modifying stored procedure p1 no longer invalidates prepared
        statement "call p1" -- we can re-use the prepared statement
        without invalidation.
      mysql-test/t/sp-error.test:
        Use a constant for an error value.
      mysql-test/t/sp-lock.test:
        Add test coverage for Bug#30977.
      sql/lock.cc:
        Implement lock_routine_name() - a way to acquire an 
        exclusive metadata lock (ex- name-lock) on 
        stored procedure/function.
      sql/sp.cc:
        Change semantics of sp_cache_routine() -- now it has an option
        to make sure that the routine that is cached is up to date (has
        the latest sp cache version).
        
        Add sp_cache_invalidate() to sp_drop_routine(), where it was
        missing (a bug!).
        
        Acquire metadata locks for SP DDL (ALTER/CREATE/DROP). This is
        the core of the fix for Bug#30977.
        
        Since caching and cache invalidation scheme was changed, make 
        sure we don't invalidate the SP cache in the middle of a stored
        routine execution. At the same time, make sure we don't access
        stale data due to lack of invalidation. 
        For that, change ALTER FUNCTION/PROCEDURE to not use the cache,
        and SHOW PROCEDURE CODE/SHOW CREATE PROCEDURE/FUNCTION to always
        read an up to date version of the routine from the cache.
      sql/sp.h:
        Add a helper wrapper around sp_cache_routine().
      sql/sp_cache.cc:
        Implement new sp_cache_version() and sp_cache_flush_obsolete().
        Now we flush stale routines individually, rather than all at once.
      sql/sp_cache.h:
        Update signatures of sp_cache_version() and sp_cache_flush_obsolete().
      sql/sp_head.cc:
        Add a default initialization of sp_head::m_sp_cache_version.
        Remove a redundant sp_head::create().
      sql/sp_head.h:
        Add m_sp_cache_version to sp_head class - we now 
        keep track of every routine in the stored procedure cache, rather than
        of the entire cache.
      sql/sql_base.cc:
        Implement prelocking for stored routines. Validate stored
        routines after they were locked.
        Flush obsolete routines upon next access, one by one, not all at once
        (Bug#41804).
        Style fixes.
      sql/sql_class.h:
        Rename a Open_table_context method.
      sql/sql_parse.cc:
        Make sure stored procedures DDL commits the active transaction 
        (issues an implicit commit before and after).
        Remove sp_head::create(), a pure redundancy.
        Move the semantical check during alter routine inside sp_update_routine() code in order to:
        - avoid using SP cache during update, it may be obsolete.
        - speed up and simplify the update procedure.
        
        Remove sp_cache_flush_obsolete() calls, we no longer flush the entire
        cache, ever, stale routines are flushed before next use, one at a time.
      sql/sql_prepare.cc:
        Move routine metadata validation to open_and_process_routine().
        Fix Bug#49972 (don't swap flags at reprepare).
        Reset Sroutine_hash_entries in reinit_stmt_before_use().
        Remove SP cache invalidation, it's now done by open_tables().
      sql/sql_show.cc:
        Fix a warning: remove an unused label.
      sql/sql_table.cc:
        Reset mdl_request.ticket for tickets acquired for routines inlined
        through a view, in CHECK TABLE statement, to satisfy an MDL assert.
      sql/sql_update.cc:
        Move the cleanup of "translation items" to close_tables_for_reopen(),
        since it's needed in all cases when we back off, not just
        the back-off in multi-update. This fixes a bug when the server
        would crash on attempt to back off when opening tables
        for a statement that uses information_schema tables.
      d7a3acdc
  19. 22 Dec, 2009 2 commits
    • Konstantin Osipov's avatar
      A prerequisite patch for the fix for Bug#46224 · a2878a39
      Konstantin Osipov authored
      "HANDLER statements within a transaction might lead to deadlocks".
      Introduce a notion of a sentinel to MDL_context. A sentinel
      is a ticket that separates all tickets in the context into two
      groups: before and after it. Currently we can have (and need) only
      one designated sentinel -- it separates all locks taken by LOCK
      TABLE or HANDLER statement, which must survive COMMIT and ROLLBACK
      and all other locks, which must be released at COMMIT or ROLLBACK.
      The tricky part is maintaining the sentinel up to date when
      someone release its corresponding ticket. This can happen, e.g.
      if someone issues DROP TABLE under LOCK TABLES (generally,
      see all calls to release_all_locks_for_name()).
      MDL_context::release_ticket() is modified to take care of it.
      
      ******
      A fix and a test case for Bug#46224 "HANDLER statements within a
      transaction might lead to deadlocks".
      
      An attempt to mix HANDLER SQL statements, which are transaction-
      agnostic, an open multi-statement transaction,
      and DDL against the involved tables (in a concurrent connection) 
      could lead to a deadlock. The deadlock would occur when
      HANDLER OPEN or HANDLER READ would have to wait on a conflicting
      metadata lock. If the connection that issued HANDLER statement
      also had other metadata locks (say, acquired in scope of a 
      transaction), a classical deadlock situation of mutual wait
      could occur.
      
      Incompatible change: entering LOCK TABLES mode automatically
      closes all open HANDLERs in the current connection.
      
      Incompatible change: previously an attempt to wait on a lock
      in a connection that has an open HANDLER statement could wait
      indefinitely/deadlock. After this patch, an error ER_LOCK_DEADLOCK
      is produced.
      
      The idea of the fix is to merge thd->handler_mdl_context
      with the main mdl_context of the connection, used for transactional
      locks. This makes deadlock detection possible, since all waits
      with locks are "visible" and available to analysis in a single
      MDL context of the connection.
      
      Since HANDLER locks and transactional locks have a different life
      cycle -- HANDLERs are explicitly open and closed, and so
      are HANDLER locks, explicitly acquired and released, whereas
      transactional locks "accumulate" till the end of a transaction
      and are released only with COMMIT, ROLLBACK and ROLLBACK TO SAVEPOINT,
      a concept of "sentinel" was introduced to MDL_context.
      All locks, HANDLER and others, reside in the same linked list.
      However, a selected element of the list separates locks with
      different life cycle. HANDLER locks always reside at the
      end of the list, after the sentinel. Transactional locks are
      prepended to the beginning of the list, before the sentinel.
      Thus, ROLLBACK, COMMIT or ROLLBACK TO SAVEPOINT, only
      release those locks that reside before the sentinel. HANDLER locks
      must be released explicitly as part of HANDLER CLOSE statement,
      or an implicit close. 
      The same approach with sentinel
      is also employed for LOCK TABLES locks. Since HANDLER and LOCK TABLES
      statement has never worked together, the implementation is
      made simple and only maintains one sentinel, which is used either
      for HANDLER locks, or for LOCK TABLES locks.
      
      
      mysql-test/include/handler.inc:
        Add test coverage for Bug#46224 "HANDLER statements within a
        transaction might lead to deadlocks".
        Extended HANDLER coverage to cover a mix of HANDLER, transactions
        and DDL statements.
      mysql-test/r/handler_innodb.result:
        Update results (Bug#46224).
      mysql-test/r/handler_myisam.result:
        Update results (Bug#46224).
      sql/lock.cc:
        Remove thd->some_tables_deleted, it's never used.
      sql/log_event.cc:
        No need to check for thd->locked_tables_mode, 
        it's done inside release_transactional_locks().
      sql/mdl.cc:
        Implement the concept of HANDLER and LOCK TABLES "sentinel".
        Implement a method to clone an acquired ticket.
        Do not return tickets beyond the sentinel when acquiring
        locks, create a copy.
        Remove methods to merge and backup MDL_context, they are now
        not used (Hurra!). This opens a path to a proper constructor
        and destructor of class MDL_context (to be done in a separate
        patch).
        Modify find_ticket() to provide information about where
        the ticket position is with regard to the sentinel.
      sql/mdl.h:
        Add declarations necessary for the implementation of the concept
        of "sentinel", a dedicated ticket separating transactional and
        non-transactional locks.
      sql/mysql_priv.h:
        Add mark_tmp_table_for_reuse() declaration, 
        a function to "close" a single session (temporary) table.
      sql/sql_base.cc:
        Remove thd->some_tables_deleted.
        Modify deadlock-prevention asserts and deadlock detection
        heuristics to take into account that from now on HANDLER locks
        reside in the same locking context.
        Add broadcast_refresh() to mysql_notify_thread_having_shared_lock():
        this is necessary for the case when a thread having a shared lock
        is asleep in tdc_wait_for_old_versions(). This situation is only
        possible with HANDLER t1 OPEN; FLUSH TABLE (since all over code paths
        that lead to tdc_wait_for_old_versions() always have an
        empty MDL_context). Previously the server would simply deadlock
        in this situation.
      sql/sql_class.cc:
        Remove now unused member "THD::some_tables_deleted". 
        Move mysql_ha_cleanup() a few lines above in THD::cleanup() 
        to make sure that all handlers are closed when it's time to 
        destroy the MDL_context of this connection.
        Remove handler_mdl_context and handler_tables.
      sql/sql_class.h:
        Remove THD::handler_tables, THD::handler_mdl_context,
        THD::some_tables_deleted.
      sql/sql_handler.cc:
        Remove thd->handler_tables.
        Remove thd->handler_mdl_context.
        Rewrite mysql_ha_open() to have no special provision for MERGE
        tables, now that we don't have to manipulate with thd->handler_tables
        it's easy to do.
        Remove dead code.
        Fix a bug in mysql_ha_flush() when we would always flush
        a temporary HANDLER when mysql_ha_flush() is called (actually
        mysql_ha_flush() never needs to flush temporary tables).
      sql/sql_insert.cc:
        Update a comment, no more thd->some_tables_deleted.
      sql/sql_parse.cc:
        Implement an incompatible change: entering LOCK TABLES closes
        active HANDLERs, if any.
        Now that we have a sentinel, we don't need to check
        for thd->locked_tables_mode when releasing metadata locks in
        COMMIT/ROLLBACK.
      sql/sql_plist.h:
        Add new (now necessary) methods to the list class.
      sql/sql_prepare.cc:
        Make sure we don't release HANDLER locks when rollback to a
        savepoint, set to not keep locks taken at PREPARE.
      sql/sql_servers.cc:
        Update to a new signature of MDL_context::release_all_locks().
      sql/sql_table.cc:
        Remove thd->some_tables_deleted.
      sql/transaction.cc:
        Add comments. 
        Make sure rollback to (MDL) savepoint works under LOCK TABLES and
        with HANDLER tables.
      a2878a39
    • Sergei Golubchik's avatar
      WL#4738 streamline/simplify @@variable creation process · 6f262201
      Sergei Golubchik authored
      Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables
      Bug#20415 Output of mysqld --help --verbose is incomplete
      Bug#25430 variable not found in SELECT @@global.ft_max_word_len;
      Bug#32902 plugin variables don't know their names
      Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting!
      Bug#34829 No default value for variable and setting default does not raise error
      Bug#34834 ? Is accepted as a valid sql mode
      Bug#34878 Few variables have default value according to documentation but error occurs  
      Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var.
      Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status
      Bug#40988 log_output_basic.test succeeded though syntactically false.
      Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails)
      Bug#42103 Setting key_buffer_size to a negative value may lead t...
      6f262201
  20. 17 Dec, 2009 1 commit
    • Davi Arnaut's avatar
      Bug#48983: Bad strmake calls (length one too long) · c2fb2a9a
      Davi Arnaut authored
      The problem is a somewhat common misusage of the strmake function.
      The strmake(dst, src, len) function writes at most /len/ bytes to
      the string pointed to by src, not including the trailing null byte.
      Hence, if /len/ is the exact length of the destination buffer, a
      one byte buffer overflow can occur if the length of the source
      string is equal to or greater than /len/.
      
      client/mysqldump.c:
        Make room for the trailing null byte.
      libmysql/libmysql.c:
        Add comment, there is enough room in the buffer.
        Increase buffer length, two strings are concatenated.
      libmysqld/lib_sql.cc:
        Make room for the trailing null byte.
      mysys/default.c:
        Make room for the trailing null bytes.
      mysys/mf_pack.c:
        Make room for the trailing null byte.
      server-tools/instance-manager/commands.cc:
        Copy only if overflow isn't possible in both cases.
      server-tools/instance-manager/listener.cc:
        Make room for the trailing null byte.
      sql/log.cc:
        Make room for the trailing null byte.
      sql/sp_pcontext.h:
        Cosmetic fix.
      sql/sql_acl.cc:
        MAX_HOSTNAME already specifies space for the trailing null byte.
      sql/sql_parse.cc:
        Make room for the trailing null byte.
      sql/sql_table.cc:
        Make room for the trailing null byte.
      c2fb2a9a
  21. 16 Dec, 2009 1 commit
    • Sergey Vojtovich's avatar
      Backport from 6.0-codebase. · adb35154
      Sergey Vojtovich authored
      Bug #36098 Audit plugin (wl 3771) feature disabled in 6.0
      avoid recusrive locking of LOCK_plugin
      
      include/mysql/plugin_audit.h:
        fix incorrect version
      sql/log.cc:
        move the common code to a shared header
      sql/mysqld.cc:
        restore the deleted functionality
      sql/set_var.cc:
        remove unused parameter
      sql/sql_audit.h:
        two inline convenience functions
      sql/sql_parse.cc:
        use a simplified convenience call
      sql/sql_plugin.cc:
        unlock LOCK_plugin for plugin->init() call, add missing OOM check,
        issue "unknown variable" error in find_sys_var, not down the stack
      adb35154
  22. 15 Dec, 2009 2 commits
    • Sergey Vojtovich's avatar
      Backport from 6.0-codebase. · 540f8521
      Sergey Vojtovich authored
      WL#3771
        "Audit Plugin Interface"
        Implement new plug-in type - AUDIT
        New plug-in: audit_null
          simply increments counter for how many times it was called.
      
      include/Makefile.am:
        wl3771
          add new headers to distribution
      include/mysql/plugin.h:
        wl3771
          define new AUDIT plugin type
          Split out fulltext plugin type into its own header
      include/mysql/plugin.h.pp:
        wl3771
          no real API change, just re-arranged some code
      include/mysql/plugin_audit.h:
        wl3771
          pluggable audit interface
      include/mysql/plugin_ftparser.h:
        wl3771
          Split out fulltext plugin type into its own header
      libmysqld/CMakeLists.txt:
        wl3771
          add sql_audit.cc to build
      libmysqld/Makefile.am:
        wl3771
          add sql_audit.cc to build
      plugin/audit_null:
        wl3771
          an example plugin for testing pluggable audit interface
      plugin/audit_null/Makefile.am:
        wl3771
          an example plugin for testing pluggable audit interface
      plugin/audit_null/audit_null.c:
        wl3771
          an example plugin for testing pluggable audit interface
      plugin/audit_null/plug.in:
        wl3771
          an example plugin for testing pluggable audit interface
      sql/CMakeLists.txt:
        wl3771
          add sql_audit.cc to build
      sql/Makefile.am:
        wl3771
          add sql_audit.cc to build
      sql/event_queue.cc:
        wl3771
          release audit resources before waiting
      sql/log.cc:
        wl3771
          add general audit call for log
      sql/mysqld.cc:
        wl3771
          add audit initialize/finalize
          add general audit call for error
      sql/sql_audit.cc:
        wl3771
          pluggable audit interface implementation
      sql/sql_audit.h:
        wl3771
          pluggable audit interface implementation
      sql/sql_class.cc:
        wl3771
          add thd audit init/deinit calls
      sql/sql_class.h:
        wl3771
          add required data structures for audit to THD
      sql/sql_connect.cc:
        wl3771
          release audit resources before waiting
      sql/sql_insert.cc:
        wl3771
          release audit plugins before waiting
      sql/sql_parse.cc:
        wl3771
          add general audit call for results
      sql/sql_plugin.cc:
        wl3771
          add declarations for audit plugin type
      540f8521
    • Jon Olav Hauglid's avatar
      Bug #48940 MDL deadlocks against mysql_rm_db · a4d01b7c
      Jon Olav Hauglid authored
      This deadlock would occur between two connections A and B if statements
      where executed in the following way:
      1) Connection A executes a DML statement against table s1.t1 with
      autocommit off. This causes a shared metadata lock on s1.t1 to be 
      acquired. (With autocommit on, the metadata lock will be dropped once
      the statment completes and the deadlock will not occour.)
      2) Connection B tries to DROP DATABASE s1. This will block against the
      metadata lock connection A holds on s1.t1. While blocking, connection B
      will hold the LOCK_mysql_create_db mutex.
      3) Connection A tries to ALTER DATABASE s1. This will block when trying
      to get LOCK_mysql_create_db mutex held by connection B.
      4) Deadlock between DROP DATABASE and ALTER DATABASE (which has autocommit
      off).
      
      If Connection A used an explicitly started transaction rather than having
      autocommit off, this deadlock did not happen as ALTER DATABASE is 
      disallowed inside transactions.
      
      This patch fixes the problem by changing ALTER DATABASE to cause an
      implicit commit before executing. This will cause the metadata 
      lock on s1.t1 to be dropped, allowing DROP DATABASE to proceed. 
      This will in turn cause the LOCK_mysql_create_db mutex to be unlocked, 
      allowing ALTER DATABASE to proceed.
      
      Note that SQL commands other than ALTER DATABASE that also use 
      LOCK_mysql_create_db, already cause an implicit commit. 
      
      Incompatible change: ALTER DATABASE (and its synonym ALTER SCHEMA)
      now cause an implicit commit. This must be reflected in the 
      documentation.
      
      Test case added to schema.test.
      
      
      sql/sql_parse.cc:
        Added CF_AUTO_COMMIT_TRANS to SQLCOM_ALTER_DB.
        
        Removed thd->active_transaction() checks from SQLCOM_DROP_DB, 
        SQLCOM_ALTER_DB_UPGRADE and SQLCOM_ALTER_DB as these statements
        cause an implicit commit.
      a4d01b7c
  23. 11 Dec, 2009 2 commits
    • Marc Alff's avatar
      Merge cleanup · cbb0d4f3
      Marc Alff authored
      cbb0d4f3
    • Konstantin Osipov's avatar
      Backport of: · e4127942
      Konstantin Osipov authored
      ------------------------------------------------------------
       2599.161.3 Ingo Struewing      2009-07-21
       Bug#20667 - Truncate table fails for a write locked table
      
       TRUNCATE TABLE was not allowed under LOCK TABLES.
      
       The patch removes this restriction. mysql_truncate()
       does now handle that case.
      
      
      mysql-test/r/merge.result:
        Bug#20667 - Truncate table fails for a write locked table
        Updated test result.
      mysql-test/r/truncate.result:
        Bug#20667 - Truncate table fails for a write locked table
        Updated test result.
      mysql-test/r/truncate_coverage.result:
        Bug#20667 - Truncate table fails for a write locked table
        New test result.
      mysql-test/t/merge.test:
        Bug#20667 - Truncate table fails for a write locked table
        Updated test case due to now working TRUNCATE under LOCK TABLES.
        Added some SELECTs to show that child tables are truncated.
      mysql-test/t/truncate.test:
        Bug#20667 - Truncate table fails for a write locked table
        Added test cases for TRUNCATE under LOCK TABLE.
      mysql-test/t/truncate_coverage.test:
        Bug#20667 - Truncate table fails for a write locked table
        New test file. Coverage tests for TRUNCATE.
      sql/sql_delete.cc:
        Bug#20667 - Truncate table fails for a write locked table
        Added branches for thd->locked_tables_mode.
      sql/sql_parse.cc:
        Bug#20667 - Truncate table fails for a write locked table
        Deleted rejection of TRUNCATE in case of LOCK TABLES.
      e4127942
  24. 10 Dec, 2009 5 commits
    • Jon Olav Hauglid's avatar
      Backport of revno: 3685 · 7696a241
      Jon Olav Hauglid authored
      Bug #48210 FLUSH TABLES WITH READ LOCK deadlocks
                 against concurrent CREATE PROCEDURE
      
      This deadlock occured between
      a) CREATE PROCEDURE (or other commands listed below)
      b) FLUSH TABLES WITH READ LOCK
      
      If the execution of them happened in the following order:
      - a) opens a table (e.g. mysql.proc)
      - b) locks the global read lock (or GRL)
      - a) sleeps inside wait_if_global_read_lock()
      - b) increases refresh_version and sleeps waiting 
           for old tables to go away
      
      Note that a) must start waiting on the GRL before FLUSH increases
      refresh_version. Otherwise a) won't wait on the GRL and instead
      close its tables for reopen, allowing FLUSH to complete and thus
      avoid the deadlock.
      
      With this patch the deadlock is avoided by making CREATE PROCEDURE
      acquire a protection against global read locks before it starts
      executing. This means that FLUSH TABLES WITH READ LOCK will have
      to wait until CREATE PROCEDURE completes before acquiring the global
      read lock, thereby avoiding the deadlock.
      
      This is implemented by introducing a new SQL command flag called
      CF_PROTECT_AGAINST_GRL. Commands marked with this flag will
      acquire a GRL protection in the beginning of mysql_execute_command().
      This patch adds the flag to CREATE, ALTER and DROP for PROCEDURE
      and FUNCTION, as well as CREATE USER, DROP USER, RENAME USER and 
      REVOKE ALL. All these commands either call open_grant_tables() or
      open_system_table_for_updated() which make them susceptible for
      this deadlock.
      
      The patch also adds the CF_PROTECT_AGAINST_GRL flag to a number
      of commands that previously acquired GRL protection in their
      respective SQLCOM case in mysql_execute_command().
      
      Test case that checks for GRL protection for CREATE PROCEDURE
      and CREATE USER added to mdl_sync.test.
      7696a241
    • Jon Olav Hauglid's avatar
      Backport of revno: 2617.71.1 · 1f09da44
      Jon Olav Hauglid authored
      Bug#42546 Backup: RESTORE fails, thinking it finds an existing table
      
      The problem occured when a MDL locking conflict happened for a non-existent 
      table between a CREATE and a INSERT statement. The code for CREATE 
      interpreted this lock conflict to mean that the table existed, 
      which meant that the statement failed when it should not have.
      The problem could occur for CREATE TABLE, CREATE TABLE LIKE and
      ALTER TABLE RENAME.
      
      This patch fixes the problem for CREATE TABLE and CREATE TABLE LIKE.
      It is based on code backported from the mysql-6.1-fk tree written
      by Dmitry Lenev. CREATE now uses normal open_and_lock_tables() code 
      to acquire exclusive locks. This means that for the test case in the bug 
      description, CREATE will wait until INSERT completes so that it can 
      get the exclusive lock. This resolves the reported bug.
      
      The patch also prohibits CREATE TABLE and CREATE TABLE LIKE under 
      LOCK TABLES. Note that this is an incompatible change and must 
      be reflected in the documentation. Affected test cases have been
      updated.
      
      mdl_sync.test contains tests for CREATE TABLE and CREATE TABLE LIKE.
      
      Fixing the issue for ALTER TABLE RENAME is beyond the scope of this
      patch. ALTER TABLE cannot be prohibited from working under LOCK TABLES
      as this could seriously impact customers and a proper fix would require
      a significant rewrite.
      1f09da44
    • Magne Mahre's avatar
      Bug #46495 Crash in reload_acl_and_cache on SIGHUP · 23f7db77
      Magne Mahre authored
            
      An assert in reload_acl_and_cache didn't account for the
      case when the function is called with a NULL thd.  A
      null thd is used whenever the function is called from the
      SIGHUP signal handler.
      
      Backported from 6.0-codebase  (revid: 2617.69.35)
      
      23f7db77
    • Konstantin Osipov's avatar
      Backport of: · bcc9473e
      Konstantin Osipov authored
      ------------------------------------------------------------
      revno: 2617.68.25
      committer: Dmitry Lenev <dlenev@mysql.com>
      branch nick: mysql-next-bg-pre2-2
      timestamp: Wed 2009-09-16 18:26:50 +0400
      message:
        Follow-up for one of pre-requisite patches for fixing bug #30977
        "Concurrent statement using stored function and DROP FUNCTION
        breaks SBR".
      
        Made enum_mdl_namespace enum part of MDL_key class and removed MDL_
        prefix from the names of enum members. In order to do the latter
        changed name of PROCEDURE symbol to PROCEDURE_SYM (otherwise macro
        which was automatically generated for this symbol conflicted with
        MDL_key::PROCEDURE enum member).
      bcc9473e
    • Marc Alff's avatar
      WL#2360 Performance schema · 76d33819
      Marc Alff authored
      Part III: mysys instrumentation
      76d33819
  25. 09 Dec, 2009 4 commits
    • Jon Olav Hauglid's avatar
      Backport of revno: 2617.68.13 · ca5cd40c
      Jon Olav Hauglid authored
      Introduce a counter for protection against global read lock on thread level.
      
      The functions for protection against global read lock sometimes need a local
      variable to signal when the protection is set, and hence need to be released.
      It would be better to control this behaviour via a counter on the THD struct,
      telling how many times the protection has been claimed by the current thread.
      A side-effect of the fix is that if protection is claimed twice for a thread,
      only a simple increment is required for the second claim, instead of a
      mutex-protected increment of the global variable protect_against_global_read_lock.
      
      
      sql/lock.cc:
        Count how many times that we have claimed protection against global read lock.
        Assert that we really have the protection when releasing it.
        Added comments to all functions operating on global_read_lock.
      sql/sql_class.cc:
        Added the counter variable global_read_lock_protection.
      sql/sql_class.h:
        Added the counter variable global_read_lock_protection.
      sql/sql_parse.cc:
        Replaced test on local variable need_start_waiting with test on
        thd->global_read_lock_protection.
      sql/sql_table.cc:
        Replaced test on local variable need_start_waiting with test on
        thd->global_read_lock_protection.
      sql/sql_trigger.cc:
        Inserted test on thd->global_read_lock_protection.
      ca5cd40c
    • Jon Olav Hauglid's avatar
      Backport of revno: 2617.31.30 · b97beb08
      Jon Olav Hauglid authored
      Bug #21793 Missing CF_CHANGES_DATA and CF_STATUS_COMMAND for 
                 handful of commands
      
      CF_CHANGES_DATA and CF_STATUS_COMMAND flags added to the 
      commands mentioned in the bug description. With the following
      two exceptions: 
      
      1) 4 commands do not exist: 
      SQLCOM_RENAME_DB
      SQLCOM_LOAD_MASTER_DATA
      SQLCOM_LOAD_MASTER_TABLE
      SQLCOM_SHOW_COLUMN_TYPES
      
      2) All SQLCOM_SHOW_* commands already had CF_STATUS_COMMAND,
      leaving only SQLCOM_BINLOG_BASE64_EVENT.
      
      Further, check_prepared_statement() in sql_prepare.cc has been
      simplified by taking advantage of the CF_STATUS_COMMAND flag.
      
      Note that no test case has been added.
      b97beb08
    • Jon Olav Hauglid's avatar
      Backport of revno: 2617.76.2 · faf5bea5
      Jon Olav Hauglid authored
      Bug #47107 assert in notify_shared_lock on incorrect CREATE TABLE , HANDLER
      
      Attempts to create a table (using CREATE TABLE, CREATE TABLE LIKE or
      CREATE TABLE SELECT statements) which already existed and was opened
      by the same connection through HANDLER statement, led to a stalled
      connection (for production builds of the server) or to the server being
      aborted due to an assertion failure (for debug builds of the server).
      
      This problem was introduced by the new implementation of a metadata
      locking subsystem and didn't affect earlier versions of the server.
      
      The cause of the problem was that the HANDLER was not closed by CREATE TABLE
      before CREATE tried to open and lock the table. Acquiring an exclusive MDL
      lock on the table to be created would therefore fail since HANDLER
      already had a shared MDL lock. This triggered an assert as the 
      HANDLER and CREATE statements came from the same thread (self-deadlock).
      
      This patch resolves the issue by closing any open HANDLERs on tables
      to be created by CREATE TABLE, similar to what is already done for 
      DROP and ALTER TABLE.
      
      Test case added to create.test.
      faf5bea5
    • Jon Olav Hauglid's avatar
      Backport of revno: 2617.69.40 · 942e8c7d
      Jon Olav Hauglid authored
      A pre-requisite patch for Bug#30977 "Concurrent statement using 
      stored function and DROP FUNCTION breaks SBR".
      
      This patch changes the MDL API by introducing a namespace for
      lock keys: MDL_TABLE for tables and views and MDL_PROCEDURE
      for stored procedures and functions. The latter is needed for
      the fix for Bug#30977.
      942e8c7d
  26. 08 Dec, 2009 2 commits
    • Konstantin Osipov's avatar
      Backport of: · fcad8201
      Konstantin Osipov authored
      ----------------------------------------------------------
      revno: 2617.69.24
      committer: Konstantin Osipov <kostja@sun.com>
      branch nick: 5.4-42546
      timestamp: Fri 2009-08-14 19:22:05 +0400
      message:
        A pre-requisite for a fix for Bug#42546 "Backup: RESTORE fails, thinking it
        finds an existing table"
        Back-port from WL 148 "Foreign keys" feature tree a patch
        that introduced Prelocking_strategy class -- a way to parameterize
        open_tables() behaviour, implemented by Dmitry Lenev.
      
      (Part of WL#4284).
      
      sql/sql_base.cc:
        Implement different prelocking strategies. Use an instance of
        prelocking_strategy in open_tables().
      sql/sql_class.h:
        Add declarations for class Prelocking_strategy.
      sql/sql_lex.h:
        Add a helper method to access last table of the global table list
        (lex->query_tables).
      sql/sql_parse.cc:
        Use a special prelocking strategy when locking tables for LOCK TABLES.
      sql/sql_table.cc:
        Use normal open_and_lock_tables_derived() in ALTER TABLE.
      sql/sql_yacc.yy:
        Modify the grammar to not pollute the global table list with tables
        that should not be opened.
      fcad8201
    • Konstantin Osipov's avatar
      Backport of: · 6d86b560
      Konstantin Osipov authored
      ----------------------------------------------------------
      revno: 2617.69.20
      committer: Konstantin Osipov <kostja@sun.com>
      branch nick: 5.4-4284-1-assert
      timestamp: Thu 2009-08-13 18:29:55 +0400
      message:
        WL#4284 "Transactional DDL locking"
        A review fix.
        Since WL#4284 implementation separated MDL_request and MDL_ticket,
        MDL_request becamse a utility object necessary only to get a ticket.
        Store it by-value in TABLE_LIST with the intent to merge
        MDL_request::key with table_list->table_name and table_list->db
        in future.
        Change the MDL subsystem to not require MDL_requests to
        stay around till close_thread_tables().
        Remove the list of requests from the MDL context.
        Requests for shared metadata locks acquired in open_tables()
        are only used as a list in recover_from_failed_open_table_attempt(),
        which calls mdl_context.wait_for_locks() for this list.
        To keep such list for recover_from_failed_open_table_attempt(),
        introduce a context class (Open_table_context), that collects
        all requests.
        A lot of minor cleanups and simplications that became possible
        with this change.
      
      
      sql/event_db_repository.cc:
        Remove alloc_mdl_requests(). Now MDL_request instance is a member
        of TABLE_LIST, and init_one_table() initializes it.
      sql/ha_ndbcluster_binlog.cc:
        Remove now unnecessary declaration and initialization
        of binlog_mdl_request.
      sql/lock.cc:
        No need to allocate MDL requests in lock_table_names() now.
      sql/log.cc:
        Use init_one_table() method, remove alloc_mdl_requests(),
        which is now unnecessary.
      sql/log_event.cc:
        No need to allocate mdl_request separately now.
        Use init_one_table() method.
      sql/log_event_old.cc:
        Update to the new signature of close_tables_for_reopen().
      sql/mdl.cc:
        Update try_acquire_exclusive_lock() to be more easy to use.
        Function lock_table_name_if_not_cached() has been removed.
        Make acquire_shared_lock() signature consistent with
        try_acquire_exclusive_lock() signature.
        Remove methods that are no longer used.
        Update comments.
      sql/mdl.h:
        Implement an assignment operator that doesn't
        copy MDL_key (MDL_key::operator= is private and
        should remain private).
        This is a hack to work-around assignment of TABLE_LIST
        by value in several places. Such assignments violate
        encapsulation, since only perform a shallow copy.
        In most cases these assignments are a hack on their own.
      sql/mysql_priv.h:
        Update signatures of close_thread_tables() and close_tables_for_reopen().
      sql/sp.cc:
        Allocate TABLE_LIST in thd->mem_root.
        Use init_one_table().
      sql/sp_head.cc:
        Use init_one_table().
        Remove thd->locked_tables_root, it's no longer needed.
      sql/sql_acl.cc:
        Use init_mdl_requests() and init_one_table().
      sql/sql_base.cc:
        Update to new signatures of try_acquire_shared_lock() and
        try_acquire_exclusive_lock().
        Remove lock_table_name_if_not_cached().
        Fix a bug in open_ltable() that would not return ER_LOCK_DEADLOCK
        in case of a failed lock_tables() and a multi-statement
        transaction.
        Fix a bug in open_and_lock_tables_derived() that would
        not return ER_LOCK_DEADLOCK in case of a multi-statement
        transaction and a failure of lock_tables().
        Move assignment of enum_open_table_action to a method of Open_table_context, a new class that maintains information
        for backoff actions.
        Minor rearrangements of the code.
        Remove alloc_mdl_requests() in functions that work with system
        tables: instead the patch ensures that callers always initialize
        TABLE_LIST argument.
      sql/sql_class.cc:
        THD::locked_tables_root is no more.
      sql/sql_class.h:
        THD::locked_tables_root is no more.
        Add a declaration for Open_table_context class.
      sql/sql_delete.cc:
        Update to use the simplified MDL API.
      sql/sql_handler.cc:
        TABLE_LIST::mdl_request is stored by-value now.
        Ensure that mdl_request.ticket is NULL for every request
        that is passed into MDL, to satisfy MDL asserts.
        @ sql/sql_help.cc
        Function open_system_tables_for_read() no longer initializes
        mdl_requests.
        Move TABLE_LIST::mdl_request initialization closer to
        TABLE_LIST initialization.
      sql/sql_help.cc:
        Function open_system_tables_for_read() no longer initializes
        mdl_requests.
        Move TABLE_LIST::mdl_request initialization closer to
        TABLE_LIST initialization.
      sql/sql_insert.cc:
        Remove assignment by-value of TABLE_LIST in
        TABLEOP_HOOKS. We can't carry over a granted
        MDL ticket from one table list to another.
      sql/sql_parse.cc:
        Change alloc_mdl_requests() -> init_mdl_requests().
        @todo We can remove init_mdl_requests() altogether
        in some places: all places that call add_table_to_list()
        already have mdl requests initialized.
      sql/sql_plugin.cc:
        Use init_one_table().
        THD::locked_tables_root is no more.
      sql/sql_servers.cc:
        Use init_one_table().
      sql/sql_show.cc:
        Update acquire_high_priority_shared_lock() to use
        TABLE_LIST::mdl_request rather than allocate an own.
        Fix get_trigger_table_impl() to use init_one_table(),
        check for out of memory, follow the coding style.
      sql/sql_table.cc:
        Update to work with TABLE_LIST::mdl_request by-value.
        Remove lock_table_name_if_not_cached().
        The code that used to delegate to it is quite simple and
        concise without it now.
      sql/sql_udf.cc:
        Use init_one_table().
      sql/sql_update.cc:
        Update to use the new signature of close_tables_for_reopen().
      sql/table.cc:
        Move re-setting of mdl_requests for prepared statements
        and stored procedures from close_thread_tables() to
        reinit_stmt_before_use().
        Change alloc_mdl_requests() to init_mdl_requests().
        init_mdl_requests() is a hack that can't be deleted
        until we don't have a list-aware TABLE_LIST constructor.
        Hopefully its use will be minimal
      sql/table.h:
        Change alloc_mdl_requests() to init_mdl_requests()
        TABLE_LIST::mdl_request is stored by value.
      sql/tztime.cc:
        We no longer initialize mdl requests in open_system_tables_for*()
        functions. Move this initialization closer to initialization
        of the rest of TABLE_LIST members.
      storage/myisammrg/ha_myisammrg.cc:
        Simplify mdl_request initialization.
      6d86b560