1# ==== Purpose ==== 2# 3# Get the file name and file size of the last relay log. 4# 5# ==== Usage ==== 6# 7# [--let $rpl_channel_name= NAME] 8# --source include/rpl_get_end_of_relay_log.inc 9# --echo Last relay log: $relay_log_file 10# --echo Size of last relay log: $relay_log_size 11 12--let $include_filename= include/rpl_get_end_of_relay_log.inc 13--source include/begin_include_file.inc 14 15--let _RGEORL_CHANNEL_NAME= $rpl_channel_name 16--let _RGEORL_OUTPUT_FILE= `SELECT CONCAT('$MYSQLTEST_VARDIR/tmp/_end_of_relay_log-', UUID(), '.txt')` 17--let _RGEORL_INDEX_FILE= `SELECT @@GLOBAL.RELAY_LOG_INDEX` 18--let _RGEORL_DATADIR= `SELECT @@GLOBAL.DATADIR` 19if ($rpl_debug) 20{ 21 --echo _RGEORL_OUTPUT_FILE='$_RGEORL_OUTPUT_FILE' 22 --echo _RGEORL_INDEX_FILE='$_RGEORL_INDEX_FILE' 23 --echo _RGEORL_DATADIR='$_RGEORL_DATADIR' 24} 25 26perl; 27 # Compute relay log filename. 28 my $index_file= $ENV{'_RGEORL_INDEX_FILE'}; 29 my $channel_name= $ENV{'_RGEORL_CHANNEL_NAME'}; 30 if ($channel_name) { 31 $index_file =~ s/(.*)(\.index)/$1-$channel_name$2/; 32 } 33 34 # Read relay log filename. 35 open FILE, "$index_file" or die "Error $? opening $index_file: $!"; 36 my $relay_log_file= ''; 37 while (<FILE>) { 38 $relay_log_file= $_; 39 } 40 chomp($relay_log_file); 41 $relay_log_file =~ s{^\.[/\\]}{}; 42 close FILE or die "Error $? closing $index_file: $!"; 43 44 # Get relay log size. 45 my $datadir= $ENV{'_RGEORL_DATADIR'}; 46 my $relay_log_size= (stat("$datadir/$relay_log_file"))[7]; 47 48 # Write output file. 49 my $output_file= $ENV{'_RGEORL_OUTPUT_FILE'}; 50 open FILE, "> $output_file" or die "Error $? opening $output_file: $!"; 51 printf FILE "% 10d%s", $relay_log_size, $relay_log_file or die "Error $? writing to $output_file: $!"; 52 close FILE or die "Error $? writing to $output_file: $!"; 53EOF 54 55# Read output file into mtr variables 56--let $size_and_file= `SELECT LOAD_FILE('$_RGEORL_OUTPUT_FILE')` 57--remove_file $_RGEORL_OUTPUT_FILE 58--let $relay_log_size= `SELECT TRIM(SUBSTR('$size_and_file', 1, 10))` 59--let $relay_log_file= `SELECT TRIM(SUBSTR('$size_and_file', 11))` 60 61if ($rpl_debug) 62{ 63 --echo relay_log_file=$relay_log_file relay_log_size=$relay_log_size 64} 65 66--let $include_filename= include/rpl_get_end_of_relay_log.inc 67--source include/end_include_file.inc 68