Skip to content

Commit 5a9e7bc

Browse files
committed
MDEV-13603 innodb_fast_shutdown=0 may fail to purge all history
srv_purge_should_exit(): Remove the parameter n_purged. If we happened to have n_purged==0 while some transaction was still active, and then that transaction was added to the history list, we were prematurely stopping the purge. It is more appropriate to first check for trx_sys.any_active_transactions() == 0 (this count can only decrease during shutdown) and then for trx_sys.history_size() == 0 (that count typically decreases, but can increase when any remaining active transactions are committed or rolled back). innodb.dml_purge: Remove a server restart, and explicitly wait for purge, and use FLUSH TABLE FOR EXPORT to read the file contents. This will make the test run faster, easier to debug, and also allow it to run with --embedded. This might also help repeat MDEV-11802 better. The issue MDEV-13603 remains will remain tested by innodb.table_flags.
1 parent df44e75 commit 5a9e7bc

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

mysql-test/suite/innodb/r/dml_purge.result

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
SET @saved_frequency = @@GLOBAL.innodb_purge_rseg_truncate_frequency;
2+
SET GLOBAL innodb_purge_rseg_truncate_frequency = 1;
13
#
24
# MDEV-12288 Reset DB_TRX_ID when the history is removed,
35
# to speed up MVCC
@@ -7,7 +9,8 @@ CREATE TABLE t1(a INT PRIMARY KEY, b INT NOT NULL)
79
ROW_FORMAT=REDUNDANT ENGINE=InnoDB;
810
INSERT INTO t1 VALUES(1,2),(3,4);
911
UPDATE t1 SET b=-3 WHERE a=3;
10-
SET GLOBAL innodb_fast_shutdown=0;
12+
InnoDB 0 transactions not purged
13+
FLUSH TABLE t1 FOR EXPORT;
1114
Clustered index root page contents:
1215
N_RECS=2; LEVEL=0
1316
header=0x010000030087 (a=0x696e66696d756d00)
@@ -20,8 +23,10 @@ header=0x000018090074 (a=0x80000003,
2023
DB_ROLL_PTR=0x80000000000000,
2124
b=0x7ffffffd)
2225
header=0x030008030000 (a=0x73757072656d756d00)
26+
UNLOCK TABLES;
2327
SELECT * FROM t1;
2428
a b
2529
1 2
2630
3 -3
2731
DROP TABLE t1;
32+
SET GLOBAL innodb_purge_rseg_truncate_frequency = @saved_frequency;

mysql-test/suite/innodb/t/dml_purge.test

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
--source include/innodb_page_size.inc
2-
--source include/not_embedded.inc
32

43
let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
54
let MYSQLD_DATADIR=`select @@datadir`;
5+
SET @saved_frequency = @@GLOBAL.innodb_purge_rseg_truncate_frequency;
6+
SET GLOBAL innodb_purge_rseg_truncate_frequency = 1;
67

78
--echo #
89
--echo # MDEV-12288 Reset DB_TRX_ID when the history is removed,
@@ -13,12 +14,14 @@ SET GLOBAL innodb_purge_rseg_truncate_frequency = 1;
1314

1415
CREATE TABLE t1(a INT PRIMARY KEY, b INT NOT NULL)
1516
ROW_FORMAT=REDUNDANT ENGINE=InnoDB;
17+
1618
INSERT INTO t1 VALUES(1,2),(3,4);
1719
UPDATE t1 SET b=-3 WHERE a=3;
1820

1921
# Initiate a full purge, which should reset all DB_TRX_ID.
20-
SET GLOBAL innodb_fast_shutdown=0;
21-
--source include/shutdown_mysqld.inc
22+
--source include/wait_all_purged.inc
23+
24+
FLUSH TABLE t1 FOR EXPORT;
2225
# The following is based on innodb.table_flags:
2326
--perl
2427
use strict;
@@ -54,6 +57,7 @@ for (my $offset= 0x65; $offset;
5457
}
5558
close(FILE) || die "Unable to close $file\n";
5659
EOF
57-
--source include/start_mysqld.inc
60+
UNLOCK TABLES;
5861
SELECT * FROM t1;
5962
DROP TABLE t1;
63+
SET GLOBAL innodb_purge_rseg_truncate_frequency = @saved_frequency;

storage/innobase/srv/srv0srv.cc

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,12 +2446,8 @@ DECLARE_THREAD(srv_master_thread)(
24462446
goto loop;
24472447
}
24482448

2449-
/** Check if purge should stop.
2450-
@param[in] n_purged pages purged in the last batch
2451-
@return whether purge should exit */
2452-
static
2453-
bool
2454-
srv_purge_should_exit(ulint n_purged)
2449+
/** @return whether purge should exit due to shutdown */
2450+
static bool srv_purge_should_exit()
24552451
{
24562452
ut_ad(srv_shutdown_state == SRV_SHUTDOWN_NONE
24572453
|| srv_shutdown_state == SRV_SHUTDOWN_CLEANUP);
@@ -2463,12 +2459,7 @@ srv_purge_should_exit(ulint n_purged)
24632459
return(true);
24642460
}
24652461
/* Slow shutdown was requested. */
2466-
if (n_purged) {
2467-
/* The previous round still did some work. */
2468-
return(false);
2469-
}
2470-
/* Exit if there are no active transactions to roll back. */
2471-
return(trx_sys.any_active_transactions() == 0);
2462+
return !trx_sys.any_active_transactions() && !trx_sys.history_size();
24722463
}
24732464

24742465
/*********************************************************************//**
@@ -2643,9 +2634,9 @@ srv_do_purge(ulint* n_total_purged)
26432634

26442635
*n_total_purged += n_pages_purged;
26452636

2646-
} while (!srv_purge_should_exit(n_pages_purged)
2647-
&& n_pages_purged > 0
2648-
&& purge_sys.state == PURGE_STATE_RUN);
2637+
} while (n_pages_purged > 0
2638+
&& purge_sys.state == PURGE_STATE_RUN
2639+
&& !srv_purge_should_exit());
26492640

26502641
return(rseg_history_len);
26512642
}
@@ -2776,14 +2767,14 @@ DECLARE_THREAD(srv_purge_coordinator_thread)(
27762767

27772768
ut_ad(!slot->suspended);
27782769

2779-
if (srv_purge_should_exit(n_total_purged)) {
2770+
if (srv_purge_should_exit()) {
27802771
break;
27812772
}
27822773

27832774
n_total_purged = 0;
27842775

27852776
rseg_history_len = srv_do_purge(&n_total_purged);
2786-
} while (!srv_purge_should_exit(n_total_purged));
2777+
} while (!srv_purge_should_exit());
27872778

27882779
/* The task queue should always be empty, independent of fast
27892780
shutdown state. */

0 commit comments

Comments
 (0)