Skip to content

Commit 2aff2f2

Browse files
committed
Added --print-log-control-file option to aria_read_log
1 parent 1077f32 commit 2aff2f2

File tree

3 files changed

+141
-4
lines changed

3 files changed

+141
-4
lines changed

storage/maria/ma_control_file.c

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,4 +608,124 @@ my_bool ma_control_file_inited(void)
608608
return (control_file_fd >= 0);
609609
}
610610

611+
/**
612+
Print content of aria_log_control file
613+
*/
614+
615+
my_bool print_aria_log_control()
616+
{
617+
uchar buffer[CF_MAX_SIZE];
618+
char name[FN_REFLEN], uuid_str[MY_UUID_STRING_LENGTH+1];
619+
const char *errmsg;
620+
uint new_cf_create_time_size, new_cf_changeable_size;
621+
my_off_t file_size;
622+
ulong logno;
623+
ulonglong trid,checkpoint_lsn;
624+
int open_flags= O_BINARY | /*O_DIRECT |*/ O_RDWR | O_CLOEXEC;
625+
int error= CONTROL_FILE_UNKNOWN_ERROR;
626+
uint recovery_fails;
627+
File file;
628+
DBUG_ENTER("ma_control_file_open");
629+
630+
if (fn_format(name, CONTROL_FILE_BASE_NAME,
631+
maria_data_root, "", MYF(MY_WME)) == NullS)
632+
DBUG_RETURN(CONTROL_FILE_UNKNOWN_ERROR);
633+
634+
if ((file= mysql_file_open(key_file_control, name,
635+
open_flags, MYF(MY_WME))) < 0)
636+
{
637+
errmsg= "Can't open file";
638+
goto err;
639+
}
640+
641+
file_size= mysql_file_seek(file, 0, SEEK_END, MYF(MY_WME));
642+
if (file_size == MY_FILEPOS_ERROR)
643+
{
644+
errmsg= "Can't read size";
645+
goto err;
646+
}
647+
if (file_size < CF_MIN_SIZE)
648+
{
649+
/*
650+
Given that normally we write only a sector and it's atomic, the only
651+
possibility for a file to be of too short size is if we crashed at the
652+
very first startup, between file creation and file write. Quite unlikely
653+
(and can be made even more unlikely by doing this: create a temp file,
654+
write it, and then rename it to be the control file).
655+
What's more likely is if someone forgot to restore the control file,
656+
just did a "touch control" to try to get Maria to start, or if the
657+
disk/filesystem has a problem.
658+
So let's be rigid.
659+
*/
660+
error= CONTROL_FILE_TOO_SMALL;
661+
errmsg= "Size of control file is smaller than expected";
662+
goto err;
663+
}
664+
665+
/* Check if control file is unexpectedly big */
666+
if (file_size > CF_MAX_SIZE)
667+
{
668+
error= CONTROL_FILE_TOO_BIG;
669+
errmsg= "File size bigger than expected";
670+
goto err;
671+
}
672+
673+
if (mysql_file_pread(file, buffer, (size_t)file_size, 0, MYF(MY_FNABP)))
674+
{
675+
errmsg= "Can't read file";
676+
goto err;
677+
}
678+
679+
if (memcmp(buffer + CF_MAGIC_STRING_OFFSET,
680+
CF_MAGIC_STRING, CF_MAGIC_STRING_SIZE))
681+
{
682+
error= CONTROL_FILE_BAD_MAGIC_STRING;
683+
errmsg= "Missing valid id at start of file. File is not a valid aria control file";
684+
goto err;
685+
}
686+
687+
printf("Aria file version: %u\n", buffer[CF_VERSION_OFFSET]);
688+
689+
new_cf_create_time_size= uint2korr(buffer + CF_CREATE_TIME_SIZE_OFFSET);
690+
new_cf_changeable_size= uint2korr(buffer + CF_CHANGEABLE_SIZE_OFFSET);
691+
692+
if (new_cf_create_time_size < CF_MIN_CREATE_TIME_TOTAL_SIZE ||
693+
new_cf_changeable_size < CF_MIN_CHANGEABLE_TOTAL_SIZE ||
694+
new_cf_create_time_size + new_cf_changeable_size != file_size)
695+
{
696+
error= CONTROL_FILE_INCONSISTENT_INFORMATION;
697+
errmsg= "Sizes stored in control file are inconsistent";
698+
goto err;
699+
}
700+
checkpoint_lsn= lsn_korr(buffer + new_cf_create_time_size +
701+
CF_LSN_OFFSET);
702+
logno= uint4korr(buffer + new_cf_create_time_size + CF_FILENO_OFFSET);
703+
my_uuid2str(buffer + CF_UUID_OFFSET, uuid_str);
704+
uuid_str[MY_UUID_STRING_LENGTH]= 0;
705+
706+
printf("Block size: %u\n", uint2korr(buffer + CF_BLOCKSIZE_OFFSET));
707+
printf("maria_uuid: %s\n", uuid_str);
708+
printf("last_checkpoint_lsn: " LSN_FMT "\n", LSN_IN_PARTS(checkpoint_lsn));
709+
printf("last_log_number: %lu\n", (ulong) logno);
710+
if (new_cf_changeable_size >= (CF_MAX_TRID_OFFSET + CF_MAX_TRID_SIZE))
711+
{
712+
trid= transid_korr(buffer + new_cf_create_time_size + CF_MAX_TRID_OFFSET);
713+
printf("trid: %llu\n", (ulonglong) trid);
714+
}
715+
if (new_cf_changeable_size >= (CF_RECOV_FAIL_OFFSET + CF_RECOV_FAIL_SIZE))
716+
{
717+
recovery_fails=
718+
(buffer + new_cf_create_time_size + CF_RECOV_FAIL_OFFSET)[0];
719+
printf("recovery_failuers: %u\n", recovery_fails);
720+
}
721+
722+
DBUG_RETURN(0);
723+
724+
err:
725+
my_printf_error(HA_ERR_INITIALIZATION,
726+
"Got error '%s' when trying to use aria control file "
727+
"'%s'", 0, errmsg, name);
728+
DBUG_RETURN(error);
729+
}
730+
611731
#endif /* EXTRACT_DEFINITIONS */

