blib/lib/DBIx/QuickDB/Driver/MariaDB.pm

filter: Statementstmt 93.6% 117 / 125 Branchbran 73.2% 41 / 56 Conditioncond 52.3% 22 / 42 MC/DCmcdc 23.0% 6 / 26 Subroutinesub 95.8% 23 / 24 Podpod 22.2% 2 / 9 totaltotal 74.8% 211 / 282 CC 45 SCAR 26.8
CC
45
Cov
81%
viable
36.4
provider_info
9.3
broken_version_check
7.0
CRAP 14.6
« blib/lib/Test2/Tools/QuickDB.pm ↑ Summary blib/lib/DBIx/QuickDB/Driver/SQLite.pm »
1 package DBIx::QuickDB::Driver::MariaDB;
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 13 our $VERSION = '0.000066';
6  
7 13 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use Capture::Tiny qw/capture/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use File::Basename qw/basename dirname/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 13 ▶use parent 'DBIx::QuickDB::Driver::MySQL';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 ▶use DBIx::QuickDB::Util::HashBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 28 ▶sub provider { 'MariaDB' }
Subroutine provider: called CC=1 SCAR=0.0
Pod undocumented
16  
17 9 ▶sub verify_provider {
Subroutine verify_provider: called CC=3 SCAR=11.1
Pod undocumented
18 9 my $class = shift;
19 9 my ($bin, $provider) = @_;
20  
21 9 ▶ $provider //= $class->provider;
Condition33%1/3
$provider //= $class->provider
l!l&&r!l&&!r
090
MC/DC0%0/2
$provider //= $class->provider
$provider $class->provider
Truth table33%1/3
A //= B
A= $providerB= $class->provider
ABresult
1X1
011
000
22  
23 9 ▶ my ($v, $stderr) = capture { system($bin, '-V') };
Subroutine __ANON__: called CC=1 SCAR=0.0
24 9 ▶ return 1 if $v =~ m/$provider/i;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /$provider/i 3 6 9
25 6 return 0;
26 }
27  
28 14 ▶sub server_bin_list { qw/mariadbd mysqld/ }
Subroutine server_bin_list: called CC=1 SCAR=0.0
Pod undocumented
29 2 ▶sub client_bin_list { qw/mariadb mysql/ }
Subroutine client_bin_list: called CC=1 SCAR=0.0
Pod undocumented
30 13 ▶sub install_bin_list { qw/mariadb-install-db mysql_install_db/ }
Subroutine install_bin_list: called CC=1 SCAR=0.0
Pod undocumented
31  
32 14 ▶sub _install_root {
Subroutine _install_root: called CC=3 SCAR=11.3
33 14 my ($this, $server) = @_;
34 14 ▶ $server //= $this->server_bin;
Condition66%2/3
$server //= $this->server_bin
l!l&&r!l&&!r
1130
MC/DC0%0/2
$server //= $this->server_bin
$server $this->server_bin
Truth table66%2/3
A //= B
A= $serverB= $this->server_bin
ABresult
1X1
011
000
35 14 ▶ return undef unless $server;
Branch: 1 branch
BranchTrueFalseTotal
unless $server 0 14 14
36 14 return dirname(dirname($server));
37 }
38  
39 # MariaDB's relocatable/source-style installs put the server in bin/ but the
40 # installation helper in scripts/. Searching PATH alone can therefore pair a
41 # selected developer/vendor server with an unrelated system helper. Prefer a
42 # helper next to, or under the same installation root as, the selected server.
43 # Packaged installations commonly put both commands in /usr/bin, while
44 # source-style installs use <root>/bin + <root>/scripts.
45 70 ▶sub provider_info {
Subroutine provider_info: called CC=9 SCAR=22.3
46 70 my $this = shift;
47  
48 70 my $info = { %{$this->SUPER::provider_info(@_)} };
49 70 ▶ my $server = $info->{server_bin} or return $info;
Branch: 1 branch
BranchTrueFalseTotal
my $server = $info->{"server_bin"} or return $info 11 59 70
50  
51 11 my $bin_dir = dirname($server);
52 11 my $root = $this->_install_root($server);
53 11 my @names = $this->install_bin_list;
54  
55 11 for my $dir ($bin_dir, File::Spec->catdir($root, 'scripts')) {
56 22 for my $name (@names) {
57 39 my $candidate = File::Spec->catfile($dir, $name);
58 39 ▶ if (-x $candidate) {
Branch: 1 branch
BranchTrueFalseTotal
if (-x $candidate) 5 34 39
59 5 $info->{install_bin} = $candidate;
60 5 return $info;
61 }
62 }
63 }
64  
65 # Retain provider_info's PATH fallback only when it resolves under the
66 # same conventional installation root. A helper from some other MariaDB
67 # installation can silently initialize the datadir with the wrong server
68 # and shipped SQL assets.
69 6 ▶ if (my $helper = $info->{install_bin}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $helper = $info->{"install_bin"}) 6 0 6
70 6 my $helper_dir = dirname($helper);
71 6 ▶ my $helper_root = basename($helper_dir) =~ /^(?:bin|sbin|scripts)$/
Branch: 1 branch
BranchTrueFalseTotal
basename($helper_dir) =~ /^(?:bin|sbin|scripts)$/ ? : 6 0 6
72 ? dirname($helper_dir)
73 : undef;
74 delete $info->{install_bin}
75 6 ▶ unless defined($helper_root) && $helper_root eq $root;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $helper_root and $helper_root eq $root 6 0 6
Condition33%1/3
defined $helper_root and $helper_root eq $root
!ll&&!rl&&r
060
MC/DC0%0/2
defined $helper_root and $helper_root eq $root
defined $helper_root $helper_root eq $root
Truth table33%1/3
A and B
A= defined $helper_rootB= $helper_root eq $root
ABresult
0X0
100
111
76 }
77  
78 6 return $info;
79 }
80  
81 19 ▶sub dbd_driver_order { my $class = shift; $class->SUPER::dbd_driver_order($ENV{QDB_MARIADB_DBD}, $ENV{QDB_MYSQLD_DBD}) }
Subroutine dbd_driver_order: called CC=1 SCAR=0.0
Pod undocumented
82  
83 0 ▶sub list_env_vars {
Subroutine list_env_vars: not called CC=1 SCAR=6.9
Pod documented
84 0 my $self = shift;
85  
86 0 my @list = $self->SUPER::list_env_vars();
87  
88 return (
89 @list,
90 0 map { my $x = "$_"; $x =~ s/MYSQL/MARIADB/g; $x } @list,
91 );
92 }
93  
94 2 ▶sub _default_config {
Subroutine _default_config: called CC=2 SCAR=7.0
95 2 my $self = shift;
96  
97 2 my %config = $self->SUPER::_default_config(@_);
98  
99 2 ▶ if (defined($ENV{QDB_MARIADB_SSL_FIPS})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"QDB_MARIADB_SSL_FIPS"}) 0 2 2
100 0 $config{mysqld}->{'ssl_fips_mode'} = "$ENV{QDB_MARIADB_SSL_FIPS}";
101 }
102  
103 2 $config{mysqld}->{'query_cache_limit'} = '1M';
104 2 $config{mysqld}->{'query_cache_size'} = '20M';
105  
106 2 $config{mariadbd} = $config{mysqld};
107 2 $config{mariadb} = $config{mysql};
108 2 $config{mariadb_safe} = $config{mysql_safe};
109  
110 2 return %config;
111 }
112  
113 # Releases where an information_schema 'table_constraints' or
114 # 'referential_constraints' scan that reaches information_schema's own tables
115 # locks a never-initialized ACL mutex under --skip-grant-tables and blocks
116 # forever: immune to KILL, and it prevents graceful server shutdown. QuickDB
117 # always starts the server with --skip-grant-tables, so these releases are not
118 # safe to use. Broken by upstream MDEV-38209, fixed by MDEV-38811.
119 13 my %BROKEN_IS_ACL_VERSIONS = (
120 '10.11.16' => 'fixed in 10.11.17',
121 '11.4.10' => 'fixed in 11.4.11',
122 '11.8.6' => 'fixed in 11.8.7',
123 '12.2.2' => 'never fixed, 12.2.2 is the final 12.2 release; use another series',
124 '12.3.1' => 'fixed in 12.3.2',
125 );
126  
127 14 ▶sub broken_version_check {
Subroutine broken_version_check: called CC=7 SCAR=19.5
Pod undocumented
128 14 my $this = shift;
129 14 my ($bin) = @_;
130  
131 14 ▶ return undef if $ENV{QDB_MARIADB_IGNORE_BROKEN};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"QDB_MARIADB_IGNORE_BROKEN"} 1 13 14
132 13 ▶ return undef unless $bin && -x $bin;
Branch: 1 branch
BranchTrueFalseTotal
unless $bin and -x $bin 2 11 13
Condition100%3/3
$bin and -x $bin
!ll&&!rl&&r
1111
MC/DC100%2/2
$bin and -x $bin
$bin -x $bin
Truth table100%3/3
A and B
A= $binB= -x $bin
ABresult
0X0
100
111
133  
134 11 ▶ my ($out) = capture { system($bin, '-V') };
Subroutine __ANON__: called CC=1 SCAR=0.0
135 11 ▶ return undef unless $out && $out =~ m/\bVer\s+(\d+\.\d+\.\d+)-MariaDB\b/;
Branch: 1 branch
BranchTrueFalseTotal
unless $out and $out =~ /\bVer\s+(\d+\.\d+\.\d+)-MariaDB\b/ 1 10 11
Condition66%2/3
$out and $out =~ /\bVer\s+(\d+\.\d+\.\d+)-MariaDB\b/
!ll&&!rl&&r
0110
MC/DC50%1/2
$out and $out =~ /\bVer\s+(\d+\.\d+\.\d+)-MariaDB\b/
$out $out =~ /\bVer\s+(\d+\.\d+\.\d+)-MariaDB\b/
Truth table66%2/3
A and B
A= $outB= $out =~ /\bVer\s+(\d+\.\d+\.\d+)-MariaDB\b/
ABresult
0X0
100
111
136  
137 10 my $version = $1;
138 10 ▶ my $fix = $BROKEN_IS_ACL_VERSIONS{$version} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $fix = $BROKEN_IS_ACL_VERSIONS{$version} or return undef 4 6 10
139  
140 4 return "MariaDB $version hangs unkillably on information_schema"
141 . " 'table_constraints' and 'referential_constraints' scans under"
142 . " --skip-grant-tables, which DBIx::QuickDB always uses (upstream bug"
143 . " MDEV-38811; $fix). Set QDB_MARIADB_IGNORE_BROKEN=1 to use this"
144 . " server anyway.";
145 }
146  
147 3 ▶sub _bootstrap_installer_error {
Subroutine _bootstrap_installer_error: called CC=2 SCAR=7.1
148 3 my $this = shift;
149  
150 3 my $root = $this->_install_root;
151  
152 3 ▶ return "No executable 'mariadb-install-db' or 'mysql_install_db' found in the selected MariaDB installation"
Branch: 1 branch
BranchTrueFalseTotal
defined $root ? : 3 0 3
153 . (defined($root) ? " ($root)" : "")
154 . ", needed for bootstrap; helpers from different installations are not used";
155 }
156  
157 23 ▶sub viable {
Subroutine viable: called CC=22 SCAR=35.9
Pod documented
158 23 my $this = shift;
159 23 my ($spec) = @_;
160  
161 23 ▶ my %check = (ref($this) ? %$this : (), $this->_default_paths, %$spec);
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 0 23 23
162  
163 23 my @bad;
164  
165 23 ▶ push @bad => "Could not load either 'DBD::MariaDB' or 'DBD::mysql', needed for everything"
Branch: 1 branch
BranchTrueFalseTotal
unless $this->dbd_driver 19 4 23
166 unless $this->dbd_driver;
167  
168 23 ▶ push @bad => $this->_watcher_unsupported_reason($spec) // ();
Condition66%2/3
$this->_watcher_unsupported_reason($spec) // ()
l!l&&r!l&&!r
1022
MC/DC50%1/2
$this->_watcher_unsupported_reason($spec) // ()
$this->_watcher_unsupported_reason($spec) ()
Truth table66%2/3
A // B
A= $this->_watcher_unsupported_reason($spec)B= ()
ABresult
1X1
011
000
169  
170 23 ▶ if (!keys %{$this->provider_info}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not keys %{$this->provider_info;}) { } 19 4 23
171 19 push @bad => "Installed MySQL is not " . $this->provider;
172 }
173 else {
174 4 ▶ if ($spec->{bootstrap}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($spec->{'bootstrap'}) { } 3 1 4
elsif ($spec->{'autostart'}) { } 1 0 1
175 3 ▶ push @bad => "'mysqld' and 'mariadbd' commands are missing, needed for bootstrap" unless $check{server} && -x $check{server};
Branch: 1 branch
BranchTrueFalseTotal
unless $check{"server"} and -x $check{"server"} 0 3 3
Condition33%1/3
$check{"server"} and -x $check{"server"}
!ll&&!rl&&r
003
MC/DC0%0/2
$check{"server"} and -x $check{"server"}
$check{"server"} -x $check{"server"}
Truth table33%1/3
A and B
A= $check{"server"}B= -x $check{"server"}
ABresult
0X0
100
111
176 3 my $install = $this->install_bin;
177 3 ▶ push @bad => $this->_bootstrap_installer_error
Branch: 1 branch
BranchTrueFalseTotal
unless $install and -x $install 2 1 3
Condition66%2/3
$install and -x $install
!ll&&!rl&&r
201
MC/DC50%1/2
$install and -x $install
$install -x $install
Truth table66%2/3
A and B
A= $installB= -x $install
ABresult
0X0
100
111
178 unless $install && -x $install;
179 }
180 elsif ($spec->{autostart}) {
181 1 ▶ push @bad => "'mysqld' and 'mariadbd' commands are missing, needed for autostart" unless $check{server} && -x $check{server};
Branch: 1 branch
BranchTrueFalseTotal
unless $check{"server"} and -x $check{"server"} 0 1 1
Condition33%1/3
$check{"server"} and -x $check{"server"}
!ll&&!rl&&r
001
MC/DC0%0/2
$check{"server"} and -x $check{"server"}
$check{"server"} -x $check{"server"}
Truth table33%1/3
A and B
A= $check{"server"}B= -x $check{"server"}
ABresult
0X0
100
111
182 }
183  
184 4 ▶ if ($spec->{load_sql}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"load_sql"}) 4 0 4
185 4 ▶ push @bad => "'mysql' and 'mariadb' commands are missing, needed for load_sql" unless $check{client} && -x $check{client};
Branch: 1 branch
BranchTrueFalseTotal
unless $check{"client"} and -x $check{"client"} 0 4 4
Condition33%1/3
$check{"client"} and -x $check{"client"}
!ll&&!rl&&r
004
MC/DC0%0/2
$check{"client"} and -x $check{"client"}
$check{"client"} -x $check{"client"}
Truth table33%1/3
A and B
A= $check{"client"}B= -x $check{"client"}
ABresult
0X0
100
111
186 }
187  
188 4 ▶ if (($spec->{bootstrap} || $spec->{autostart}) && $check{server} && -x $check{server}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"bootstrap"} || $spec->{"autostart"} and $check{"server"} and -x $check{"server"}) 4 0 4
Condition44%4/9
$spec->{"bootstrap"} || $spec->{"autostart"} and $check{"server"} and -x $check{"server"}
!ll&&!rl&&r
004
$spec->{"bootstrap"} || $spec->{"autostart"} and $check{"server"}
!ll&&!rl&&r
004
$spec->{"bootstrap"} or $spec->{"autostart"}
l!l&&r!l&&!r
310
MC/DC0%0/4
$spec->{"bootstrap"} || $spec->{"autostart"} and $check{"server"} and -x $check{"server"}
$spec->{"bootstrap"} $spec->{"autostart"} $check{"server"} -x $check{"server"}
Truth table28%2/7
A or B and C and D
A= $spec->{"bootstrap"}B= $spec->{"autostart"}C= $check{"server"}D= -x $check{"server"}
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
189 4 ▶ if (my $broken = $this->broken_version_check($check{server})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $broken = $this->broken_version_check($check{"server"})) 0 4 4
190 0 push @bad => $broken;
191 }
192 }
193 }
194  
195 23 ▶ return (1, undef) unless @bad;
Branch: 1 branch
BranchTrueFalseTotal
unless @bad 2 21 23
196 21 return (0, join "\n" => @bad);
197 }
198  
199 2 ▶sub bootstrap {
Subroutine bootstrap: called CC=4 SCAR=13.9
200 2 my $self = shift;
201  
202 2 my $install = $self->install_bin;
203 2 ▶ croak $self->_bootstrap_installer_error
Branch: 1 branch
BranchTrueFalseTotal
unless $install and -x $install 1 1 2
Condition66%2/3
$install and -x $install
!ll&&!rl&&r
101
MC/DC50%1/2
$install and -x $install
$install -x $install
Truth table66%2/3
A and B
A= $installB= -x $install
ABresult
0X0
100
111
204 unless $install && -x $install;
205  
206 1 my $init_file = $self->SUPER::bootstrap(@_);
207 1 my $data_dir = $self->{+DATA_DIR};
208 1 my $cfg_file = $self->{+CFG_FILE};
209  
210 # Bootstrap is much faster without InnoDB, we will turn InnoDB back on later, and things will use it.
211 1 $self->write_config(
212 mariadbd => {
213 skip => qr/innodb/i,
214 add => {'default-storage-engine' => 'MyISAM'}
215 },
216 mysqld => {
217 skip => qr/innodb/i,
218 add => {'default-storage-engine' => 'MyISAM'}
219 }
220 );
221  
222 # A bare `mariadbd --bootstrap` with only QuickDB's CREATE DATABASE input
223 # does not create MariaDB's mysql/performance-schema definitions. Older
224 # servers tolerated that for many features, but MariaDB 13.1 requires
225 # mysql.event even for trigger DDL and information_schema.triggers. Use
226 # MariaDB's own installer so every version gets the complete, matching set
227 # of system tables and companion data supplied by that installation.
228 # PERL5LIB can make the vendor script load modules from the application
229 # under test. Keep the helper isolated just as the MySQLCom path does.
230 1 local $ENV{PERL5LIB} = "";
231 1 ▶ my @root = $self->_run_as_root ? ('--user=root') : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->_run_as_root ? : 0 1 1
232 1 $self->run_command(
233 [
234 $install,
235 "--defaults-file=$cfg_file",
236 "--datadir=$data_dir",
237 @root,
238 ]
239 );
240  
241 # Use the existing fast bootstrap for QuickDB's application database (and
242 # portable test-schema cleanup).
243 1 $self->run_command([$self->start_command, '--bootstrap'], {stdin => $init_file});
244  
245 # Turn InnoDB back on
246 1 $self->write_config();
247  
248 1 return;
249 }
250  
251 13 1;
252  
253 __END__
« blib/lib/Test2/Tools/QuickDB.pm ↑ Summary blib/lib/DBIx/QuickDB/Driver/SQLite.pm »