Uploaded image for project: 'MariaDB ColumnStore'
  1. MariaDB ColumnStore
  2. MCOL-5603

Online alter can break data consistency

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Critical
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      Online alter (LOCK=NONE, which is default) works as follows:
      1. Acquire an exclusive MDL lock for a short duration
      2. Acquire TL_READ
      3. Downgrade MDL to MDL_SHARED_UPGRADABLE to allow concurrent writes
      4. Copy and replicate online changes
      5. Unlock TL
      6. Replicate the rest of online changes
      5. Upgrade to MDL_EXCLUSIVE
      6. Unlock all

      This means that now MCS can end up with inconsistent data if some concurrent writes were executed during alter table:

      con1: ALTER TABLE t ....
      con1: # concider it reached stage 4
      con2: INSERT y; COMMIT;
      

      this may end up in the record y inserted twice in the resulting table.

      Context: MDL – Metadata lock, multi-granular lock that protects table metadata. Represented by MDL_request class and TABLE_LIST::mdl_request field respectively. See enum_mdl_type for the granularity types and MDL_lock::MDL_object_lock::m_granted_incompatible for the compatibility matrix.
      TL lock - a table data lock represented by thr_lock_type enum and stored in TABLE_LIST::lock_type and TABLE::reg_info.lock_type. Typically propagated to a stronger lock type then provided by a storage engine in handler::store_lock. Refer to mysql_lock_tables/mysql_unlock_tables for further info.

      Reproduction:
      1. Compile the sql server with -DCMAKE_BUILD_TYPE=Debug
      2. Run the mtr test

      create or replace table t1 (a int, b int, key(a)) engine=columnstore;
      insert t1 values (1, 11);
      insert t1 values (2, 22);
      insert t1 values (3, 33);
      insert t1 values (4, 44);
      insert t1 values (5, 55);
       
      set debug_sync= 'alter_table_online_downgraded SIGNAL downgraded WAIT_FOR ins';
      send alter table t1 add c int algorithm= copy, lock= none;
       
      --connect (con1, localhost, root,,)
      set debug_sync= 'now WAIT_FOR downgraded';
      set lock_wait_timeout= 0; # the correct behavior is to wait until alter table ends
      --error 0,ER_LOCK_WAIT_TIMEOUT
      insert t1 values (7, 77); # autocommit
       
      set debug_sync= 'now SIGNAL ins';
       
      --connection default
      reap;
       
      # row 7, 77 should not happen twice! (but can be 0 times in case of lock timeout)
      select * from t1; 
      
      

      Attachments

        Issue Links

          Activity

            People

              drrtuy Roman
              nikitamalyavin Nikita Malyavin
              Kirill Perov Kirill Perov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.