MongoDB/Op/_EndTxn.pm

filter: Statementstmt 64.5% 31 / 48 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 81.8% 9 / 11 Podpod 0.0% 0 / 1 totaltotal 56.3% 40 / 71 CC 5 SCAR 23.7
CC
5
Cov
54%
_get_query_maybe_with_write_concern
30.0
execute
2.0
BEGIN
1.0
CRAP 10.7
« MongoDB/Cursor.pm ↑ Summary MongoDB/Op/_BatchInsert.pm »
1 # Copyright 2015 - present MongoDB, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14  
15 59 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 59 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 package MongoDB::Op::_EndTxn;
18  
19 # Encapsulate code path for end transaction commands
20  
21 59 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 59 our $VERSION = 'v2.2.2';
23  
24 59 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 59 ▶use MongoDB::Op::_Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 59 ▶use MongoDB::_Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
28 Document
29 to_IxHash
30 59 );
31 59 ▶use MongoDB::_Constants qw( TXN_WTIMEOUT_RETRY_DEFAULT );
Subroutine BEGIN: called CC=1 SCAR=0.0
32 59 ▶use Types::Standard qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
33 HashRef
34 Maybe
35 Int
36 59 );
37  
38 59 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 59 with $_ for qw(
41 MongoDB::Role::_PrivateConstructor
42 MongoDB::Role::_DatabaseOp
43 MongoDB::Role::_SessionSupport
44 MongoDB::Role::_CommandMonitoring
45 );
46  
47 59 has query => (
48 is => 'ro',
49 required => 1,
50 writer => '_set_query',
51 isa => Document,
52 );
53  
54 0 ▶sub _get_query_maybe_with_write_concern {
Subroutine _get_query_maybe_with_write_concern: not called CC=5 SCAR=34.0
55 0 my ( $self, $topology ) = @_;
56  
57 0 my $query = to_IxHash( $self->query );
58  
59 0 ▶ if ( $self->session->_has_attempted_end_transaction ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->session->_has_attempted_end_transaction) 0 0 0
60 0 my $wc_existing = $self->session->_get_transaction_write_concern;
61 0 my $wc = $wc_existing->as_args->[1];
62  
63 0 ▶ $query->Push( writeConcern => {
Branch: 1 branch
BranchTrueFalseTotal
$wc ? : 0 0 0
64 # allows for an override if set
65 wtimeout => TXN_WTIMEOUT_RETRY_DEFAULT,
66 ( $wc ? %$wc : () ),
67 # must be a majority on retrying
68 w => 'majority',
69 });
70 }
71  
72 # If we've gotten this far and a sharded topology doesnt support
73 # transactions, something has gone seriously wrong
74 0 ▶ if ( $topology eq 'Sharded' && defined $self->session->_recovery_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topology eq "Sharded" and defined $self->session->_recovery_token) 0 0 0
Condition0%0/3
$topology eq "Sharded" and defined $self->session->_recovery_token
!ll&&!rl&&r
000
MC/DC0%0/2
$topology eq "Sharded" and defined $self->session->_recovery_token
$topology eq "Sharded" defined $self->session->_recovery_token
Truth table0%0/3
A and B
A= $topology eq "Sharded"B= defined $self->session->_recovery_token
ABresult
0X0
100
111
75 0 $query->Push( recoveryToken => $self->session->_recovery_token );
76 }
77  
78 0 return $query;
79 }
80  
81 0 ▶sub execute {
Subroutine execute: not called CC=1 SCAR=6.9
Pod undocumented
82 0 my ( $self, $link, $topology ) = @_;
83  
84 0 my $query = $self->_get_query_maybe_with_write_concern( $topology );
85 # Set that an attempt to commit the transaction has been made after getting
86 # query but before execute - stops error unwind losing it
87 0 $self->session->_has_attempted_end_transaction( 1 );
88 my $op = MongoDB::Op::_Command->_new(
89 query_flags => {},
90 query => $query,
91 0 map { $_ => $self->$_ } qw(db_name bson_codec session monitoring_callback)
92 );
93 0 my $result = $op->execute( $link, $topology );
94 0 $result->assert_no_write_concern_error;
95 0 return $result;
96 }
97  
98 59 1;
« MongoDB/Cursor.pm ↑ Summary MongoDB/Op/_BatchInsert.pm »