Skip to content

Commit 8f33f49

Browse files
committed
Aria: Add transaction id to log of create table
In the case of a crash directly after a creation of an Aria table, Aria recovery would think that the table was from another system and require a repair of the table and inform that the table is 'zerofilled". This would cause no harm, but was confusing to see when testing atomic alter table. Fixed by logging the create transaction id to the log. Other things: - Added "show table status from sys" to maria_empy_logs. This ensures one does not get any zerofill warnings when sys/sys_config is used by other tests. - aria_chk --describe now prints a warning if the table was moved from another system. - Logging of truncate (maria_delete_all_rows) is changed to use the current trid for the create table. This is to ensure that we do not run into the same problem with truncate. - Changed back sys_config table to Aria as this patch should fix the "zerofill" problem in buildbot. - Added scripts/mysql_sys_schema.sql to .gitignore
1 parent 1055cf9 commit 8f33f49

File tree

9 files changed

+45
-10
lines changed

9 files changed

+45
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ scripts/maria_add_gis_sp_bootstrap.sql
138138
scripts/galera_new_cluster
139139
scripts/galera_recovery
140140
scripts/mysql_convert_table_format.pl
141+
scripts/mysql_sys_schema.sql
141142
scripts/mysqld_multi.pl
142143
scripts/mysqldumpslow.pl
143144
scripts/mysqlhotcopy.pl

mysql-test/include/maria_empty_logs.inc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,15 @@ eval use $default_db;
9494
--enable_query_log
9595

9696
#
97-
# Ensure that we don't get warnings from mysql.priv (used by check_mysqld)
98-
# or test running after this one.
97+
# Ensure that we don't get warnings from mysql.priv (used by check_mysqld),
98+
# sys_config or from test running after this one.
9999
#
100100
--disable_query_log
101101
--disable_warnings
102102
--disable_result_log
103+
# Zerofill all Aria tables in mysql and sys
103104
show table status from mysql;
105+
show table status from sys;
104106
--enable_result_log
105107
--enable_warnings
106108
--enable_query_log

scripts/sys_schema/tables/sys_config.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ CREATE TABLE IF NOT EXISTS sys_config (
2424
value VARCHAR(128),
2525
set_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
2626
set_by VARCHAR(128)
27-
) ENGINE = MyISAM;
27+
) ENGINE = Aria;
2828

2929

