Commit a5da1c64 authored by Marko Mäkelä's avatar Marko Mäkelä

Merge 10.2 into 10.3

parents 12ed50cc bc250145
...@@ -248,12 +248,6 @@ MY_CHECK_AND_SET_COMPILER_FLAG(-ggdb3 DEBUG) ...@@ -248,12 +248,6 @@ MY_CHECK_AND_SET_COMPILER_FLAG(-ggdb3 DEBUG)
OPTION(ENABLED_LOCAL_INFILE OPTION(ENABLED_LOCAL_INFILE
"If we should should enable LOAD DATA LOCAL by default" ${IF_WIN}) "If we should should enable LOAD DATA LOCAL by default" ${IF_WIN})
OPTION(WITH_INNODB_DISALLOW_WRITES "InnoDB freeze writes patch from Google" ${WITH_WSREP})
IF (WITH_INNODB_DISALLOW_WRITES)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWITH_INNODB_DISALLOW_WRITES")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWITH_INNODB_DISALLOW_WRITES")
ENDIF()
# Set DBUG_OFF and other optional release-only flags for non-debug project types # Set DBUG_OFF and other optional release-only flags for non-debug project types
FOREACH(BUILD_TYPE RELEASE RELWITHDEBINFO MINSIZEREL) FOREACH(BUILD_TYPE RELEASE RELWITHDEBINFO MINSIZEREL)
FOREACH(LANG C CXX) FOREACH(LANG C CXX)
...@@ -267,7 +261,7 @@ ENDFOREACH() ...@@ -267,7 +261,7 @@ ENDFOREACH()
# Add safemutex for debug configurations, except on Windows # Add safemutex for debug configurations, except on Windows
# (safemutex has never worked on Windows) # (safemutex has never worked on Windows)
IF(NOT WIN32 AND NOT WITH_INNODB_MEMCACHED) IF(NOT WIN32)
FOREACH(LANG C CXX) FOREACH(LANG C CXX)
SET(CMAKE_${LANG}_FLAGS_DEBUG "${CMAKE_${LANG}_FLAGS_DEBUG} -DSAFE_MUTEX") SET(CMAKE_${LANG}_FLAGS_DEBUG "${CMAKE_${LANG}_FLAGS_DEBUG} -DSAFE_MUTEX")
ENDFOREACH() ENDFOREACH()
......
...@@ -1428,6 +1428,10 @@ void backup_release() ...@@ -1428,6 +1428,10 @@ void backup_release()
history_lock_time = time(NULL) - history_lock_time; history_lock_time = time(NULL) - history_lock_time;
} }
if (opt_lock_ddl_per_table) {
mdl_unlock_all();
}
if (opt_safe_slave_backup && sql_thread_started) { if (opt_safe_slave_backup && sql_thread_started) {
msg("Starting slave SQL thread\n"); msg("Starting slave SQL thread\n");
xb_mysql_query(mysql_connection, xb_mysql_query(mysql_connection,
......
...@@ -868,6 +868,76 @@ stop_query_killer() ...@@ -868,6 +868,76 @@ stop_query_killer()
os_event_wait_time(kill_query_thread_stopped, 60000); os_event_wait_time(kill_query_thread_stopped, 60000);
} }
/*
Killing connections that wait for MDL lock.
If lock-ddl-per-table is used, there can be some DDL statements
FLUSH TABLES would hang infinitely, if DDL statements are waiting for
MDL lock, which mariabackup currently holds. Therefore we start killing
those statements from a dedicated thread, until FLUSH TABLES WITH READ LOCK
succeeds.
*/
static os_event_t mdl_killer_stop_event;
static os_event_t mdl_killer_finished_event;
static
os_thread_ret_t
DECLARE_THREAD(kill_mdl_waiters_thread(void *))
{
MYSQL *mysql;
if ((mysql = xb_mysql_connect()) == NULL) {
msg("Error: kill mdl waiters thread failed to connect\n");
goto stop_thread;
}
for(;;){
if (os_event_wait_time(mdl_killer_stop_event, 1000) == 0)
break;
MYSQL_RES *result = xb_mysql_query(mysql,
"SELECT ID, COMMAND FROM INFORMATION_SCHEMA.PROCESSLIST "
" WHERE State='Waiting for table metadata lock'",
true, true);
while (MYSQL_ROW row = mysql_fetch_row(result))
{
char query[64];
msg_ts("Killing MDL waiting query '%s' on connection '%s'\n",
row[1], row[0]);
snprintf(query, sizeof(query), "KILL QUERY %s", row[0]);
xb_mysql_query(mysql, query, true);
}
}
mysql_close(mysql);
stop_thread:
msg_ts("Kill mdl waiters thread stopped\n");
os_event_set(mdl_killer_finished_event);
os_thread_exit();
return os_thread_ret_t(0);
}
static void start_mdl_waiters_killer()
{
mdl_killer_stop_event = os_event_create(0);
mdl_killer_finished_event = os_event_create(0);
os_thread_create(kill_mdl_waiters_thread, 0, 0);
}
/* Tell MDL killer to stop and finish for its completion*/
static void stop_mdl_waiters_killer()
{
os_event_set(mdl_killer_stop_event);
os_event_wait(mdl_killer_finished_event);
os_event_destroy(mdl_killer_stop_event);
os_event_destroy(mdl_killer_finished_event);
}
/*********************************************************************//** /*********************************************************************//**
Function acquires either a backup tables lock, if supported Function acquires either a backup tables lock, if supported
by the server, or a global read lock (FLUSH TABLES WITH READ LOCK) by the server, or a global read lock (FLUSH TABLES WITH READ LOCK)
...@@ -890,6 +960,10 @@ lock_tables(MYSQL *connection) ...@@ -890,6 +960,10 @@ lock_tables(MYSQL *connection)
return(true); return(true);
} }
if (opt_lock_ddl_per_table) {
start_mdl_waiters_killer();
}
if (!opt_lock_wait_timeout && !opt_kill_long_queries_timeout) { if (!opt_lock_wait_timeout && !opt_kill_long_queries_timeout) {
/* We do first a FLUSH TABLES. If a long update is running, the /* We do first a FLUSH TABLES. If a long update is running, the
...@@ -930,6 +1004,10 @@ lock_tables(MYSQL *connection) ...@@ -930,6 +1004,10 @@ lock_tables(MYSQL *connection)
xb_mysql_query(connection, "FLUSH TABLES WITH READ LOCK", false); xb_mysql_query(connection, "FLUSH TABLES WITH READ LOCK", false);
if (opt_lock_ddl_per_table) {
stop_mdl_waiters_killer();
}
if (opt_kill_long_queries_timeout) { if (opt_kill_long_queries_timeout) {
stop_query_killer(); stop_query_killer();
} }
...@@ -1647,25 +1725,6 @@ mdl_lock_init() ...@@ -1647,25 +1725,6 @@ mdl_lock_init()
} }
} }
#ifndef DBUG_OFF
/* Test that table is really locked, if lock_ddl_per_table is set.
The test is executed in DBUG_EXECUTE_IF block inside mdl_lock_table().
*/
static void check_mdl_lock_works(const char *table_name)
{
MYSQL *test_con= xb_mysql_connect();
char *query;
xb_a(asprintf(&query,
"SET STATEMENT max_statement_time=1 FOR ALTER TABLE %s FORCE",
table_name));
int err = mysql_query(test_con, query);
DBUG_ASSERT(err);
int err_no = mysql_errno(test_con);
DBUG_ASSERT(err_no == ER_STATEMENT_TIMEOUT);
mysql_close(test_con);
free(query);
}
#endif
void void
mdl_lock_table(ulint space_id) mdl_lock_table(ulint space_id)
{ {
...@@ -1681,13 +1740,10 @@ mdl_lock_table(ulint space_id) ...@@ -1681,13 +1740,10 @@ mdl_lock_table(ulint space_id)
while (MYSQL_ROW row = mysql_fetch_row(mysql_result)) { while (MYSQL_ROW row = mysql_fetch_row(mysql_result)) {
std::string full_table_name = ut_get_name(0,row[0]); std::string full_table_name = ut_get_name(0,row[0]);
std::ostringstream lock_query; std::ostringstream lock_query;
lock_query << "SELECT * FROM " << full_table_name << " LIMIT 0"; lock_query << "SELECT 1 FROM " << full_table_name << " LIMIT 0";
msg_ts("Locking MDL for %s\n", full_table_name.c_str()); msg_ts("Locking MDL for %s\n", full_table_name.c_str());
xb_mysql_query(mdl_con, lock_query.str().c_str(), false, false); xb_mysql_query(mdl_con, lock_query.str().c_str(), false, false);
DBUG_EXECUTE_IF("check_mdl_lock_works",
check_mdl_lock_works(full_table_name.c_str()););
} }
pthread_mutex_unlock(&mdl_lock_con_mutex); pthread_mutex_unlock(&mdl_lock_con_mutex);
......
...@@ -433,6 +433,91 @@ datafiles_iter_free(datafiles_iter_t *it) ...@@ -433,6 +433,91 @@ datafiles_iter_free(datafiles_iter_t *it)
free(it); free(it);
} }
#ifndef DBUG_OFF
struct dbug_thread_param_t
{
MYSQL *con;
const char *query;
int expect_err;
int expect_errno;
os_event_t done_event;
};
/* Thread procedure used in dbug_start_query_thread. */
extern "C"
os_thread_ret_t
DECLARE_THREAD(dbug_execute_in_new_connection)(void *arg)
{
mysql_thread_init();
dbug_thread_param_t *par= (dbug_thread_param_t *)arg;
int err = mysql_query(par->con, par->query);
int err_no = mysql_errno(par->con);
DBUG_ASSERT(par->expect_err == err);
if (err && par->expect_errno)
DBUG_ASSERT(err_no == par->expect_errno);
mysql_close(par->con);
mysql_thread_end();
os_event_t done = par->done_event;
delete par;
os_event_set(done);
os_thread_exit();
return os_thread_ret_t(0);
}
/*
Execute query from a new connection, in own thread.
@param query - query to be executed
@param wait_state - if not NULL, wait until query from new connection
reaches this state (value of column State in I_S.PROCESSLIST)
@param expected_err - if 0, query is supposed to finish successfully,
otherwise query should return error.
@param expected_errno - if not 0, and query finished with error,
expected mysql_errno()
*/
static os_event_t dbug_start_query_thread(
const char *query,
const char *wait_state,
int expected_err,
int expected_errno)
{
dbug_thread_param_t *par = new dbug_thread_param_t;
par->query = query;
par->expect_err = expected_err;
par->expect_errno = expected_errno;
par->done_event = os_event_create(0);
par->con = xb_mysql_connect();
os_thread_create(dbug_execute_in_new_connection, par, 0);
if (!wait_state)
return par->done_event;
char q[256];
snprintf(q, sizeof(q),
"SELECT 1 FROM INFORMATION_SCHEMA.PROCESSLIST where ID=%lu"
" AND Command='Query' AND State='%s'",
mysql_thread_id(par->con), wait_state);
for (;;) {
MYSQL_RES *result = xb_mysql_query(mysql_connection,q, true, true);
if (mysql_fetch_row(result)) {
goto end;
}
msg_ts("Waiting for query '%s' on connection %lu to "
" reach state '%s'", query, mysql_thread_id(par->con),
wait_state);
my_sleep(1000);
}
end:
msg_ts("query '%s' on connection %lu reached state '%s'", query,
mysql_thread_id(par->con), wait_state);
return par->done_event;
}
os_event_t dbug_alter_thread_done;
#endif
void mdl_lock_all() void mdl_lock_all()
{ {
mdl_lock_init(); mdl_lock_init();
...@@ -448,6 +533,11 @@ void mdl_lock_all() ...@@ -448,6 +533,11 @@ void mdl_lock_all()
mdl_lock_table(node->space->id); mdl_lock_table(node->space->id);
} }
datafiles_iter_free(it); datafiles_iter_free(it);
DBUG_EXECUTE_IF("check_mdl_lock_works",
dbug_alter_thread_done =
dbug_start_query_thread("ALTER TABLE test.t ADD COLUMN mdl_lock_column int",
"Waiting for table metadata lock",1, ER_QUERY_INTERRUPTED););
} }
/** Check if the space id belongs to the table which name should /** Check if the space id belongs to the table which name should
...@@ -2460,7 +2550,6 @@ xtrabackup_copy_logfile(copy_logfile copy) ...@@ -2460,7 +2550,6 @@ xtrabackup_copy_logfile(copy_logfile copy)
recv_sys->parse_start_lsn = log_copy_scanned_lsn; recv_sys->parse_start_lsn = log_copy_scanned_lsn;
recv_sys->scanned_lsn = log_copy_scanned_lsn; recv_sys->scanned_lsn = log_copy_scanned_lsn;
recv_sys->recovered_lsn = log_copy_scanned_lsn;
start_lsn = ut_uint64_align_down(log_copy_scanned_lsn, start_lsn = ut_uint64_align_down(log_copy_scanned_lsn,
OS_FILE_LOG_BLOCK_SIZE); OS_FILE_LOG_BLOCK_SIZE);
...@@ -3984,6 +4073,8 @@ xtrabackup_backup_func() ...@@ -3984,6 +4073,8 @@ xtrabackup_backup_func()
/* copy log file by current position */ /* copy log file by current position */
log_copy_scanned_lsn = checkpoint_lsn_start; log_copy_scanned_lsn = checkpoint_lsn_start;
recv_sys->recovered_lsn = log_copy_scanned_lsn;
if (xtrabackup_copy_logfile(COPY_FIRST)) if (xtrabackup_copy_logfile(COPY_FIRST))
goto fail; goto fail;
...@@ -4070,6 +4161,11 @@ xtrabackup_backup_func() ...@@ -4070,6 +4161,11 @@ xtrabackup_backup_func()
backup_release(); backup_release();
DBUG_EXECUTE_IF("check_mdl_lock_works",
os_event_wait(dbug_alter_thread_done);
os_event_destroy(dbug_alter_thread_done);
);
if (ok) { if (ok) {
backup_finish(); backup_finish();
} }
...@@ -4079,10 +4175,6 @@ xtrabackup_backup_func() ...@@ -4079,10 +4175,6 @@ xtrabackup_backup_func()
goto fail; goto fail;
} }
if (opt_lock_ddl_per_table) {
mdl_unlock_all();
}
xtrabackup_destroy_datasinks(); xtrabackup_destroy_datasinks();
msg("mariabackup: Redo log (from LSN " LSN_PF " to " LSN_PF msg("mariabackup: Redo log (from LSN " LSN_PF " to " LSN_PF
......
...@@ -110,6 +110,7 @@ extern my_bool opt_noversioncheck; ...@@ -110,6 +110,7 @@ extern my_bool opt_noversioncheck;
extern my_bool opt_no_backup_locks; extern my_bool opt_no_backup_locks;
extern my_bool opt_decompress; extern my_bool opt_decompress;
extern my_bool opt_remove_original; extern my_bool opt_remove_original;
extern my_bool opt_lock_ddl_per_table;
extern char *opt_incremental_history_name; extern char *opt_incremental_history_name;
extern char *opt_incremental_history_uuid; extern char *opt_incremental_history_uuid;
......
...@@ -12604,6 +12604,165 @@ EXPLAIN ...@@ -12604,6 +12604,165 @@ EXPLAIN
DROP TABLE t1,t2; DROP TABLE t1,t2;
SET sql_mode = DEFAULT; SET sql_mode = DEFAULT;
# #
# MDEV-15579: incorrect removal of sub-formulas to be pushed
# into WHERE of materialized derived with GROUP BY
#
CREATE TABLE t1 (a INT, b INT, c INT, d INT);
CREATE TABLE t2 (x INT, y INT, z INT);
INSERT INTO t1 VALUES (1,1,66,1), (1,1,56,2), (3,2,42,3);
INSERT INTO t2 VALUES (1,1,66), (1,12,32);
SELECT *
FROM t2,
(
SELECT a, b, max(c) AS max_c
FROM t1
GROUP BY a
HAVING max_c > 37
) AS v1
WHERE (v1.a=1) AND (v1.b=v1.a) AND
(v1.a=t2.x) AND (v1.max_c>30);
x y z a b max_c
1 1 66 1 1 66
1 12 32 1 1 66
EXPLAIN SELECT *
FROM t2,
(
SELECT a, b, max(c) AS max_c
FROM t1
GROUP BY a
HAVING max_c > 37
) AS v1
WHERE (v1.a=1) AND (v1.b=v1.a) AND
(v1.a=t2.x) AND (v1.max_c>30);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 3 Using where
EXPLAIN FORMAT=JSON SELECT *
FROM t2,
(
SELECT a, b, max(c) AS max_c
FROM t1
GROUP BY a
HAVING max_c > 37
) AS v1
WHERE (v1.a=1) AND (v1.b=v1.a) AND
(v1.a=t2.x) AND (v1.max_c>30);
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 2,
"filtered": 100,
"attached_condition": "t2.x = 1"
},
"block-nl-join": {
"table": {
"table_name": "<derived2>",
"access_type": "ALL",
"rows": 3,
"filtered": 100,
"attached_condition": "v1.a = 1 and v1.b = 1 and v1.max_c > 30"
},
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "max_c > 37 and max_c > 30 and t1.b = 1",
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 3,
"filtered": 100,
"attached_condition": "t1.a = 1"
}
}
}
}
}
}
SELECT *
FROM t2,
(
SELECT a, b, d, max(c) AS max_c
FROM t1
GROUP BY a,d
HAVING max_c > 37
) AS v1
WHERE (v1.a=1) AND (v1.b=v1.a) AND (v1.b=v1.d) AND
(v1.a=t2.x) AND (v1.max_c>30);
x y z a b d max_c
1 1 66 1 1 1 66
1 12 32 1 1 1 66
EXPLAIN SELECT *
FROM t2,
(
SELECT a, b, d, max(c) AS max_c
FROM t1
GROUP BY a,d
HAVING max_c > 37
) AS v1
WHERE (v1.a=1) AND (v1.b=v1.a) AND (v1.b=v1.d) AND
(v1.a=t2.x) AND (v1.max_c>30);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 3 Using where
EXPLAIN FORMAT=JSON SELECT *
FROM t2,
(
SELECT a, b, d, max(c) AS max_c
FROM t1
GROUP BY a,d
HAVING max_c > 37
) AS v1
WHERE (v1.a=1) AND (v1.b=v1.a) AND (v1.b=v1.d) AND
(v1.a=t2.x) AND (v1.max_c>30);
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 2,
"filtered": 100,
"attached_condition": "t2.x = 1"
},
"block-nl-join": {
"table": {
"table_name": "<derived2>",
"access_type": "ALL",
"rows": 3,
"filtered": 100,
"attached_condition": "v1.a = 1 and v1.b = 1 and v1.d = 1 and v1.max_c > 30"
},
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL",
"materialized": {
"query_block": {
"select_id": 2,
"having_condition": "max_c > 37 and max_c > 30 and t1.b = 1",
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 3,
"filtered": 100,
"attached_condition": "t1.a = 1 and t1.d = 1"
}
}
}
}
}
}
DROP TABLE t1,t2;
#
# MDEV-10855: Pushdown into derived with window functions # MDEV-10855: Pushdown into derived with window functions
# #
set @save_optimizer_switch= @@optimizer_switch; set @save_optimizer_switch= @@optimizer_switch;
......
...@@ -2165,6 +2165,51 @@ DROP TABLE t1,t2; ...@@ -2165,6 +2165,51 @@ DROP TABLE t1,t2;
SET sql_mode = DEFAULT; SET sql_mode = DEFAULT;
--echo #
--echo # MDEV-15579: incorrect removal of sub-formulas to be pushed
--echo # into WHERE of materialized derived with GROUP BY
--echo #
CREATE TABLE t1 (a INT, b INT, c INT, d INT);
CREATE TABLE t2 (x INT, y INT, z INT);
INSERT INTO t1 VALUES (1,1,66,1), (1,1,56,2), (3,2,42,3);
INSERT INTO t2 VALUES (1,1,66), (1,12,32);
LET $query=
SELECT *
FROM t2,
(
SELECT a, b, max(c) AS max_c
FROM t1
GROUP BY a
HAVING max_c > 37
) AS v1
WHERE (v1.a=1) AND (v1.b=v1.a) AND
(v1.a=t2.x) AND (v1.max_c>30);
EVAL $query;
EVAL EXPLAIN $query;
EVAL EXPLAIN FORMAT=JSON $query;
LET $query=
SELECT *
FROM t2,
(
SELECT a, b, d, max(c) AS max_c
FROM t1
GROUP BY a,d
HAVING max_c > 37
) AS v1
WHERE (v1.a=1) AND (v1.b=v1.a) AND (v1.b=v1.d) AND
(v1.a=t2.x) AND (v1.max_c>30);
EVAL $query;
EVAL EXPLAIN $query;
EVAL EXPLAIN FORMAT=JSON $query;
DROP TABLE t1,t2;
# Start of 10.3 tests
--echo # --echo #
--echo # MDEV-10855: Pushdown into derived with window functions --echo # MDEV-10855: Pushdown into derived with window functions
--echo # --echo #
......
...@@ -8451,6 +8451,7 @@ Item* TABLE_LIST::build_pushable_cond_for_table(THD *thd, Item *cond) ...@@ -8451,6 +8451,7 @@ Item* TABLE_LIST::build_pushable_cond_for_table(THD *thd, Item *cond)
return 0; return 0;
List_iterator<Item> li(*((Item_cond*) cond)->argument_list()); List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
Item *item; Item *item;
bool is_fix_needed= false;
while ((item=li++)) while ((item=li++))
{ {
if (item->get_extraction_flag() == NO_EXTRACTION_FL) if (item->get_extraction_flag() == NO_EXTRACTION_FL)
...@@ -8464,8 +8465,16 @@ Item* TABLE_LIST::build_pushable_cond_for_table(THD *thd, Item *cond) ...@@ -8464,8 +8465,16 @@ Item* TABLE_LIST::build_pushable_cond_for_table(THD *thd, Item *cond)
return 0; return 0;
if (!fix) if (!fix)
continue; continue;
if (fix->type() == Item::COND_ITEM &&
((Item_cond*) fix)->functype() == Item_func::COND_AND_FUNC)
is_fix_needed= true;
new_cond->argument_list()->push_back(fix, thd->mem_root); new_cond->argument_list()->push_back(fix, thd->mem_root);
} }
if (is_fix_needed)
new_cond->fix_fields(thd, 0);
switch (new_cond->argument_list()->elements) switch (new_cond->argument_list()->elements)
{ {
case 0: case 0:
......
...@@ -219,6 +219,12 @@ ELSE() ...@@ -219,6 +219,12 @@ ELSE()
ADD_DEFINITIONS(-DMUTEX_SYS) ADD_DEFINITIONS(-DMUTEX_SYS)
ENDIF() ENDIF()
OPTION(WITH_INNODB_DISALLOW_WRITES "InnoDB freeze writes patch from Google" ${WITH_WSREP})
IF (WITH_INNODB_DISALLOW_WRITES)
ADD_DEFINITIONS(-DWITH_INNODB_DISALLOW_WRITES)
ENDIF()
# Include directories under innobase # Include directories under innobase
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/storage/innobase/include INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/storage/innobase/include
${CMAKE_SOURCE_DIR}/storage/innobase/handler) ${CMAKE_SOURCE_DIR}/storage/innobase/handler)
......
...@@ -1085,17 +1085,17 @@ log_buffer_switch() ...@@ -1085,17 +1085,17 @@ log_buffer_switch()
OS_FILE_LOG_BLOCK_SIZE); OS_FILE_LOG_BLOCK_SIZE);
if (log_sys->first_in_use) { if (log_sys->first_in_use) {
log_sys->first_in_use = false;
ut_ad(log_sys->buf == ut_align(log_sys->buf, ut_ad(log_sys->buf == ut_align(log_sys->buf,
OS_FILE_LOG_BLOCK_SIZE)); OS_FILE_LOG_BLOCK_SIZE));
log_sys->buf += log_sys->buf_size; log_sys->buf += log_sys->buf_size;
} else { } else {
log_sys->first_in_use = true;
log_sys->buf -= log_sys->buf_size; log_sys->buf -= log_sys->buf_size;
ut_ad(log_sys->buf == ut_align(log_sys->buf, ut_ad(log_sys->buf == ut_align(log_sys->buf,
OS_FILE_LOG_BLOCK_SIZE)); OS_FILE_LOG_BLOCK_SIZE));
} }
log_sys->first_in_use = !log_sys->first_in_use;
/* Copy the last block to new buf */ /* Copy the last block to new buf */
ut_memcpy(log_sys->buf, ut_memcpy(log_sys->buf,
old_buf + area_end - OS_FILE_LOG_BLOCK_SIZE, old_buf + area_end - OS_FILE_LOG_BLOCK_SIZE,
...@@ -1235,6 +1235,9 @@ log_write_up_to( ...@@ -1235,6 +1235,9 @@ log_write_up_to(
log_group_set_fields(&log_sys->log, log_sys->write_lsn); log_group_set_fields(&log_sys->log, log_sys->write_lsn);
log_mutex_exit(); log_mutex_exit();
/* Erase the end of the last log block. */
memset(write_buf + end_offset, 0, ~end_offset & OS_FILE_LOG_BLOCK_SIZE);
/* Calculate pad_size if needed. */ /* Calculate pad_size if needed. */
pad_size = 0; pad_size = 0;
if (write_ahead_size > OS_FILE_LOG_BLOCK_SIZE) { if (write_ahead_size > OS_FILE_LOG_BLOCK_SIZE) {
...@@ -1251,12 +1254,9 @@ log_write_up_to( ...@@ -1251,12 +1254,9 @@ log_write_up_to(
/* The first block in the unit was initialized /* The first block in the unit was initialized
after the last writing. after the last writing.
Needs to be written padded data once. */ Needs to be written padded data once. */
pad_size = write_ahead_size - end_offset_in_unit; pad_size = std::min(
ulint(write_ahead_size) - end_offset_in_unit,
if (area_end + pad_size > log_sys->buf_size) { log_sys->buf_size - area_end);
pad_size = log_sys->buf_size - area_end;
}
::memset(write_buf + area_end, 0, pad_size); ::memset(write_buf + area_end, 0, pad_size);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment