1. 16 Dec, 2009 3 commits
  2. 15 Dec, 2009 4 commits
    • Konstantin Osipov's avatar
      Merge next-mr -> next-4284. · 34177cc9
      Konstantin Osipov authored
      34177cc9
    • Konstantin Osipov's avatar
      Merge next-mr -> next-4284. · 75fa4b6a
      Konstantin Osipov authored
      75fa4b6a
    • Konstantin Osipov's avatar
      Merge next-mr -> next-4284. · a16c0512
      Konstantin Osipov authored
      a16c0512
    • 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
  3. 11 Dec, 2009 11 commits
    • 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
    • Konstantin Osipov's avatar
      Backport of: · 6dc51c81
      Konstantin Osipov authored
      -----------------------------------------------------------
      2630.28.28 Magne Mahre  2008-12-05
      Bug #38661 'all threads hang in "opening tables" or "waiting for table"
                  and cpu is at 100%'
                            
      Concurrent execution of FLUSH TABLES statement and at least two statements
      using the same table might have led to live-lock which caused all three
      connections to stall and hog 100% of CPU.
              
      tdc_wait_for_old_versions() wrongly assumed that there cannot be a share
      with an old version and no used TABLE instances and thus was failing to
      perform wait in situation when such old share was cached in MDL subsystem
      thanks to a still active metadata lock on the table. So it might have
      happened that two or more connections simultaneously executing statements
      which involve table being flushed managed to prevent each other from
      waiting in this function by keeping shared metadata lock on the table 
      constantly active (i.e. one of the statements managed to take/hold this
      lock while other statements were calling tdc_wait_for_old_versions()).
      Thus they were forcing each other to loop infinitely in open_tables() - 
      close_thread_tables_for_reopen() - tdc_wait_for_old_versions() cycle
      causing CPU hogging.
              
      This patch fixes this problem by removing this false assumption from
      tdc_wait_for_old_versions().
       
      Note that the problem is specific only for server versions >= 6.0.
              
      No test case is submitted for this test, as the test infrastructure
      hasn't got the necessary primitives to test the behaviour.  The
      manifestation is that throughput will decrease to a low level
      (possibly 0) after some time, and stay at that level. Several
      transactions will not complete. 
              
      Manual testing can be done by running the code submitted by Shane 
      Bester attached to the bug report.  If the bug persists, the 
      transaction thruput will almost immediately drop to near zero 
      (shown as the transaction count output from the test program staying 
      on a close to constant value, instead of increasing rapidly).
      6dc51c81
    • Konstantin Osipov's avatar
      Partial backport of: · 9f37eecd
      Konstantin Osipov authored
      -----------------------------------------------------------
      2497.392.1 Michael Widenius	2008-08-19
      Fixes for Bug #38016 Maria: trying to access freed memory when
      committing a transaction.
      Don't write out states if they haven't changed.
      
      
      sql/sql_table.cc:
        Call extra(HA_EXTRA_PREPARE_FOR_RENAME) before renaming a table.
      9f37eecd
    • Konstantin Osipov's avatar
      Partial backport of: · 25793f1e
      Konstantin Osipov authored
      ----------------------------------------------------
      2736.2.10 Michael Widenius	2008-10-22
      Fix for bug#39395 Maria: ma_extra.c:286: maria_extra: 
      Assertion `share->reopen == 1' failed
      
      
      sql/sql_base.cc:
        Race condition in wait_while_table_is_used() where a table used 
        by another connection could be forced closed, but there was no protection against the other thread re-opening the table and trying to lock it 
        again before the table was name locked by original thread.
      25793f1e
    • Konstantin Osipov's avatar
      Merge with next-4284. · 3ca7625f
      Konstantin Osipov authored
      3ca7625f
    • Alexander Nozdrin's avatar
      Auto-merge from mysql-trunk. · dee03a1c
      Alexander Nozdrin authored
      dee03a1c
    • Alexander Nozdrin's avatar
      Remove BitKeeper dir and .cvsignore. · 1d6ef03b
      Alexander Nozdrin authored
      1d6ef03b
    • Alexander Nozdrin's avatar
      Auto-merge (empty) from mysql-next-mr. · 3ec9ef42
      Alexander Nozdrin authored
      3ec9ef42
    • Alexander Nozdrin's avatar
      Auto-merge (empty) from mysql-trunk. · caef759b
      Alexander Nozdrin authored
      caef759b
    • Alexander Nozdrin's avatar
      13257ccc
    • Alexander Nozdrin's avatar
      Auto-merge from mysql-trunk-bugfixing. · 7152c65f
      Alexander Nozdrin authored
      7152c65f
  4. 10 Dec, 2009 22 commits
    • Alexander Nozdrin's avatar
      c9b4bac2
    • Magne Mahre's avatar
      Bug#46374 crash, INSERT INTO t1 uses function, function modifies t1 · 2930b825
      Magne Mahre authored
                        
      An error occuring in the execution of a stored procedure, called
      from do_select is masked, since the error condition is not
      propagated back to the caller (join->conds->val_int() returns
      a result value, and not an error code)
                        
      An explicit check was added to see if the thd error code has been
      set, and if so, the loop status is set to the error state.
      
      Backport from 6.0-codebase (revid: 2617.68.31)
      2930b825
    • Magne Mahre's avatar
      Bug#41425 Assertion in Protocol::end_statement() (pushbuild2) · d23b9ff1
      Magne Mahre authored
                (diagnostics_area)
            
      Execution of CREATE TABLE ... SELECT statement was not atomic in
      the sense that concurrent statements trying to affect its target
      table might have sneaked in between the moment when the table was
      created and moment when it was filled according to SELECT clause.
      This resulted in inconsistent binary log, unexpected target table
      contents. In cases when concurrent statement was a DDL statement
      CREATE TABLE ... SELECT might have failed with ER_CANT_LOCK error.
            
      In more detail:
      Due to premature metadata lock downgrade which occured after CREATE
      TABLE SELECT statement created table but before it managed to obtain
      table-level lock on it other statements were allowed to open, lock
      and change target table in the middle of CREATE TABLE SELECT
      execution. This also meant that it was possible that CREATE TABLE
      SELECT would wait in mysql_lock_tables() when it was called for newly
      created table and that this wait could have been aborted by concurrent
      DDL. The latter led to execution of unexpected branch of code and
      CREATE TABLE SELECT ending with ER_CANT_LOCK error.
            
      The premature downgrade occured because open_table(), which was called
      for newly created table, decided that it is OK to downgrade metadata
      lock from exclusive to shared since table exists, even although it
      was not acquired within this call.
            
      This fix ensures that open_table() does not downgrade metadata lock
      if it is not acquired during its current invocation.
            
      Testing:
      The bug is exposed in a race condition, and is thus difficult to
      expose in a standard mysql-test-run test case.  Instead, a stress
      test using the Random Query Generator (https://launchpad.net/randgen)
      will trip the problem occasionally.
            
         % perl  runall.pl \
                  --basedir=<build dir> \
                   --mysqld=--table-lock-wait-timeout=5 \
                   --mysqld=--skip-safemalloc \
                   --grammar=conf/maria_bulk_insert.yy \
                   --reporters=ErrorLog,Backtrace,WinPackage \
                   --mysqld=--log-output=file  \
                   --queries=100000 \
                   --threads=10 \
                   --engine=myisam
            
      Note: You will need a debug build to expose the bug
            
      When the bug is tripped, the server will abort and dump core.
      
      
      Backport from 6.0-codebase   (revid: 2617.53.4)
      d23b9ff1
    • Alexander Nozdrin's avatar
      3d209a97
    • Alexander Nozdrin's avatar
      Auto-merge (empty) from mysql-trunk. · 3e5d33c9
      Alexander Nozdrin authored
      3e5d33c9
    • Alexander Nozdrin's avatar
      Auto-merge from mysql-next-mr. · b35892bc
      Alexander Nozdrin authored
      b35892bc
    • Jon Olav Hauglid's avatar
      Backport of revno: 3690 · f797ba9e
      Jon Olav Hauglid authored
      Postfix for Bug#48210 FLUSH TABLES WITH READ LOCK deadlocks
                            against concurrent CREATE PROCEDURE
      
      Rewrote the second test to use DROP PROCEDURE instead of 
      CREATE USER as CREATE USER does not work with embedded server.
      f797ba9e
    • 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
    • Konstantin Osipov's avatar
      Backport of: · 60372471
      Konstantin Osipov authored
       2630.16.14 Sergei Golubchik	2008-08-25
       fixed a crash in partition tests
       introduced by HA_EXTRA_PREPARE_FOR_DROP patch
      
      
      sql/sql_base.cc:
        Don't call ::extra() for closed tables.
      60372471
    • Jon Olav Hauglid's avatar
      Backport of revno: 2617.80.1 · 2768ed9f
      Jon Olav Hauglid authored
      Also re-enables the test for Bug #43867
      
      Followup to Bug#46654 False deadlock on concurrent DML/DDL with partitions, 
                            inconsistent behavior
      
      Partition_sync.test uses features only available in debug builds.
      Disabling the test for non-debug builds.
      2768ed9f
    • Konstantin Osipov's avatar
      Backport a part of Monty's fix for Bug#39396, rev. 2736.2.11 · 569c31f4
      Konstantin Osipov authored
      "ha_maria.cc:2415: assertion in ha_maria::store_lock()".
      
      sql/lock.cc:
        Fixed wrong cleanup of mysql_lock_tables()
        - We must call read_lock_data() BEFORE we set 
        lock_count to 0. Added DBUG statements.
      569c31f4
    • Jon Olav Hauglid's avatar
      Backport of revno: 2617.68.37 · a7dbba6e
      Jon Olav Hauglid authored
      Bug #46654 False deadlock on concurrent DML/DDL with partitions, 
                 inconsistent behavior
      
      The problem was that if one connection is running a multi-statement 
      transaction which involves a single partitioned table, and another 
      connection attempts to alter the table, the first connection gets 
      ER_LOCK_DEADLOCK and cannot proceed anymore, even when the ALTER TABLE 
      statement in another connection has timed out or failed.
      
      The reason for this was that the prepare phase for ALTER TABLE for 
      partitioned tables removed all instances of the table from the table 
      definition cache before it started waiting on the lock. The transaction 
      running in the first connection would notice this and report ER_LOCK_DEADLOCK. 
      
      This patch changes the prep_alter_part_table() ALTER TABLE code so that 
      tdc_remove_table() is no longer called. Instead, only the TABLE instance
      changed by prep_alter_part_table() is marked as needing reopen.
      
      The patch also removes an unnecessary call to tdc_remove_table() from 
      mysql_unpack_partition() as the changed TABLE object is destroyed by the 
      caller at a later point.
      
      Test case added in partition_sync.test.
      a7dbba6e
    • Jon Olav Hauglid's avatar
      Backport of revno: 3514 · 38f010b2
      Jon Olav Hauglid authored
      Bug#40181 Made use of tdc_remove_table instead of just 
      setting share->version to 0 to make sure all unused table
      instances go away as part of CREATE/ALTER TABLE.
      38f010b2
    • Jon Olav Hauglid's avatar
      Backport of revno: 3673 · 91af324f
      Jon Olav Hauglid authored
      Bug #47313 assert in check_key_in_view during CALL procedure
      
      View definitions are inlined in a stored procedure when the procedure
      is fist called. This means that if a temporary table is later added
      with the same name as the view, the stored procedure will still
      use the view. This happens even if temporary tables normally shadow
      base tables/views.
      
      The reason for the assert was that even if the stored procedure
      referenced the view, open_table() still tried to open the
      temporary table. This "half view/half temporary table" state
      caused the assert.
      
      The bug was not present in 5.1 as open_table() is not called
      for the view there. This code was changed with the introduction 
      of MDL in order to properly lock the view and any objects it 
      refers to.
      
      This patch fixes the problem by instructing open_table()
      to open base tables/views (using OT_BASE_ONLY) when reopening
      tables/views used by stored procedures. This also means that
      a prepared statement is no longer invalidated if a temporary
      table is created with the same name as a view used in the
      prepared statement.
      
      Test case added to sp.test. The test case also demonstrates
      the effect of sp cache invalidation between CALLs.
      
      
      mysql-test/t/ps_ddl.test:
        Extended the VIEW->TEMPORARY TABLE transition test to cover not only
        merged views, but now also materialized views and views containing
        a reference to an information schema table. 
        
        Test also updated to reflect the change to prepared statement
        invalidatation.
      91af324f
    • Jon Olav Hauglid's avatar
      Backport of revno: 2617.68.45 · 16f5800d
      Jon Olav Hauglid authored
      Bug #47635 assert in start_waiting_global_read_lock during CREATE VIEW
      
      The problem was that CREATE VIEW would trigger an assert if
      a temporary table with the same name already existed.
      
      This bug was fixed by the patch for Bug#47335. CREATE/ALTER VIEW
      will now ignore temporary tables. See Bug#47335 for more information.
      
      Test case added to view.test.
      16f5800d
    • Jon Olav Hauglid's avatar
      Backport of revno: 2617.68.43 · 49c76ae7
      Jon Olav Hauglid authored
      Bug #47335 assert in get_table_share
      
      The assert would happen if ALTER VIEW was used to alter a view (existing 
      or non-existing) and a temporary table with the same name already existed.
      
      The assert is triggered if the current statement does not have a MDL lock on 
      the view to be altered. This would happen because open_table() would open 
      the temporary table instead and MDL locks are not taken for temporary 
      tables (since they are local to one connection).
      
      The patch changes open_type for CREATE/ALTER VIEW to OT_BASE_ONLY. This prevents 
      open_table() from trying to open a temporary table with the same name should
      one exist. Now the view will be altered if it exists or ER_NO_SUCH_TABLE will
      be reported if it does not.
      
      Test case added to view.test
      49c76ae7
    • Jon Olav Hauglid's avatar
      Backport of revno: 2617.68.3 · 0c5786f4
      Jon Olav Hauglid authored
      Followup to Bug#42546 Backup: RESTORE fails, thinking it finds an existing table
      
      This patch updates lowercase_table2.test with the changed error message
      CREATE TABLE produces if it fails because it finds an matching TABLE_SHARE 
      in the TDC even if the .FRM/.MYD has been removed from disk.
      
      With the changes introduced in Bug#42546, CREATE TABLE uses open_tables()
      which will find the TDC entry and fail in open_table_from_share() with
      ER_FILE_NOT_FOUND. Before, CREATE TABLE would not use open_tables() and
      fail with ER_TABLE_EXISTS_ERROR upon finding the TDC entry in
      mysql_create_table_no_lock().
      0c5786f4
    • 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
    • Sergey Vojtovich's avatar
    • Konstantin Osipov's avatar
      Merge with next-4284. · 65ded56f
      Konstantin Osipov authored
      65ded56f
    • 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