Skip to content

MDEV-36017 Alter table aborts when temporary directory is full #3903

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions mysql-test/suite/innodb/r/alter_temp_fail.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# MDEV-36017 Alter table aborts when temporary
# directory is full
#
CREATE TABLE t1(f1 INT NOT NULL, f2 CHAR(100),
f3 CHAR(100))ENGINE=InnoDB;
INSERT INTO t1 SELECT seq, 'a', 'b' FROM seq_1_to_4096;
SET DEBUG_SYNC="inplace_after_index_build SIGNAL dml_start WAIT_FOR dml_commit";
ALTER TABLE t1 ADD KEY(f1), ADD INDEX(f3(10));
connect con1,localhost,root,,,;
SET DEBUG_SYNC="now WAIT_FOR dml_start";
BEGIN;
INSERT INTO t1 SELECT * FROM t1;
SET STATEMENT DEBUG_DBUG="+d,os_file_write_fail" FOR COMMIT;
SET DEBUG_SYNC="now SIGNAL dml_commit";
connection default;
ERROR HY000: Temporary file write failure
disconnect con1;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
DROP TABLE t1;
SET STATEMENT DEBUG_DBUG="+d,ddl_log_write_fail" FOR
CREATE TABLE t1(f1 INT NOT NULL)ENGINE=InnoDB;
DROP TABLE t1;
1 change: 1 addition & 0 deletions mysql-test/suite/innodb/t/alter_temp_fail.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--innodb_sort_buffer_size=64k
30 changes: 30 additions & 0 deletions mysql-test/suite/innodb/t/alter_temp_fail.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--source include/have_innodb.inc
--source include/have_sequence.inc
--source include/have_debug.inc
--echo #
--echo # MDEV-36017 Alter table aborts when temporary
--echo # directory is full
--echo #
CREATE TABLE t1(f1 INT NOT NULL, f2 CHAR(100),
f3 CHAR(100))ENGINE=InnoDB;
INSERT INTO t1 SELECT seq, 'a', 'b' FROM seq_1_to_4096;
SET DEBUG_SYNC="inplace_after_index_build SIGNAL dml_start WAIT_FOR dml_commit";
SEND ALTER TABLE t1 ADD KEY(f1), ADD INDEX(f3(10));

connect(con1,localhost,root,,,);
SET DEBUG_SYNC="now WAIT_FOR dml_start";
BEGIN;
INSERT INTO t1 SELECT * FROM t1;
SET STATEMENT DEBUG_DBUG="+d,os_file_write_fail" FOR COMMIT;
SET DEBUG_SYNC="now SIGNAL dml_commit";

connection default;
--error ER_TEMP_FILE_WRITE_FAILURE
reap;
disconnect con1;
CHECK TABLE t1;
DROP TABLE t1;

