mirror of
https://github.com/MariaDB/server.git
synced 2026-05-16 20:07:13 +02:00
WL#3072 Maria Recovery
- new program maria_read_log to display and apply log records found in a Maria log (see file's revision comment) - minor, misc fixes storage/maria/Makefile.am: new program maria_read_log storage/maria/ha_maria.cc: create control file if missing storage/maria/ma_blockrec.c: 0 -> LSN_IMPOSSIBLE; comments storage/maria/ma_checkpoint.h: preparations for Checkpoint module storage/maria/ma_close.c: comment storage/maria/ma_control_file.c: renaming constants. Possibility to say "open control file but don't create it if it's missing" (used by maria_read_log which does not want to create anything) storage/maria/ma_control_file.h: renaming constants storage/maria/ma_create.c: I had duplicated "linkname" and "linkname_ptr", now I see it's not needed, reverting. Indeed those variables don't contain interesting information; fixing log record accordingly (the links are in ci->data/index_file_name). Storing keystart in log record is needed, to know at which size we must extend the file if we replay LOGREC_CREATE_TABLE. storage/maria/ma_loghandler.c: some structures need to be known to maria_read_log.c, taking them to ma_loghandler.h storage/maria/ma_loghandler.h: we have page_store, adding page_korr. translog_lock() made public, because Checkpoint will need it (to write to control file). Some structures moved from ma_loghandler.c because maria_read_log.c needs them (needs to know the execute-in-REDO-phase hooks of each record). storage/maria/ma_loghandler_lsn.h: constants defined in ma_control_file.h serve everywhere, and they relate to LSNs, so putting them in ma_loghandler_lsn.h. Stronger constraints in LSN_VALID(). storage/maria/ma_pagecache.c: renaming constants storage/maria/ma_recovery.h: copyright storage/maria/ma_test1.c: new prototype storage/maria/ma_test2.c: new prototype storage/maria/trnman_public.h: double-inclusion safe storage/maria/unittest/ma_control_file-t.c: constants renamed, new prototype storage/maria/unittest/ma_test_loghandler-t.c: constants renamed, new prototype storage/maria/unittest/ma_test_loghandler_multigroup-t.c: constants renamed, new prototype storage/maria/unittest/ma_test_loghandler_multithread-t.c: constants renamed, new prototype storage/maria/unittest/ma_test_loghandler_pagecache-t.c: constants renamed, new prototype storage/myisam/mi_close.c: comment storage/maria/maria_read_log.c: program to read and print log records from a Maria transaction log, and optionally apply them to tables. Very basic, early version. Should serve as a base for Recovery's code. Designed to be idempotent. Create a log by running maria.test, then cd to var/master-data and run "maria_read_log --only-display" to see info about records; run "maria_read_log --display-and-apply" to also apply the records to tables (it's more interesting if you first wipe out the tables in var/master-data/test, to see how they get re-created). Only a few records are handled by now: LONG_TRANSACTION_ID, COMMIT, FILE_ID, REDO_CREATE_TABLE; place is ready for REDO_INSERT_ROW_HEAD where I could use Monty's help (search for "Monty" in the file). Note: changes to the index pages, index's header and bitmap pages are not properly logged yet, so don't expect the program to work with that.
This commit is contained in:
parent
bb8bde8f93
commit
adac9798bf
23 changed files with 1093 additions and 248 deletions
|
|
@ -40,15 +40,9 @@
|
|||
#define CONTROL_FILE_FILENO_SIZE 4
|
||||
#define CONTROL_FILE_SIZE (CONTROL_FILE_FILENO_OFFSET + CONTROL_FILE_FILENO_SIZE)
|
||||
|
||||
/*
|
||||
This module owns these two vars.
|
||||
uint32 is always atomically updated, but LSN is 8 bytes, we will need
|
||||
provisions to ensure that it's updated atomically in
|
||||
ma_control_file_write_and_force(). Probably the log mutex could be
|
||||
used. TODO.
|
||||
*/
|
||||
LSN last_checkpoint_lsn;
|
||||
uint32 last_logno;
|
||||
/* This module owns these two vars. */
|
||||
LSN last_checkpoint_lsn= LSN_IMPOSSIBLE;
|
||||
uint32 last_logno= FILENO_IMPOSSIBLE;
|
||||
|
||||
/**
|
||||
@brief If log's lock should be asserted when writing to control file.
|
||||
|
|
@ -65,16 +59,16 @@ my_bool maria_multi_threaded= FALSE;
|
|||
static int control_file_fd= -1;
|
||||
|
||||
/*
|
||||
Initialize control file subsystem
|
||||
@brief Initialize control file subsystem
|
||||
|
||||
SYNOPSIS
|
||||
ma_control_file_create_or_open()
|
||||
|
||||
Looks for the control file. If absent, it's a fresh start, creates file.
|
||||
Looks for the control file. If none and creation is requested, creates file.
|
||||
If present, reads it to find out last checkpoint's LSN and last log, updates
|
||||
the last_checkpoint_lsn and last_logno global variables.
|
||||
Called at engine's start.
|
||||
|
||||
@param create_if_missing
|
||||
|
||||
@note
|
||||
The format of the control file is:
|
||||
4 bytes: magic string
|
||||
4 bytes: checksum of the following bytes
|
||||
|
|
@ -82,11 +76,11 @@ static int control_file_fd= -1;
|
|||
4 bytes: offset in log where last checkpoint is
|
||||
4 bytes: number of last log
|
||||
|
||||
RETURN
|
||||
0 - OK
|
||||
1 - Error (in which case the file is left closed)
|
||||
@return Operation status
|
||||
@retval 0 OK
|
||||
@retval 1 Error (in which case the file is left closed)
|
||||
*/
|
||||
CONTROL_FILE_ERROR ma_control_file_create_or_open()
|
||||
CONTROL_FILE_ERROR ma_control_file_create_or_open(my_bool create_if_missing)
|
||||
{
|
||||
char buffer[CONTROL_FILE_SIZE];
|
||||
char name[FN_REFLEN];
|
||||
|
|
@ -115,6 +109,8 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open()
|
|||
|
||||
if (create_file)
|
||||
{
|
||||
if (!create_if_missing)
|
||||
DBUG_RETURN(CONTROL_FILE_MISSING);
|
||||
if ((control_file_fd= my_create(name, 0,
|
||||
open_flags, MYF(MY_SYNC_DIR))) < 0)
|
||||
DBUG_RETURN(CONTROL_FILE_UNKNOWN_ERROR);
|
||||
|
|
@ -136,8 +132,8 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open()
|
|||
*/
|
||||
|
||||
/* init the file with these "undefined" values */
|
||||
DBUG_RETURN(ma_control_file_write_and_force(CONTROL_FILE_IMPOSSIBLE_LSN,
|
||||
CONTROL_FILE_IMPOSSIBLE_FILENO,
|
||||
DBUG_RETURN(ma_control_file_write_and_force(LSN_IMPOSSIBLE,
|
||||
FILENO_IMPOSSIBLE,
|
||||
CONTROL_FILE_UPDATE_ALL));
|
||||
}
|
||||
|
||||
|
|
@ -315,8 +311,8 @@ int ma_control_file_end()
|
|||
As this module owns these variables, closing the module forbids access to
|
||||
them (just a safety):
|
||||
*/
|
||||
last_checkpoint_lsn= CONTROL_FILE_IMPOSSIBLE_LSN;
|
||||
last_logno= CONTROL_FILE_IMPOSSIBLE_FILENO;
|
||||
last_checkpoint_lsn= LSN_IMPOSSIBLE;
|
||||
last_logno= FILENO_IMPOSSIBLE;
|
||||
|
||||
DBUG_RETURN(close_error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue