Home - Waterfall Grid T-Grid Console Builders Recent Builds Buildslaves Changesources - JSON API - About

Console View


Categories: connectors experimental galera main
Legend:   Passed Failed Warnings Failed Again Running Exception Offline No data

connectors experimental galera main
Dmitry Shulga
MDEV-30645: CREATE TRIGGER FOR { STARTUP | SHUTDOWN }

Follow-up to fix issue with starting server on server with broken table mysql.event
mohitbalwani
MDEV-38696 Fix infinite loop in my_copy() function

The bug occurred when my_read() returned (size_t)-1 but was
compared against (uint)-1.It was causing the loop to
never exit when reading from a directory or other error conditions.

Changed comparison from (uint)-1 to (size_t)-1 to match the
return type of my_read().
Vladislav Vaintroub
MDEV-37788 fix uintNkorr/intNstore macros to avoid unaligned access

Replaced macros with optimized inline functions, that use memcpy
instead of unaligned access (translates to single instruction
on architectures we support). Used compiler byteswap intrinsics
where appropriate.

Removed byte_order_generic.h as well as Intel specific headers
byte_order_generic_{x86|x86_64}.h

Added some casts to places where intNstore writes into "const char*".
Vladislav Vaintroub
MDEV-37788 review fixes - optimize uint3korr, sint3korr

uint3korr - Reuse uint2korr, to remove one MOV instruction
(of previously 3) on current compilers.

sint3korr - Reuse uint3korr, and replace the conditional sign-extension
with a branchless shift-based sign extension
Daniel Black
MCOL-6313: test submodule update for MCOL-6313
Daniel Black
wsrep_info plugin config file created
Mohammad Tafzeel Shams
MDEV-22186: Add innodb_trim_core_file to exclude InnoDB memory from cores

Problem:
There is no control to include or exclude large InnoDB memory regions
such as the buffer pool and log buffer from core files, which can lead to
unnecessarily large core dumps or prevent capturing useful memory state.

Solution:
Introduce a new global dynamic system variable innodb_trim_core_file that
allows excluding large InnoDB memory regions (buffer pool and log buffer)
from core dumps using MADV_DONTDUMP where supported. When enabled and
@@core_file=ON, the server marks relevant memory regions to be omitted
from core files. The madvise state is dynamically updated when the
variable changes.

Additionally, a test helper script is introduced to inspect
/proc/<pid>/smaps and verify whether large memory regions are marked
for trimming.

- innodb_trim_core_file
  Global boolean system variable controlling whether InnoDB memory
  regions should be excluded from core dumps. Has no effect if
  @@core_file=OFF. Default: ON on non-debug builds with MADV_DONTDUMP
  support, OFF otherwise.

- innobase_should_trim_core_dump()
  Determines whether InnoDB memory allocations should be marked with
  MADV_DONTDUMP, based on @@core_file and @@innodb_trim_core_file.

- innodb_srv_trim_core_file_update()
  Update hook that sets srv_trim_core_file and triggers runtime updates
  of madvise state for both the buffer pool and log buffers.

- srv_trim_core_file
  Global variable backing @@innodb_trim_core_file.

- buf_pool_t::buf_pool_should_madvise_dont_dump
  Tracks the current madvise state for the buffer pool memory.

- buf_pool_t::madvise_update_dump()
  Re-evaluates whether the buffer pool should be excluded from core
  dumps and applies ut_dontdump() or ut_dodump() accordingly.

- buf_pool_t::create()
  Initializes madvise state based on innobase_should_trim_core_dump()
  and conditionally applies MADV_DONTDUMP to the buffer pool memory.

- buf_pool_t::resize()
  Reapplies MADV_DONTDUMP to newly allocated memory regions when
  resizing if innodb_trim_core_file=ON

- log_t::log_buf_should_madvise_dont_dump
  Tracks the madvise state for the InnoDB log buffers.

- log_t::madvise_dontdump()
  Marks log buffers and resize buffers with MADV_DONTDUMP.

- log_t::madvise_dodump()
  Restores inclusion of log buffers in core dumps using MADV_DODUMP.

- log_t::madvise_update_dump()
  Updates the madvise state for log buffers when
  @@innodb_trim_core_file changes.

- log_t::attach()
  Call ut_dodump() for log_t::buf & log_t::flush_buf on successful
  allocation and innodb_trim_core_file=OFF

- log_t::resize_start()
  Call ut_dodump() for log_t::resize_buf & log_t::resize_flush_buf on
  successful allocation and innodb_trim_core_file=OFF

- check_core_dump_trim.inc
  Test helper that inspects /proc/<pid>/smaps to detect memory regions
  with the dd VmFlag and determine whether the core file is expected
  to be trimmed based on buffer pool and log buffer sizes.
Dave Gosselin
MDEV-39005: Assertion failure on hint-forced Split-Materialized plan

Using a hint to force splitting can force the optimizer to choose a
split plan that would otherwise be considered invalid.
SPLIT_MATERIALIZED(DT) forces splitting, the optimizer must still
respect the invariants checked by apply_selectivity_for_table() for
what would otherwise be a splitting that would never be chosen
naturally.

In the attached test case, a derived table DT performs GROUP BY/HAVING
and is then joined to t2. With the hint forcing a split, the splitting
code can compute a `records` estimate that makes the effective
selectivity (`sel`) exceed the bound assumed in
apply_selectivity_for_table() (specifically the
`use_cond_selectivity > 1` assertion path), i.e. it can exceed:

  s->table->opt_range_condition_rows / table_records

To fix this, when a split is hint-forced, clamp `records` to the
unsplit derived cardinality (`spl_opt_info->unsplit_card`). This
effectively bounds `records` to:

  min(unsplit_card, unsplit_card * split_sel)

and prevents `sel` from exceeding the range-condition-rows ratio in
the assertion.
bsrikanth-mariadb
MDEV-38805: Tests refactoring

1. store round_cost() in a separate .inc file so that it can be
  reused across multiple tests
2. Change the usage of "--error 1290" with
  "--error ER_OPTION_PREVENTS_STATEMENT"
Sergei Petrunia
Improve  strdup_root(mem_root, string) function
Vladislav Vaintroub
MDEV-37788 review fixes - optimize uint3korr, sint3korr, and intNstore

uint3korr - Reuse uint2korr, to remove one MOV instruction
(of previously 3) on current compilers.

sint3korr - Reuse uint3korr, and replace the conditional sign-extension
with a branchless shift-based sign extension

int3store, int5store, int6store - reuse int2store and int4store.
Aleksey Midenkov
MDEV-28619 with_flags cleanup

The best practice is to init as much info as possible in class
constructor. with_flags access may be needed before fix_fields() or
fix_fields() may be not called at all like it takes place in
MDEV-28619. The fix for MDEV-28619 requires WINDOW_FUNC check on
unfixed item.
Vladislav Vaintroub
MDEV-37788 review fixes - optimize uint3korr, sint3korr

uint3korr - Reuse uint2korr, to remove one MOV instruction
(of previously 3) on current compilers.

sint3korr - Reuse uint3korr, and replace the conditional sign-extension
with a branchless shift-based sign extension
bsrikanth-mariadb
MDEV-38805: use charset utf8mb4, for client-server communication

REPLACE INTO statements would now use my_charset_utf8mb4_bin conversion
Also, the sql_script file structure would now look like

SET NAMES utf8mb4;
SET var1=value1;
.
.
CREATE DATABASE 'name' if NOT..;
USE DATABASE 'name';
CREATE TABLE ...;
.
REPLACE INTO ..;
.
.
set @opt_context='...';
.
.

Additionally, made few changes to the documentation comments
Sergei Petrunia
Cleanup: de-couple opt_range context recording from optimizer trace.

Instead, do recording in on e record_multi_range_read_info_const()
call.
Vladislav Vaintroub
MDEV-37788 review fixes - optimize uint3korr, sint3korr, and intNstore

uint3korr - Reuse uint2korr, to remove one MOV instruction
(of previously 3) on current compilers.

sint3korr - Reuse uint3korr, and replace the conditional sign-extension
with a branchless shift-based sign extension

int3store, int5store, int6store - reuse int2store and int4store.
Nikita Malyavin
Fix ninja build for DEB layout

In DEB layout, mariadbclient is named libmariadb.a

In install.cmake:
SET(LIBMARIADB_STATIC_DEB "mariadb")

This causes a duplicate target for libmariadb.a, and moreover,
a symlink recipe with reference to already existing file.

Make builds don't report a dupliate problem, and besides,
"file already exists" is not reported somehow.
Ninja build reports error.

The only check that has to be done is comparison
against INSTALL_LAYOUT, because LIBMARIADB_STATIC_NAME
is unconditionally set to the layout's value:
SET(LIBMARIADB_STATIC_NAME ${LIBMARIADB_STATIC_${INSTALL_LAYOUT}})
Vladislav Vaintroub
Revert "MDEV-38989 main.ctype_utf16le SEGV in Ubuntu 26.04 (x86-64-v3)"

This reverts commit 6318d5001597fff28ea7ba7f957d66edd7e3e954.

uint2korr is now fixed in MDEV-37788, thus partial workarounds are not necessary anymore.
Daniel Black
deb: no wsrep_on until cluster address set
Vladislav Vaintroub
MDEV-37788 review fixes - optimize uint3korr, sint3korr

uint3korr - Reuse uint2korr, to remove one MOV instruction
(of previously 3) on current compilers.

sint3korr - Reuse uint3korr, and replace the conditional sign-extension
with a branchless shift-based sign extension
Marko Mäkelä
fixup! 1d57f26b50436d3e59ccce9a2b8cd7a9836c07ac

Skip log_checkpoint_low() if innodb_log_recovery_target is set
Aleksey Midenkov
MDEV-28619 Server crash and UBSAN null-pointer-use in Window_funcs_sort::setup

Optimization in st_select_lex_unit::prepare() removes ORDER BY for
certain subqueries. That excludes ORDER BY items from being fixed, but
sl->window_funcs still contains window function items and those
related to optimized out ORDER BY are unfixed. The error about missing
window spec is thrown when the item is fixed. Hence we get redundant
processing of window function items without checking window spec
existence.

The fix removes the related window function items when ORDER BY is
optimized out. ORDER accumulates window_funcs at parser stage which
are then removed from SELECT_LEX::window_funcs. The fix also updates
similar optimization in mysql_make_view().
Aleksey Midenkov
MDEV-36362 MariaDB crashes when parsing fuzzer generated PARTITION

Function calls in INTERVAL expression of DDL have little
sense. SETVAL() fails because sequences require opened tables and
vers_set_interval() is called at earlier stage.

The fix disables function calls in INTERVAL expressions and limits it
to signal_allowed_expr (literal, variable, simple_ident).
Yuchen Pei
MDEV-38732 Correctly construct queries with NULL uservar values in spider

The subsequent assertion failure in end_statement is likely caused by
HA_ERR_OUT_OF_MEM not correctly handled, but it should not return an
HA_ERR_OUT_OF_MEM here in the first place.
Aleksey Midenkov
MDEV-32317 Trace for ref_ptrs array (ref_array keyword)

Usage:

  mtr --mysqld=--debug=d,ref_array,query:i:o,/tmp/mdl.log
