Skip to content

Commit

Permalink
Merge branch '10.10' into 10.11
Browse files Browse the repository at this point in the history
  • Loading branch information
mariadb-YuchenPei committed Oct 13, 2023
2 parents 034848c + 3b38c2f commit 17810b7
Show file tree
Hide file tree
Showing 69 changed files with 1,388 additions and 776 deletions.
8 changes: 6 additions & 2 deletions extra/mariabackup/xtrabackup.cc
Expand Up @@ -4669,7 +4669,9 @@ static bool xtrabackup_backup_func()
goto fail;
}

log_sys.create();
if (!log_sys.create()) {
goto fail;
}
/* get current checkpoint_lsn */
{
mysql_mutex_lock(&recv_sys.mutex);
Expand Down Expand Up @@ -6039,7 +6041,9 @@ static bool xtrabackup_prepare_func(char** argv)
}

recv_sys.create();
log_sys.create();
if (!log_sys.create()) {
goto error;
}
recv_sys.recovery_on = true;

xb_fil_io_init();
Expand Down
6 changes: 6 additions & 0 deletions mysql-test/suite/mariabackup/data_directory.result
Expand Up @@ -11,3 +11,9 @@ SELECT * FROM t;
a
1
DROP TABLE t;
#
# MDEV-18200 MariaBackup full backup failed with InnoDB: Failing assertion: success
#
#
# End of 10.4 tests
#
15 changes: 15 additions & 0 deletions mysql-test/suite/mariabackup/data_directory.test
Expand Up @@ -21,4 +21,19 @@ rmdir $table_data_dir;
SELECT * FROM t;
DROP TABLE t;
rmdir $targetdir;

--echo #
--echo # MDEV-18200 MariaBackup full backup failed with InnoDB: Failing assertion: success
--echo #
let $DATADIR= `select @@datadir`;
chmod 0000 $DATADIR/ibdata1;
--disable_result_log
--error 1
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir;
--enable_result_log
chmod 0755 $DATADIR/ibdata1;
rmdir $table_data_dir;
rmdir $targetdir;
--echo #
--echo # End of 10.4 tests
--echo #
14 changes: 14 additions & 0 deletions mysql-test/suite/parts/r/alter_table.result
Expand Up @@ -344,3 +344,17 @@ connection default;
drop database EXISTENT;
drop user alan;
drop tables t1, tp1, tp2, tp4;
#
# MDEV-31014 Database privileges are insufficient for CONVERT TABLE TO PARTITION
#
create database db;
create user u@localhost;
grant all on db.* to u@localhost;
connect con1,localhost,u,,db;
create table t1 (a int) partition by range(a) (p1 values less than (100), p2 values less than (1000));
alter table t1 convert partition p2 to table tp;
alter table t1 convert table tp to partition p2 values less than (1000);
disconnect con1;
connection default;
drop user u@localhost;
drop database db;
18 changes: 18 additions & 0 deletions mysql-test/suite/parts/t/alter_table.test
Expand Up @@ -301,3 +301,21 @@ alter table t1 convert partition p1 to table tp1;
drop database EXISTENT;
drop user alan;
drop tables t1, tp1, tp2, tp4;

--echo #
--echo # MDEV-31014 Database privileges are insufficient for CONVERT TABLE TO PARTITION
--echo #
create database db;
create user u@localhost;
grant all on db.* to u@localhost;

--connect (con1,localhost,u,,db)
create table t1 (a int) partition by range(a) (p1 values less than (100), p2 values less than (1000));
alter table t1 convert partition p2 to table tp;
alter table t1 convert table tp to partition p2 values less than (1000);

# Cleanup
--disconnect con1
--connection default
drop user u@localhost;
drop database db;
1 change: 1 addition & 0 deletions sql/handler.cc
Expand Up @@ -1804,6 +1804,7 @@ int ha_commit_trans(THD *thd, bool all)
(void) trans_rollback_stmt(thd);
goto err;
}
trt.table->file->extra(HA_EXTRA_RESET_STATE);
// Here, the call will not commit inside InnoDB. It is only working
// around closing thd->transaction.stmt open by TR_table::open().
if (all)
Expand Down
8 changes: 8 additions & 0 deletions sql/sql_alter.cc
Expand Up @@ -493,6 +493,14 @@ bool Sql_cmd_alter_table::execute(THD *thd)
0, 0))
DBUG_RETURN(TRUE); /* purecov: inspected */

if ((alter_info.partition_flags & ALTER_PARTITION_CONVERT_IN))
{
TABLE_LIST *tl= first_table->next_local;
tl->grant.privilege= first_table->grant.privilege;
tl->grant.m_internal= first_table->grant.m_internal;
}


/* If it is a merge table, check privileges for merge children. */
if (create_info.merge_list)
{
Expand Down
5 changes: 3 additions & 2 deletions storage/innobase/fil/fil0fil.cc
Expand Up @@ -334,6 +334,7 @@ fil_node_t* fil_space_t::add(const char* name, pfs_os_file_t handle,
return node;
}

__attribute__((warn_unused_result, nonnull))
/** Open a tablespace file.
@param node data file
@return whether the file was successfully opened */
Expand Down Expand Up @@ -362,9 +363,9 @@ static bool fil_node_open_file_low(fil_node_t *node)
: OS_FILE_OPEN | OS_FILE_ON_ERROR_NO_EXIT,
OS_FILE_AIO, type,
srv_read_only_mode, &success);
if (node->is_open())

if (success && node->is_open())
{
ut_ad(success);
#ifndef _WIN32
if (!node->space->id && !srv_read_only_mode && my_disable_locking &&
os_file_lock(node->handle, node->name))
Expand Down
23 changes: 18 additions & 5 deletions storage/innobase/include/log0log.h
Expand Up @@ -356,15 +356,31 @@ typedef srw_lock log_rwlock_t;
/** @return end of resize_buf */
inline const byte *resize_buf_end() const noexcept
{ return resize_buf + resize_target; }

/** Initialise the redo log subsystem. */
void create_low();
/** Initialise the redo log subsystem.
@return whether the initialisation succeeded */
bool create() { create_low(); return true; }

/** Attach a log file.
@return whether the memory allocation succeeded */
bool attach(log_file_t file, os_offset_t size);
#else
/** Initialise the redo log subsystem.
@return whether the initialisation succeeded */
bool create();
/** Attach a log file. */
void attach_low(log_file_t file, os_offset_t size);
bool attach(log_file_t file, os_offset_t size)
{ attach_low(file, size); return true; }
#endif

#if defined __linux__ || defined _WIN32
/** Try to enable or disable file system caching (update log_buffered) */
void set_buffered(bool buffered);
#endif

void attach(log_file_t file, os_offset_t size);

void close_file();

/** Calculate the checkpoint safety margins. */
Expand Down Expand Up @@ -421,9 +437,6 @@ typedef srw_lock log_rwlock_t;
/** Make previous write_buf() durable and update flushed_to_disk_lsn. */
bool flush(lsn_t lsn) noexcept;

/** Initialise the redo log subsystem. */
void create();

/** Shut down the redo log subsystem. */
void close();

Expand Down
5 changes: 3 additions & 2 deletions storage/innobase/include/log0recv.h
Expand Up @@ -254,9 +254,10 @@ struct recv_sys_t
/** The contents of the doublewrite buffer */
recv_dblwr_t dblwr;

inline void read(os_offset_t offset, span<byte> buf);
__attribute__((warn_unused_result))
inline dberr_t read(os_offset_t offset, span<byte> buf);
inline size_t files_size();
void close_files() { files.clear(); files.shrink_to_fit(); }
void close_files();

/** Advance pages_it if it matches the iterator */
void pages_it_invalidate(const map::iterator &p)
Expand Down
63 changes: 52 additions & 11 deletions storage/innobase/log/log0log.cc
Expand Up @@ -95,25 +95,39 @@ void log_t::set_capacity()
log_sys.max_checkpoint_age = margin;
}

