File: print_ddl_recovery_log.pl.in

package info (click to toggle)
mariadb 1%3A11.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 772,520 kB
  • sloc: ansic: 2,414,714; cpp: 1,791,394; asm: 381,336; perl: 62,905; sh: 49,647; pascal: 40,897; java: 39,363; python: 20,791; yacc: 20,432; sql: 17,907; xml: 12,344; ruby: 8,544; cs: 6,542; makefile: 6,145; ada: 1,879; lex: 1,193; javascript: 996; objc: 80; tcl: 73; awk: 46; php: 22
file content (120 lines) | stat: -rwxr-xr-x 3,587 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!@PERL_PATH@
use warnings;
use Fcntl qw(:seek);
use Getopt::Long;

# Constants based on the source
use constant {
    BLOCK_SIZE               => 4096,
    DDL_LOG_ACTION_TYPE_POS  => 1,
    DDL_LOG_PHASE_POS        => 2,
    DDL_LOG_NEXT_ENTRY_POS   => 4,
    DDL_LOG_FLAG_POS         => 8,
    DDL_LOG_XID_POS          => 10,
    DDL_LOG_UUID_POS         => 18,
    MY_UUID_SIZE             => 16,
    DDL_LOG_ID_POS           => 34,
    DDL_LOG_END_POS          => 42,
    NAME_START_POS           => 56,
};

package main;

my @log_entrys= ("Unknown", "EXECUTE", "ENTRY", "IGNORED" );
my @log_actions= ("Unknown", "DELETE_FRM", "RENAME_FRM", "REPLACE", "EXCHANGE",
                  "RENAME_TABLE", "RENAME_VIEW", "DROP_INIT", "DROP_TABLE",
                  "DROP_VIEW", "DROP_TRIGGER", "DROP_DB", "CREATE_TABLE",
                  "CREATE_VIEW", "DELETE_TMP_FILE", "CREATE_TRIGGER",
                  "ALTER_TABLE", "STORE_QUERY");

$opt_skip_not_used= undef;
$opt_skip_ignored= undef;

sub usage
{
    print <<EOF;
Usage $0 [OPTIONS] path-to-MariaDB-ddl_recovery.log

Print the content of the MariaDB ddl_recovery.log.
One can also just provide the directory for the ddl_recover.log.

Options:
--skip-not-used\tSkip not used ddl log entries
--skip-ignored\tSkip ignored ddl log entries
EOF
    exit 0;
}

GetOptions("skip-not-used", "skip-ignored") or usage();

my $file = shift;
my $fh;

if (!defined($file))
{
    usage();
}

if (-d $file)
{
    $file= $file . "/ddl_recovery.log";
}

open $fh, '<:raw', $file or die "Cannot open $file: $!";

# Skip header block
exit 0 if (!read($fh, my $block, BLOCK_SIZE));

my $entry_num = 1;

while (read($fh, my $block, BLOCK_SIZE)) {

    my $entry_type    = unpack("C", substr($block, 0, 1));
    my $action_type   = unpack("C", substr($block, DDL_LOG_ACTION_TYPE_POS, 1));
    my $phase         = unpack("C", substr($block, DDL_LOG_PHASE_POS, 1));
    my $next_entry    = unpack("V", substr($block, DDL_LOG_NEXT_ENTRY_POS, 4));
    my $flags         = unpack("v", substr($block, DDL_LOG_FLAG_POS, 2));
    my $xid           = unpack("Q<", substr($block, DDL_LOG_XID_POS, 8));
    my $uuid_bin      = substr($block, DDL_LOG_UUID_POS, MY_UUID_SIZE);
    my $unique_id     = unpack("Q<", substr($block, DDL_LOG_ID_POS, 8));

    my $uuid = unpack("H8H4H4H4H12", $uuid_bin);
    $uuid = join('-', $uuid =~ /(.{8})(.{4})(.{4})(.{4})(.{12})/);

    my $pos = NAME_START_POS;
    my @strings;
    for (1..7) {
        my ($str, $len);
        $len = unpack("v", substr($block, $pos, 2));
        $pos += 2;
        last if ($pos + $len > BLOCK_SIZE);
        $str = substr($block, $pos, $len);
        $pos += $len+1;
        push @strings, $str;
    }

    print "\n" if ($entry_num > 1);
    print "=== DDL Log Entry $entry_num ===\n";
    $entry_num++;

    print "Entry Type     : $log_entrys[$entry_type]\n";
    next if ($opt_skip_not_used && $entry_type == 0);
    next if ($opt_skip_ignored && $entry_type >= 3);

    print "Action Type    : $log_actions[$action_type]\n";
    print "Phase          : $phase\n";
    print "Next Entry     : $next_entry\n";
    print "Flags          : $flags\n";
    print "XID            : $xid\n";
    print "UUID           : $uuid\n";
    print "Unique ID      : $unique_id\n";
    print "Handler Name   : $strings[0]\n";
    print "DB             : $strings[1]\n";
    print "Name           : $strings[2]\n";
    print "From Handler   : $strings[3]\n";
    print "From DB        : $strings[4]\n";
    print "From Name      : $strings[5]\n";
    print "Temp/Extra     : $strings[6]\n";
}

close $fh;