Vladislav Vaintroub
MDEV-37788 review fixes - optimize uint3korr, sint3korr, and intNstore

uint3korr - Reuse uint2korr, to remove one MOV instruction
(of previously 3) on current compilers.

sint3korr - Reuse uint3korr, and replace the conditional sign-extension
with a branchless shift-based sign extension

int3store, int5store, int6store - reuse int2store and int4store.
Fariha Shaikh
MDEV-38020 Master & relay log info files read 2^31 and above incorrectly

Master and relay log positions are 64-bit unsigned but were read using
atoi(), which only handles signed 32-bit integers. Values >= 2^31 overflow
and corrupt after restart.

Add init_ullongvar_from_file() using my_strtoll10() to correctly parse
64-bit values. Update rpl_rli.cc and rpl_mi.cc to use ulonglong variables
and this new function.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.

Reviewed-by: Brandon Nesterenko <[email protected]>
Marko Mäkelä
fixup! 1d57f26b50436d3e59ccce9a2b8cd7a9836c07ac

log_t::checkpoint_margin(): Properly wait for log file rotation
Vladislav Vaintroub
Revert "MDEV-38989 main.ctype_utf16le SEGV in Ubuntu 26.04 (x86-64-v3)"

This reverts commit 6318d5001597fff28ea7ba7f957d66edd7e3e954.

uint2korr is now fixed in MDEV-37788, thus partial workarounds are not necessary anymore.
Vladislav Vaintroub
MDEV-37788 review fixes - optimize uint3korr, sint3korr, and intNstore

uint3korr - Reuse uint2korr, to remove one MOV instruction
(of previously 3) on current compilers.

sint3korr - Reuse uint3korr, and replace the conditional sign-extension
with a branchless shift-based sign extension

int3store, int5store, int6store - reuse int2store and int4store.
Marko Mäkelä
MDEV-37949: Implement innodb_log_archive

The InnoDB write-ahead log file in the old innodb_log_archive=OFF
format is named ib_logfile0, pre-allocated to innodb_log_file_size and
written as a ring buffer. This is good for write performance and space
management, but unsuitable for arbitrary point-in-time recovery or for
facilitating efficient incremental backup.

innodb_log_archive=ON: A new format where InnoDB will create and
preallocate files ib_%016x.log, instead of writing a circular file
ib_logfile0. Each file will be pre-allocated to innodb_log_file_size
(between 4M and 4G; we impose a stricter upper limit of 4 GiB for
innodb_log_archive=ON). Once a log fills up, we will create and
pre-allocate another log file, to which log records will be written.
Upon the completion of the first log checkpoint in a recently created
log file, the old log file will be marked read-only, signaling that
there will be no further writes to that file, and that the file may
safely be moved to long-term storage.

The file name includes the log sequence number (LSN) at file offset
12288 (log_t::START_OFFSET). Limiting the file size to 4 GiB allows us
to identify each checkpoint by storing a 32-bit big-endian offset into
the optional FILE_MODIFY and the mandatory FILE_CHECKPOINT records,
between 12288 and the end of the file.

The innodb_encrypt_log format is identified by storing the encryption
information at the start of the log file. The first 32-bit value will
be 1, which is an invalid checkpoint offset. Each
innodb_log_archive=ON log must use the same encryption parameters.
Changing innodb_encrypt_log or related parameters is only possible by
setting innodb_log_archive=OFF and restarting the server, which will
permanently lose the history of the archived log.

The maximum number of log checkpoints that the innodb_log_archive=ON
file header can represent is limited to 12288/4=3072 when using
innodb_encrypt_log=OFF. If we run out of slots in a log file, each
subsequently completed checkpoint in that log file will overwrite the
last slot in the checkpoint header, until we switch to the next log.

innodb_log_recovery_start: The checkpoint LSN to start recovery from.
This will be useful when recovering from an archived log. This is useful
for restoring an incremental backup (applying InnoDB log files that were
copied since the previous restore).

innodb_log_recovery_target: The requested LSN to end recovery at.
When this is set, all persistent InnoDB tables will be read-only, and
no writes to the log are allowed. The intended purpose of this setting
is to prepare an incremental backup, as well as to allow data
retrieval as of a particular logical point of time.

Setting innodb_log_recovery_target>0 is much like setting
innodb_read_only=ON, with the exception that the data files may be
written to by crash recovery, and locking reads will conflict with any
incomplete transactions as necessary, and all transaction isolation
levels will work normally (not hard-wired to READ UNCOMMITTED).

srv_read_only_mode: When this is set (innodb_read_only=ON), also
recv_sys.rpo (innodb_log_recovery_target) will be set to the current LSN.
This ensures that it will suffice to check only one of these variables
when blocking writes to persistent tables.

The status variable innodb_lsn_archived will reflect the LSN
since when a complete InnoDB log archive is available. Its initial
value will be that of the new parameter innodb_log_archive_start.
If that variable is 0 (the default), the innodb_lsn_archived will
be recovered from the available log files. If innodb_log_archive=OFF,
innodb_lsn_archived will be adjusted to the latest checkpoint every
time a log checkpoint is executed. If innodb_log_archive=ON, the value
should not change.

SET GLOBAL innodb_log_archive=!@@GLOBAL.innodb_log_archive will take
effect as soon as possible, possibly after a log checkpoint has been
completed. The log file will be renamed between ib_logfile0 and
ib_%016x.log as appropriate.

When innodb_log_archive=ON, the setting SET GLOBAL innodb_log_file_size
will affect subsequently created log files when the file that is being
currently written is running out. If we are switching log files exactly
at the same time, then a somewhat misleading error message
"innodb_log_file_size change is already in progress" will be issued.