/** Initialize the redo log subsystem. */
void log_t::create()
#ifdef HAVE_PMEM
void log_t::create_low()
#else
bool log_t::create()
#endif
{
ut_ad(this == &log_sys);
ut_ad(!is_initialised());

latch.SRW_LOCK_INIT(log_latch_key);
init_lsn_lock();

/* LSN 0 and 1 are reserved; @see buf_page_t::oldest_modification_ */
lsn.store(FIRST_LSN, std::memory_order_relaxed);
flushed_to_disk_lsn.store(FIRST_LSN, std::memory_order_relaxed);
write_lsn= FIRST_LSN;

#ifndef HAVE_PMEM
buf= static_cast<byte*>(ut_malloc_dontdump(buf_size, PSI_INSTRUMENT_ME));
TRASH_ALLOC(buf, buf_size);
if (!buf)
{
alloc_fail:
sql_print_error("InnoDB: Cannot allocate memory;"
" too large innodb_log_buffer_size?");
return false;
}
flush_buf= static_cast<byte*>(ut_malloc_dontdump(buf_size,
PSI_INSTRUMENT_ME));
if (!flush_buf)
{
ut_free_dodump(buf, buf_size);
buf= nullptr;
goto alloc_fail;
}

TRASH_ALLOC(buf, buf_size);
TRASH_ALLOC(flush_buf, buf_size);
checkpoint_buf= static_cast<byte*>(aligned_malloc(4096, 4096));
memset_aligned<4096>(checkpoint_buf, 0, 4096);
Expand All @@ -123,6 +137,9 @@ void log_t::create()
ut_ad(!flush_buf);
#endif

latch.SRW_LOCK_INIT(log_latch_key);
init_lsn_lock();

max_buf_free= buf_size / LOG_BUF_FLUSH_RATIO - LOG_BUF_FLUSH_MARGIN;
set_check_flush_or_checkpoint();

Expand All @@ -136,6 +153,9 @@ void log_t::create()
buf_free= 0;

ut_ad(is_initialised());
#ifndef HAVE_PMEM
return true;
#endif
}

dberr_t log_file_t::close() noexcept
Expand All @@ -149,6 +169,7 @@ dberr_t log_file_t::close() noexcept
return DB_SUCCESS;
}

__attribute__((warn_unused_result))
dberr_t log_file_t::read(os_offset_t offset, span<byte> buf) noexcept
{
ut_ad(is_opened());
Expand Down Expand Up @@ -201,7 +222,11 @@ static void *log_mmap(os_file_t file, os_offset_t size)
}
#endif

void log_t::attach(log_file_t file, os_offset_t size)
#ifdef HAVE_PMEM
bool log_t::attach(log_file_t file, os_offset_t size)
#else
void log_t::attach_low(log_file_t file, os_offset_t size)
#endif
{
log= file;
ut_ad(!size || size >= START_OFFSET + SIZE_OF_FILE_CHECKPOINT);
Expand All @@ -218,18 +243,33 @@ void log_t::attach(log_file_t file, os_offset_t size)
log.close();
mprotect(ptr, size_t(size), PROT_READ);
buf= static_cast<byte*>(ptr);
#if defined __linux__ || defined _WIN32
# if defined __linux__ || defined _WIN32
set_block_size(CPU_LEVEL1_DCACHE_LINESIZE);
#endif
# endif
log_maybe_unbuffered= true;
log_buffered= false;
return;
return true;
}
}
buf= static_cast<byte*>(ut_malloc_dontdump(buf_size, PSI_INSTRUMENT_ME));
TRASH_ALLOC(buf, buf_size);
if (!buf)
{
alloc_fail:
max_buf_free= 0;
sql_print_error("InnoDB: Cannot allocate memory;"
" too large innodb_log_buffer_size?");
return false;
}
flush_buf= static_cast<byte*>(ut_malloc_dontdump(buf_size,
PSI_INSTRUMENT_ME));
if (!flush_buf)
{
ut_free_dodump(buf, buf_size);
buf= nullptr;
goto alloc_fail;
}

