| 1 | package Cassandra::Client; | ||||||||||||||||||||||||||||
| 2 | 13 | our $AUTHORITY = 'cpan:TVDW'; | |||||||||||||||||||||||||||
| 3 | 13 | $Cassandra::Client::VERSION = '0.21'; | |||||||||||||||||||||||||||
| 4 | # ABSTRACT: Perl library for accessing Cassandra using its binary network protocol | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use Cassandra::Client::AsyncAnyEvent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 13 | ▶ | use Cassandra::Client::AsyncEV; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use Cassandra::Client::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 13 | ▶ | use Cassandra::Client::Connection; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 13 | ▶ | use Cassandra::Client::Metadata; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 13 | ▶ | use Cassandra::Client::Policy::Queue::Default; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 13 | ▶ | use Cassandra::Client::Policy::Retry::Default; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 13 | ▶ | use Cassandra::Client::Policy::Retry; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 13 | ▶ | use Cassandra::Client::Policy::Throttle::Default; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 13 | ▶ | use Cassandra::Client::Policy::LoadBalancing::Default; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 13 | ▶ | use Cassandra::Client::Pool; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 13 | ▶ | use Cassandra::Client::TLSHandling; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 13 | ▶ | use Cassandra::Client::Util qw/series whilst/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 13 | ▶ | use Clone 0.36 qw/clone/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 13 | ▶ | use List::Util qw/shuffle/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 13 | ▶ | use AnyEvent::XSPromises qw/deferred/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 13 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 13 | ▶ | use Ref::Util 0.008 qw/is_ref/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 13 | ▶ | use Devel::GlobalDestruction 0.11; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 13 | ▶ | use XSLoader; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 13 | ▶ | our $XS_VERSION = ($Cassandra::Client::VERSION || ''); | ||||||||||||||||||||||||||
|
Condition50%1/2
$Cassandra::Client::VERSION || ''
MC/DC0%0/1
$Cassandra::Client::VERSION || ''
$Cassandra::Client::VERSION
Truth table50%1/2
A
A= $Cassandra::Client::VERSION
| |||||||||||||||||||||||||||||
| 33 | 13 | $XS_VERSION =~ s/\A(\d+)\.(\d+)(\d{3})\z/$1.$2_$3/; | |||||||||||||||||||||||||||
| 34 | 13 | XSLoader::load(__PACKAGE__, $XS_VERSION); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 0 | my ($class, %args)= @_; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | my $self= bless { | |||||||||||||||||||||||||||
| 40 | connected => 0, | ||||||||||||||||||||||||||||
| 41 | connect_callbacks => undef, | ||||||||||||||||||||||||||||
| 42 | shutdown => 0, | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | active_queries => 0, | ||||||||||||||||||||||||||||
| 45 | }, $class; | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | my $options= Cassandra::Client::Config->new( | |||||||||||||||||||||||||||
| 48 | \%args | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $self->{throttler}= $options->{throttler} || Cassandra::Client::Policy::Throttle::Default->new(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$options->{'throttler'} || 'Cassandra::Client::Policy::Throttle::Default'->new
MC/DC0%0/2
$options->{'throttler'} || 'Cassandra::Client::Policy::Throttle::Default'->new
$options->{'throttler'}
'Cassandra::Client::Policy::Throttle::Default'->new
Truth table0%0/3
A || B
A= $options->{'throttler'}B= 'Cassandra::Client::Policy::Throttle::Default'->new
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $self->{retry_policy}= $options->{retry_policy} || Cassandra::Client::Policy::Retry::Default->new(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$options->{'retry_policy'} || 'Cassandra::Client::Policy::Retry::Default'->new
MC/DC0%0/2
$options->{'retry_policy'} || 'Cassandra::Client::Policy::Retry::Default'->new
$options->{'retry_policy'}
'Cassandra::Client::Policy::Retry::Default'->new
Truth table0%0/3
A || B
A= $options->{'retry_policy'}B= 'Cassandra::Client::Policy::Retry::Default'->new
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $self->{command_queue}= $options->{command_queue} || Cassandra::Client::Policy::Queue::Default->new(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$options->{'command_queue'} || 'Cassandra::Client::Policy::Queue::Default'->new
MC/DC0%0/2
$options->{'command_queue'} || 'Cassandra::Client::Policy::Queue::Default'->new
$options->{'command_queue'}
'Cassandra::Client::Policy::Queue::Default'->new
Truth table0%0/3
A || B
A= $options->{'command_queue'}B= 'Cassandra::Client::Policy::Queue::Default'->new
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $self->{load_balancing_policy}= $options->{load_balancing_policy} || Cassandra::Client::Policy::LoadBalancing::Default->new(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$options->{'load_balancing_policy'} || 'Cassandra::Client::Policy::LoadBalancing::Default'->new
MC/DC0%0/2
$options->{'load_balancing_policy'} || 'Cassandra::Client::Policy::LoadBalancing::Default'->new
$options->{'load_balancing_policy'}
'Cassandra::Client::Policy::LoadBalancing::Default'->new
Truth table0%0/3
A || B
A= $options->{'load_balancing_policy'}B= 'Cassandra::Client::Policy::LoadBalancing::Default'->new
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my $async_class= $options->{anyevent} ? "Cassandra::Client::AsyncAnyEvent" : "Cassandra::Client::AsyncEV"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | my $async_io= $async_class->new( | |||||||||||||||||||||||||||
| 58 | options => $options, | ||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||
| 60 | 0 | my $metadata= Cassandra::Client::Metadata->new( | |||||||||||||||||||||||||||
| 61 | options => $options, | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | my $pool= Cassandra::Client::Pool->new( | ||||||||||||||||||||||||||||
| 64 | client => $self, | ||||||||||||||||||||||||||||
| 65 | options => $options, | ||||||||||||||||||||||||||||
| 66 | metadata => $metadata, | ||||||||||||||||||||||||||||
| 67 | async_io => $async_io, | ||||||||||||||||||||||||||||
| 68 | load_balancing_policy => $self->{load_balancing_policy}, | ||||||||||||||||||||||||||||
| 69 | 0 | ); | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | my $tls= $options->{tls} ? Cassandra::Client::TLSHandling->new() : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | $self->{options}= $options; | |||||||||||||||||||||||||||
| 73 | 0 | $self->{async_io}= $async_io; | |||||||||||||||||||||||||||
| 74 | 0 | $self->{metadata}= $metadata; | |||||||||||||||||||||||||||
| 75 | 0 | $self->{pool}= $pool; | |||||||||||||||||||||||||||
| 76 | 0 | $self->{tls}= $tls; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | return $self; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub _connect { | ||||||||||||||||||||||||||
|
Subroutine
_connect: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 82 | 0 | my ($self, $callback)= @_; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | return _cb($callback) if $self->{connected}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | return _cb($callback, 'Cannot connect: shutdown() has been called') if $self->{shutdown}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # This is ONLY useful if the user doesn't throw away the C::C object on connect errors. | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if (!$self->{connecting} && (my $error= $self->{throttler}->should_fail())) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $self->{"connecting"} and my $error = $self->{"throttler"}->should_fail
MC/DC0%0/2
not $self->{"connecting"} and my $error = $self->{"throttler"}->should_fail
not $self->{"connecting"}
my $error = $self->{"throttler"}->should_fail
Truth table0%0/3
not(A) and B
A= not $self->{"connecting"}B= my $error = $self->{"throttler"}->should_fail
| |||||||||||||||||||||||||||||
| 88 | 0 | return _cb($callback, $error); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | push @{$self->{connect_callbacks}||=[]}, $callback; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"connect_callbacks"} ||= []
MC/DC0%0/1
$self->{"connect_callbacks"} ||= []
$self->{"connect_callbacks"}
Truth table0%0/2
A
A= $self->{"connect_callbacks"}
| |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ($self->{connecting}++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | return; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | my @contact_points= shuffle @{$self->{options}{contact_points}}; | |||||||||||||||||||||||||||
| 97 | 0 | my $last_error= "No hosts to connect to"; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | my $next_connect; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | $next_connect= sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 101 | 0 | my $contact_point= shift @contact_points; | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | if (!$contact_point) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | delete $self->{connecting}; | |||||||||||||||||||||||||||
| 104 | 0 | undef $next_connect; | |||||||||||||||||||||||||||
| 105 | 0 | _cb($_, "Unable to connect to any Cassandra server. Last error: $last_error") for @{delete $self->{connect_callbacks}}; | |||||||||||||||||||||||||||
| 106 | 0 | return; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | my $connection= Cassandra::Client::Connection->new( | ||||||||||||||||||||||||||||
| 110 | client => $self, | ||||||||||||||||||||||||||||
| 111 | options => $self->{options}, | ||||||||||||||||||||||||||||
| 112 | host => $contact_point, | ||||||||||||||||||||||||||||
| 113 | async_io => $self->{async_io}, | ||||||||||||||||||||||||||||
| 114 | metadata => $self->{metadata}, | ||||||||||||||||||||||||||||
| 115 | 0 | ); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | series([ | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 119 | 0 | my ($next)= @_; | |||||||||||||||||||||||||||
| 120 | 0 | $connection->connect($next); | |||||||||||||||||||||||||||
| 121 | }, | ||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 123 | 0 | my ($next)= @_; | |||||||||||||||||||||||||||
| 124 | 0 | $self->{pool}->init($next, $connection); | |||||||||||||||||||||||||||
| 125 | }, | ||||||||||||||||||||||||||||
| 126 | 0 | ▶ | ], sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 127 | 0 | my $error= shift; | |||||||||||||||||||||||||||
| 128 | 0 | $self->{throttler}->count($error); | |||||||||||||||||||||||||||
| 129 | 0 | ▶ | if ($error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | $last_error= "On $contact_point: $error"; | |||||||||||||||||||||||||||
| 131 | 0 | return $next_connect->(); | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | undef $next_connect; | |||||||||||||||||||||||||||
| 135 | 0 | $self->{connected}= 1; | |||||||||||||||||||||||||||
| 136 | 0 | delete $self->{connecting}; | |||||||||||||||||||||||||||
| 137 | 0 | _cb($_) for @{delete $self->{connect_callbacks}}; | |||||||||||||||||||||||||||
| 138 | 0 | }); | |||||||||||||||||||||||||||
| 139 | 0 | }; | |||||||||||||||||||||||||||
| 140 | 0 | $next_connect->(); | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | return; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub shutdown { | ||||||||||||||||||||||||||
|
Subroutine
shutdown: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 146 | 0 | my ($self)= @_; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | return if $self->{shutdown}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 0 | $self->{shutdown}= 1; | |||||||||||||||||||||||||||
| 150 | 0 | $self->{connected}= 0; | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | $self->{pool}->shutdown; | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | return; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub is_active { | ||||||||||||||||||||||||||
|
Subroutine
is_active: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 158 | 0 | my ($self)= @_; | |||||||||||||||||||||||||||
| 159 | 0 | ▶ | return 0 unless $self->{connected}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 0 | return 1; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | sub _disconnected { | ||||||||||||||||||||||||||
|
Subroutine
_disconnected: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 164 | 0 | my ($self, $connid)= @_; | |||||||||||||||||||||||||||
| 165 | 0 | $self->{pool}->remove($connid); | |||||||||||||||||||||||||||
| 166 | 0 | return; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub _handle_topology_change { | ||||||||||||||||||||||||||
|
Subroutine
_handle_topology_change: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 170 | 0 | my ($self, $change, $ipaddress)= @_; | |||||||||||||||||||||||||||
| 171 | 0 | ▶ | if ($change eq 'NEW_NODE') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 172 | 0 | $self->{pool}->event_added_node($ipaddress); | |||||||||||||||||||||||||||
| 173 | } elsif ($change eq 'REMOVED_NODE') { | ||||||||||||||||||||||||||||
| 174 | 0 | $self->{pool}->event_removed_node($ipaddress); | |||||||||||||||||||||||||||
| 175 | } else { | ||||||||||||||||||||||||||||
| 176 | 0 | warn "Received unknown topology change: $change for $ipaddress"; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | ▶ | sub _handle_status_change { | ||||||||||||||||||||||||||
|
Subroutine
_handle_status_change: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 181 | 0 | my ($self, $change, $ipaddress)= @_; | |||||||||||||||||||||||||||
| 182 | # XXX Ignored, for now | ||||||||||||||||||||||||||||
| 183 | 0 | $self->{pool}->connect_if_needed; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | # Query functions | ||||||||||||||||||||||||||||
| 189 | 0 | ▶ | sub _prepare { | ||||||||||||||||||||||||||
|
Subroutine
_prepare: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 190 | 0 | my ($self, $callback, $query)= @_; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | # Fast path: we're already done | ||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if ($self->{metadata}->is_prepared(\$query)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 0 | return _cb($callback); | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | $self->_command("prepare", $callback, [ $query ]); | |||||||||||||||||||||||||||
| 198 | 0 | return; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | sub _execute { | ||||||||||||||||||||||||||
|
Subroutine
_execute: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 202 | 0 | my ($self, $callback, $query, $params, $attribs)= @_; | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | my $attribs_clone= clone($attribs); | |||||||||||||||||||||||||||
| 205 | 0 | ▶ | $attribs_clone->{consistency} ||= $self->{options}{default_consistency}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$attribs_clone->{"consistency"} ||= $self->{"options"}{"default_consistency"}
MC/DC0%0/2
$attribs_clone->{"consistency"} ||= $self->{"options"}{"default_consistency"}
$attribs_clone->{"consistency"}
$self->{"options"}{"default_consistency"}
Truth table0%0/3
A ||= B
A= $attribs_clone->{"consistency"}B= $self->{"options"}{"default_consistency"}
| |||||||||||||||||||||||||||||
| 206 | 0 | ▶ | $attribs_clone->{idempotent} ||= $self->{options}{default_idempotency}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$attribs_clone->{"idempotent"} ||= $self->{"options"}{"default_idempotency"}
MC/DC0%0/2
$attribs_clone->{"idempotent"} ||= $self->{"options"}{"default_idempotency"}
$attribs_clone->{"idempotent"}
$self->{"options"}{"default_idempotency"}
Truth table0%0/3
A ||= B
A= $attribs_clone->{"idempotent"}B= $self->{"options"}{"default_idempotency"}
| |||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 0 | $self->_command("execute_prepared", $callback, [ \$query, clone($params), $attribs_clone ]); | |||||||||||||||||||||||||||
| 209 | 0 | return; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 0 | ▶ | sub _batch { | ||||||||||||||||||||||||||
|
Subroutine
_batch: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 213 | 0 | my ($self, $callback, $queries, $attribs)= @_; | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | my $attribs_clone= clone($attribs); | |||||||||||||||||||||||||||
| 216 | 0 | ▶ | $attribs_clone->{consistency} ||= $self->{options}{default_consistency}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$attribs_clone->{"consistency"} ||= $self->{"options"}{"default_consistency"}
MC/DC0%0/2
$attribs_clone->{"consistency"} ||= $self->{"options"}{"default_consistency"}
$attribs_clone->{"consistency"}
$self->{"options"}{"default_consistency"}
Truth table0%0/3
A ||= B
A= $attribs_clone->{"consistency"}B= $self->{"options"}{"default_consistency"}
| |||||||||||||||||||||||||||||
| 217 | 0 | ▶ | $attribs_clone->{idempotent} ||= $self->{options}{default_idempotency}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$attribs_clone->{"idempotent"} ||= $self->{"options"}{"default_idempotency"}
MC/DC0%0/2
$attribs_clone->{"idempotent"} ||= $self->{"options"}{"default_idempotency"}
$attribs_clone->{"idempotent"}
$self->{"options"}{"default_idempotency"}
Truth table0%0/3
A ||= B
A= $attribs_clone->{"idempotent"}B= $self->{"options"}{"default_idempotency"}
| |||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 0 | $self->_command("execute_batch", $callback, [ clone($queries), $attribs_clone ]); | |||||||||||||||||||||||||||
| 220 | 0 | return; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 0 | ▶ | sub _wait_for_schema_agreement { | ||||||||||||||||||||||||||
|
Subroutine
_wait_for_schema_agreement: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 224 | 0 | my ($self, $callback)= @_; | |||||||||||||||||||||||||||
| 225 | 0 | $self->_command("wait_for_schema_agreement", $callback, []); | |||||||||||||||||||||||||||
| 226 | 0 | return; | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | # Command queue | ||||||||||||||||||||||||||||
| 231 | 0 | ▶ | sub _command { | ||||||||||||||||||||||||||
|
Subroutine
_command: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 232 | 0 | my ($self, $command, $callback, $args)= @_; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 0 | my $command_info= { | |||||||||||||||||||||||||||
| 235 | start_time => Time::HiRes::time(), | ||||||||||||||||||||||||||||
| 236 | }; | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | goto OVERFLOW if $self->{active_queries} >= $self->{options}{max_concurrent_queries}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 0 | ▶ | goto SLOWPATH if !$self->{connected}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 0 | my $connection= $self->{pool}->get_one; | |||||||||||||||||||||||||||
| 243 | 0 | ▶ | goto SLOWPATH if !$connection; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | ▶ | if (my $error= $self->{throttler}->should_fail()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 0 | return $self->_command_failed($command, $callback, $args, $command_info, $error); | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | $self->{active_queries}++; | |||||||||||||||||||||||||||
| 250 | 0 | ▶ | $connection->$command(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 251 | 0 | my ($error, $result)= @_; | |||||||||||||||||||||||||||
| 252 | 0 | $self->{throttler}->count($error); | |||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 0 | $self->{active_queries}--; | |||||||||||||||||||||||||||
| 255 | 0 | ▶ | $self->_schedule_command_dequeue if $self->{command_queue}{has_any}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 0 | ▶ | return $self->_command_failed($command, $callback, $args, $command_info, $error) if $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 0 | $self->_report_stats($command, $command_info); | |||||||||||||||||||||||||||
| 260 | 0 | return _cb($callback, $error, $result); | |||||||||||||||||||||||||||
| 261 | 0 | }, @$args); | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 0 | return; | |||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 0 | SLOWPATH: | |||||||||||||||||||||||||||
| 266 | return $self->_command_slowpath($command, $callback, $args, $command_info); | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | OVERFLOW: | |||||||||||||||||||||||||||
| 269 | return $self->_command_enqueue($command, $callback, $args, $command_info); | ||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 0 | ▶ | sub _command_slowpath { | ||||||||||||||||||||||||||
|
Subroutine
_command_slowpath: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 273 | 0 | my ($self, $command, $callback, $args, $command_info)= @_; | |||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | 0 | $self->{active_queries}++; | |||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | series([ | ||||||||||||||||||||||||||||
| 278 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 279 | 0 | my ($next)= @_; | |||||||||||||||||||||||||||
| 280 | 0 | $self->_connect($next); | |||||||||||||||||||||||||||
| 281 | 0 | ▶ | }, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 282 | 0 | my ($next)= @_; | |||||||||||||||||||||||||||
| 283 | 0 | $self->{pool}->get_one_cb($next); | |||||||||||||||||||||||||||
| 284 | 0 | ▶ | }, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 285 | 0 | my ($next, $connection)= @_; | |||||||||||||||||||||||||||
| 286 | 0 | ▶ | if (my $error= $self->{throttler}->should_fail()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | 0 | return $next->($error); | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | 0 | $connection->$command($next, @$args); | |||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | 0 | ▶ | ], sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 292 | 0 | my ($error, $result)= @_; | |||||||||||||||||||||||||||
| 293 | 0 | $self->{throttler}->count($error); | |||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | $self->{active_queries}--; | |||||||||||||||||||||||||||
| 296 | 0 | ▶ | $self->_schedule_command_dequeue if $self->{command_queue}{has_any}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 0 | ▶ | return $self->_command_failed($command, $callback, $args, $command_info, $error) if $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 0 | $self->_report_stats($command, $command_info); | |||||||||||||||||||||||||||
| 301 | 0 | return _cb($callback, $error, $result); | |||||||||||||||||||||||||||
| 302 | 0 | }); | |||||||||||||||||||||||||||
| 303 | 0 | return; | |||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 0 | ▶ | sub _command_retry { | ||||||||||||||||||||||||||
|
Subroutine
_command_retry: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 307 | 0 | my ($self, $command, $callback, $args, $command_info)= @_; | |||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 0 | $command_info->{retries}++; | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 0 | my $delay= 0.1 * (2 ** $command_info->{retries}); | |||||||||||||||||||||||||||
| 312 | 0 | ▶ | $self->{async_io}->timer(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if ($self->{active_queries} >= $self->{options}{max_concurrent_queries}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 314 | 0 | $self->_command_enqueue($command, $callback, $args, $command_info); | |||||||||||||||||||||||||||
| 315 | } else { | ||||||||||||||||||||||||||||
| 316 | 0 | $self->_command_slowpath($command, $callback, $args, $command_info); | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | 0 | }, $delay); | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 0 | ▶ | sub _command_failed { | ||||||||||||||||||||||||||
|
Subroutine
_command_failed: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||
| 322 | 0 | my ($self, $command, $callback, $args, $command_info, $error)= @_; | |||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | ▶ | if (is_ref($error)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | 0 | my $retry_decision; | |||||||||||||||||||||||||||
| 326 | 0 | ▶ | my $statement = $command eq 'execute_prepared' ? {idempotent => $args->[2]->{idempotent}} : {}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 0 | ▶ | if ($error->do_retry) { | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 329 | 0 | $retry_decision= Cassandra::Client::Policy::Retry::retry; | |||||||||||||||||||||||||||
| 330 | } elsif ($error->is_request_error) { | ||||||||||||||||||||||||||||
| 331 | 0 | ▶ | $retry_decision= $self->{retry_policy}->on_request_error($statement, undef, $error, ($command_info->{retries}||0)); | ||||||||||||||||||||||||||
|
Condition0%0/2
$command_info->{'retries'} || 0
MC/DC0%0/1
$command_info->{'retries'} || 0
$command_info->{'retries'}
Truth table0%0/2
A
A= $command_info->{'retries'}
| |||||||||||||||||||||||||||||
| 332 | } elsif ($error->isa('Cassandra::Client::Error::WriteTimeoutException')) { | ||||||||||||||||||||||||||||
| 333 | 0 | ▶ | $retry_decision= $self->{retry_policy}->on_write_timeout($statement, $error->cl, $error->write_type, $error->blockfor, $error->received, ($command_info->{retries}||0)); | ||||||||||||||||||||||||||
|
Condition0%0/2
$command_info->{'retries'} || 0
MC/DC0%0/1
$command_info->{'retries'} || 0
$command_info->{'retries'}
Truth table0%0/2
A
A= $command_info->{'retries'}
| |||||||||||||||||||||||||||||
| 334 | } elsif ($error->isa('Cassandra::Client::Error::ReadTimeoutException')) { | ||||||||||||||||||||||||||||
| 335 | 0 | ▶ | $retry_decision= $self->{retry_policy}->on_read_timeout($statement, $error->cl, $error->blockfor, $error->received, $error->data_retrieved, ($command_info->{retries}||0)); | ||||||||||||||||||||||||||
|
Condition0%0/2
$command_info->{'retries'} || 0
MC/DC0%0/1
$command_info->{'retries'} || 0
$command_info->{'retries'}
Truth table0%0/2
A
A= $command_info->{'retries'}
| |||||||||||||||||||||||||||||
| 336 | } elsif ($error->isa('Cassandra::Client::Error::UnavailableException')) { | ||||||||||||||||||||||||||||
| 337 | 0 | ▶ | $retry_decision= $self->{retry_policy}->on_unavailable($statement, $error->cl, $error->required, $error->alive, ($command_info->{retries}||0)); | ||||||||||||||||||||||||||
|
Condition0%0/2
$command_info->{'retries'} || 0
MC/DC0%0/1
$command_info->{'retries'} || 0
$command_info->{'retries'}
Truth table0%0/2
A
A= $command_info->{'retries'}
| |||||||||||||||||||||||||||||
| 338 | } else { | ||||||||||||||||||||||||||||
| 339 | 0 | $retry_decision= Cassandra::Client::Policy::Retry::rethrow; | |||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if ($retry_decision && $retry_decision eq 'retry') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$retry_decision and $retry_decision eq "retry"
MC/DC0%0/2
$retry_decision and $retry_decision eq "retry"
$retry_decision
$retry_decision eq "retry"
Truth table0%0/3
A and B
A= $retry_decisionB= $retry_decision eq "retry"
| |||||||||||||||||||||||||||||
| 343 | 0 | return $self->_command_retry($command, $callback, $args, $command_info); | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 0 | $self->_report_stats($command, $command_info); | |||||||||||||||||||||||||||
| 348 | 0 | return $callback->($error); | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | 0 | ▶ | sub _command_enqueue { | ||||||||||||||||||||||||||
|
Subroutine
_command_enqueue: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 352 | 0 | my ($self, $command, $callback, $args, $command_info)= @_; | |||||||||||||||||||||||||||
| 353 | 0 | ▶ | if (my $error= $self->{command_queue}->enqueue([$command, $callback, $args, $command_info])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 354 | 0 | return $self->_command_failed($command, $callback, $args, $command_info, "Cannot $command: $error"); | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | 0 | return; | |||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 0 | ▶ | sub _schedule_command_dequeue { | ||||||||||||||||||||||||||
|
Subroutine
_schedule_command_dequeue: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 360 | 0 | my ($self)= @_; | |||||||||||||||||||||||||||
| 361 | 0 | ▶ | unless ($self->{command_callback_scheduled}++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 362 | 0 | ▶ | $self->{async_io}->later(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 363 | 0 | delete $self->{command_callback_scheduled}; | |||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 0 | ▶ | while ($self->{command_queue}{has_any} && $self->{active_queries} < $self->{options}{max_concurrent_queries}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"command_queue"}{"has_any"} and $self->{"active_queries"} < $self->{"options"}{"max_concurrent_queries"}
MC/DC0%0/2
$self->{"command_queue"}{"has_any"} and $self->{"active_queries"} < $self->{"options"}{"max_concurrent_queries"}
$self->{"command_queue"}{"has_any"}
$self->{"active_queries"} < $self->{"options"}{"max_concurrent_queries"}
Truth table0%0/3
A and B
A= $self->{"command_queue"}{"has_any"}B= $self->{"active_queries"} < $self->{"options"}{"max_concurrent_queries"}
| |||||||||||||||||||||||||||||
| 366 | 0 | ▶ | my $item= $self->{command_queue}->dequeue or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | 0 | $self->_command_slowpath(@$item); | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | 0 | }); | |||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 0 | ▶ | sub _report_stats { | ||||||||||||||||||||||||||
|
Subroutine
_report_stats: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 374 | 0 | my ($self, $command, $command_info)= @_; | |||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | 0 | $command_info->{end_time}= Time::HiRes::time(); | |||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 0 | ▶ | if (my $stats_hook= $self->{options}{stats_hook}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | _cb($stats_hook, timing => { | ||||||||||||||||||||||||||||
| 380 | command => $command, | ||||||||||||||||||||||||||||
| 381 | start_time => $command_info->{start_time}, | ||||||||||||||||||||||||||||
| 382 | end_time => $command_info->{end_time}, | ||||||||||||||||||||||||||||
| 383 | 0 | }); | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | # Utility functions that wrap query functions | ||||||||||||||||||||||||||||
| 388 | 0 | ▶ | sub _each_page { | ||||||||||||||||||||||||||
|
Subroutine
_each_page: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 389 | 0 | my ($self, $callback, $query, $params, $attribs, $page_callback)= @_; | |||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | 0 | ▶ | my $params_copy= $params ? clone($params) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 392 | 0 | ▶ | my $attribs_copy= $attribs ? clone($attribs) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 0 | my $done= 0; | |||||||||||||||||||||||||||
| 395 | whilst( | ||||||||||||||||||||||||||||
| 396 | 0 | ▶ | sub { !$done }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 397 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 398 | 0 | my $next= shift; | |||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | 0 | ▶ | $self->_execute(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 401 | # Completion handler, with page data (or an error) | ||||||||||||||||||||||||||||
| 402 | 0 | my ($error, $result)= @_; | |||||||||||||||||||||||||||
| 403 | 0 | ▶ | return $next->($error) if $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 0 | my $next_page_id= $result->next_page; | |||||||||||||||||||||||||||
| 406 | 0 | _cb($page_callback, $result); # Note that page_callback doesn't get an error argument, that's intentional | |||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 0 | ▶ | if ($next_page_id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 409 | 0 | $attribs_copy->{page}= $next_page_id; | |||||||||||||||||||||||||||
| 410 | } else { | ||||||||||||||||||||||||||||
| 411 | 0 | $done= 1; | |||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | 0 | return $next->(); | |||||||||||||||||||||||||||
| 414 | 0 | }, $query, $params_copy, $attribs_copy); | |||||||||||||||||||||||||||
| 415 | }, | ||||||||||||||||||||||||||||
| 416 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 417 | 0 | my $error= shift; | |||||||||||||||||||||||||||
| 418 | 0 | return _cb($callback, $error); | |||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | 0 | ); | |||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | 0 | return; | |||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 426 | 0 | local $@; | |||||||||||||||||||||||||||
| 427 | 0 | ▶ | return if in_global_destruction; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | 0 | my $self= shift; | |||||||||||||||||||||||||||
| 430 | 0 | ▶ | if ($self->{connected}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 431 | 0 | $self->shutdown; | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | # Utility functions for callers | ||||||||||||||||||||||||||||
| 437 | 0 | ▶ | sub _get_stacktrace { | ||||||||||||||||||||||||||
|
Subroutine
_get_stacktrace: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 438 | # This gets called a lot. Let's keep it fast. | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | 0 | my $trace= ''; | |||||||||||||||||||||||||||
| 441 | 0 | my ($c, $file, $line)= caller(1); | |||||||||||||||||||||||||||
| 442 | 0 | $trace .= " $c ($file:$line)\n"; | |||||||||||||||||||||||||||
| 443 | 0 | ▶ | ($c, $file, $line)= caller(2) or goto DONE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 444 | 0 | $trace .= " $c ($file:$line)\n"; | |||||||||||||||||||||||||||
| 445 | 0 | ▶ | ($c, $file, $line)= caller(3) or goto DONE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 446 | 0 | $trace .= " $c ($file:$line)\n"; | |||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | 0 | DONE: | |||||||||||||||||||||||||||
| 449 | return $trace; | ||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | 0 | ▶ | sub _cb { | ||||||||||||||||||||||||||
|
Subroutine
_cb: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 453 | 0 | my $cb= shift; | |||||||||||||||||||||||||||
| 454 | eval { | ||||||||||||||||||||||||||||
| 455 | 0 | &$cb; 1 | |||||||||||||||||||||||||||
| 456 | 0 | ▶ | } or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 457 | 0 | ▶ | my $error= $@ || "unknown error"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'unknown error'
MC/DC0%0/1
$@ || 'unknown error'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||
| 458 | 0 | warn "Ignoring unhandled exception in callback: $error"; | |||||||||||||||||||||||||||
| 459 | }; | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | 0 | return; | |||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | 78 | ▶ | sub _mksync { # Translates an asynchronous call into something that looks like Perl | ||||||||||||||||||||||||||
|
Subroutine
_mksync: called CC=1 SCAR=4.1
| |||||||||||||||||||||||||||||
| 465 | 78 | my ($sub)= @_; | |||||||||||||||||||||||||||
| 466 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 467 | 0 | my $self= shift; | |||||||||||||||||||||||||||
| 468 | 0 | $sub->($self, $self->{async_io}->wait(my $w), @_); | |||||||||||||||||||||||||||
| 469 | 0 | my ($err, @output)= $w->(); | |||||||||||||||||||||||||||
| 470 | 0 | ▶ | if ($err) { die $err; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 471 | 0 | return @output; | |||||||||||||||||||||||||||
| 472 | 78 | }; | |||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | 78 | ▶ | sub _mkcall { # Basically _mksync, but returns the error instead of dying | ||||||||||||||||||||||||||
|
Subroutine
_mkcall: called CC=1 SCAR=2.0
| |||||||||||||||||||||||||||||
| 476 | 78 | my ($sub)= @_; | |||||||||||||||||||||||||||
| 477 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 478 | 0 | my $self= shift; | |||||||||||||||||||||||||||
| 479 | 0 | $sub->($self, $self->{async_io}->wait(my $w), @_); | |||||||||||||||||||||||||||
| 480 | 0 | return $w->(); | |||||||||||||||||||||||||||
| 481 | 78 | }; | |||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | 78 | ▶ | sub _mkpromise { | ||||||||||||||||||||||||||
|
Subroutine
_mkpromise: called CC=1 SCAR=4.7
| |||||||||||||||||||||||||||||
| 485 | 78 | my ($sub)= @_; | |||||||||||||||||||||||||||
| 486 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 487 | 0 | my $self= shift; | |||||||||||||||||||||||||||
| 488 | 0 | my $trace= &_get_stacktrace; | |||||||||||||||||||||||||||
| 489 | 0 | my $deferred= deferred; | |||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | 0 | ▶ | $sub->($self, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 492 | 0 | my ($error, @output)= @_; | |||||||||||||||||||||||||||
| 493 | 0 | ▶ | if ($error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 494 | 0 | $deferred->reject("$error\n\nTrace:\n$trace"); | |||||||||||||||||||||||||||
| 495 | } else { | ||||||||||||||||||||||||||||
| 496 | 0 | $deferred->resolve(@output); | |||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||
| 498 | 0 | }, @_); | |||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | 0 | return $deferred->promise; | |||||||||||||||||||||||||||
| 501 | 78 | }; | |||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | 78 | ▶ | sub _mkfuture { | ||||||||||||||||||||||||||
|
Subroutine
_mkfuture: called CC=1 SCAR=4.6
| |||||||||||||||||||||||||||||
| 505 | 78 | my ($sub)= @_; | |||||||||||||||||||||||||||
| 506 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 507 | 0 | my $self= shift; | |||||||||||||||||||||||||||
| 508 | 0 | my $trace= &_get_stacktrace; | |||||||||||||||||||||||||||
| 509 | 0 | $sub->($self, $self->{async_io}->wait(my $w), @_); | |||||||||||||||||||||||||||
| 510 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 511 | 0 | my ($error, @output)= $w->(); | |||||||||||||||||||||||||||
| 512 | 0 | ▶ | if ($error) { die "$error\n\nTrace:\n$trace"; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 513 | 0 | return @output; | |||||||||||||||||||||||||||
| 514 | 0 | }; | |||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||
| 516 | 78 | } | |||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | 78 | ▶ | sub _mkfuture_call { | ||||||||||||||||||||||||||
|
Subroutine
_mkfuture_call: called CC=1 SCAR=2.0
| |||||||||||||||||||||||||||||
| 519 | 78 | my ($sub)= @_; | |||||||||||||||||||||||||||
| 520 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 521 | 0 | my $self= shift; | |||||||||||||||||||||||||||
| 522 | 0 | $sub->($self, $self->{async_io}->wait(my $w), @_); | |||||||||||||||||||||||||||
| 523 | 0 | return $w; | |||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | 78 | } | |||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | PUBLIC_METHODS: { | ||||||||||||||||||||||||||||
| 528 | 13 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 529 | 13 | for (qw/ | |||||||||||||||||||||||||||
| 530 | batch | ||||||||||||||||||||||||||||
| 531 | connect | ||||||||||||||||||||||||||||
| 532 | execute | ||||||||||||||||||||||||||||
| 533 | each_page | ||||||||||||||||||||||||||||
| 534 | prepare | ||||||||||||||||||||||||||||
| 535 | wait_for_schema_agreement | ||||||||||||||||||||||||||||
| 536 | /) { | ||||||||||||||||||||||||||||
| 537 | 78 | *{$_}= _mksync (\&{"_$_"}); | |||||||||||||||||||||||||||
| 538 | 78 | *{"call_$_"}= _mkcall (\&{"_$_"}); | |||||||||||||||||||||||||||
| 539 | 78 | *{"async_$_"}= _mkpromise (\&{"_$_"}); | |||||||||||||||||||||||||||
| 540 | 78 | *{"future_$_"}= _mkfuture (\&{"_$_"}); | |||||||||||||||||||||||||||
| 541 | 78 | *{"future_call_$_"}= _mkfuture_call (\&{"_$_"}); | |||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | 13 | 1; | |||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | __END__ | ||||||||||||||||||||||||||||