Commit graph

21123 commits

Author SHA1 Message Date
Marko Mäkelä
3afae13b54 Merge 10.3 into 10.4 2018-11-30 12:47:38 +02:00
Marko Mäkelä
e46a3aa42e MDEV-17881 Assertion failure in cmp_dtuple_rec_with_match_bytes after instant ADD COLUMN
The special flag REC_INFO_MIN_REC_FLAG used to be only set on the
first record in the leftmost node pointer page of each level of the tree.
It was never set on leaf pages.

MDEV-11369 Instant ADD COLUMN in MariaDB Server 10.3 repurposed the flag
to identify a hidden metadata record, which is stored in the first record
on the leftmost leaf page.

If the adaptive hash index points to records in the leftmost leaf page
after instant ALTER TABLE, we would have such a metadata record in the
table, an assertion could fail when trying to validate the index record.
In a release build, we might wrongly qualify the hidden metadata record
and thus return garbage results.

cmp_dtuple_rec_with_match_bytes(): If the REC_INFO_MIN_REC_FLAG is
set on the record, assert that this is the first record on the
leftmost page and that the record is a metadata record, and finally
return 1, because by definition, anything is greater than the
minimum record.
2018-11-30 12:40:03 +02:00
Marko Mäkelä
b374246730 Merge 10.3 into 10.4 2018-11-30 11:05:46 +02:00
Marko Mäkelä
0abd2766b1 Merge 10.2 into 10.3
Also, related to MDEV-15522, MDEV-17304, MDEV-17835,
remove the Galera xtrabackup tests, because xtrabackup never worked
with MariaDB Server 10.3 due to InnoDB redo log format changes.
2018-11-30 09:38:56 +02:00
Marko Mäkelä
447e493179 Remove some unnecessary InnoDB #include 2018-11-29 12:53:44 +02:00
Marko Mäkelä
be998bfdc5 MDEV-17859: Clean up the FOREIGN KEY handling
dict_create_add_foreigns_to_dictionary(): Do not commit the transaction.
The operation can still fail in dict_load_foreigns(), and we want
to be able to roll back the transaction.

create_table_info_t::create_table(): Never reset m_drop_before_rollback,
and never commit the transaction. We use a single point of rollback
in ha_innobase::create(). Merge the logic from
row_table_add_foreign_constraints().
2018-11-29 09:16:48 +02:00
Marko Mäkelä
3a393f8c84 Merge dict_index_copy_rec_order_prefix() to its only caller
btr_pcur_store_position(): Merge the code from
dict_index_copy_rec_order_prefix().
2018-11-28 20:47:27 +02:00
Marko Mäkelä
3fe0369309 Merge 10.3 into 10.4 2018-11-28 19:54:48 +02:00
Marko Mäkelä
35184902db Merge 10.2 into 10.3 2018-11-28 15:23:23 +02:00
Marko Mäkelä
b26e603aeb MDEV-17859 Operating system errors in file operations after failed CREATE
This is a regression due to MDEV-17816.

When creating a table fails, we must roll back the dictionary
transaction. Because the rollback may rename tables, and because
InnoDB lacks proper undo logging for CREATE operations, we must
drop the incompletely created table before rolling back the
transaction, which could include a RENAME operation.
But, we must not blindly drop the table by name; after all,
the operation could have failed because another table by the
same name already existed.

create_table_info_t::m_drop_before_rollback: A flag that is set
if the table needs to be dropped before transaction rollback.

create_table_info_t::create_table(): Remove some duplicated
error handling.