TRASH_ALLOC(buf, buf_size);
TRASH_ALLOC(flush_buf, buf_size);
#endif

Expand All @@ -244,6 +284,7 @@ void log_t::attach(log_file_t file, os_offset_t size)
#ifdef HAVE_PMEM
checkpoint_buf= static_cast<byte*>(aligned_malloc(block_size, block_size));
memset_aligned<64>(checkpoint_buf, 0, block_size);
return true;
#endif
}

Expand Down
30 changes: 23 additions & 7 deletions storage/innobase/log/log0recv.cc
Expand Up @@ -1201,12 +1201,13 @@ inline void recv_sys_t::trim(const page_id_t page_id, lsn_t lsn)
DBUG_VOID_RETURN;
}

inline void recv_sys_t::read(os_offset_t total_offset, span<byte> buf)
inline dberr_t recv_sys_t::read(os_offset_t total_offset, span<byte> buf)
{
size_t file_idx= static_cast<size_t>(total_offset / log_sys.file_size);
os_offset_t offset= total_offset % log_sys.file_size;
dberr_t err= recv_sys.files[file_idx].read(offset, buf);
ut_a(err == DB_SUCCESS);
return file_idx
? recv_sys.files[file_idx].read(offset, buf)
: log_sys.log.read(offset, buf);
}

inline size_t recv_sys_t::files_size()
Expand Down Expand Up @@ -1365,6 +1366,15 @@ static void fil_name_process(const char *name, ulint len, uint32_t space_id,
}
}

void recv_sys_t::close_files()
{
for (auto &file : files)
if (file.is_opened())
file.close();
files.clear();
files.shrink_to_fit();
}

/** Clean up after recv_sys_t::create() */
void recv_sys_t::close()
{
Expand Down Expand Up @@ -1601,7 +1611,8 @@ ATTRIBUTE_COLD static dberr_t recv_log_recover_pre_10_2()
if (source_offset < (log_sys.is_pmem() ? log_sys.file_size : 4096))
memcpy_aligned<512>(buf, &log_sys.buf[source_offset & ~511], 512);
else
recv_sys.read(source_offset & ~511, {buf, 512});
if (dberr_t err= recv_sys.read(source_offset & ~511, {buf, 512}))
return err;

if (log_block_calc_checksum_format_0(buf) !=
mach_read_from_4(my_assume_aligned<4>(buf + 508)) &&
Expand Down Expand Up @@ -1640,7 +1651,8 @@ static dberr_t recv_log_recover_10_5(lsn_t lsn_offset)
memcpy_aligned<512>(buf, &log_sys.buf[lsn_offset & ~511], 512);
else
{
recv_sys.read(lsn_offset & ~lsn_t{4095}, {buf, 4096});
if (dberr_t err= recv_sys.read(lsn_offset & ~lsn_t{4095}, {buf, 4096}))
return err;
buf+= lsn_offset & 0xe00;
}

Expand Down Expand Up @@ -1691,13 +1703,17 @@ dberr_t recv_sys_t::find_checkpoint()
else if (size < log_t::START_OFFSET + SIZE_OF_FILE_CHECKPOINT)
{
too_small:
os_file_close(file);
sql_print_error("InnoDB: File %.*s is too small",
int(path.size()), path.data());
err_exit:
os_file_close(file);
return DB_ERROR;
}
else if (!log_sys.attach(file, size))
goto err_exit;
else
file= OS_FILE_CLOSED;

log_sys.attach(file, size);
recv_sys.files.emplace_back(file);
for (int i= 1; i < 101; i++)
{
Expand Down

0 comments on commit 17810b7

Please sign in to comment.