| 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 | 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::_KillCursors; | ||||||||||
| 18 | |||||||||||
| 19 | # Encapsulate a cursor kill operation; returns true | ||||||||||
| 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::_Protocol; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 59 | ▶ | use Types::Standard qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | ArrayRef | ||||||||||
| 29 | 59 | ); | |||||||||
| 30 | |||||||||||
| 31 | 59 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | |||||||||||
| 33 | 59 | has cursor_ids => ( | |||||||||
| 34 | is => 'ro', | ||||||||||
| 35 | required => 1, | ||||||||||
| 36 | isa => ArrayRef, | ||||||||||
| 37 | ); | ||||||||||
| 38 | |||||||||||
| 39 | 59 | with $_ for qw( | |||||||||
| 40 | MongoDB::Role::_CollectionOp | ||||||||||
| 41 | MongoDB::Role::_DatabaseOp | ||||||||||
| 42 | MongoDB::Role::_PrivateConstructor | ||||||||||
| 43 | ); | ||||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||
| 46 | 0 | my ( $self, $link ) = @_; | |||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | if ( $link->supports_query_commands ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | # Spec says that failures should be ignored: cursor kills often happen | ||||||||||
| 50 | # via destructors and users can't do anything about failure anyway. | ||||||||||
| 51 | 0 | eval { | |||||||||
| 52 | 0 | MongoDB::Op::_Command->_new( | |||||||||
| 53 | db_name => $self->db_name, | ||||||||||
| 54 | query => [ | ||||||||||
| 55 | killCursors => $self->coll_name, | ||||||||||
| 56 | cursors => $self->cursor_ids, | ||||||||||
| 57 | ], | ||||||||||
| 58 | query_flags => {}, | ||||||||||
| 59 | bson_codec => $self->bson_codec, | ||||||||||
| 60 | session => $self->session, | ||||||||||
| 61 | monitoring_callback => $self->monitoring_callback, | ||||||||||
| 62 | )->execute($link); | ||||||||||
| 63 | }; | ||||||||||
| 64 | } | ||||||||||
| 65 | # Server never sends a reply, so ignoring failure here is automatic. | ||||||||||
| 66 | else { | ||||||||||
| 67 | my ($msg, $request_id) = MongoDB::_Protocol::write_kill_cursors( | ||||||||||
| 68 | 0 | @{ $self->cursor_ids }, | |||||||||
| 69 | ); | ||||||||||
| 70 | |||||||||||
| 71 | 0 | my $start_event; | |||||||||
| 72 | 0 | ▶ | $start_event = $self->_legacy_publish_command_started( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | $link, | ||||||||||
| 74 | $request_id, | ||||||||||
| 75 | ) if $self->monitoring_callback; | ||||||||||
| 76 | 0 | my $start = time; | |||||||||
| 77 | |||||||||||
| 78 | 0 | eval { | |||||||||
| 79 | 0 | $link->write($msg); | |||||||||
| 80 | }; | ||||||||||
| 81 | |||||||||||
| 82 | 0 | my $duration = time - $start; | |||||||||
| 83 | 0 | ▶ | if (my $err = $@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 0 | ▶ | $self->_legacy_publish_command_exception( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | $start_event, | ||||||||||
| 86 | $duration, | ||||||||||
| 87 | $err, | ||||||||||
| 88 | ) if $self->monitoring_callback; | ||||||||||
| 89 | 0 | die $err; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 0 | ▶ | $self->_legacy_publish_command_reply($start_event, $duration) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | if $self->monitoring_callback; | ||||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 0 | return 1; | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 0 | ▶ | sub _legacy_publish_command_started { | ||||||||
|
Subroutine
_legacy_publish_command_started: not called CC=1 SCAR=6.9
| |||||||||||
| 100 | 0 | my ($self, $link, $request_id) = @_; | |||||||||
| 101 | |||||||||||
| 102 | 0 | my %cmd; | |||||||||
| 103 | 0 | tie %cmd, "Tie::IxHash", ( | |||||||||
| 104 | killCursors => $self->coll_name, | ||||||||||
| 105 | cursors => $self->cursor_ids, | ||||||||||
| 106 | ); | ||||||||||
| 107 | |||||||||||
| 108 | 0 | my $event = { | |||||||||
| 109 | type => 'command_started', | ||||||||||
| 110 | databaseName => $self->db_name, | ||||||||||
| 111 | commandName => 'killCursors', | ||||||||||
| 112 | command => \%cmd, | ||||||||||
| 113 | requestId => $request_id, | ||||||||||
| 114 | connectionId => $link->address, | ||||||||||
| 115 | }; | ||||||||||
| 116 | |||||||||||
| 117 | 0 | eval { $self->monitoring_callback->($event) }; | |||||||||
| 118 | |||||||||||
| 119 | 0 | return $event; | |||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | 0 | ▶ | sub _legacy_publish_command_exception { | ||||||||
|
Subroutine
_legacy_publish_command_exception: not called CC=1 SCAR=6.9
| |||||||||||
| 123 | 0 | my ($self, $start_event, $duration, $err) = @_; | |||||||||
| 124 | |||||||||||
| 125 | my $event = { | ||||||||||
| 126 | type => 'command_failed', | ||||||||||
| 127 | databaseName => $start_event->{databaseName}, | ||||||||||
| 128 | commandName => $start_event->{commandName}, | ||||||||||
| 129 | requestId => $start_event->{requestId}, | ||||||||||
| 130 | connectionId => $start_event->{connectionId}, | ||||||||||
| 131 | 0 | durationSecs => $duration, | |||||||||
| 132 | reply => {}, | ||||||||||
| 133 | failure => "$err", | ||||||||||
| 134 | eval_error => $err, | ||||||||||
| 135 | }; | ||||||||||
| 136 | |||||||||||
| 137 | 0 | eval { $self->monitoring_callback->($event) }; | |||||||||
| 138 | |||||||||||
| 139 | 0 | return; | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | 0 | ▶ | sub _legacy_publish_command_reply { | ||||||||
|
Subroutine
_legacy_publish_command_reply: not called CC=1 SCAR=6.9
| |||||||||||
| 143 | 0 | my ($self, $start_event, $duration) = @_; | |||||||||
| 144 | |||||||||||
| 145 | my $event = { | ||||||||||
| 146 | type => 'command_succeeded', | ||||||||||
| 147 | databaseName => $start_event->{databaseName}, | ||||||||||
| 148 | commandName => $start_event->{commandName}, | ||||||||||
| 149 | requestId => $start_event->{requestId}, | ||||||||||
| 150 | connectionId => $start_event->{connectionId}, | ||||||||||
| 151 | 0 | durationSecs => $duration, | |||||||||
| 152 | reply => { | ||||||||||
| 153 | ok => 1, | ||||||||||
| 154 | cursorsUnknown => $self->cursor_ids, | ||||||||||
| 155 | }, | ||||||||||
| 156 | }; | ||||||||||
| 157 | |||||||||||
| 158 | 0 | eval { $self->monitoring_callback->($event) }; | |||||||||
| 159 | |||||||||||
| 160 | 0 | return; | |||||||||
| 161 | } | ||||||||||
| 162 | |||||||||||
| 163 | 59 | 1; | |||||||||