Commit graph

5390 commits

Author SHA1 Message Date
Jan Lindström
564891c532 MDEV-14508: encryption.innodb-compressed-blob failed in buildbot, assertion in btr0cur.cc line 1398
Before that line there is call to buf_page_get_gen that could
return block = NULL when decrypting a page fails. However,
we should set error to be != DB_SUCCESS also. In error log
there was error about decompression but in that code there
is one case where error is not set correctly.
2018-02-09 17:17:32 +02:00
Marko Mäkelä
5559905d41 Merge 10.2 into bb-10.2-ext 2018-02-09 12:48:23 +02:00
Marko Mäkelä
e4da20d438 MDEV-14238 Bogus assertion on row_get_rec_trx_id()
page_zip_write_rec(): Do not attempt to access a non-existing
DB_TRX_ID column when writing a record to a non-leaf page.
2018-02-09 08:26:47 +02:00
Marko Mäkelä
e3cf577948 MDEV-14663 Assertion page_is_root(block->frame) failed in innobase_add_instant_try
innobase_add_instant_try(): If the leftmost leaf page does not contain
other records than the 'default row', only empty the table if there
are no successor pages.

When a table or partition which was not empty during a previous
instant ADD COLUMN became empty later, and now with this subsequent
instant ADD COLUMN we have the opportunity to convert the empty table
or partition to 'non-instant' format.

Similarly, if the table or partition is empty to begin with, that is,
it does not even contain a 'default row' record, we can use the
'non-instant' format.
2018-02-08 22:45:16 +02:00
Marko Mäkelä
32170f8c6d Add page_has_prev(), page_has_next(), page_has_siblings()
Until now, InnoDB inefficiently compared the aligned fields
FIL_PAGE_PREV, FIL_PAGE_NEXT to the byte-order-agnostic value FIL_NULL.
2018-02-08 22:34:21 +02:00
Marko Mäkelä
c567369ad7 Merge 10.2 into bb-10.2-ext 2018-02-08 17:48:19 +02:00
Alexander Barkov
3cad31f2a7 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2018-02-08 19:06:25 +04:00
Vladislav Vaintroub
627d33d9cf Innodb, Windows : Reenable compiler optimizations for mem0mem.cc
Compiler optimizations were switched off due to
MySQL Bug #19424, #36366, #34297, due to an alleged compiler bug.
No  proper analysis of code generation was done back then, thus proof of
a compiler bug is missing.

Even if there was a compiler bug 13 years ago, it could have been fixed.
Will wait and see if there are any complains or crashes
2018-02-08 12:16:06 +00:00
Marko Mäkelä
db25305780 MDEV-14407 Assertion failure during rollback
Rollback attempted to dereference DB_ROLL_PTR=0, which cannot possibly
be a valid undo log pointer. A safe canonical value would be
roll_ptr_t(1) << ROLL_PTR_INSERT_FLAG_POS
which is what was chosen in MDEV-12288.

This bug was reproduced in 10.3 only. Potentially, the problem could
have been introduced by MDEV-11415, which suppresses undo logging for
ALGORITHM=COPY operations. In those operations, we should actually
have written the safe value of DB_ROLL_PTR instead of writing 0.
However, the test in commit 5421e3aee7
demonstrates that access to the rebuilt table by earlier-started
transactions should actually have been refused with ER_TABLE_DEF_CHANGED.

btr_cur_ins_lock_and_undo(): When undo logging is disabled, use the
safe value of DB_ROLL_PTR.

btr_cur_optimistic_insert(): Validate the DB_TRX_ID,DB_ROLL_PTR before
inserting into a clustered index leaf page.

ins_node_t::sys_buf[]: Replaces row_id_buf and trx_id_buf and some
heap usage.

row_ins_alloc_sys_fields(): Initialize ins_node_t::sys_buf[].

trx_undo_page_report_modify(): Assert that the DB_ROLL_PTR is not 0.

trx_undo_get_undo_rec_low(): Assert that the roll_ptr is valid before
trying to dereference it.

dict_index_t::is_primary(): Check if the index is the primary key.
2018-02-08 13:55:57 +02:00
Marko Mäkelä
be6307c0fa Merge 10.1 into 10.2 2018-02-08 13:53:21 +02:00
Marko Mäkelä
871f2a6ee2 Merge 10.0 into 10.1 2018-02-08 13:29:08 +02:00
Marko Mäkelä
5421e3aee7 MDEV-15249 Crash in MVCC read after IMPORT TABLESPACE
PageConverter::adjust_cluster_record(): Instead of writing
the invalid value DB_ROLL_PTR=0, write a value that indicates
a fresh insert, that is, prevents the DB_ROLL_PTR from being
dereferenced in any circumstances.

It can be argued that IMPORT TABLESPACE should actually
update the dict_index_t::trx_id to prevent older transactions
from accessing the table, similar to what I did on table
rebuild in MySQL 5.6.6 in
03f81a55f2
2018-02-08 12:59:32 +02:00
Marko Mäkelä
bbdb47ffe4 Revert an accidental change
trx_undo_rec_copy(): Use a debug assertion. In a non-debug build,
with len<0 (which this assertion is really testing for)
we should still typically crash due to running out of memory.
2018-02-08 12:28:07 +02:00
Marko Mäkelä
7660d8c94e Remove dict_table_t::is_clust()
Replace all occurrences of the is_clust() method with is_primary(),
because that is what is actually meant. (Also the change buffer
tree would count as a clustered index.)
2018-02-08 12:18:07 +02:00
Marko Mäkelä
609d0a9194 MDEV-14407 Assertion failure during rollback
Rollback attempted to dereference DB_ROLL_PTR=0, which cannot possibly
be a valid undo log pointer. A safer canonical value would be
roll_ptr_t(1) << ROLL_PTR_INSERT_FLAG_POS
which is what was chosen in MDEV-12288, corresponding to reset_trx_id.