no_checkpoint_prepare.inc: A new file, to prepare for subsequent
inclusion of no_checkpoint_end.inc. We will invoke the server to
parse the log and to determine the latest checkpoint.

All --suite=encryption tests that use innodb_encrypt_log
will be skipped for innodb_log_archive=ON, because enabling
or disabling encryption on the log is not possible without
temporarily setting innodb_log_archive=OFF and restarting
the server. The idea is to add the following arguments to an
invocation of mysql-test/mtr:

--mysqld=--loose-innodb-log-archive \
--mysqld=--loose-innodb-log-recovery-start=12288 \
--mysqld=--loose-innodb-log-file-mmap=OFF \
--skip-test=mariabackup

Alternatively, specify --mysqld=--loose-innodb-log-file-mmap=ON
to cover both code paths.

The mariabackup test suite must be skipped when using the
innodb_log_archive=ON format, because mariadb-backup will only
support the old ib_logfile0 format (innodb_log_archive=OFF).

A number of tests would fail when the parameter
innodb_log_recovery_start=12288 is present, which is forcing
recovery to start from the beginning of the history
(the database creation). The affected tests have been adjusted with
explicit --innodb-log-recovery-start=0 to override that:

(0) Some injected corruption may be "healed" by replaying the log
from the beginning. Some tests expect an empty buffer pool after
a restart, with no page I/O due to crash recovery.
(1) Any test that sets innodb_read_only=ON would fail with an error
message that the setting prevents crash recovery, unless
innodb_log_recovery_start=0.
(2) Any test that changes innodb_undo_tablespaces would fail in crash
recovery, because crash recovery assumes that the undo tablespace ID
that is available from the undo* files corresponds with the start of
the log. This is an unforunate design bug which we cannot fix easily.

log_sys.first_lsn: The start of the current log file, to be consulted
in log_t::write_checkpoint() when renaming files.

log_sys.archived_lsn: New field: The value of innodb_lsn_archived.

log_sys.end_lsn: New field: The log_sys.get_lsn() when the latest
checkpoint was initiated. That is, the start LSN of a possibly empty
sequence of FILE_MODIFY records followed by FILE_CHECKPOINT.

log_sys.resize_target: The value of innodb_log_file_size that will be
used for creating the next archive log file once the current file (of
log_sys.file_size) fills up.

log_sys.archive: New field: The value of innodb_log_archive.

log_sys.next_checkpoint_no: Widen to uint16_t. There may be up to
12288/4=3072 checkpoints in the header.

log_sys.log: If innodb_log_archive=ON, this file handle will be kept
open also in the PMEM code path.

log_sys.resize_log: If innodb_log_archive=ON, we may have two log
files open both during normal operation and when parsing the log. This
will store the other handle (old or new file).

log_sys.resize_buf: In the memory-mapped code path, this will point
to the file resize_log when innodb_log_archive=ON.

recv_sys.log_archive: All innodb_log_archive=ON files that will be
considered in recovery.

recv_sys.was_archive: A flag indicating that an innodb_log_archive=ON
file is in innodb_log_archive=OFF format.

recv_sys.file_checkpoint_parsed: The LSN of the parsed
FILE_CHECKPOINT record that points to the desired checkpoint.

log_sys.is_pmem, log_t::is_mmap_writeable(): A new predicate.
If is_mmap_writeable(), we assert and guarantee buf_size == capacity().

log_t::archive_new_write(): Create and allocate a new log file, and
write the outstanding data to both the current and the new file, or
only to the new file, until write_checkpoint() completes the first
checkpoint in the new file.

log_t::archived_mmap_switch_prepare(): Create and memory-map a new log
file, and update file_size to resize_target. Remember the file handle
of the current log in resize_log, so that write_checkpoint() will be
able to make it read-only.

log_t::archived_mmap_switch_complete(): Switch to the buffer that was
created in archived_mmap_switch_prepare().

log_t::write_checkpoint(): Allow an old checkpoint to be completed in
the old log file even after a new one has been created. If we are
writing the first checkpoint in a new log file, we will mark the old
log file read-only. We will also update log_sys.first_lsn unless it
was already updated in ARCHIVED_MMAP code path. In that code path,
there is the special case where log_sys.resize_buf == nullptr and
log_sys.checkpoint_buf points to log_sys.resize_log (the old log file
that is about to be made read-only). In this case, log_sys.first_lsn
will already point to the start of the current log_sys.log, even
though the switch has not been fully completed yet.

log_t::header_rewrite(my_bool): Rewrite the log file header before or
after renaming the log file, and write a message about the change,
so that there will be a chance to recover in case the server is being
killed during this operation.  The recovery of the last ib_%016%.log
does tolerate also the ib_logfile0 format.

log_t::set_archive(my_bool,THD): Implement SET GLOBAL innodb_log_archive.
An error will be returned if non-archived SET GLOBAL innodb_log_file_size
(log file resizing) is in progress. Wait for checkpoint if necessary.
The current log file will be renamed to either ib_logfile0 or
ib_%016x.log, as appropriate.

log_t::archive_rename(): Rename an archived log to ib_logfile0 on recovery
in case there had been a crash during set_archive().

log_t::archive_set_size(): A new function, to ensure that
log_sys.resize_target is set on startup.

log_checkpoint_low(): Do not prevent a checkpoint at the start of a file.
We want the first innodb_log_archive=ON file to start with a checkpoint.

log_t::create(lsn_t): Initialize last_checkpoint_lsn. Initialize the
log header as specified by log_sys.archive (innodb_log_archive).

log_write_buf(): Add the parameter max_length, the file wrap limit.