SET STATEMENT DEBUG_DBUG="+d,ddl_log_write_fail" FOR
CREATE TABLE t1(f1 INT NOT NULL)ENGINE=InnoDB;
DROP TABLE t1;
4 changes: 3 additions & 1 deletion sql/ddl_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3029,13 +3029,15 @@ static bool ddl_log_write(DDL_LOG_STATE *ddl_state,
error= ((ddl_log_write_entry(ddl_log_entry, &log_entry)) ||
ddl_log_write_execute_entry(log_entry->entry_pos,
&ddl_state->execute_entry));
mysql_mutex_unlock(&LOCK_gdl);
DBUG_EXECUTE_IF("ddl_log_write_fail", error= true;);
if (error)
{
if (log_entry)
ddl_log_release_memory_entry(log_entry);
mysql_mutex_unlock(&LOCK_gdl);
DBUG_RETURN(1);
}
mysql_mutex_unlock(&LOCK_gdl);
add_log_entry(ddl_state, log_entry);
ddl_state->flags|= ddl_log_entry->flags; // Update cache
DBUG_RETURN(0);
Expand Down
11 changes: 9 additions & 2 deletions storage/innobase/btr/btr0cur.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3696,8 +3696,10 @@ btr_cur_optimistic_update(
*offsets = rec_get_offsets(rec, index, *offsets, index->n_core_fields,
ULINT_UNDEFINED, heap);
#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
/* Blob pointer can be null if InnoDB was killed or
ran out of space while allocating a page. */
ut_a(!rec_offs_any_null_extern(rec, *offsets)
|| thr_get_trx(thr) == trx_roll_crash_recv_trx);
|| thr_get_trx(thr)->in_rollback);
#endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */

if (UNIV_LIKELY(!update->is_metadata())
Expand Down Expand Up @@ -4370,7 +4372,12 @@ btr_cur_pessimistic_update(
cursor, offsets, offsets_heap,
new_entry, &rec,
&dummy_big_rec, n_ext, NULL, mtr);
ut_a(err == DB_SUCCESS);
if (err) {
/* This should happen when InnoDB tries to extend the
tablespace */
ut_ad(err == DB_OUT_OF_FILE_SPACE);
return err;
}
ut_a(rec);
ut_a(dummy_big_rec == NULL);
ut_ad(rec_offs_validate(rec, cursor->index(), *offsets));
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/fil/fil0fil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ fil_space_extend_must_retry(
*success = os_file_set_size(node->name, node->handle, new_size,
node->punch_hole == 1);

os_has_said_disk_full = *success;
os_has_said_disk_full = !*success;
if (*success) {
os_file_flush(node->handle);
last_page_no = size;
Expand Down
5 changes: 5 additions & 0 deletions storage/innobase/row/row0log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,17 @@ bool row_log_online_op(dict_index_t *index, const dtuple_t *tuple,
}

log->tail.blocks++;
DBUG_EXECUTE_IF("os_file_write_fail",
log->error = DB_TEMP_FILE_WRITE_FAIL;
goto write_failed;);

if (os_file_write(
IORequestWrite,
"(modification log)",
log->fd,
buf, byte_offset, srv_sort_buf_size)
!= DB_SUCCESS) {
log->error = DB_TEMP_FILE_WRITE_FAIL;
write_failed:
index->type |= DICT_CORRUPT;
}
Expand Down
18 changes: 2 additions & 16 deletions storage/innobase/row/row0umod.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1128,29 +1128,15 @@ row_undo_mod_upd_exist_sec(
dtuple_t* entry = row_build_index_entry(
node->row, node->ext, index, heap);
if (UNIV_UNLIKELY(!entry)) {
/* The server must have crashed in
row_upd_clust_rec_by_insert() before
the updated externally stored columns (BLOBs)
/* InnoDB must have run of space or been killed
before the updated externally stored columns (BLOBs)
of the new clustered index entry were written. */

/* The table must be in DYNAMIC or COMPRESSED
format. REDUNDANT and COMPACT formats
store a local 768-byte prefix of each
externally stored column. */
ut_a(dict_table_has_atomic_blobs(index->table));

/* This is only legitimate when
rolling back an incomplete transaction
after crash recovery. */
ut_a(thr_get_trx(thr)->is_recovered);

/* The server must have crashed before
completing the insert of the new
clustered index entry and before
inserting to the secondary indexes.
Because node->row was not yet written
to this index, we can ignore it. But
we must restore node->undo_row. */
} else {
/* NOTE that if we updated the fields of a
delete-marked secondary index record so that
Expand Down
15 changes: 5 additions & 10 deletions storage/innobase/row/row0upd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1414,16 +1414,11 @@ row_upd_changes_ord_field_binary_func(
if (UNIV_LIKELY_NULL(buf)) {
if (UNIV_UNLIKELY(buf == field_ref_zero)) {
/* The externally stored field
was not written yet. This
record should only be seen by
trx_rollback_recovered()
when the server had crashed before
storing the field. */
ut_ad(!thr
|| thr->graph->trx->is_recovered);
ut_ad(!thr
|| thr->graph->trx
== trx_roll_crash_recv_trx);
was not written yet. InnoDB must
have ran out of space or been killed
before storing the page */
ut_ad(thr);
ut_ad(thr->graph->trx->in_rollback);
return(TRUE);
}

Expand Down