ha_innobase::create(): On error, only drop the table if it was
actually created.
2018-11-28 15:17:56 +02:00
Sergei Petrunia
0485e51935 MDEV-13155: XA recovery not supported for RocksDB
Added a testcase
2018-11-28 12:39:36 +03:00
Marko Mäkelä
926b04e550 Merge 10.3 into 10.4 2018-11-28 01:18:30 +02:00
Marko Mäkelä
babb000a36 Merge 10.2 into 10.3 2018-11-28 01:02:46 +02:00
Marko Mäkelä
4a92165ff0 Remove unused mem_heap_allocator
The code became unused in commit 10590dd39c.
2018-11-28 00:52:30 +02:00
Marko Mäkelä
e82e216e37 MDEV-17849 Undo tablespace truncation recovery fails to shrink file
fil_space_t::add(): Replaces fil_node_create(), fil_node_create_low().
Let the caller pass fil_node_t::handle, to avoid having to close and
re-open files.

fil_node_t::read_page0(): Refactored from fil_node_open_file().
Read the first page of a data file.

fil_node_open_file(): Open the file only once.

srv_undo_tablespace_open(): Set the file handle for the opened
undo tablespace. This should ensure that ut_ad(file->is_open())
no longer fails in recv_add_trim().

xtrabackup_backup_func(): Remove some dead code.

xb_fil_cur_open(): Open files only if needed. Undo tablespaces
should already have been opened.
2018-11-27 14:49:39 +02:00
Marko Mäkelä
eb6364619f Remove the redundant variable fil_n_file_opened 2018-11-27 14:30:39 +02:00
Marko Mäkelä
b9824074a6 MDEV-17851 Assertion failure srv_undo_tablespaces > 1
trx_assign_rseg_low(): Skip dedicated undo tablespaces if
innodb_undo_tablespaces=0 has been set after the database was created.
2018-11-27 14:02:24 +02:00
Marko Mäkelä
861038f2e8 MDEV-17816: Follow-up fix
When dropping a partially created table due to failure,
use SQLCOM_TRUNCATE instead of SQLCOM_DROP_DB, so that
no foreign key constraints will be touched. If any
constraints were added as part of the creation, they would
be reverted as part of the transaction rollback.

We need an explicit call to row_drop_table_for_mysql(),
because InnoDB does not do proper undo logging for CREATE TABLE,
but would only drop the table at the end of the rollback.
This would not work if the transaction combines both
RENAME and CREATE, like TRUNCATE now does.
2018-11-26 17:32:57 +02:00
Marko Mäkelä
7dcbc33db5 Merge 10.3 into 10.4 2018-11-26 17:20:07 +02:00
Marko Mäkelä
8fe34dd45f MDEV-17831 Assertion `supports_instant()' failed in dict_table_t::prepare_instant upon ADD COLUMN on table with KEY_BLOCK_SIZE
dict_table_t::prepare_instant(): Remove too strict assertions that
could fail if the MariaDB and InnoDB data dictionaries are out of sync.

That the dictionaries got out of sync during TRUNCATE TABLE
is a separate bug was fixed in 10.2 by
commit 971e1d8677.
2018-11-26 16:42:44 +02:00
Marko Mäkelä
1afed20774 Merge 10.2 into 10.3
The test galera_sst_mariabackup_table_options was disabled,
because the server refuses to start up due to wrong parameters.
2018-11-26 14:05:15 +02:00
Jan Lindström
9669536c23 MDEV-17811: Add deprecation information for xtrabackup 2018-11-26 12:58:42 +02:00
Marko Mäkelä
2a31b82831 MDEV-17816 Crash in TRUNCATE TABLE when table creation fails
The error handling in the MDEV-13564 TRUNCATE TABLE was broken
when an error occurred during table creation.

row_create_index_for_mysql(): Do not drop the table on error.

fts_create_one_common_table(), fts_create_one_index_table():
Do drop the table on error.

create_index(), create_table_info_t::create_table():
Let the caller handle the index creation errors.

ha_innobase::create(): If create_table_info_t::create_table()
fails, drop the incomplete table, roll back the transaction,
and finally return an error to the caller.
2018-11-26 12:50:27 +02:00
Marko Mäkelä
a81fceafb1 MDEV-14409 Assertion `page_rec_is_leaf(rec)' failed in lock_rec_validate_page
lock_rec_queue_validate(): Assert page_rec_is_leaf(rec), except when
the record is a page infimum or supremum.

