DBIx/QuickDB/Driver/MariaDB.pm

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