log_write_up_to(), mtr_t::commit_log_release<bool mmap=true>():
If we are switching log files, invoke buf_flush_ahead(lsn, true)
to ensure that a log checkpoint will be completed in the new file.

mtr_t::finish_writer(): Specialize for innodb_log_archive=ON.

mtr_t::commit_file(): Ensure that log archive rotation will complete.

log_t::append_prepare<log_t::ARCHIVED_MMAP>(): Special case.

log_t::get_path(): Get the name of the current log file.

log_t::get_circular_path(size_t): Get the path name of a circular file.
Replaces get_log_file_path().

log_t::get_archive_path(lsn_t): Return a name of an archived log file.

log_t::get_next_archive_path(): Return the name of the next archived log.

log_t::append_archive_name(): Append the archive log file name
to a path string.

mtr_t::finish_writer(): Invoke log_close() only if innodb_log_archive=OFF.
In the innodb_log_archive=ON, we only force log checkpoints after creating
a new archive file, to ensure that the first checkpoint will be written
as soon as possible.

log_t::checkpoint_margin(): Replaces log_checkpoint_margin().
If a new archived log file has been created, wait for the
first checkpoint in that file.

srv_log_rebuild_if_needed(): Never rebuild if innodb_log_archive=ON.
The setting innodb_log_file_size will affect the creation of
subsequent log files. The parameter innodb_encrypt_log cannot be
changed while the log is in the innodb_log_archive=ON format.

log_t::attach(), log_mmap(): Add the parameter log_access,
to distinguish memory-mapped or read-only access.

log_t::attach(): When disabling innodb_log_file_mmap, read
checkpoint_buf from the last innodb_log_archive=ON file.

log_t::clear_mmap(): Clear the tail of the checkpoint buffer
if is_mmap_writeable().

log_t::set_recovered(): Invoke clear_mmap(), and restore the
log buffer to the correct position.

recv_sys_t::apply(): Let log_t::clear_mmap() enable log writes.

recv_sys_t::find_checkpoint(): Find and remember the checkpoint position
in the last file when innodb_log_recovery_start points to an older file.
When innodb_log_file_mmap=OFF, restore log_sys.checkpoint_buf from
the latest log file. If the last archive log file is actually
in innodb_log_archive=OFF format despite being named ib_%016.log,
try to recover it in that format. If the circular ib_logfile0 is missing,
determine the oldest archived log file with contiguous LSN.
If innodb_log_archive=ON, refuse to start if ib_logfile0 exists.
Open non-last archived log files in read-only mode.

recv_sys_t::find_checkpoint_archived(): Validate each checkpoint in
the current file header, and by default aim to recover from the last
valid one. Terminate the search if the last validated checkpoint
spanned two files. If innodb_log_recovery_start has been specified,
attempt to validate it even if there is no such information stored
in the checkpoint header.

log_parse_file(): Do not invoke fil_name_process() during
recv_sys_t::find_checkpoint_archived(), when we tolerate FILE_MODIFY
records while looking for a FILE_CHECKPOINT record.

recv_scan_log(): Invoke log_t::archived_switch_recovery() upon
reaching the end of the current archived log file.

log_t::archived_switch_recovery_prepare(): Make use of
recv_sys.log_archive and open all but the last file read-only.

log_t::archived_switch_recovery(): Switch files in the pread() code path.

log_t::archived_mmap_switch_recovery_complete(): Switch files in the
memory-mapped code path.

recv_warp: A pointer wrapper for memory-mapped parsing that spans two
archive log files.

recv_sys_t::parse_mmap(): Use recv_warp for innodb_log_archive=ON.

recv_sys_t::parse(): Tweak some logic for innodb_log_archive=ON.

log_t::set_recovered_checkpoint(): Set the checkpoint on recovery.
Updates also the end_lsn.

log_t::set_recovered_lsn(): Also update flush_lock and write_lock,
to ensure that log_write_up_to() will be a no-op.

log_t::persist(): Even if the flushed_to_disk_lsn does not change,
we may want to reset the write_lsn_offset.
Sergei Petrunia
Cleanup in Optimizer_context_recorder

- Introduce init_optimizer_context_recorder_if_needed() which is called
at query start. We n longer create the recorder lazily.

- Recorder functions no longer take MEM_ROOT to store data on as an
  argument. The recorder knows the MEM_ROOT it should use.
Vladislav Vaintroub
MDEV-37788 fix uintNkorr/intNstore macros to avoid unaligned access

Replaced macros with optimized inline functions, that use memcpy
instead of unaligned access (translates to single instruction
on architectures we support). Used compiler byteswap intrinsics
where appropriate.

Removed byte_order_generic.h as well as Intel specific headers
byte_order_generic_{x86|x86_64}.h

Added some casts to places where intNstore writes into "const char*".
Marko Mäkelä
MDEV-37949: Implement innodb_log_archive

The InnoDB write-ahead log file in the old innodb_log_archive=OFF
format is named ib_logfile0, pre-allocated to innodb_log_file_size and
written as a ring buffer. This is good for write performance and space
management, but unsuitable for arbitrary point-in-time recovery or for
facilitating efficient incremental backup.

innodb_log_archive=ON: A new format where InnoDB will create and
preallocate files ib_%016x.log, instead of writing a circular file
ib_logfile0. Each file will be pre-allocated to innodb_log_file_size
(between 4M and 4G; we impose a stricter upper limit of 4 GiB for
innodb_log_archive=ON). Once a log fills up, we will create and
pre-allocate another log file, to which log records will be written.
Upon the completion of the first log checkpoint in a recently created
log file, the old log file will be marked read-only, signaling that
there will be no further writes to that file, and that the file may
safely be moved to long-term storage.