storage/maria/aria_chk.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,12 @@ static void descript(HA_CHECK *param, register MARIA_HA *info, char *name)
15881588
buff[MY_UUID_STRING_LENGTH]= 0;
15891589
my_uuid2str(share->base.uuid, buff);
15901590
printf("UUID: %s\n", buff);
1591+
if (ma_control_file_inited() &&
1592+
memcmp(share->base.uuid, maria_uuid, MY_UUID_SIZE))
1593+
printf("Warning: File UUID not match control file UUID! "
1594+
"File is probably moved\n"
1595+
"It will be updated to new system on first usage if zerofill is "
1596+
"not done\n");
15911597
pos=buff;
15921598
if (share->state.changed & STATE_CRASHED)
15931599
strmov(buff, share->state.changed & STATE_CRASHED_ON_REPAIR ?

storage/maria/ma_create.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <my_bit.h>
2121
#include "ma_blockrec.h"
2222
#include "trnman_public.h"
23+
#include "trnman.h"
2324
#include "ma_crypt.h"
2425

2526
#if defined(MSDOS) || defined(__WIN__)
@@ -82,6 +83,7 @@ int maria_create(const char *name, enum data_file_type datafile_type,
8283
enum en_fieldtype type;
8384
enum data_file_type org_datafile_type= datafile_type;
8485
MARIA_SHARE share;
86+
TRN tmp_transaction_object;
8587
MARIA_KEYDEF *keydef,tmp_keydef;
8688
MARIA_UNIQUEDEF *uniquedef;
8789
HA_KEYSEG *keyseg,tmp_keyseg;
@@ -1084,7 +1086,7 @@ int maria_create(const char *name, enum data_file_type datafile_type,
10841086
{
10851087
/*
10861088
we log the first bytes and then the size to which we extend; this is
1087-
not log 1 KB of mostly zeroes if this is a small table.
1089+
a log of about 1 KB of mostly zeroes if this is a small table.
10881090
*/
10891091
char empty_string[]= "";
10901092
LEX_CUSTRING log_array[TRANSLOG_INTERNAL_PARTS + 4];
@@ -1149,9 +1151,10 @@ int maria_create(const char *name, enum data_file_type datafile_type,
11491151
called external_lock(), so have no TRN. It does not matter, as all
11501152
these operations are non-transactional and sync their files.
11511153
*/
1154+
trnman_init_tmp_trn_for_logging_trid(&tmp_transaction_object);
11521155
if (unlikely(translog_write_record(&lsn,
11531156
LOGREC_REDO_CREATE_TABLE,
1154-
&dummy_transaction_object, NULL,
1157+
&tmp_transaction_object, NULL,
11551158
total_rec_length,
11561159
sizeof(log_array)/sizeof(log_array[0]),
11571160
log_array, NULL, NULL) ||
@@ -1172,7 +1175,7 @@ int maria_create(const char *name, enum data_file_type datafile_type,
11721175
store LSN into file, needed for Recovery to not be confused if a
11731176
DROP+CREATE happened (applying REDOs to the wrong table).
11741177
*/
1175-
if (_ma_update_state_lsns_sub(&share, lsn, trnman_get_min_safe_trid(),
1178+
if (_ma_update_state_lsns_sub(&share, lsn, tmp_transaction_object.trid,
11761179
FALSE, TRUE))
11771180
goto err;
11781181
my_free(log_data);

storage/maria/ma_delete_all.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ int maria_delete_all_rows(MARIA_HA *info)
131131
my_bool error= _ma_state_info_write(share,
132132
MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET |
133133
MA_STATE_INFO_WRITE_LOCK) ||
134-
_ma_update_state_lsns(share, lsn, trnman_get_min_trid(), FALSE, FALSE) ||
134+
_ma_update_state_lsns(share, lsn, info->trn->trid, FALSE, FALSE) ||
135135
_ma_sync_table_files(info);
136136
info->trn->rec_lsn= LSN_IMPOSSIBLE;
137137
if (error)

storage/maria/ma_open.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,8 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags,
568568
memcmp(share->base.uuid, maria_uuid, MY_UUID_SIZE))))))
569569
{
570570
DBUG_PRINT("warning", ("table is moved from another system. uuid_diff: %d create_trid: %lu max_trid: %lu",
571-
memcmp(share->base.uuid, maria_uuid,
572-
MY_UUID_SIZE) != 0,
571+
memcmp(share->base.uuid, maria_uuid,
572+
MY_UUID_SIZE) != 0,
573573
(ulong) share->state.create_trid,
574574
(ulong) trnman_get_max_trid()));
575575
if (open_flags & HA_OPEN_FOR_REPAIR)

storage/maria/trnman.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ int trnman_init(TrID initial_trid)
194194
DBUG_RETURN(0);
195195
}
196196

197+
197198
/*
198199
NOTE
199200
this could only be called in the "idle" state - no transaction can be
@@ -229,6 +230,7 @@ void trnman_destroy()
229230
DBUG_VOID_RETURN;
230231
}
231232

233+
232234
/*
233235
NOTE
234236
TrID is limited to 6 bytes. Initial value of the generator
@@ -267,7 +269,7 @@ static uint get_short_trid(TRN *trn)
267269
}
268270

269271
/**
270-
Allocates and initialzies a new TRN object
272+
Allocates and initializes a new TRN object
271273
272274
@note the 'wt' parameter can only be 0 in a single-threaded code (or,
273275
generally, where threads cannot block each other), otherwise the
@@ -384,6 +386,26 @@ TRN *trnman_new_trn(WT_THD *wt)
384386
DBUG_RETURN(trn);
385387
}
386388

389+
390+
/*
391+
Initialize a temporary TRN object for logging a new transaction id (trid)
392+
to it. Used by create table to associate a create trid to the table.
393+
394+
Out: trn->trid is updated with next available trid
395+
*/
396+
397+
void trnman_init_tmp_trn_for_logging_trid(TRN *trn)
398+
{
399+
*trn= dummy_transaction_object;
400+
/* Avoid logging short_id */
401+
trn->short_id= 1;
402+
/* Trid gets logged in translog_write_record */
403+
trn->first_undo_lsn= 0;
404+
/* Get next free trid */
405+
trn->trid= trnman_get_min_safe_trid();
406+
}
407+
408+
387409
/*
388410
remove a trn from the active list.
389411
if necessary - move to committed list and set commit_trid

storage/maria/trnman_public.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ uint trnman_has_locked_tables(TRN *trn);
5858
void trnman_reset_locked_tables(TRN *trn, uint locked_tables);
5959
TRN *trnman_recreate_trn_from_recovery(uint16 shortid, TrID longid);
6060
TRN *trnman_get_any_trn(void);
61+
void trnman_init_tmp_trn_for_logging_trid(TRN *trn);
6162
TrID trnman_get_min_trid(void);
6263
TrID trnman_get_max_trid(void);
6364
TrID trnman_get_min_safe_trid();

0 commit comments

Comments
 (0)