summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2021-03-19 14:46:38 +0200
committerMonty <monty@mariadb.org>2021-03-20 14:09:26 +0200
commitac636a02733a8cee1725e30b8303278b80790d79 (patch)
treeb68db3c197be80f7ff1c3b32fa68679b8ca7e22d
parent4eeea4e212755408ca963d22faa11c12963c1d0a (diff)
downloadmariadb-git-ac636a02733a8cee1725e30b8303278b80790d79.tar.gz
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
-rw-r--r--.gitignore1
-rw-r--r--mysql-test/include/maria_empty_logs.inc6
-rw-r--r--scripts/sys_schema/tables/sys_config.sql2
-rw-r--r--storage/maria/aria_chk.c6
-rw-r--r--storage/maria/ma_create.c9
-rw-r--r--storage/maria/ma_delete_all.c2
-rw-r--r--storage/maria/ma_open.c4
-rw-r--r--storage/maria/trnman.c24
-rw-r--r--storage/maria/trnman_public.h1
9 files changed, 45 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
index d58dd2aa2b8..9eb935f127c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -138,6 +138,7 @@ scripts/maria_add_gis_sp_bootstrap.sql
scripts/galera_new_cluster
scripts/galera_recovery
scripts/mysql_convert_table_format.pl
+scripts/mysql_sys_schema.sql
scripts/mysqld_multi.pl
scripts/mysqldumpslow.pl
scripts/mysqlhotcopy.pl
diff --git a/mysql-test/include/maria_empty_logs.inc b/mysql-test/include/maria_empty_logs.inc
index f1835c0d2c3..a4f893d7fd4 100644
--- a/mysql-test/include/maria_empty_logs.inc
+++ b/mysql-test/include/maria_empty_logs.inc
@@ -94,13 +94,15 @@ eval use $default_db;
--enable_query_log
#
-# Ensure that we don't get warnings from mysql.priv (used by check_mysqld)
-# or test running after this one.
+# Ensure that we don't get warnings from mysql.priv (used by check_mysqld),
+# sys_config or from test running after this one.
#
--disable_query_log
--disable_warnings
--disable_result_log
+# Zerofill all Aria tables in mysql and sys
show table status from mysql;
+show table status from sys;
--enable_result_log
--enable_warnings
--enable_query_log
diff --git a/scripts/sys_schema/tables/sys_config.sql b/scripts/sys_schema/tables/sys_config.sql
index 96d48613064..f887d050875 100644
--- a/scripts/sys_schema/tables/sys_config.sql
+++ b/scripts/sys_schema/tables/sys_config.sql
@@ -24,6 +24,6 @@ CREATE TABLE IF NOT EXISTS sys_config (
value VARCHAR(128),
set_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
set_by VARCHAR(128)
-) ENGINE = MyISAM;
+) ENGINE = Aria;
diff --git a/storage/maria/aria_chk.c b/storage/maria/aria_chk.c
index 8f7f1b11b6f..0955d467bcb 100644
--- a/storage/maria/aria_chk.c
+++ b/storage/maria/aria_chk.c
@@ -1588,6 +1588,12 @@ static void descript(HA_CHECK *param, register MARIA_HA *info, char *name)
buff[MY_UUID_STRING_LENGTH]= 0;
my_uuid2str(share->base.uuid, buff);
printf("UUID: %s\n", buff);
+ if (ma_control_file_inited() &&
+ memcmp(share->base.uuid, maria_uuid, MY_UUID_SIZE))
+ printf("Warning: File UUID not match control file UUID! "
+ "File is probably moved\n"
+ "It will be updated to new system on first usage if zerofill is "
+ "not done\n");
pos=buff;
if (share->state.changed & STATE_CRASHED)
strmov(buff, share->state.changed & STATE_CRASHED_ON_REPAIR ?
diff --git a/storage/maria/ma_create.c b/storage/maria/ma_create.c
index 91344a835df..8eabc869a82 100644
--- a/storage/maria/ma_create.c
+++ b/storage/maria/ma_create.c
@@ -20,6 +20,7 @@
#include <my_bit.h>
#include "ma_blockrec.h"
#include "trnman_public.h"
+#include "trnman.h"
#include "ma_crypt.h"
#if defined(MSDOS) || defined(__WIN__)
@@ -82,6 +83,7 @@ int maria_create(const char *name, enum data_file_type datafile_type,
enum en_fieldtype type;
enum data_file_type org_datafile_type= datafile_type;
MARIA_SHARE share;
+ TRN tmp_transaction_object;
MARIA_KEYDEF *keydef,tmp_keydef;
MARIA_UNIQUEDEF *uniquedef;
HA_KEYSEG *keyseg,tmp_keyseg;
@@ -1084,7 +1086,7 @@ int maria_create(const char *name, enum data_file_type datafile_type,
{
/*
we log the first bytes and then the size to which we extend; this is
- not log 1 KB of mostly zeroes if this is a small table.
+ a log of about 1 KB of mostly zeroes if this is a small table.
*/
char empty_string[]= "";
LEX_CUSTRING log_array[TRANSLOG_INTERNAL_PARTS + 4];
@@ -1149,9 +1151,10 @@ int maria_create(const char *name, enum data_file_type datafile_type,
called external_lock(), so have no TRN. It does not matter, as all
these operations are non-transactional and sync their files.
*/
+ trnman_init_tmp_trn_for_logging_trid(&tmp_transaction_object);
if (unlikely(translog_write_record(&lsn,
LOGREC_REDO_CREATE_TABLE,
- &dummy_transaction_object, NULL,
+ &tmp_transaction_object, NULL,
total_rec_length,
sizeof(log_array)/sizeof(log_array[0]),
log_array, NULL, NULL) ||
@@ -1172,7 +1175,7 @@ int maria_create(const char *name, enum data_file_type datafile_type,
store LSN into file, needed for Recovery to not be confused if a
DROP+CREATE happened (applying REDOs to the wrong table).
*/
- if (_ma_update_state_lsns_sub(&share, lsn, trnman_get_min_safe_trid(),
+ if (_ma_update_state_lsns_sub(&share, lsn, tmp_transaction_object.trid,
FALSE, TRUE))
goto err;
my_free(log_data);
diff --git a/storage/maria/ma_delete_all.c b/storage/maria/ma_delete_all.c
index c1019c01c66..e06974fed66 100644
--- a/storage/maria/ma_delete_all.c
+++ b/storage/maria/ma_delete_all.c
@@ -131,7 +131,7 @@ int maria_delete_all_rows(MARIA_HA *info)
my_bool error= _ma_state_info_write(share,
MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET |
MA_STATE_INFO_WRITE_LOCK) ||
- _ma_update_state_lsns(share, lsn, trnman_get_min_trid(), FALSE, FALSE) ||
+ _ma_update_state_lsns(share, lsn, info->trn->trid, FALSE, FALSE) ||
_ma_sync_table_files(info);
info->trn->rec_lsn= LSN_IMPOSSIBLE;
if (error)
diff --git a/storage/maria/ma_open.c b/storage/maria/ma_open.c
index 9e7106ab5d3..95ee9d636b4 100644
--- a/storage/maria/ma_open.c
+++ b/storage/maria/ma_open.c
@@ -568,8 +568,8 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags,
memcmp(share->base.uuid, maria_uuid, MY_UUID_SIZE))))))
{
DBUG_PRINT("warning", ("table is moved from another system. uuid_diff: %d create_trid: %lu max_trid: %lu",
- memcmp(share->base.uuid, maria_uuid,
- MY_UUID_SIZE) != 0,
+ memcmp(share->base.uuid, maria_uuid,
+ MY_UUID_SIZE) != 0,
(ulong) share->state.create_trid,
(ulong) trnman_get_max_trid()));
if (open_flags & HA_OPEN_FOR_REPAIR)
diff --git a/storage/maria/trnman.c b/storage/maria/trnman.c
index 56f6c52b2f5..0c7f6c54f5e 100644
--- a/storage/maria/trnman.c
+++ b/storage/maria/trnman.c
@@ -194,6 +194,7 @@ int trnman_init(TrID initial_trid)
DBUG_RETURN(0);
}
+
/*
NOTE
this could only be called in the "idle" state - no transaction can be
@@ -229,6 +230,7 @@ void trnman_destroy()
DBUG_VOID_RETURN;
}
+
/*
NOTE
TrID is limited to 6 bytes. Initial value of the generator
@@ -267,7 +269,7 @@ static uint get_short_trid(TRN *trn)
}
/**
- Allocates and initialzies a new TRN object
+ Allocates and initializes a new TRN object
@note the 'wt' parameter can only be 0 in a single-threaded code (or,
generally, where threads cannot block each other), otherwise the
@@ -384,6 +386,26 @@ TRN *trnman_new_trn(WT_THD *wt)
DBUG_RETURN(trn);
}
+
+/*
+ Initialize a temporary TRN object for logging a new transaction id (trid)
+ to it. Used by create table to associate a create trid to the table.
+
+ Out: trn->trid is updated with next available trid
+*/
+
+void trnman_init_tmp_trn_for_logging_trid(TRN *trn)
+{
+ *trn= dummy_transaction_object;
+ /* Avoid logging short_id */
+ trn->short_id= 1;
+ /* Trid gets logged in translog_write_record */
+ trn->first_undo_lsn= 0;
+ /* Get next free trid */
+ trn->trid= trnman_get_min_safe_trid();
+}
+
+
/*
remove a trn from the active list.
if necessary - move to committed list and set commit_trid
diff --git a/storage/maria/trnman_public.h b/storage/maria/trnman_public.h
index a62c98bf078..97b8cc2fff3 100644
--- a/storage/maria/trnman_public.h
+++ b/storage/maria/trnman_public.h
@@ -58,6 +58,7 @@ uint trnman_has_locked_tables(TRN *trn);
void trnman_reset_locked_tables(TRN *trn, uint locked_tables);
TRN *trnman_recreate_trn_from_recovery(uint16 shortid, TrID longid);
TRN *trnman_get_any_trn(void);
+void trnman_init_tmp_trn_for_logging_trid(TRN *trn);
TrID trnman_get_min_trid(void);
TrID trnman_get_max_trid(void);
TrID trnman_get_min_safe_trid();