@@ -608,4 +608,124 @@ my_bool ma_control_file_inited(void)
608
608
return (control_file_fd >= 0 );
609
609
}
610
610
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
+
611
731
#endif /* EXTRACT_DEFINITIONS */
0 commit comments