No deterministic test case for the bug was found. The simplest test
cases may be related to MDEV-11415, which suppresses undo logging for
ALGORITHM=COPY operations. In those operations, in the spirit of
MDEV-12288, we should actually have written reset_trx_id instead of
using the transaction identifier of the current transaction
(and a bogus value of DB_ROLL_PTR=0). However, thanks to MySQL Bug#28432
which I had fixed in MySQL 5.6.8 as part of WL#6255, access to the
rebuilt table by earlier-started transactions should actually have been
refused with ER_TABLE_DEF_CHANGED.

reset_trx_id: Move the definition to data0type.cc and the declaration
to data0type.h.

btr_cur_ins_lock_and_undo(): When undo logging is disabled, use the
safe value that corresponds to reset_trx_id.

btr_cur_optimistic_insert(): Validate the DB_TRX_ID,DB_ROLL_PTR before
inserting into a clustered index leaf page.

ins_node_t::sys_buf[]: Replaces row_id_buf and trx_id_buf and some
heap usage.

row_ins_alloc_sys_fields(): Init ins_node_t::sys_buf[] to reset_trx_id.

row_ins_buf(): Only if undo logging is enabled, copy trx->id
to node->sys_buf. Otherwise, rely on the initialization in
row_ins_alloc_sys_fields().

row_purge_reset_trx_id(): Invoke mlog_write_string() with reset_trx_id
directly. (No functional change.)

trx_undo_page_report_modify(): Assert that the DB_ROLL_PTR is not 0.

trx_undo_get_undo_rec_low(): Assert that the roll_ptr is valid before
trying to dereference it.

dict_index_t::is_primary(): Check if the index is the primary key.

PageConverter::adjust_cluster_record(): Fix
MDEV-15249 Crash in MVCC read after IMPORT TABLESPACE
by resetting the system fields to reset_trx_id instead of writing
the current transaction ID (which will be committed at the
end of the IMPORT TABLESPACE) and DB_ROLL_PTR=0.
This can partially be viewed as a follow-up fix of MDEV-12288,
because IMPORT should already then have written
DB_TRX_ID=0 and DB_ROLL_PTR=1<<55 to prevent unnecessary
DB_TRX_ID lookups in subsequent accesses to the table.
2018-02-08 12:14:34 +02:00
Vladislav Vaintroub
53476abce8 Windows, compiling : use /permissive- switch to improve conformance
fix a couple "initialization skipped by goto" and other new errors.
2018-02-07 20:22:30 +00:00
Vladislav Vaintroub
d995dd2865 Windows : reenable warning C4805 (unsafe mix of types in bool operations) 2018-02-07 20:12:12 +00:00
Marko Mäkelä
10590dd39c MDEV-15199 Referential integrity broken in ON DELETE CASCADE
MDEV-14222 Unnecessary 'cascade' memory allocation for every updated row
when there is no FOREIGN KEY

This reverts the MySQL 5.7.2 change
377774689b
which introduced these problems. MariaDB 10.2.2 inherited these problems
in commit 2e814d4702.

The FOREIGN KEY CASCADE and SET NULL operations implemented as
procedural recursion are consuming more than 8 kilobytes of stack
(9 stack frames) per iteration in a non-debug GNU/Linux AMD64 build.
This is why we need to limit the maximum recursion depth to 15 steps
instead of the 255 that it used to be in MySQL 5.7 and MariaDB 10.2.

A corresponding change was made in MySQL 5.7.21 in
7b26dc98a6
2018-02-07 10:39:12 +02:00
Marko Mäkelä
5d7e9fd46c InnoDB UPDATE cleanup
row_upd_store_v_row(): Declare static

row_upd_clust_rec_by_insert(), row_upd_del_mark_clust_rec():
Pass the parameter 'foreign' only #ifdef WITH_WSREP
2018-02-07 10:39:12 +02:00
Marko Mäkelä
b68dac88b3 MDEV-15219 FOREIGN KEY CASCADE or SET NULL operations will not resume after lock wait
This corruption was introduced in MDEV-13331. It would have been caught
by the MySQL 5.7 test innodb.update-cascade which MariaDB was missing
until now.

row_ins_check_foreign_constraint(): Never replace err == DB_LOCK_WAIT
with other values than DB_LOCK_WAIT_TIMEOUT.
2018-02-07 10:39:12 +02:00
Marko Mäkelä
1789e0ff03 Remove useless debug instrumentation row_print_geometry_data 2018-02-07 10:39:12 +02:00
Marko Mäkelä
5815c8ee85 Remove useless code
srv_mbr_print(): Remove. Geometry fields are already being output
in raw form, and we do not need bogus MBR output for non-spatial
indexes.
2018-02-07 10:39:12 +02:00
Marko Mäkelä
4cec63af44 Foreign key code cleanup
row_ins_cascade_calc_update_vec(): Remove the output parameter
fts_col_affected, and instead return whether any fulltext index
is affected by the cascade operation.

row_ins_foreign_check_on_constraint(): Narrow the scope of some
variables.