The file name includes the log sequence number (LSN) at file offset
12288 (log_t::START_OFFSET). Limiting the file size to 4 GiB allows us
to identify each checkpoint by storing a 32-bit big-endian offset into
the optional FILE_MODIFY and the mandatory FILE_CHECKPOINT records,
between 12288 and the end of the file.

The innodb_encrypt_log format is identified by storing the encryption
information at the start of the log file. The first 32-bit value will
be 1, which is an invalid checkpoint offset. Each
innodb_log_archive=ON log must use the same encryption parameters.
Changing innodb_encrypt_log or related parameters is only possible by
setting innodb_log_archive=OFF and restarting the server, which will
permanently lose the history of the archived log.

The maximum number of log checkpoints that the innodb_log_archive=ON
file header can represent is limited to 12288/4=3072 when using
innodb_encrypt_log=OFF. If we run out of slots in a log file, each
subsequently completed checkpoint in that log file will overwrite the
last slot in the checkpoint header, until we switch to the next log.

innodb_log_recovery_start: The checkpoint LSN to start recovery from.
This will be useful when recovering from an archived log. This is useful
for restoring an incremental backup (applying InnoDB log files that were
copied since the previous restore).

innodb_log_recovery_target: The requested LSN to end recovery at.
When this is set, all persistent InnoDB tables will be read-only, and
no writes to the log are allowed. The intended purpose of this setting
is to prepare an incremental backup, as well as to allow data
retrieval as of a particular logical point of time.

Setting innodb_log_recovery_target>0 is much like setting
innodb_read_only=ON, with the exception that the data files may be
written to by crash recovery, and locking reads will conflict with any
incomplete transactions as necessary, and all transaction isolation
levels will work normally (not hard-wired to READ UNCOMMITTED).

srv_read_only_mode: When this is set (innodb_read_only=ON), also
recv_sys.rpo (innodb_log_recovery_target) will be set to the current LSN.
This ensures that it will suffice to check only one of these variables
when blocking writes to persistent tables.

The status variable innodb_lsn_archived will reflect the LSN
since when a complete InnoDB log archive is available. Its initial
value will be that of the new parameter innodb_log_archive_start.
If that variable is 0 (the default), the innodb_lsn_archived will
be recovered from the available log files. If innodb_log_archive=OFF,
innodb_lsn_archived will be adjusted to the latest checkpoint every
time a log checkpoint is executed. If innodb_log_archive=ON, the value
should not change.

SET GLOBAL innodb_log_archive=!@@GLOBAL.innodb_log_archive will take
effect as soon as possible, possibly after a log checkpoint has been
completed. The log file will be renamed between ib_logfile0 and
ib_%016x.log as appropriate.

When innodb_log_archive=ON, the setting SET GLOBAL innodb_log_file_size
will affect subsequently created log files when the file that is being
currently written is running out. If we are switching log files exactly
at the same time, then a somewhat misleading error message
"innodb_log_file_size change is already in progress" will be issued.

no_checkpoint_prepare.inc: A new file, to prepare for subsequent
inclusion of no_checkpoint_end.inc. We will invoke the server to
parse the log and to determine the latest checkpoint.

All --suite=encryption tests that use innodb_encrypt_log
will be skipped for innodb_log_archive=ON, because enabling
or disabling encryption on the log is not possible without
temporarily setting innodb_log_archive=OFF and restarting
the server. The idea is to add the following arguments to an
invocation of mysql-test/mtr:

--mysqld=--loose-innodb-log-archive \
--mysqld=--loose-innodb-log-recovery-start=12288 \
--mysqld=--loose-innodb-log-file-mmap=OFF \
--skip-test=mariabackup

Alternatively, specify --mysqld=--loose-innodb-log-file-mmap=ON
to cover both code paths.

The mariabackup test suite must be skipped when using the
innodb_log_archive=ON format, because mariadb-backup will only
support the old ib_logfile0 format (innodb_log_archive=OFF).

A number of tests would fail when the parameter
innodb_log_recovery_start=12288 is present, which is forcing
recovery to start from the beginning of the history
(the database creation). The affected tests have been adjusted with
explicit --innodb-log-recovery-start=0 to override that:

(0) Some injected corruption may be "healed" by replaying the log
from the beginning. Some tests expect an empty buffer pool after
a restart, with no page I/O due to crash recovery.
(1) Any test that sets innodb_read_only=ON would fail with an error
message that the setting prevents crash recovery, unless
innodb_log_recovery_start=0.
(2) Any test that changes innodb_undo_tablespaces would fail in crash
recovery, because crash recovery assumes that the undo tablespace ID
that is available from the undo* files corresponds with the start of
the log. This is an unforunate design bug which we cannot fix easily.

log_sys.first_lsn: The start of the current log file, to be consulted
in log_t::write_checkpoint() when renaming files.

log_sys.archived_lsn: New field: The value of innodb_lsn_archived.

log_sys.end_lsn: New field: The log_sys.get_lsn() when the latest
checkpoint was initiated. That is, the start LSN of a possibly empty
sequence of FILE_MODIFY records followed by FILE_CHECKPOINT.

log_sys.resize_target: The value of innodb_log_file_size that will be
used for creating the next archive log file once the current file (of
log_sys.file_size) fills up.

log_sys.archive: New field: The value of innodb_log_archive.

log_sys.next_checkpoint_no: Widen to uint16_t. There may be up to
12288/4=3072 checkpoints in the header.

log_sys.log: If innodb_log_archive=ON, this file handle will be kept
open also in the PMEM code path.

log_sys.resize_log: If innodb_log_archive=ON, we may have two log
files open both during normal operation and when parsing the log. This
will store the other handle (old or new file).