lock_rec_validate_page(): Relax the assertion that failed.
The assertion was reachable when the record lock bitmap was empty.

lock_rec_insert_check_and_lock(): Assert page_is_leaf().
2018-11-26 10:10:49 +02:00
Alexander Barkov
4447a02cf1 MDEV-16991 Rounding vs truncation for TIME, DATETIME, TIMESTAMP 2018-11-26 08:10:47 +04:00
Marko Mäkelä
2c4844c9e7 MDEV-17813 Crash in instant ALTER TABLE due to purge concurrently emptying table
Several race conditions between MDEV-15562 instant ALTER TABLE and purge
were observed.

The most obvious race condition resulted in a reported assertion failure in
dict_index_t::instant_add_field(): instant.n_core_fields == n_core_fields
would not hold if the table was emptied by purge after the time
dict_table_t::prepare_instant() was called.

During purge, it can turn out that the table is logically empty, only
containing a metadata record. If the metadata record is of the type
created by MDEV-11369 instant ADD COLUMN, it can be removed and
dict_index_t::clear_instant_add() can be called. This will convert the
table to the canonical non-instant format. (If the metadata record is
of the MDEV-15562 type, then it can only be deleted if the table becomes
empty as the result of rollback of an instant ALTER TABLE operation.)

row_purge_remove_clust_if_poss_low(): Add a debug check that ensures
that purge can never remove a MDEV-15562 metadata record.

ha_innobase::open(): Add a comment about the necessity of rolling
back any recovered instant ALTER TABLE transaction on the table.

instant_metadata_lock(): An auxiliary function to acquire a page latch
on the metadata record, to prevent race conditions.

dict_table_t::prepare_instant(), dict_index_t::instant_add_field(),
dict_table_t::rollback_instant(), innobase_instant_try():
Invoke instant_metadata_lock() in order to prevent race conditions.

dict_index_t::instant_add_field(): Correct debug assertions.
The == was guaranteed by code in dict_table_t::prepare_instant()
that was introduced in MDEV-15562. Due to the race condition,
we could occasionally have <=, but never >= like the code was
after MDEV-11369.

ha_innobase_inplace_ctx::instant_column(): Wrapper for
dict_table_t::instant_column(). Add debug assertions.
2018-11-23 16:22:14 +02:00
Marko Mäkelä
46a411088c Fix the -DWITH_WSREP:BOOL=OFF build 2018-11-22 17:29:49 +02:00
Marko Mäkelä
06e5f28f9f MDEV-12266: Remove a level of pointer indirection
Replace table->space->id with table->space_id.
2018-11-22 17:10:26 +02:00
Marko Mäkelä
4be0855cf5 MDEV-17794 Do not assign persistent ID for temporary tables
InnoDB in MySQL 5.7 introduced two new parameters to the function
dict_hdr_get_new_id(), to allow redo logging to be disabled when
assigning identifiers to temporary tables or during the
backup-unfriendly TRUNCATE TABLE that was replaced in MariaDB
by MDEV-13564.

Now that MariaDB 10.4.0 removed the crash recovery code for the
backup-unfriendly TRUNCATE, we can revert dict_hdr_get_new_id()
to be used only for persistent data structures.

dict_table_assign_new_id(): Remove. This was a simple 2-line function
that was called from few places.

dict_table_open_on_id_low(): Declare in the only file where it
is called.

dict_sys_t::temp_id_hash: A separate lookup table for temporary tables.
Table names will be in the common dict_sys_t::table_hash.

dict_sys_t::get_temporary_table_id(): Assign a temporary table ID.

dict_sys_t::get_table(): Look up a persistent table.

dict_sys_t::get_temporary_table(): Look up a temporary table.

dict_sys_t::temp_table_id: The sequence of temporary table identifiers.
Starts from DICT_HDR_FIRST_ID, so that we can continue to simply compare
dict_table_t::id to a few constants for the persistent hard-coded
data dictionary tables.

undo_node_t::state: Distinguish temporary and persistent tables.

lock_check_dict_lock(), lock_get_table_id(): Assert that there cannot
be locks on temporary tables.

row_rec_to_index_entry_impl(): Assert that there cannot be metadata
records on temporary tables.

row_undo_ins_parse_undo_rec(): Distinguish temporary and persistent tables.
Move some assertions from the only caller. Return whether the table was
found.

row_undo_ins(): Add some assertions.

row_undo_mod_clust(), row_undo_mod(): Do not assign node->state.
Let row_undo() do that.

row_undo_mod_parse_undo_rec(): Distinguish temporary and persistent tables.
Move some assertions from the only caller. Return whether the table was
found.

row_undo_try_truncate(): Renamed and simplified from trx_roll_try_truncate().

row_undo_rec_get(): Replaces trx_roll_pop_top_rec_of_trx() and
trx_roll_pop_top_rec(). Fetch an undo log record, and assign undo->state
accordingly.

trx_undo_truncate_end(): Acquire the rseg->mutex only for the minimum
required duration, and release it between mini-transactions.
2018-11-22 15:42:52 +02:00
Marko Mäkelä
23ff318d03 MDEV-17793 follow-up: Also update SYS_VIRTUAL 2018-11-22 15:42:52 +02:00
Marko Mäkelä
2ebb110c36 MDEV-17793 Crash in purge after instant DROP and emptying the table
There was a race condition between ALTER TABLE and purge.

If a table turns out to be logically empty when instant ALTER TABLE
is executing, we will convert the table to the canonical format,
to avoid overhead during subsequent accesses, and to allow the
data file to be imported into older versions of MariaDB.

It could happen that at the time the table is logically empty,
there still exists an undo log record for updating the hidden
metadata record for an earlier instant ALTER TABLE operation.
If the table was converted to the canonical format before
purge processes this undo log record, the undo log record
could be referring to index fields that no longer exist,
causing a crash.

To prevent the race condition, we must delete the old undo log records.
We do this lazily by assigning a new table ID, so that the table lookup
for the old undo log records will fail.

dict_table_t::reassign_id(): Reassign the table_id to
effectively lazily delete old undo log records.

innobase_instant_try(): Invoke index->table->reassign_id() before
index->clear_instant_alter().
2018-11-22 10:41:15 +02:00
Monty
0fe90263c8 Fixed compiler warnings in tokudb_sysvars.cc 2018-11-22 01:08:15 +02:00
Marko Mäkelä
9fdb8c59eb MDEV-17721: Corrupted data dictionary after instant DROP COLUMN
dict_index_t::clear_instant_alter(): Remove a loop that became
redundant in commit ae2004c616
and caused corruption of n_nullable when dropping the last column
which was not declared NOT NULL.
2018-11-21 13:59:04 +02:00
Marko Mäkelä
1ee0144db7 Merge 10.3 into 10.4 2018-11-21 12:28:00 +02:00
Marko Mäkelä
ae2004c616 MDEV-17721: Corrupted data dictionary after instant DROP COLUMN
dict_index_t::clear_instant_alter(): Correctly move all fields
corresponding to instantly dropped columns to the end of the array.
This fixes a regression that was introduced in
commit 5aaee3746e.
2018-11-21 12:24:49 +02:00
Sergei Golubchik
f0f0d07250 MDEV-14500 filesort to support engines with slow rnd_pos
If the engine wants to avoid rnd_pos() - force a temporary table
before a filesort. But don't do it if addon_fields are used.
2018-11-20 15:06:03 +01:00
Sergei Golubchik
1823ce7304 cleanup: rename a flag, keep old name for compatibility 2018-11-20 15:05:52 +01:00
Sergei Golubchik
649465db41 cleanup: remove HA_WANTS_PRIMARY_KEY as redundant
We don't have many bits left, no need to add another InnoDB-specific flag.
Instead, we say that HA_REQUIRE_PRIMARY_KEY does not apply to SEQUENCE.
Meaning, if the engine declares HA_CAN_TABLES_WITHOUT_ROLLBACK (required
for SEQUENCE) it *must* support tables without a primary key.
2018-11-20 15:05:46 +01:00
Marko Mäkelä
4210e7bf6f Merge 10.2 into 10.3 2018-11-20 15:08:41 +02:00
Marko Mäkelä
b86e18cb44 MDEV-17780 innodb.truncate_recover crashes in recovery due to out-of-bounds page read
recv_addr_trim(): Do not try to detach the hash bucket, because
the code for doing that does not always work.