storage/maria/ma_control_file.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,6 @@ int ma_control_file_write_and_force(LSN last_checkpoint_lsn_arg,
7070
uint8 recovery_failures_arg);
7171
int ma_control_file_end(void);
7272
my_bool ma_control_file_inited(void);
73+
my_bool print_aria_log_control(void);
7374
C_MODE_END
7475
#endif

storage/maria/maria_read_log.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const char *default_dbug_option= "d:t:o,/tmp/aria_read_log.trace";
3131
#endif /* DBUG_OFF */
3232
static my_bool opt_display_only, opt_apply, opt_apply_undo, opt_silent;
3333
static my_bool opt_check;
34+
static my_bool opt_print_aria_log_control;
3435
static const char *opt_tmpdir;
3536
static ulong opt_translog_buffer_size;
3637
static ulonglong opt_page_buffer_size;
@@ -59,6 +60,12 @@ int main(int argc, char **argv)
5960
goto err;
6061
}
6162
maria_block_size= 0; /* Use block size from file */
63+
if (opt_print_aria_log_control)
64+
{
65+
if (print_aria_log_control())
66+
goto err;
67+
goto end;
68+
}
6269
/* we don't want to create a control file, it MUST exist */
6370
if (ma_control_file_open(FALSE, TRUE))
6471
{
@@ -209,6 +216,10 @@ static struct my_option my_long_options[] =
209216
&opt_page_buffer_size, &opt_page_buffer_size, 0,
210217
GET_ULL, REQUIRED_ARG, PAGE_BUFFER_INIT,
211218
PAGE_BUFFER_INIT, SIZE_T_MAX, MALLOC_OVERHEAD, (long) IO_SIZE, 0},
219+
{ "print-log-control-file", 'l',
220+
"Print the content of the aria_log_control_file",
221+
&opt_print_aria_log_control, &opt_print_aria_log_control, 0,
222+
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
212223
{ "start-from-lsn", 'o', "Start reading log from this lsn",
213224
&opt_start_from_lsn, &opt_start_from_lsn,
214225
0, GET_ULL, REQUIRED_ARG, 0, 0, ~(longlong) 0, 0, 0, 0 },
@@ -249,7 +260,7 @@ static struct my_option my_long_options[] =
249260

250261
static void print_version(void)
251262
{
252-
printf("%s Ver 1.3 for %s on %s\n",
263+
printf("%s Ver 1.4 for %s on %s\n",
253264
my_progname_short, SYSTEM_TYPE, MACHINE_TYPE);
254265
}
255266

@@ -271,6 +282,11 @@ static void usage(void)
271282
#endif
272283
printf("\nUsage: %s OPTIONS [-d | -a] -h `aria_log_directory`\n",
273284
my_progname_short);
285+
printf("or\n");
286+
printf("Usage: %s OPTIONS -h `aria_log_directory` "
287+
"--print-aria-log-control\n\n",
288+
my_progname_short);
289+
274290
my_print_help(my_long_options);
275291
print_defaults("my", load_default_groups);
276292
my_print_variables(my_long_options);
@@ -339,12 +355,12 @@ static void get_options(int *argc,char ***argv)
339355
need_help= 1;
340356
fprintf(stderr, "Too many arguments given\n");
341357
}
342-
if ((opt_display_only + opt_apply) != 1)
358+
if ((opt_display_only + opt_apply + opt_print_aria_log_control) != 1)
343359
{
344360
need_help= 1;
345361
fprintf(stderr,
346-
"You must use one and only one of the options 'display-only' or "
347-
"'apply'\n");
362+
"You must use one and only one of the options 'display-only', \n"
363+
"'print-log-control-file' and 'apply'\n");
348364
}
349365

350366
if (need_help)

0 commit comments

Comments
 (0)