log_sys.resize_buf: In the memory-mapped code path, this will point
to the file resize_log when innodb_log_archive=ON.

recv_sys.log_archive: All innodb_log_archive=ON files that will be
considered in recovery.

recv_sys.was_archive: A flag indicating that an innodb_log_archive=ON
file is in innodb_log_archive=OFF format.

log_sys.is_pmem, log_t::is_mmap_writeable(): A new predicate.
If is_mmap_writeable(), we assert and guarantee buf_size == capacity().

log_t::archive_new_write(): Create and allocate a new log file, and
write the outstanding data to both the current and the new file, or
only to the new file, until write_checkpoint() completes the first
checkpoint in the new file.

log_t::archived_mmap_switch_prepare(): Create and memory-map a new log
file, and update file_size to resize_target. Remember the file handle
of the current log in resize_log, so that write_checkpoint() will be
able to make it read-only.

log_t::archived_mmap_switch_complete(): Switch to the buffer that was
created in archived_mmap_switch_prepare().

log_t::write_checkpoint(): Allow an old checkpoint to be completed in
the old log file even after a new one has been created. If we are
writing the first checkpoint in a new log file, we will mark the old
log file read-only. We will also update log_sys.first_lsn unless it
was already updated in ARCHIVED_MMAP code path. In that code path,
there is the special case where log_sys.resize_buf == nullptr and
log_sys.checkpoint_buf points to log_sys.resize_log (the old log file
that is about to be made read-only). In this case, log_sys.first_lsn
will already point to the start of the current log_sys.log, even
though the switch has not been fully completed yet.

log_t::header_rewrite(my_bool): Rewrite the log file header before or
after renaming the log file, and write a message about the change,
so that there will be a chance to recover in case the server is being
killed during this operation.  The recovery of the last ib_%016%.log
does tolerate also the ib_logfile0 format.

log_t::set_archive(my_bool,THD): Implement SET GLOBAL innodb_log_archive.
An error will be returned if non-archived SET GLOBAL innodb_log_file_size
(log file resizing) is in progress. Wait for checkpoint if necessary.
The current log file will be renamed to either ib_logfile0 or
ib_%016x.log, as appropriate.

log_t::archive_rename(): Rename an archived log to ib_logfile0 on recovery
in case there had been a crash during set_archive().

log_t::archive_set_size(): A new function, to ensure that
log_sys.resize_target is set on startup.

log_checkpoint_low(): Do not prevent a checkpoint at the start of a file.
We want the first innodb_log_archive=ON file to start with a checkpoint.

log_t::create(lsn_t): Initialize last_checkpoint_lsn. Initialize the
log header as specified by log_sys.archive (innodb_log_archive).

log_write_buf(): Add the parameter max_length, the file wrap limit.

log_write_up_to(), mtr_t::commit_log_release<bool mmap=true>():
If we are switching log files, invoke buf_flush_ahead(lsn, true)
to ensure that a log checkpoint will be completed in the new file.

mtr_t::finish_writer(): Specialize for innodb_log_archive=ON.

mtr_t::commit_file(): Ensure that log archive rotation will complete.

log_t::append_prepare<log_t::ARCHIVED_MMAP>(): Special case.

log_t::get_path(): Get the name of the current log file.

log_t::get_circular_path(size_t): Get the path name of a circular file.
Replaces get_log_file_path().

log_t::get_archive_path(lsn_t): Return a name of an archived log file.

log_t::get_next_archive_path(): Return the name of the next archived log.

log_t::append_archive_name(): Append the archive log file name
to a path string.

mtr_t::finish_writer(): Invoke log_close() only if innodb_log_archive=OFF.
In the innodb_log_archive=ON, we only force log checkpoints after creating
a new archive file, to ensure that the first checkpoint will be written
as soon as possible.

log_t::checkpoint_margin(): Replaces log_checkpoint_margin().
If a new archived log file has been created, wait for the
first checkpoint in that file.

srv_log_rebuild_if_needed(): Never rebuild if innodb_log_archive=ON.
The setting innodb_log_file_size will affect the creation of
subsequent log files. The parameter innodb_encrypt_log cannot be
changed while the log is in the innodb_log_archive=ON format.

log_t::attach(), log_mmap(): Add the parameter log_access,
to distinguish memory-mapped or read-only access.

log_t::attach(): When disabling innodb_log_file_mmap, read
checkpoint_buf from the last innodb_log_archive=ON file.

log_t::clear_mmap(): Clear the tail of the checkpoint buffer
if is_mmap_writeable().

log_t::set_recovered(): Invoke clear_mmap(), and restore the
log buffer to the correct position.

recv_sys_t::apply(): Let log_t::clear_mmap() enable log writes.

recv_sys_t::find_checkpoint(): Find and remember the checkpoint position
in the last file when innodb_log_recovery_start points to an older file.
When innodb_log_file_mmap=OFF, restore log_sys.checkpoint_buf from
the latest log file. If the last archive log file is actually
in innodb_log_archive=OFF format despite being named ib_%016.log,
try to recover it in that format. If the circular ib_logfile0 is missing,
determine the oldest archived log file with contiguous LSN.
If innodb_log_archive=ON, refuse to start if ib_logfile0 exists.
Open non-last archived log files in read-only mode.

recv_sys_t::find_checkpoint_archived(): Validate each checkpoint in
the current file header, and by default aim to recover from the last
valid one. Terminate the search if the last validated checkpoint
spanned two files. If innodb_log_recovery_start has been specified,
attempt to validate it even if there is no such information stored
in the checkpoint header.

log_parse_file(): Do not invoke fil_name_process() during
recv_sys_t::find_checkpoint_archived(), when we tolerate FILE_MODIFY
records while looking for a FILE_CHECKPOINT record.

