Skip to content

Commit 7d4b2b9

Browse files
MDEV-29570 InnoDB fails to clean bulk buffer when server does rollback operation
- During bulk insert, server detects the error and does rollback operation. At that time, InnoDB fails to clean up the bulk insert buffer trx_t::rollback_finish(): Removed the clean up of modified tables from transaction trx_t::commit_cleanup(): Free the bulk buffer for bulk insert operation trx_t::commit(): Check whether modified table wasn't dropped only for non-dictionary transaction
1 parent 7c7ac6d commit 7d4b2b9

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,13 @@ CREATE TABLE t1 (a INT) ENGINE=InnoDB PARTITION BY HASH(a) PARTITIONS 2;
304304
INSERT INTO t1 VALUES (1),(2);
305305
ALTER TABLE t1 REBUILD PARTITION p0;
306306
DROP TABLE t1;
307+
#
308+
# MDEV-29570 InnoDB fails to clean bulk buffer when server
309+
# does rollback operation
310+
#
311+
CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=InnoDB
312+
PARTITION BY RANGE (pk) (
313+
PARTITION pn VALUES LESS THAN (20));
314+
INSERT INTO t1 VALUES (1),(21);
315+
ERROR HY000: Table has no partition for value 21
316+
DROP TABLE t1;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,15 @@ INSERT INTO t1 VALUES (1),(2);
315315
ALTER TABLE t1 REBUILD PARTITION p0;
316316
# Cleanup
317317
DROP TABLE t1;
318+
319+
--echo #
320+
--echo # MDEV-29570 InnoDB fails to clean bulk buffer when server
321+
--echo # does rollback operation
322+
--echo #
323+
CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=InnoDB
324+
PARTITION BY RANGE (pk) (
325+
PARTITION pn VALUES LESS THAN (20));
326+
--error ER_NO_PARTITION_FOR_GIVEN_VALUE
327+
INSERT INTO t1 VALUES (1),(21);
328+
# Cleanup
329+
DROP TABLE t1;

storage/innobase/include/trx0trx.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ class trx_mod_table_time_t
433433

434434
/** Buffer to store insert opertion */
435435
row_merge_bulk_t *bulk_store= nullptr;
436+
437+
friend struct trx_t;
436438
public:
437439
/** Constructor
438440
@param rows number of modified rows so far */
@@ -517,11 +519,9 @@ class trx_mod_table_time_t
517519
}
518520

519521
/** @return whether the buffer storage exist */
520-
bool bulk_buffer_exist()
522+
bool bulk_buffer_exist() const
521523
{
522-
if (is_bulk_insert() && bulk_store)
523-
return true;
524-
return false;
524+
return bulk_store && is_bulk_insert();
525525
}
526526
};
527527

storage/innobase/trx/trx0roll.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ const trx_t* trx_roll_crash_recv_trx;
5959
@retval false if the rollback was aborted by shutdown */
6060
inline bool trx_t::rollback_finish()
6161
{
62-
mod_tables.clear();
6362
apply_online_log= false;
6463
if (UNIV_LIKELY(error_state == DB_SUCCESS))
6564
{

storage/innobase/trx/trx0trx.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,10 @@ void trx_t::commit_cleanup()
13881388
ut_ad(!dict_operation);
13891389
ut_ad(!was_dict_operation);
13901390

1391+
if (is_bulk_insert())
1392+
for (auto &t : mod_tables)
1393+
delete t.second.bulk_store;
1394+
13911395
mutex.wr_lock();
13921396
state= TRX_STATE_NOT_STARTED;
13931397
mod_tables.clear();
@@ -1479,8 +1483,11 @@ void trx_t::commit()
14791483
ut_d(was_dict_operation= dict_operation);
14801484
dict_operation= false;
14811485
commit_persist();
1486+
#ifdef UNIV_DEBUG
1487+
if (!was_dict_operation)
1488+
for (const auto &p : mod_tables) ut_ad(!p.second.is_dropped());
1489+
#endif /* UNIV_DEBUG */
14821490
ut_d(was_dict_operation= false);
1483-
ut_d(for (const auto &p : mod_tables) ut_ad(!p.second.is_dropped()));
14841491
commit_cleanup();
14851492
}
14861493

0 commit comments

Comments
 (0)