ib_dec_in_dtor: Remove.
2018-02-07 10:39:12 +02:00
Marko Mäkelä
883496782f Merge bb-10.2-ext into 10.3 2018-02-06 17:12:17 +02:00
Marko Mäkelä
560b9895d4 MDEV-15115 Assertion failure in CREATE SEQUENCE...ROW_FORMAT=REDUNDANT
dict_tf_is_valid(): Allow no-rollback tables in ROW_FORMAT=REDUNDANT.
2018-02-06 17:09:26 +02:00
Sergei Golubchik
4771ae4b22 Merge branch 'github/10.1' into 10.2 2018-02-06 14:50:50 +01:00
Marko Mäkelä
eda142590f Improve the documentation of some TRX_RSEG fields 2018-02-06 15:44:21 +02:00
Vladislav Vaintroub
6c279ad6a7 MDEV-15091 : Windows, 64bit: reenable and fix warning C4267 (conversion from 'size_t' to 'type', possible loss of data)
Handle string length as size_t, consistently (almost always:))
Change function prototypes to accept size_t, where in the past
ulong or uint were used. change local/member variables to size_t
when appropriate.

This fix excludes rocksdb, spider,spider, sphinx and connect for now.
2018-02-06 12:55:58 +00:00
Jan Lindström
60f51af755 MDEV-15042: INSERT ON DUPLICATE KEY UPDATE produces error 1032 (Can't find record)
Problem was that wrong error message was returned when insert
returned FK-error and there was no duplicate key to process.

row_ins
	If error from insert was DB_NO_REFERENCED_ROW and there was
	no duplicate key we should ignore ON DUPLICATE KEY UPDATE
	and return original error message.
2018-02-05 18:21:28 +02:00
Marko Mäkelä
d6ed077fc8 Clarify a comment after MDEV-15061 2018-02-04 13:11:49 +02:00
Marko Mäkelä
ec03390f9b fil_write_flushed_lsn(): Ensure that the return value is initialized
Previously, the function could theoretically return an uninitialized
value if the system tablespace contained no data files. It should be
impossible for InnoDB to start up in such scenario.
2018-02-03 12:52:25 +02:00
Marko Mäkelä
9390ff53fc MDEV-14958 Merge new release of InnoDB MySQL 5.7.21 to 10.2
Two follow-up tasks were filed for MySQL 5.7.21 changes that
were not applied here:

MDEV-15179 performance_schema.file_instances does not reflect RENAME TABLE
MDEV-14222 Unnecessary 'cascade' memory allocation for every updated
row when there is no FOREIGN KEY
2018-02-02 21:11:49 +02:00
Marko Mäkelä
f69a3b2e92 After-merge fix for commit d4df7bc9b1
The merge omitted some InnoDB and XtraDB conflict resolutions,
most notably, failing to merge the fix of MDEV-12173.

ibuf_merge_or_delete_for_page(), lock_rec_block_validate():
Invoke fil_space_acquire_silent() instead of fil_space_acquire().
This fixes MDEV-12173.

wsrep_debug, wsrep_trx_is_aborting(): Removed unused declarations.

_fil_io(): Remove. Instead, declare default parameters for the XtraDB
fil_io().

buf_read_page_low(): Declare default parameters, and clean up some
callers.

os_aio(): Correct the macro that is defined when !UNIV_PFS_IO.
2018-02-02 19:57:59 +02:00
Marko Mäkelä
d13fbc6212 Remove code related to InnoDB native partitioning in MySQL 5.7
row_rename_partitions_for_mysql(): Remove. This should only be relevant
in an upgrade into MySQL 5.7, which has InnoDB native partitioning.
2018-02-02 16:16:52 +02:00
Jimmy Yang
6266493fc3 Bug #25729649 LOCK0LOCK.CC:NNN:ADD_POSITION != __NULL
Reviewed-by: Sunny Bains <sunny.bains@oracle.com>
2018-02-02 16:15:30 +02:00
Marko Mäkelä
4c731a2d7c Adapt a MySQL 5.7 fix for SET GLOBAL innodb_buffer_pool_size
Bug#23590280 NO WARNING WHEN REDUCING INNODB_BUFFER_POOL_SIZE
INSIZE (sic) THE FIRST CHUNK

innodb_buffer_pool_size_validate(): Issue a warning if the
requested innodb_buffer_pool_size is less than
innodb_buffer_pool_chunk_size, because we cannot shrink individual
chunks.
2018-02-02 16:15:13 +02:00
Marko Mäkelä
d4ea179e13 MDEV-13626: Merge InnoDB test cases from MySQL 5.7 (part 7)
Import and adjust the innodb.innodb_buffer_pool_resize tests,
except innodb.innodb_buffer_pool_resize_debug, which would time out.

buf_pool_clear_hash_index(): Adjust assertions.
2018-02-02 16:15:13 +02:00
Sergei Golubchik
d4df7bc9b1 Merge branch 'github/10.0' into 10.1 2018-02-02 10:09:44 +01:00
Marko Mäkelä
44314c768f MDEV-15165 InnoDB purge for index on virtual column is trying to access an incomplete record
The algorithm change is based on a MySQL 8.0 fix for
BUG #26818787: ASSERTION: DATA0DATA.IC:430:TUPLE
by Krzysztof Kapuścik
ee606e62bb

If a record had been inserted in place of a delete-marked purgeable
record by modifying that record, and purge was accessing that record
before the off-page columns were written, row_build_index_entry()
would have returned NULL, causing a crash.

row_vers_non_virtual_fields_equal(): Check whether all non-virtual fields
of an index are equal. Replaces row_vers_non_vc_match(). A more complex
version of this function was called row_vers_non_vc_index_entry_match()
in the MySQL 8.0 fix.

row_vers_impl_x_locked_low(): This change is not directly related to
the reported problem, but apparently to the removal of the function
row_vers_non_vc_match(). This function checks if a secondary index
record was modified by a transaction that has not been committed yet.
For comparing the non-virtual columns, construct a secondary index
tuple from the table row.

row_vers_vc_matches_cluster(): Replace row_vers_non_vc_match() with
code that is equivalent to the row_vers_non_vc_index_entry_match()
in the MySQL 8.0 fix. Also, deduplicate some code by using goto.
2018-02-01 18:53:41 +02:00
Marko Mäkelä
29240b50e3 Correct a comment about incomplete records
The comment that I made in
commit 06299dddd4
is inaccurate. Replace the comment, and make the assertion
debug-only, because I cannot remember any reports of
it ever failing in these 10 years.
2018-02-01 18:53:41 +02:00
Marko Mäkelä
78716fffce Silence a bogus warning about uninitialized m_size
If crypt_block != NULL the entire object crypt_pfx should be
guaranteed to be initialized, including m_size, which will have been
initialized either in allocate_large(), either directly or via
allocate_trace().
2018-02-01 18:53:41 +02:00
Marko Mäkelä
97a39ba212 Follow-up to reverting MDEV-6938
Do not call mtr_t::start() with trx_t*.
2018-02-01 18:53:33 +02:00
Sergey Vojtovich
bc7a1dc1fb MDEV-15104 - Optimise MVCC snapshot
With trx_sys_t::rw_trx_ids removal, MVCC snapshot overhead became
slightly higher. That is instead of copying an array we now have to
iterate LF_HASH. All this done under trx_sys.mutex protection.

This patch moves MVCC snapshot out of trx_sys.mutex.

Clean-ups:

Removed MVCC: doesn't make too much sense to keep it in a separate class
anymore.

Refactored ReadView so that it now calls register()/deregister() routines
(it was vice versa before).

ReadView doesn't have friends anymore. :(

Even less trx_sys.mutex references.
2018-01-31 20:13:34 +04:00
Sergey Vojtovich
c0d5d7c0ef MDEV-15104 - Remove trx_sys_t::serialisation_list
serialisation_list was supposed to instantly give minimum registered
transaction serialisation number. However maintaining and accessing
this list requires global mutex protection.

Since we already take MVCC snapshot by iterating trx_sys_t::rw_trx_hash,
it is cheap to integrate minimum registered transaction lookup into this
iteration.
2018-01-31 16:23:56 +04:00
Sergey Vojtovich
53cc9aa5be MDEV-15104 - Remove trx_sys_t::rw_trx_ids
Take snapshot of registered read-write transaction identifiers directly
from rw_trx_hash. It immediately saves one trx_sys.mutex lock, reduces
size of another critical section protected by this mutex, and makes
further optimisations like removing trx_sys_t::serialisation_list
possible.

Downside of this approach is bigger overhead for view opening, because
iterating LF_HASH is more expensive compared to taking snapshot of an
array. However for low concurrency overhead difference is negligible,
while for high concurrency mutex is much bigger evil.

Currently we still take trx_sys.mutex to serialise ReadView creation.
This is required to keep serialisation_list ordered by trx->no as well
as not to let purge thread to create more recent snapshot while another
thread gets suspended during creation of older snapshot. This will
become completely mutex free along with serialisation_list removal.

Compared to previous implementation removing element from rw_trx_hash
and serialisation_list is not atomic. We disregard all possible bad
consequences (if there're any) since it will be solved along with
serialisation_list removal.
2018-01-31 15:18:21 +04:00
Sergey Vojtovich
af566d8a63 Reduce number of trx_sys.mutex references
trx->state change must be guarded by trx->mutex.
Moved mutex locking to MVCC::view_close().
2018-01-31 15:18:21 +04:00
Marko Mäkelä
dcc09afa63 Follow-up fix to MDEV-15132 Avoid accessing the TRX_SYS page
trx_undo_mem_create_at_db_start(): Do not read TRX_UNDO_TRX_NO
unless the field is known to be valid, that is, the transaction
has been serialized and trx_purge_add_undo_to_history() has been
invoked.

Normally InnoDB pages would be zero-initialized on allocation
(since MySQL 5.5 or so), but the undo log pages skip that
mechanism. So, reused undo log pages can contain garbage.
Undo log headers can start at any offset (there can be
multiple undo log headers in the same undo log page).
Therefore, because the TRX_UNDO_TRX_NO is never explicitly
initialized on undo log header creation, its contents may
be garbage.
2018-01-31 13:16:35 +02:00
Marko Mäkelä
67d89e4d7d MDEV-15143 InnoDB: Rollback of trx with id 0 completed
When InnoDB has completed the rollback of a recovered transaction,
it used to display the transaction identifier.

This was broken in MySQL 5.7.2 in
2f5f3cd3ac
which was merged to MariaDB 10.2.2 in
commit 2e814d4702.

trx_rollback_active(): Cache the transaction ID before it will be
reset by transaction commit. Do not display the message if the
rollback was interrupted by shutdown (MDEV-13797, MDEV-12352).
2018-01-31 12:06:46 +02:00
Marko Mäkelä
5db9c6e490 MDEV-15132 Avoid accessing the TRX_SYS page
trx_write_serialisation_history(): Only invoke trx_sysf_get()
to exclusively lock the TRX_SYS page if some change really
has to be written to the page.

On transaction commit, we will still write some binlog and
Galera WSREP XID information.

FIXME: If this information has to be written, it should be
partitioned into the rollback segment pages.
2018-01-31 10:41:33 +02:00
Marko Mäkelä
c7d0448797 MDEV-15132 Avoid accessing the TRX_SYS page
InnoDB maintains an internal persistent sequence of transaction
identifiers. This sequence is used for assigning both transaction
start identifiers (DB_TRX_ID=trx->id) and end identifiers (trx->no)
as well as end identifiers for the mysql.transaction_registry table
that was introduced in MDEV-12894.

TRX_SYS_TRX_ID_WRITE_MARGIN: Remove. After this many updates of
the sequence we used to update the TRX_SYS page. We can avoid accessing
the TRX_SYS page if we modify the InnoDB startup so that resurrecting
the sequence from other pages of the transaction system.

TRX_SYS_TRX_ID_STORE: Deprecate. The field only exists for the purpose
of upgrading from an earlier version of MySQL or MariaDB.

Starting with this fix, MariaDB will rely on the fields
TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO in the undo log header page of
each non-committed transaction, and on the new field
TRX_RSEG_MAX_TRX_ID in rollback segment header pages.

Because of this change, setting innodb_force_recovery=5 or 6 may cause
the system to recover with trx_sys.get_max_trx_id()==0. We must adjust
checks for invalid DB_TRX_ID and PAGE_MAX_TRX_ID accordingly.

We will change the startup and shutdown messages to display the
trx_sys.get_max_trx_id() in addition to the log sequence number.

trx_sys_t::flush_max_trx_id(): Remove.

trx_undo_mem_create_at_db_start(), trx_undo_lists_init():
Add an output parameter max_trx_id, to be updated from
TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO.

TRX_RSEG_MAX_TRX_ID: New field, for persisting
trx_sys.get_max_trx_id() at the time of the latest transaction commit.
Startup is not reading the undo log pages of committed transactions.
We want to avoid additional page accesses on startup, as well as
trouble when all undo logs have been emptied.
On startup, we will simply determine the maximum value from all pages
that are being read anyway.

TRX_RSEG_FORMAT: Redefined from TRX_RSEG_MAX_SIZE.

Old versions of InnoDB wrote uninitialized garbage to unused data fields.
Because of this, we cannot simply introduce a new field in the
rollback segment pages and expect it to be always zero, like it would
if the database was created by a recent enough InnoDB version.

Luckily, it looks like the field TRX_RSEG_MAX_SIZE was always written
as 0xfffffffe. We will indicate a new subformat of the page by writing
0 to this field. This has the nice side effect that after a downgrade
to older versions of InnoDB, transactions should fail to allocate any
undo log, that is, writes will be blocked. So, there is no problem of
getting corrupted transaction identifiers after downgrading.

trx_rseg_t::max_size: Remove.

trx_rseg_header_create(): Remove the parameter max_size=ULINT_MAX.

trx_purge_add_undo_to_history(): Update TRX_RSEG_MAX_SIZE
(and TRX_RSEG_FORMAT if needed). This is invoked on transaction commit.

trx_rseg_mem_restore(): If TRX_RSEG_FORMAT contains 0,
read TRX_RSEG_MAX_SIZE.

trx_rseg_array_init(): Invoke trx_sys.init_max_trx_id(max_trx_id + 1)
where max_trx_id was the maximum that was encountered in the rollback
segment pages and the undo log pages of recovered active, XA PREPARE,
or some committed transactions. (See trx_purge_add_undo_to_history()
which invokes trx_rsegf_set_nth_undo(..., FIL_NULL, ...);
not all committed transactions will be immediately detached from the
rollback segment header.)
2018-01-31 10:24:19 +02:00
Marko Mäkelä
bb441ca4ad Clean up trx_undo_page_get_end() 2018-01-31 08:52:16 +02:00
Marko Mäkelä
6058f92f5c Simplify undo log access during InnoDB startup
trx_rseg_mem_restore(): Update the max_trx_id from the undo log pages.

trx_sys_init_at_db_start(): Remove; merge with trx_lists_init_at_db_start().

trx_undo_lists_init(): Move to the only calling module, trx0rseg.cc.

trx_undo_mem_create_at_db_start(): Declare globally. Return the number
of pages.
2018-01-31 08:52:16 +02:00
Marko Mäkelä
d24229baa2 Do not call trx_rseg_mem_restore() when creating rollback segment
trx_rseg_mem_create(): Initialize rseg->curr_size and rseg->max_size.

trx_rseg_create(), trx_temp_rseg_create():
Do not call trx_rseg_mem_restore().
2018-01-31 08:52:16 +02:00
Marko Mäkelä
0ead8d9520 Clean up some undo page accessor functions
trx_undo_page_get_prev_rec(), trx_undo_page_get_last_rec(),
trx_undo_page_get_first_rec(), trx_undo_page_get_start():
Move to the only caller, trx0undo.cc.

Add some const qualifiers.
2018-01-31 08:52:16 +02:00
Marko Mäkelä
648e8c12e5 Remove unnecessary function parameters
trx_rseg_get_nth_undo(), trx_rsegf_undo_find_free():
Add a const qualifier, and remove the unused parameter mtr_t*.
2018-01-31 08:52:16 +02:00
Marko Mäkelä
8d1d38f953 Simplify access to the TRX_SYS page
trx_sysf_t: Remove.

trx_sysf_get(): Return the TRX_SYS page, not a pointer within it.

trx_sysf_rseg_get_space(), trx_sysf_rseg_get_page_no():
Remove a parameter, and merge the declaration and definition.
Take the TRX_SYS page as a parameter.

TRX_SYS_N_RSEGS: Correct the comment.

trx_sysf_rseg_find_free(), trx_sys_update_mysql_binlog_offset(),
trx_sys_update_wsrep_checkpoint(): Take the TRX_SYS page as a parameter.

trx_rseg_header_create(): Add a parameter for the TRX_SYS page.

trx_sysf_rseg_set_space(), trx_sysf_rseg_set_page_no(): Remove;
merge to the only caller, trx_rseg_header_create().
2018-01-31 08:52:16 +02:00
Marko Mäkelä
54c715acca Avoid an assertion failure on aborted startup
srv_init_abort_low(): Call srv_shutdown_bg_undo_sources() so that if
startup aborts while creating InnoDB system tables, the shutdown will
proceed correctly.
2018-01-31 08:52:16 +02:00
Monty
b9b17e6340 Updated error message for wrong foreign key constraint 2018-01-30 21:33:56 +02:00
Monty
a7e352b54d Changed database, tablename and alias to be LEX_CSTRING
This was done in, among other things:
- thd->db and thd->db_length
- TABLE_LIST tablename, db, alias and schema_name
- Audit plugin database name
- lex->db
- All db and table names in Alter_table_ctx
- st_select_lex db

Other things:
- Changed a lot of functions to take const LEX_CSTRING* as argument
  for db, table_name and alias. See init_one_table() as an example.
- Changed some function arguments from LEX_CSTRING to const LEX_CSTRING
- Changed some lists from LEX_STRING to LEX_CSTRING
- threads_mysql.result changed because process list_db wasn't always
  correctly updated
- New append_identifier() function that takes LEX_CSTRING* as arguments
- Added new element tmp_buff to Alter_table_ctx to separate temp name
  handling from temporary space
- Ensure we store the length after my_casedn_str() of table/db names
- Removed not used version of rename_table_in_stat_tables()
- Changed Natural_join_column::table_name and db_name() to never return
  NULL (used for print)
- thd->get_db() now returns db as a printable string (thd->db.str or "")
2018-01-30 21:33:55 +02:00
Marko Mäkelä
921c5e9314 Merge bb-10.2-ext into 10.3
MDEV-11415 Remove excessive undo logging during ALTER TABLE…ALGORITHM=COPY

Move a test from innodb.rename_table_debug to innodb.alter_copy.

ha_innobase::extra(HA_EXTRA_BEGIN_ALTER_COPY): Register id-versioned
tables so that mysql.transaction_registry will be updated, even for
empty tables that are subjected to ALTER TABLE…ALGORITHM=COPY.
2018-01-30 21:26:53 +02:00
Marko Mäkelä
33714d2065 Merge bb-10.2-ext into 10.3 2018-01-30 21:04:48 +02:00
Marko Mäkelä
0c1f220611 Merge 10.2 into bb-10.2-ext 2018-01-30 20:47:12 +02:00
Marko Mäkelä
0ba6aaf030 MDEV-11415 Remove excessive undo logging during ALTER TABLE…ALGORITHM=COPY
If a crash occurs during ALTER TABLE…ALGORITHM=COPY, InnoDB would spend
a lot of time rolling back writes to the intermediate copy of the table.
To reduce the amount of busy work done, a work-around was introduced in
commit fd069e2bb3 in MySQL 4.1.8 and 5.0.2,
to commit the transaction after every 10,000 inserted rows.

A proper fix would have been to disable the undo logging altogether and
to simply drop the intermediate copy of the table on subsequent server
startup. This is what happens in MariaDB 10.3 with MDEV-14717,MDEV-14585.
In MariaDB 10.2, the intermediate copy of the table would be left behind
with a name starting with the string #sql.

This is a backport of a bug fix from MySQL 8.0.0 to MariaDB,
contributed by jixianliang <271365745@qq.com>.

Unlike recent MySQL, MariaDB supports ALTER IGNORE. For that operation
InnoDB must for now keep the undo logging enabled, so that the latest
row can be rolled back in case of an error.

In Galera cluster, the LOAD DATA statement will retain the existing
behaviour and commit the transaction after every 10,000 rows if
the parameter wsrep_load_data_splitting=ON is set. The logic to do
so (the wsrep_load_data_split() function and the call
handler::extra(HA_EXTRA_FAKE_START_STMT)) are joint work
by Ji Xianliang and Marko Mäkelä.

The original fix:

Author: Thirunarayanan Balathandayuthapani <thirunarayanan.balathandayuth@oracle.com>
Date:   Wed Dec 2 16:09:15 2015 +0530

Bug#17479594 AVOID INTERMEDIATE COMMIT WHILE DOING ALTER TABLE ALGORITHM=COPY

Problem:

During ALTER TABLE, we commit and restart the transaction for every
10,000 rows, so that the rollback after recovery would not take so long.

Fix:

Suppress the undo logging during copy alter operation. If fts_index is
present then insert directly into fts auxiliary table rather
than doing at commit time.

ha_innobase::num_write_row: Remove the variable.

ha_innobase::write_row(): Remove the hack for committing every 10000 rows.

row_lock_table_for_mysql(): Remove the extra 2 parameters.

lock_get_src_table(), lock_is_table_exclusive(): Remove.

Reviewed-by: Marko Mäkelä <marko.makela@oracle.com>
Reviewed-by: Shaohua Wang <shaohua.wang@oracle.com>
Reviewed-by: Jon Olav Hauglid <jon.hauglid@oracle.com>
2018-01-30 20:24:23 +02:00
Marko Mäkelä
6d390bab4a Merge 10.2 into bb-10.2-ext 2018-01-30 20:18:25 +02:00
Vladislav Vaintroub
28d412411d Fix type truncation warnings.
rx_i_s_cache_t is now bool, not ibool.
2018-01-29 18:31:26 +00:00
Marko Mäkelä
8b673d44ce Fix an integer type mismatch 2018-01-29 19:08:04 +02:00
Marko Mäkelä
d9c77f0341 Revert "MDEV-6928: Add trx pointer to struct mtr_t"
This reverts commit 3486135bb5.

The commit comment ended in the words: "This is needed later."
Apparently the "later" never arrived.
2018-01-29 15:45:16 +02:00
Marko Mäkelä
f74023b955 MDEV-15090 Reduce the overhead of writing undo log records
Remove unnecessary repeated lookups for undo pages.

trx_undo_assign(), trx_undo_assign_low(), trx_undo_seg_create(),
trx_undo_create(): Return the undo log block to the caller.
2018-01-29 15:15:10 +02:00
Marko Mäkelä
5d3c3b4927 MDEV-15090 Reduce the overhead of writing undo log records
Inside InnoDB, each mini-transaction that generates any redo log records
will acquire log_sys->mutex during mtr_t::commit() in order to copy the
records into the global log_sys->buf for writing into the redo log file.

For single-row transactions, this incurs quite a bit of overhead.
We would use two mini-transactions for writing a record into a
freshly updated undo log page. (Only if the undo record will
not fit in that page, then we will have to commit and restart
the mini-transaction.)

trx_undo_assign(): Assign undo log for a persistent transaction,
or return the already assigned one.

trx_undo_assign_low(): Assign undo log for an operation on a
persistent or temporary table.

trx_undo_create(), trx_undo_reuse_cached(): Remove redundant parameters.
Merge the logic from trx_undo_mark_as_dict_operation().
2018-01-29 15:15:10 +02:00
Marko Mäkelä
4981f95ffa trx_undo_seg_create(): Remove an unused parameter 2018-01-29 15:15:10 +02:00
Marko Mäkelä
706ed8552d Revert "MDEV-6928: Add trx pointer to struct mtr_t"
This reverts commit 3486135bb5.

The commit comment ended in the words: "This is needed later."
Apparently the "later" never arrived.
2018-01-29 11:05:17 +02:00
Alexander Barkov
c7a2f23a7b Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3 2018-01-29 12:44:20 +04:00
Marko Mäkelä
041a32abcd Remove trx_mod_tables_t::vers_by_trx
Only invoke set_versioned() on trx_id versioned tables.

dict_table_t::versioned_by_id(): New accessor, to determine if
a table is system versioned by transaction ID.
2018-01-28 22:21:48 +02:00
Marko Mäkelä
1da063a45b Remove unused metadata for non-existing sync_thread_mutex 2018-01-28 22:17:54 +02:00
Monty
84514ec643 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext
Conflicts:
	sql/table.cc
2018-01-27 15:20:01 +02:00
Marko Mäkelä
b8c92d752c Fixed compiler warning 2018-01-26 10:50:20 +04:00
Sergey Vojtovich
55277e8840 MDEV-15059 - Misc small InnoDB scalability fixes
Form better trx_sys API.
2018-01-26 10:25:33 +04:00
Sergey Vojtovich
064bd78038 MDEV-15059 - Misc small InnoDB scalability fixes
When cloning oldest view, don't copy ReadView::m_creator_trx_id.
It means that the owner thread is now allowed to access this member
without trx_sys.mutex protection.

To achieve this we have to keep ReadView::m_creator_trx_id in
ReadView::m_ids. This is required to not let purge thread process
records owned by transaction associated with oldest view.

It is only required if trsanction entered read-write mode before it's
view was created.

If transaction entered read-write mode after it's view was created
(trx_set_rw_mode()), purge thread won't be allowed to touch it because
m_low_limit_id >= m_creator_trx_id holds. Thus we don't have to add
this transaction id to ReadView::m_ids.

Cleanups:

ReadView::ids_t: don't seem to make any sense, just complicate matters.

ReadView::copy_trx_ids(): doesn't make sense anymore, integrated into
caller.

ReadView::copy_complete(): not needed anymore.

ReadView copy constructores: don't seem to make any sense.

trx_purge_truncate_history(): removed view argument, access
purge_sys->view directly instead.
2018-01-26 10:25:33 +04:00
Sergey Vojtovich
0499693910 MDEV-15059 - Misc small InnoDB scalability fixes
Moved lock_rec_lock_slow() inside lock_rec_lock().
2018-01-26 10:25:33 +04:00
Sergey Vojtovich
8389b45b7f MDEV-15059 - Misc small InnoDB scalability fixes
Moved mutex locking inside lock_rec_lock().
Moved monitor increment out of mutex.
Moved assertions that don't require protection out of mutex.
Removed duplicate assertions.
Moved duplicate debug injections into lock_rec_lock().
Let monitor updates use relaxed memory order.
Return directly without maintaining variables in lock_rec_lock_slow().
Moved lock_rec_lock_fast() body into lock_rec_lock(): saves at least one
trx_mutex_enter(), one switch() plus some code was moved out of mutex.
2018-01-26 10:25:33 +04:00
Sergey Vojtovich
ce04790065 MDEV-14482 - Cache line contention on ut_rnd_ulint_counter()
InnoDB RNG maintains global state, causing otherwise unnecessary bus
traffic. Even worse this is cross-mutex traffic. That is different
mutexes suffer from contention.

Fixed delay of 4 was verified to give best throughput by OLTP update
index and read-write benchmarks on Intel Broadwell (2/20/40) and
ARM (1/46/46).
2018-01-26 10:25:33 +04:00
Marko Mäkelä
92d233a512 MDEV-15061 TRUNCATE must honor InnoDB table locks
Traditionally, DROP TABLE and TRUNCATE TABLE discarded any locks that
may have been held on the table. This feels like an ACID violation.
Probably most occurrences of it were prevented by meta-data locks (MDL)
which were introduced in MySQL 5.5.

dict_table_t::n_foreign_key_checks_running: Reduce the number of
non-debug checks.

lock_remove_all_on_table(), lock_remove_all_on_table_for_trx(): Remove.

ha_innobase::truncate(): Acquire an exclusive InnoDB table lock
before proceeding. DROP TABLE and DISCARD/IMPORT were already doing
this.

row_truncate_table_for_mysql(): Convert the already started transaction
into a dictionary operation, and do not invoke lock_remove_all_on_table().

row_mysql_table_id_reassign(): Do not call lock_remove_all_on_table().
This function is only used in ALTER TABLE...DISCARD/IMPORT TABLESPACE,
which is already holding an exclusive InnoDB table lock.

TODO: Make n_foreign_key_checks running a debug-only variable.
This would require two fixes:
(1) DROP TABLE: Exclusively lock the table beforehand, to prevent
the possibility of concurrently running foreign key checks (which
would acquire a table IS lock and then record S locks).
(2) RENAME TABLE: Find out if n_foreign_key_checks_running>0 actually
constitutes a potential problem.
2018-01-25 22:43:43 +02:00
Vicențiu Ciorbaru
61e2f43e05 Remove ut_win_init_time from innodb
The patch was brought in from 5.6.39 merge and we don't need it in
MariaDB
2018-01-25 19:50:13 +02:00
Vicențiu Ciorbaru
f775ee6006 Fix innodb compilation failure on Windows
We don't need to print an error when loading kernel32.dll. If we can't
load it we'll automatically crash. Reviewed by wlad@mariadb.com
2018-01-25 11:34:56 +02:00
Jan Lindström
859d100d70 MDEV-15063: InnoDB assertion failure !is_owned() at dict0defrag_bg.cc:327
Probem was that dict_sys mutex was owned when calling function
dict_stats_save_defrag_stats() that assumes we do not own
dict_sys mutex.
2018-01-25 11:28:38 +02:00
Vicențiu Ciorbaru
3699a4b5c0 Merge branch 'merge-innodb-5.6' into 10.0 2018-01-24 18:23:25 +02:00
Vicențiu Ciorbaru
b20f821e07 Fix Innodb ASAN error on init
Backport 7c03edf2fe from xtradb to innodb
2018-01-24 15:18:36 +02:00
Marko Mäkelä
9aa461b187 Minor cleanup
ReadView::ReadView(): Define inline, and remove the memset().

ReadView::~ReadView(): Use the default destructor.
2018-01-24 14:01:45 +02:00
Sergey Vojtovich
4575ae70da Plug a memory leak 2018-01-24 14:00:42 +02:00
Marko Mäkelä
9875d5c3e1 Merge bb-10.2-ext into 10.3 2018-01-24 14:00:33 +02:00
Vicențiu Ciorbaru
d833bb65d5 Merge remote-tracking branch '5.5' into 10.0 2018-01-24 12:29:31 +02:00
Howard Su
6fe953cb71 Fix build on OSX with 10.13 SDK 2018-01-24 11:28:00 +02:00
Marko Mäkelä
62740e02c8 Merge 10.2 into bb-10.2-ext 2018-01-24 11:15:11 +02:00
Marko Mäkelä
c269f1d6fe Allocate page_cleaner and page_cleaner.slot[] statically 2018-01-24 11:10:33 +02:00
Marko Mäkelä
ac3e7f788e MDEV-15016: multiple page cleaner threads use a lot of CPU
While the bug was reported as a regression of
MDEV-11025 Make number of page cleaner threads variable dynamic
in MariaDB Server 10.3, the code that MariaDB Server 10.2
inherited from MySQL 5.7.4 (WL#6642) looks prone to similar errors.

pc_flush_slot(): If there is no work to do, reset the is_requested
signal, to avoid potential busy-waiting in
buf_flush_page_cleaner_worker(). If the coordinator thread has shut
down, avoid resetting the is_requested event, to avoid a potential
hang at shutdown if there are multiple worker threads.
2018-01-24 11:10:33 +02:00
Marko Mäkelä
8637931f11 Add ASAN instrumentation (and more strict Valgrind) to InnoDB
mem_heap_free_heap_top(): Remove UNIV_MEM_ASSERT_W() and unpoison
the memory region first, because part of it may have been poisoned
by an earlier mem_heap_free_top() call.
Poison the address range at the end.

mem_heap_block_free(): Poison the address range at the end.

UNIV_MEM_ASSERT_AND_ALLOC(): Replace with UNIV_MEM_ALLOC().
We want to keep the address ranges poisoned (unaccessible) as
long as possible.

UNIV_MEM_ASSERT_AND_FREE(): Replace with UNIV_MEM_FREE().
2018-01-23 20:34:05 +02:00
Marko Mäkelä
70a9b12de9 Silence -Wimplicit-fallthrough 2018-01-23 18:08:55 +02:00
Vicențiu Ciorbaru
3dfe148074 5.6.39 2018-01-23 17:43:37 +02:00
Alexander Barkov
ec6b8c546a Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2018-01-23 17:43:12 +04:00
Marko Mäkelä
431607237d MDEV-12173 "Error: trying to do an operation on a dropped tablespace"
InnoDB is issuing a 'noise' message that is not a sign of abnormal
operation. The only issuers of it are the debug function
lock_rec_block_validate() and the change buffer merge.
While the error should ideally never occur in transactional locking,
we happen to know that DISCARD TABLESPACE and TRUNCATE TABLE and
possibly DROP TABLE are breaking InnoDB table locks.

When it comes to the change buffer merge, the message simply is useless
noise. We know perfectly well that a tablespace can be dropped while a
change buffer merge is pending. And the code is prepared to handle that,
which is demonstrated by the fact that whenever the message was issued,
InnoDB did not crash.

fil_inc_pending_ops(): Remove the parameter print_err.
2018-01-22 16:58:13 +02:00