recv_apply_hashed_log_recs(): Do not attempt to read pages for which
there exist no redo log records.
2018-11-20 14:55:44 +02:00
Marko Mäkelä
5aaee3746e MDEV-17721: Corrupted data dictionary after instant DROP COLUMN
dict_index_t::clear_instant_alter(): Correctly sort the index fields
to correspond to the columns of the table.
2018-11-20 13:32:20 +02:00
Marko Mäkelä
dde2ca4aa1 Merge 10.3 into 10.4 2018-11-19 20:22:33 +02:00
Marko Mäkelä
fd58bb71e2 Merge 10.2 into 10.3 2018-11-19 18:45:53 +02:00
Marko Mäkelä
e669e705a1 Fix the Windows build
Commit ff88e4bb8a broke the Windows build.
Clean up one more redundant #include to fix it.
2018-11-19 13:13:39 +02:00
Marko Mäkelä
ff88e4bb8a Remove many redundant #include from InnoDB 2018-11-19 11:42:14 +02:00
Marko Mäkelä
cb5bca721b MDEV-17765 lock_discard_page() may fail to discard locks for SPATIAL INDEX
lock_discard_page(): Traverse and discard the B-tree record locks
only if they exist. Else, discard the R-tree (spatial) index locks.
2018-11-19 11:40:10 +02:00
Marko Mäkelä
f037b91098 MDEV-17726: Fix compiler warning
Compare against the correct constant 0. NOT_KILLED belongs to
enum killed_state, while THD_IS_NOT_KILLED is what we want.
2018-11-19 11:11:53 +02:00
Marko Mäkelä
7debbd7859 Fix a compilation error
ib_counter_t::ib_counter_element_t: Avoid sizeof on a std::atomic type,
because it causes errors on some version of the Microsoft compiler.
2018-11-18 15:50:43 +02:00
Marko Mäkelä
075820ab23 MDEV-17750: Fix the Windows build
Remove some redundant declarations of global variables. These declarations
can refer to undefined type names, because they occur before any #include
statement for the type definitions. On GNU/Linux, uint and ulong seem to
be defined in <sys/types.h> due to _DEFAULT_SOURCE and __USE_MISC
becoming defined in <features.h>.
2018-11-18 15:46:53 +02:00
Marko Mäkelä
f92d223fe2 MDEV-17750: Remove dict_index_get_sys_col_pos()
dict_index_t::db_trx_id(): Return the position of DB_TRX_ID.
Only valid for the clustered index.

dict_index_t::db_roll_ptr(): Return the position of DB_ROLL_PTR.
Only valid for the clustered index.

dict_index_get_sys_col_pos(): Remove. This was performing unnecessarily
complex computations, which only made sense for DB_ROW_ID, which would
exist either as the first field in the clustered index or as the last
field in a secondary index (only when a DB_ROW_ID column is materialised).

row_sel_store_row_id_to_prebuilt(): Remove, and replace with simpler code.

row_upd_index_entry_sys_field(): Remove.

btr_cur_log_sys(): Replaces row_upd_write_sys_vals_to_log().

btr_cur_write_sys(): Write DB_TRX_ID,DB_ROLL_PTR to a data tuple.
2018-11-16 20:37:06 +02:00