mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
MDEV-15250 UPSERT during ALTER TABLE results in 'Duplicate entry' error for alter
- InnoDB DDL results in `Duplicate entry' if concurrent DML throws duplicate key error. The following scenario explains the problem connection con1: ALTER TABLE t1 FORCE; connection con2: INSERT INTO t1(pk, uk) VALUES (2, 2), (3, 2); In connection con2, InnoDB throws the 'DUPLICATE KEY' error because of unique index. Alter operation will throw the error when applying the concurrent DML log. - Inserting the duplicate key for unique index logs the insert operation for online ALTER TABLE. When insertion fails, transaction does rollback and it leads to logging of delete operation for online ALTER TABLE. While applying the insert log entries, alter operation encounters 'DUPLICATE KEY' error. - To avoid the above fake duplicate scenario, InnoDB should not write any log for online ALTER TABLE before DML transaction commit. - User thread which does DML can apply the online log if InnoDB ran out of online log and index is marked as completed. Set online log error if apply phase encountered any error. It can also clear all other indexes log, marks the newly added indexes as corrupted. - Removed the old online code which was a part of DML operations commit_inplace_alter_table() : Does apply the online log for the last batch of secondary index log and does frees the log for the completed index. trx_t::apply_online_log: Set to true while writing the undo log if the modified table has active DDL trx_t::apply_log(): Apply the DML changes to online DDL tables dict_table_t::is_active_ddl(): Returns true if the table has an active DDL dict_index_t::online_log_make_dummy(): Assign dummy value for clustered index online log to indicate the secondary indexes are being rebuild. dict_index_t::online_log_is_dummy(): Check whether the online log has dummy value ha_innobase_inplace_ctx::log_failure(): Handle the apply log failure for online DDL transaction row_log_mark_other_online_index_abort(): Clear out all other online index log after encountering the error during row_log_apply() row_log_get_error(): Get the error happened during row_log_apply() row_log_online_op(): Does apply the online log if index is completed and ran out of memory. Returns false if apply log fails UndorecApplier: Introduced a class to maintain the undo log record, latched undo buffer page, parse the undo log record, maintain the undo record type, info bits and update vector UndorecApplier::get_old_rec(): Get the correct version of the clustered index record that was modified by the current undo log record UndorecApplier::clear_undo_rec(): Clear the undo log related information after applying the undo log record UndorecApplier::log_update(): Handle the update, delete undo log and apply it on online indexes UndorecApplier::log_insert(): Handle the insert undo log and apply it on online indexes UndorecApplier::is_same(): Check whether the given roll pointer is generated by the current undo log record information trx_t::rollback_low(): Set apply_online_log for the transaction after partially rollbacked transaction has any active DDL prepare_inplace_alter_table_dict(): After allocating the online log, InnoDB does create fulltext common tables. Fulltext index doesn't allow the index to be online. So removed the dead code of online log removal Thanks to Marko Mäkelä for providing the initial prototype and Matthias Leich for testing the issue patiently.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#define MY_COMPILER_INCLUDED
|
||||
|
||||
/* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
Copyright (c) 2017, 2020, MariaDB Corporation.
|
||||
Copyright (c) 2017, 2022, MariaDB Corporation.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -39,15 +39,8 @@
|
||||
|
||||
/* GNU C/C++ */
|
||||
#if defined __GNUC__
|
||||
/* Convenience macro to test the minimum required GCC version. */
|
||||
# define MY_GNUC_PREREQ(maj, min) \
|
||||
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
|
||||
/* Any after 2.95... */
|
||||
# define MY_ALIGN_EXT
|
||||
/* Comunicate to the compiler the unreachability of the code. */
|
||||
# if MY_GNUC_PREREQ(4,5)
|
||||
# define MY_ASSERT_UNREACHABLE() __builtin_unreachable()
|
||||
# endif
|
||||
# define MY_ASSERT_UNREACHABLE() __builtin_unreachable()
|
||||
|
||||
/* Microsoft Visual C++ */
|
||||
#elif defined _MSC_VER
|
||||
@@ -158,7 +151,6 @@ struct my_aligned_storage
|
||||
#ifdef __GNUC__
|
||||
# define ATTRIBUTE_NORETURN __attribute__((noreturn))
|
||||
# define ATTRIBUTE_NOINLINE __attribute__((noinline))
|
||||
# if MY_GNUC_PREREQ(4,3)
|
||||
/** Starting with GCC 4.3, the "cold" attribute is used to inform the
|
||||
compiler that a function is unlikely executed. The function is
|
||||
optimized for size rather than speed and on many targets it is placed
|
||||
@@ -167,8 +159,7 @@ appears close together improving code locality of non-cold parts of
|
||||
program. The paths leading to call of cold functions within code are
|
||||
marked as unlikely by the branch prediction mechanism. optimize a
|
||||
rarely invoked function for size instead for speed. */
|
||||
# define ATTRIBUTE_COLD __attribute__((cold))
|
||||
# endif
|
||||
# define ATTRIBUTE_COLD __attribute__((cold))
|
||||
#elif defined _MSC_VER
|
||||
# define ATTRIBUTE_NORETURN __declspec(noreturn)
|
||||
# define ATTRIBUTE_NOINLINE __declspec(noinline)
|
||||
|
Reference in New Issue
Block a user