recv_scan_log(): Invoke log_t::archived_switch_recovery() upon
reaching the end of the current archived log file.

log_t::archived_switch_recovery_prepare(): Make use of
recv_sys.log_archive and open all but the last file read-only.

log_t::archived_switch_recovery(): Switch files in the pread() code path.

log_t::archived_mmap_switch_recovery_complete(): Switch files in the
memory-mapped code path.

recv_warp: A pointer wrapper for memory-mapped parsing that spans two
archive log files.

recv_sys_t::parse_mmap(): Use recv_warp for innodb_log_archive=ON.

recv_sys_t::parse(): Tweak some logic for innodb_log_archive=ON.

log_t::set_recovered_checkpoint(): Set the checkpoint on recovery.
Updates also the end_lsn.

log_t::set_recovered_lsn(): Also update flush_lock and write_lock,
to ensure that log_write_up_to() will be a no-op.

log_t::persist(): Even if the flushed_to_disk_lsn does not change,
we may want to reset the write_lsn_offset.
Brian White
fix build with WITH_EXTRA_CHARSETS=none again
Daniel Black
MDEV-26896 Enable -Wconversion globally
Jan Lindström
MDEV-38895 : Regression on MDL conflict handling

The reason for this timeout is a regression introduced in commit
https://github.com/MariaDB/server/commit/e40277d29b7c531e1ed6b3bed7ecfc8cfeff4c7e.
Where there is incorrect condition wsrep_thd_is_BF(granted_thd, false)
because if granted thread is BF it may not be BF-killed.

In this patch following has been changed
    * Split wsrep_handle_mdl_conflict to smaller easier to understand parts
    * Improved code comments
    * Improved debug logging to contain thread ids and necessary information
    * Corrected and simplified conditions so that BF threads are not killed
    * Added few debug assertions to verify that BF threads are not killed
    * Code cleanups so that tab-characters are not used
    * Existing test cases already test rest of the cases
forkfun
MDEV-38967: STR_TO_DATE() cannot be used in indexed virtual columns

Update STR_TO_DATE() to accept an optional third argument for the locale.
DATE_FORMAT() and STR_TO_DATE() return NULL when the locale argument is NULL;
issue a warning and fall back to the session @@lc_time_names for invalid locale names.
STR_TO_DATE() can now be used in indexed virtual columns while having all 3 arguments,
but not allowed when 2 as it depends then on the session @@lc_time_names
Mohammad Tafzeel Shams
MDEV-22186: Add innodb_trim_core_file to exclude InnoDB memory from cores

Problem:
There is no control to include or exclude large InnoDB memory regions
such as the buffer pool and log buffer from core files, which can lead to
unnecessarily large core dumps or prevent capturing useful memory state.

Solution:
Introduce a new global dynamic system variable innodb_trim_core_file that
allows excluding large InnoDB memory regions (buffer pool and log buffer)
from core dumps using MADV_DONTDUMP where supported. When enabled and
@@core_file=ON, the server marks relevant memory regions to be omitted
from core files. The madvise state is dynamically updated when the
variable changes.

Additionally, a test helper script is introduced to inspect
/proc/<pid>/smaps and verify whether large memory regions are marked
for trimming.

- innodb_trim_core_file
  Global boolean system variable controlling whether InnoDB memory
  regions should be excluded from core dumps. Has no effect if
  @@core_file=OFF. Default: ON on non-debug builds with MADV_DONTDUMP
  support, OFF otherwise.

- innobase_should_trim_core_dump()
  Determines whether InnoDB memory allocations should be marked with
  MADV_DONTDUMP, based on @@core_file and @@innodb_trim_core_file.

- innodb_srv_trim_core_file_update()
  Update hook that sets srv_trim_core_file and triggers runtime updates
  of madvise state for both the buffer pool and log buffers.

- srv_trim_core_file
  Global variable backing @@innodb_trim_core_file.

- buf_pool_t::buf_pool_should_madvise_dont_dump
  Tracks the current madvise state for the buffer pool memory.

- buf_pool_t::madvise_update_dump()
  Re-evaluates whether the buffer pool should be excluded from core
  dumps and applies ut_dontdump() or ut_dodump() accordingly.

- buf_pool_t::create()
  Initializes madvise state based on innobase_should_trim_core_dump()
  and conditionally applies MADV_DONTDUMP to the buffer pool memory.

- buf_pool_t::resize()
  Reapplies MADV_DONTDUMP to newly allocated memory regions when
  resizing if innodb_trim_core_file=ON

- log_t::log_buf_should_madvise_dont_dump
  Tracks the madvise state for the InnoDB log buffers.

- log_t::madvise_dontdump()
  Marks log buffers and resize buffers with MADV_DONTDUMP.

- log_t::madvise_dodump()
  Restores inclusion of log buffers in core dumps using MADV_DODUMP.

- log_t::madvise_update_dump()
  Updates the madvise state for log buffers when
  @@innodb_trim_core_file changes.

- log_t::create()
  Call ut_dodump() for log_t::buf & log_t::flush_buf on successful
  allocation and innodb_trim_core_file=OFF

- log_t::resize_start()
  Call ut_dodump() for log_t::resize_buf & log_t::resize_flush_buf on
  successful allocation and innodb_trim_core_file=OFF

- check_core_dump_trim.inc
  Test helper that inspects /proc/<pid>/smaps to detect memory regions
  with the dd VmFlag and determine whether the core file is expected
  to be trimmed based on buffer pool and log buffer sizes.
Vladislav Vaintroub
MDEV-39027 suboptimal code for InnoDB big endian access functions (MSVC, GCC)

Optimize big endian (and some little endian) Innodb access functions