Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-15250

UPSERT during ALTER-TABLE results in 'Duplicate entry' error for alter

Details

    Description

      I have a master that very frequently executes INSERT ON DUPLICATE KEY UPDATE. On a slave I executed ALTER TABLE xx row_format=COMPRESSED;, however this resulted in an error (the specific key is a UNIQUE) from the ALTER statement, which did not succeed:

      ERROR 1062 (23000): Duplicate entry 'xxx-xxx' for key 'xxx'

      I assume this is because it received an UPSERT while it was altering the table. I think this shouldn't happen as the alter-table should have a lock on the table.

      Attachments

        Issue Links

          Activity

            sjon sjon created issue -

            Please provide SHOW CREATE TABLE for the table before and after ALTER, indicate what exactly UPDATE updates, and attach your config files. Thanks.

            elenst Elena Stepanova added a comment - Please provide SHOW CREATE TABLE for the table before and after ALTER, indicate what exactly UPDATE updates, and attach your config files. Thanks.
            elenst Elena Stepanova made changes -
            Field Original Value New Value
            Labels need_feedback
            elenst Elena Stepanova made changes -
            Fix Version/s N/A [ 14700 ]
            Resolution Incomplete [ 4 ]
            Status Open [ 1 ] Closed [ 6 ]

            I do not need a test case to confirm that this is a problem of my design of WL#5526 and WL#6255 in MySQL 5.6, affecting MariaDB 10.0 and later. The same issue was mentioned in MDEV-14535 but fixed in a special case.

            marko Marko Mäkelä added a comment - I do not need a test case to confirm that this is a problem of my design of WL#5526 and WL#6255 in MySQL 5.6, affecting MariaDB 10.0 and later. The same issue was mentioned in MDEV-14535 but fixed in a special case.
            marko Marko Mäkelä made changes -
            Assignee Marko Mäkelä [ marko ]
            Resolution Incomplete [ 4 ]
            Status Closed [ 6 ] Stalled [ 10000 ]

            The design problem is that currently, any DML operations that are being executed concurrently with an online index creation (MySQL WL#5526) or online table rebuild (MySQL WL#6625) will be logged immediately. For example, BEGIN;INSERT;ROLLBACK; will be logged as INSERT and DELETE.

            To prevent the ‘fake’ duplicates, we can simply write online_log on transaction commit. In that way, any duplicate key errors during online table rebuild will be filtered out from the online_log, because such duplicate key errors would also occur on the original table, leading to full or partial rollback of the transaction.

            That is, on transaction commit, we would check if any table in trx_t::mod_tables requires changes to be logged. If yes, we would scan the undo logs that the transaction generated, and write online_log to the affected tables during transaction commit.

            marko Marko Mäkelä added a comment - The design problem is that currently, any DML operations that are being executed concurrently with an online index creation (MySQL WL#5526) or online table rebuild (MySQL WL#6625) will be logged immediately. For example, BEGIN;INSERT;ROLLBACK; will be logged as INSERT and DELETE . To prevent the ‘fake’ duplicates, we can simply write online_log on transaction commit. In that way, any duplicate key errors during online table rebuild will be filtered out from the online_log , because such duplicate key errors would also occur on the original table, leading to full or partial rollback of the transaction. That is, on transaction commit, we would check if any table in trx_t::mod_tables requires changes to be logged. If yes, we would scan the undo logs that the transaction generated, and write online_log to the affected tables during transaction commit.
            marko Marko Mäkelä made changes -
            marko Marko Mäkelä made changes -
            marko Marko Mäkelä made changes -
            Component/s Storage Engine - InnoDB [ 10129 ]
            Fix Version/s 10.3 [ 22126 ]
            Fix Version/s 10.4 [ 22408 ]
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.7 [ 24805 ]
            Fix Version/s 10.8 [ 26121 ]
            Fix Version/s N/A [ 14700 ]
            Affects Version/s 10.0 [ 16000 ]
            Affects Version/s 10.1 [ 16100 ]
            Affects Version/s 10.2 [ 14601 ]
            Affects Version/s 10.3 [ 22126 ]
            Affects Version/s 10.4 [ 22408 ]
            Affects Version/s 10.5 [ 23123 ]
            Affects Version/s 10.6 [ 24028 ]
            Affects Version/s 10.7 [ 24805 ]
            Affects Version/s 10.8 [ 26121 ]
            Environment archlinux
            Labels need_feedback

            In secondary index creation (especially CREATE UNIQUE INDEX or ALTER TABLE…ADD UNIQUE INDEX) there is an additional phenomenon: A secondary index may be complete but not committed. That is, the online secondary index creation operation would wait for an exclusive metadata lock so that the operation can be committed. A conflicting metadata lock could be held by a transaction that is concurrently modifying the table. Such transactions will have to update the uncommitted index directly. Duplicate key errors must not be reported to the DML transaction if the unique index has not been committed yet. They are reported to the DDL transaction. Also such reporting is now premature and could lead to false duplicates. I think that we can apply changes to uncommitted indexes at transaction commit time.

            marko Marko Mäkelä added a comment - In secondary index creation (especially CREATE UNIQUE INDEX or ALTER TABLE…ADD UNIQUE INDEX ) there is an additional phenomenon: A secondary index may be complete but not committed. That is, the online secondary index creation operation would wait for an exclusive metadata lock so that the operation can be committed. A conflicting metadata lock could be held by a transaction that is concurrently modifying the table. Such transactions will have to update the uncommitted index directly. Duplicate key errors must not be reported to the DML transaction if the unique index has not been committed yet. They are reported to the DDL transaction. Also such reporting is now premature and could lead to false duplicates. I think that we can apply changes to uncommitted indexes at transaction commit time.
            marko Marko Mäkelä made changes -
            Priority Major [ 3 ] Blocker [ 1 ]
            marko Marko Mäkelä made changes -
            Priority Blocker [ 1 ] Critical [ 2 ]
            marko Marko Mäkelä made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 85494 ] MariaDB v4 [ 144475 ]
            marko Marko Mäkelä made changes -

            thiru, I hope that you can complete my prototype. I believe that fixing this may simplify the MDEV-26294 fix in the case that row_log_apply() completed but the ALTER TABLE operation was not committed yet (because the SQL layer is waiting for MDL_EXCLUSIVE, which is blocked by concurrent DML transactions).

            marko Marko Mäkelä added a comment - thiru , I hope that you can complete my prototype. I believe that fixing this may simplify the MDEV-26294 fix in the case that row_log_apply() completed but the ALTER TABLE operation was not committed yet (because the SQL layer is waiting for MDL_EXCLUSIVE , which is blocked by concurrent DML transactions).
            marko Marko Mäkelä made changes -
            marko Marko Mäkelä made changes -
            Assignee Marko Mäkelä [ marko ] Thirunarayanan Balathandayuthapani [ thiru ]
            thiru Thirunarayanan Balathandayuthapani made changes -
            Assignee Thirunarayanan Balathandayuthapani [ thiru ] Marko Mäkelä [ marko ]
            Status In Progress [ 3 ] In Review [ 10002 ]

            I posted the first batch of review comments. I did not yet thoroughly check all the new code in trx_t::apply_log(), especially the trx_undo_rec_info. Some source code comments would be very helpful in that area.

            marko Marko Mäkelä added a comment - I posted the first batch of review comments . I did not yet thoroughly check all the new code in trx_t::apply_log() , especially the trx_undo_rec_info . Some source code comments would be very helpful in that area.
            marko Marko Mäkelä made changes -
            Assignee Marko Mäkelä [ marko ] Thirunarayanan Balathandayuthapani [ thiru ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            thiru Thirunarayanan Balathandayuthapani made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            • Addressed all review comments.
            thiru Thirunarayanan Balathandayuthapani added a comment - Addressed all review comments.
            thiru Thirunarayanan Balathandayuthapani made changes -
            Assignee Thirunarayanan Balathandayuthapani [ thiru ] Marko Mäkelä [ marko ]
            Status In Progress [ 3 ] In Review [ 10002 ]

            Code coverage analysis looks better now. This is OK to push after a final round of testing by mleich.

            marko Marko Mäkelä added a comment - Code coverage analysis looks better now. This is OK to push after a final round of testing by mleich .
            marko Marko Mäkelä made changes -
            Assignee Marko Mäkelä [ marko ] Thirunarayanan Balathandayuthapani [ thiru ]
            Status In Review [ 10002 ] Stalled [ 10000 ]

            origin/bb-10.6-MDEV-15250 f9c152c9f6b770961cdd8467ce05548347812ed8 2022-04-22T18:15:48+05:30
            behaved well in RQG testing. The bad effects observed are known and in the main trees too.

            mleich Matthias Leich added a comment - origin/bb-10.6- MDEV-15250 f9c152c9f6b770961cdd8467ce05548347812ed8 2022-04-22T18:15:48+05:30 behaved well in RQG testing. The bad effects observed are known and in the main trees too.
            thiru Thirunarayanan Balathandayuthapani made changes -
            Fix Version/s 10.6.8 [ 27506 ]
            Fix Version/s 10.7.4 [ 27504 ]
            Fix Version/s 10.8.3 [ 27502 ]
            Fix Version/s 10.9.1 [ 27114 ]
            Fix Version/s 10.3 [ 22126 ]
            Fix Version/s 10.4 [ 22408 ]
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.7 [ 24805 ]
            Fix Version/s 10.8 [ 26121 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            thiru Thirunarayanan Balathandayuthapani made changes -
            marko Marko Mäkelä made changes -
            thiru Thirunarayanan Balathandayuthapani made changes -
            marko Marko Mäkelä made changes -
            marko Marko Mäkelä made changes -
            marko Marko Mäkelä made changes -
            thiru Thirunarayanan Balathandayuthapani made changes -
            marko Marko Mäkelä made changes -
            thiru Thirunarayanan Balathandayuthapani made changes -
            marko Marko Mäkelä made changes -
            marko Marko Mäkelä made changes -
            marko Marko Mäkelä made changes -
            marko Marko Mäkelä made changes -

            People

              thiru Thirunarayanan Balathandayuthapani
              sjon sjon
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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