| 1 | # Copyright 2014 - 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 | 60 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 60 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | package MongoDB::Op::_Command; | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | # Encapsulate running a command and returning a MongoDB::CommandResult | ||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 60 | ▶ | use version; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | 60 | our $VERSION = 'v2.2.2'; | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 60 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 60 | ▶ | use MongoDB::_Constants; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 27 | 60 | ▶ | use MongoDB::_Types qw( | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 28 | Document | ||||||||||||||||||||||||||||||||
| 29 | ReadPreference | ||||||||||||||||||||||||||||||||
| 30 | to_IxHash | ||||||||||||||||||||||||||||||||
| 31 | 60 | ); | |||||||||||||||||||||||||||||||
| 32 | 60 | ▶ | use List::Util qw/first/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 33 | 60 | ▶ | use Types::Standard qw( | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 34 | CodeRef | ||||||||||||||||||||||||||||||||
| 35 | HashRef | ||||||||||||||||||||||||||||||||
| 36 | Maybe | ||||||||||||||||||||||||||||||||
| 37 | InstanceOf | ||||||||||||||||||||||||||||||||
| 38 | 60 | ); | |||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 60 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 60 | has query => ( | |||||||||||||||||||||||||||||||
| 43 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 44 | required => 1, | ||||||||||||||||||||||||||||||||
| 45 | writer => '_set_query', | ||||||||||||||||||||||||||||||||
| 46 | isa => Document, | ||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 60 | has query_flags => ( | |||||||||||||||||||||||||||||||
| 50 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 51 | required => 1, | ||||||||||||||||||||||||||||||||
| 52 | isa => HashRef, | ||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 60 | has read_preference => ( | |||||||||||||||||||||||||||||||
| 56 | # Needs to be rw for transactions | ||||||||||||||||||||||||||||||||
| 57 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 58 | isa => Maybe [ReadPreference], | ||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 60 | with $_ for qw( | |||||||||||||||||||||||||||||||
| 62 | MongoDB::Role::_PrivateConstructor | ||||||||||||||||||||||||||||||||
| 63 | MongoDB::Role::_DatabaseOp | ||||||||||||||||||||||||||||||||
| 64 | MongoDB::Role::_ReadPrefModifier | ||||||||||||||||||||||||||||||||
| 65 | MongoDB::Role::_SessionSupport | ||||||||||||||||||||||||||||||||
| 66 | MongoDB::Role::_CommandMonitoring | ||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 60 | my %IS_NOT_COMPRESSIBLE = map { ($_ => 1) } qw( | |||||||||||||||||||||||||||||||
| 70 | ismaster | ||||||||||||||||||||||||||||||||
| 71 | saslstart | ||||||||||||||||||||||||||||||||
| 72 | saslcontinue | ||||||||||||||||||||||||||||||||
| 73 | getnonce | ||||||||||||||||||||||||||||||||
| 74 | authenticate | ||||||||||||||||||||||||||||||||
| 75 | createuser | ||||||||||||||||||||||||||||||||
| 76 | updateuser | ||||||||||||||||||||||||||||||||
| 77 | copydbsaslstart | ||||||||||||||||||||||||||||||||
| 78 | copydbgetnonce | ||||||||||||||||||||||||||||||||
| 79 | copydb | ||||||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 83 | 0 | my ( $self, $link, $topology_type ) = @_; | |||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $topology_type ||= 'Single'; # if not specified, assume direct | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$topology_type ||= "Single"
MC/DC0%0/1
$topology_type ||= "Single"
$topology_type
Truth table0%0/2
A
A= $topology_type
| |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 0 | $self->_apply_session_and_cluster_time( $link, \$self->{query} ); | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 0 | my ( $op_bson, $request_id ); | |||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ( $link->supports_op_msg ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 91 | # $query is passed as a reference because it *may* be replaced | ||||||||||||||||||||||||||||||||
| 92 | 0 | $self->_apply_op_msg_read_prefs( $link, $topology_type, $self->{query_flags}, \$self->{query}); | |||||||||||||||||||||||||||||||
| 93 | 0 | $self->{query} = to_IxHash( $self->{query} ); | |||||||||||||||||||||||||||||||
| 94 | 0 | $self->{query}->Push( '$db', $self->db_name ); | |||||||||||||||||||||||||||||||
| 95 | ( $op_bson, $request_id ) = | ||||||||||||||||||||||||||||||||
| 96 | 0 | MongoDB::_Protocol::write_msg( $self->{bson_codec}, undef, $self->{query} ); | |||||||||||||||||||||||||||||||
| 97 | } else { | ||||||||||||||||||||||||||||||||
| 98 | # $query is passed as a reference because it *may* be replaced | ||||||||||||||||||||||||||||||||
| 99 | 0 | $self->_apply_op_query_read_prefs( $link, $topology_type, $self->{query_flags}, \$self->{query}); | |||||||||||||||||||||||||||||||
| 100 | ( $op_bson, $request_id ) = | ||||||||||||||||||||||||||||||||
| 101 | MongoDB::_Protocol::write_query( $self->{db_name} . '.$cmd', | ||||||||||||||||||||||||||||||||
| 102 | 0 | $self->{bson_codec}->encode_one( $self->{query} ), undef, 0, -1, $self->{query_flags}); | |||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ( length($op_bson) > MAX_BSON_WIRE_SIZE ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 106 | # XXX should this become public? | ||||||||||||||||||||||||||||||||
| 107 | 0 | MongoDB::_CommandSizeError->throw( | |||||||||||||||||||||||||||||||
| 108 | message => "database command too large", | ||||||||||||||||||||||||||||||||
| 109 | size => length $op_bson, | ||||||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $self->publish_command_started( $link, $self->{query}, $request_id ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 114 | if $self->monitoring_callback; | ||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | my %write_opt = ( | ||||||||||||||||||||||||||||||||
| 117 | 0 | disable_compression => $IS_NOT_COMPRESSIBLE{ _get_command_name( $self->{query} ) }, | |||||||||||||||||||||||||||||||
| 118 | ); | ||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 0 | my $result; | |||||||||||||||||||||||||||||||
| 121 | 0 | eval { | |||||||||||||||||||||||||||||||
| 122 | 0 | $link->write( $op_bson, \%write_opt ), | |||||||||||||||||||||||||||||||
| 123 | ( $result = MongoDB::_Protocol::parse_reply( $link->read, $request_id ) ); | ||||||||||||||||||||||||||||||||
| 124 | }; | ||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if ( my $err = $@ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 126 | 0 | $self->_update_session_connection_error( $err ); | |||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $self->publish_command_exception($err) if $self->monitoring_callback; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 128 | 0 | die $err; | |||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | $self->publish_command_reply( $result->{docs} ) | ||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if $self->monitoring_callback; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | my $res = MongoDB::CommandResult->_new( | ||||||||||||||||||||||||||||||||
| 135 | 0 | output => $self->{bson_codec}->decode_one( $result->{docs} ), | |||||||||||||||||||||||||||||||
| 136 | address => $link->address, | ||||||||||||||||||||||||||||||||
| 137 | session => $self->session, | ||||||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 0 | $self->_update_session_pre_assert( $res ); | |||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | 0 | $res->assert; | |||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 0 | $self->_update_session_and_cluster_time($res); | |||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | 0 | $self->_assert_session_errors($res); | |||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | 0 | return $res; | |||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | sub _get_command_name { | ||||||||||||||||||||||||||||||
|
Subroutine
_get_command_name: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 152 | 0 | my ($doc) = @_; | |||||||||||||||||||||||||||||||
| 153 | 0 | my $type = ref $doc; | |||||||||||||||||||||||||||||||
| 154 | return | ||||||||||||||||||||||||||||||||
| 155 | $type eq 'ARRAY' || $type eq 'BSON::Doc' ? $doc->[0] | ||||||||||||||||||||||||||||||||
| 156 | : $type eq 'Tie::IxHash' ? $doc->Keys(0) | ||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | : $doc->{ [ keys %$doc ]->[0] }; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$type eq "ARRAY" or $type eq "BSON::Doc"
MC/DC0%0/2
$type eq "ARRAY" or $type eq "BSON::Doc"
$type eq "ARRAY"
$type eq "BSON::Doc"
Truth table0%0/3
A or B
A= $type eq "ARRAY"B= $type eq "BSON::Doc"
| |||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | 60 | 1; | |||||||||||||||||||||||||||||||