| 1 | package DBIO::Replicated::Pool; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Manage a pool of replicant backends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 14 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 14 | ▶ | use base 'DBIO::Base'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 14 | ▶ | use Scalar::Util 'reftype'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 14 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 14 | ▶ | use DBI (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 14 | ▶ | use DBIO::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 14 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 14 | __PACKAGE__->mk_group_accessors(simple => qw/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | maximum_lag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | last_validated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | replicant_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | storage_class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | next_unknown_replicant_id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | /); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 32 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 32 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | maximum_lag => exists $args{maximum_lag} ? $args{maximum_lag} : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | last_validated => exists $args{last_validated} ? $args{last_validated} : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | replicant_type => $args{replicant_type} || 'DBIO::Replicated::Backend::Replicant', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | storage_class => $args{storage_class} || 'DBIO::Storage::DBI', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | next_unknown_replicant_id => $args{next_unknown_replicant_id} || 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | replicants => $args{replicants} || {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 32 | ▶ | replicant_order => $args{replicant_order} || [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition70%7/10
$args{'replicant_type'} || 'DBIO::Replicated::Backend::Replicant'
$args{'storage_class'} || 'DBIO::Storage::DBI'
$args{'next_unknown_replicant_id'} || 1
$args{'replicants'} || {}
$args{'replicant_order'} || []
MC/DC100%1/1
$args{'replicant_type'} || 'DBIO::Replicated::Backend::Replicant'
$args{'replicant_type'}
MC/DC100%1/1
$args{'storage_class'} || 'DBIO::Storage::DBI'
$args{'storage_class'}
MC/DC0%0/1
$args{'next_unknown_replicant_id'} || 1
$args{'next_unknown_replicant_id'}
MC/DC0%0/1
$args{'replicants'} || {}
$args{'replicants'}
MC/DC0%0/1
$args{'replicant_order'} || []
$args{'replicant_order'}
Truth table100%2/2
A
A= $args{'replicant_type'}
Truth table100%2/2
A
A= $args{'storage_class'}
Truth table50%1/2
A
A= $args{'next_unknown_replicant_id'}
Truth table50%1/2
A
A= $args{'replicants'}
Truth table50%1/2
A
A= $args{'replicant_order'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 32 | ▶ | $self->master($args{master}) if exists $args{master}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 32 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 256 | ▶ | sub master { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
master: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 256 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 256 | ▶ | $self->{master} = $_[0] if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 256 | return $self->{master}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 127 | ▶ | sub replicants { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replicants: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 127 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 127 | ▶ | $self->{replicants} = $_[0] if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 127 | return $self->{replicants}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 46 | ▶ | sub set_replicant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_replicant: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 46 | my ($self, $key, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 46 | push @{ $self->{replicant_order} }, $key | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 46 | ▶ | unless exists $self->replicants->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 46 | return $self->replicants->{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub get_replicant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_replicant: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | return $self->replicants->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | ▶ | sub has_replicants { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_replicants: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | return scalar keys %{ $self->replicants }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub num_replicants { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num_replicants: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | return scalar keys %{ $self->replicants }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub delete_replicant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_replicant: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | $self->{replicant_order} = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | grep { $_ ne $key } @{ $self->{replicant_order} || [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'replicant_order'} || []
MC/DC0%0/1
$self->{'replicant_order'} || []
$self->{'replicant_order'}
Truth table0%0/2
A
A= $self->{'replicant_order'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | return delete $self->replicants->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 18 | ▶ | sub all_replicants { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all_replicants: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 18 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 18 | ▶ | return map { $self->replicants->{$_} } @{ $self->{replicant_order} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'replicant_order'} || []
MC/DC0%0/1
$self->{'replicant_order'} || []
$self->{'replicant_order'}
Truth table50%1/2
A
A= $self->{'replicant_order'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub connected_replicants { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connected_replicants: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return scalar grep { $_->connected } shift->all_replicants; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 17 | ▶ | sub active_replicants { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
active_replicants: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 17 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 17 | return grep { $_->active } $self->all_replicants; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 25 | ▶ | sub connect_replicants { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect_replicants: called CC=15 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 25 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 25 | my $schema = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 25 | my @newly_created; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 25 | foreach my $connect_info (@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 46 | ▶ | $connect_info = [ $connect_info ] if reftype($connect_info) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # A broker-backed replicant ([$broker]) carries no DSN in hand: the DSN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # is resolved from its CredentialSource at connect time. Never reach into | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # its blessed innards looking for dbh_maker/dsn keys. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 46 | my $is_broker = DBIO::Util::is_access_broker($connect_info->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | my $connect_coderef = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | (reftype($connect_info->[0]) || '') eq 'CODE' ? $connect_info->[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 46 | ▶ | : !$is_broker && (reftype($connect_info->[0]) || '') eq 'HASH' && $connect_info->[0]->{dbh_maker}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%10/10
builtin::reftype($connect_info->[0]) || ''
not $is_broker and (builtin::reftype($connect_info->[0]) || "") eq "HASH" and $connect_info->[0]{"dbh_maker"}
not $is_broker and (builtin::reftype($connect_info->[0]) || "") eq "HASH"
builtin::reftype($connect_info->[0]) || ''
MC/DC100%3/3
not $is_broker and (builtin::reftype($connect_info->[0]) || "") eq "HASH" and $connect_info->[0]{"dbh_maker"}
not $is_broker
builtin::reftype($connect_info->[0])
$connect_info->[0]{"dbh_maker"}
Truth table100%4/4
not(A) and B and C
A= not $is_brokerB= builtin::reftype($connect_info->[0])C= $connect_info->[0]{"dbh_maker"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 46 | my $dsn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 46 | my $replicant = do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 14 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 46 | my $connect = \&DBI::connect; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | local *DBI::connect = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $dsn = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | goto $connect; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 46 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 46 | $self->connect_replicant($schema, $connect_info); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 46 | my $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 46 | ▶ | if (!$dsn) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 46 | ▶ | if (!$connect_coderef && !$is_broker) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$connect_coderef || $is_broker
MC/DC100%2/2
$connect_coderef || $is_broker
$connect_coderef
$is_broker
Truth table100%3/3
A || B
A= $connect_coderefB= $is_broker
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 29 | $dsn = $connect_info->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 29 | ▶ | $dsn = $dsn->{dsn} if (reftype($dsn) || '') eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
builtin::reftype($dsn) || ''
MC/DC100%1/1
builtin::reftype($dsn) || ''
builtin::reftype($dsn)
Truth table100%2/2
A
A= builtin::reftype($dsn)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 17 | $key = 'UNKNOWN_' . $self->next_unknown_replicant_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 17 | $self->next_unknown_replicant_id($self->next_unknown_replicant_id + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 46 | ▶ | if ($dsn) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 29 | $replicant->dsn($dsn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 29 | ($key) = ($dsn =~ m/^dbi\:.+\:(.+)$/i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # the name is a pool key (force_pool), shown in traces and messages: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # never a password in it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 29 | ▶ | if (defined $key) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 29 | $key = join ';', grep { !/^\s*(?:password|passwd|pwd)\s*=/i } split /;/, $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 46 | $replicant->id($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 46 | $self->set_replicant($key => $replicant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 46 | push @newly_created, $replicant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 25 | return @newly_created; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 48 | ▶ | sub connect_replicant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect_replicant: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 48 | my ($self, $schema, $connect_info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 48 | my $storage_class = $self->storage_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 48 | $self->ensure_class_loaded($storage_class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 48 | DBIO::Util::assert_class_isa( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | storage_class => $storage_class, 'DBIO::Storage::DBI', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 47 | my $storage = $storage_class->new($schema); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 47 | $storage->connect_info($connect_info); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 47 | ▶ | $storage->_determine_driver if $storage->can('_determine_driver'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 47 | my $replicant_class = $self->replicant_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 47 | $self->ensure_class_loaded($replicant_class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 47 | DBIO::Util::assert_class_isa( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | replicant_type => $replicant_class, 'DBIO::Replicated::Backend::Replicant', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 46 | my $replicant = $replicant_class->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | storage => $storage, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | master => $self->master, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 46 | ▶ | if ($self->master && $self->master->storage && $self->master->storage->debugobj) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self->master and $self->master->storage and $self->master->storage->debugobj
$self->master and $self->master->storage
MC/DC0%0/3
$self->master and $self->master->storage and $self->master->storage->debugobj
$self->master
$self->master->storage
$self->master->storage->debugobj
Truth table25%1/4
A and B and C
A= $self->masterB= $self->master->storageC= $self->master->storage->debugobj
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 46 | $replicant->install_debug_proxy($self->master->storage->debugobj); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 46 | return $replicant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | sub _safely_ensure_connected { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_safely_ensure_connected: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | my ($self, $replicant, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | ▶ | return $self->_safely($replicant, '->ensure_connected', sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | $replicant->ensure_connected(@args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | ▶ | sub _safely { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_safely: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | my ($self, $replicant, $name, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 1 | ▶ | return try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | $code->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # names the replicant by its DSN: never the password in it (karr k297) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | my $info = $replicant->storage->_dbi_connect_info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | $replicant->debugobj->print(DBIO::Util::mask_connect_secrets( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | "Exception trying to $name for replicant %s, error is %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | $info->[0], $_, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | $info, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | sub validate_replicants { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_replicants: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | foreach my $replicant ($self->all_replicants) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if ($self->_safely_ensure_connected($replicant)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $is_replicating = $replicant->is_replicating; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | unless (defined $is_replicating) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $replicant->debugobj->print( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | "Storage Driver " . ref($replicant->storage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | . " does not support 'is_replicating'. Assuming manual management.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | if ($is_replicating) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my $lag_behind_master = $replicant->lag_behind_master; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | unless (defined $lag_behind_master) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $replicant->debugobj->print( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | "Storage Driver " . ref($replicant->storage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | . " does not support 'lag_behind_master'. Assuming manual management.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | $replicant->active($lag_behind_master <= $self->maximum_lag ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $replicant->active(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $replicant->active(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $self->last_validated(time); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 14 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||