line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
59
|
|
407
|
use strict; |
|
59
|
|
|
|
|
134
|
|
|
59
|
|
|
|
|
1730
|
|
16
|
59
|
|
|
59
|
|
330
|
use warnings; |
|
59
|
|
|
|
|
147
|
|
|
59
|
|
|
|
|
2169
|
|
17
|
|
|
|
|
|
|
package MongoDB::Op::_CreateIndexes; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Encapsulate index creation operations; returns a MongoDB::CommandResult |
20
|
|
|
|
|
|
|
# or a MongoDB::InsertManyResult, depending on the server version |
21
|
|
|
|
|
|
|
|
22
|
59
|
|
|
59
|
|
321
|
use version; |
|
59
|
|
|
|
|
175
|
|
|
59
|
|
|
|
|
332
|
|
23
|
|
|
|
|
|
|
our $VERSION = 'v2.2.1'; |
24
|
|
|
|
|
|
|
|
25
|
59
|
|
|
59
|
|
5008
|
use Moo; |
|
59
|
|
|
|
|
166
|
|
|
59
|
|
|
|
|
331
|
|
26
|
|
|
|
|
|
|
|
27
|
59
|
|
|
59
|
|
18962
|
use MongoDB::Op::_Command; |
|
59
|
|
|
|
|
181
|
|
|
59
|
|
|
|
|
2105
|
|
28
|
59
|
|
|
59
|
|
25061
|
use MongoDB::Op::_BatchInsert; |
|
59
|
|
|
|
|
214
|
|
|
59
|
|
|
|
|
2406
|
|
29
|
59
|
|
|
|
|
490
|
use Types::Standard qw( |
30
|
|
|
|
|
|
|
ArrayRef |
31
|
|
|
|
|
|
|
HashRef |
32
|
59
|
|
|
59
|
|
448
|
); |
|
59
|
|
|
|
|
144
|
|
33
|
59
|
|
|
|
|
388
|
use MongoDB::_Types qw( |
34
|
|
|
|
|
|
|
Numish |
35
|
59
|
|
|
59
|
|
53868
|
); |
|
59
|
|
|
|
|
147
|
|
36
|
|
|
|
|
|
|
|
37
|
59
|
|
|
59
|
|
56069
|
use namespace::clean; |
|
59
|
|
|
|
|
154
|
|
|
59
|
|
|
|
|
304
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has indexes => ( |
40
|
|
|
|
|
|
|
is => 'ro', |
41
|
|
|
|
|
|
|
required => 1, |
42
|
|
|
|
|
|
|
isa => ArrayRef [HashRef], |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has max_time_ms => ( |
46
|
|
|
|
|
|
|
is => 'ro', |
47
|
|
|
|
|
|
|
isa => Numish, |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
with $_ for qw( |
51
|
|
|
|
|
|
|
MongoDB::Role::_PrivateConstructor |
52
|
|
|
|
|
|
|
MongoDB::Role::_CollectionOp |
53
|
|
|
|
|
|
|
MongoDB::Role::_WriteOp |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub has_collation { |
57
|
0
|
|
|
0
|
0
|
|
return grep { defined $_->{collation} } @{ $_[0]->indexes }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub execute { |
61
|
0
|
|
|
0
|
0
|
|
my ( $self, $link ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
0
|
|
|
|
if ( $self->has_collation && !$link->supports_collation ) { |
64
|
0
|
|
|
|
|
|
MongoDB::UsageError->throw( |
65
|
|
|
|
|
|
|
"MongoDB host '" . $link->address . "' doesn't support collation" ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
my $res = |
69
|
|
|
|
|
|
|
$link->supports_write_commands |
70
|
|
|
|
|
|
|
? $self->_command_create_indexes($link) |
71
|
|
|
|
|
|
|
: $self->_legacy_index_insert($link); |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return $res; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _command_create_indexes { |
77
|
0
|
|
|
0
|
|
|
my ( $self, $link, $op_doc ) = @_; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $op = MongoDB::Op::_Command->_new( |
80
|
|
|
|
|
|
|
db_name => $self->db_name, |
81
|
|
|
|
|
|
|
query => [ |
82
|
|
|
|
|
|
|
createIndexes => $self->coll_name, |
83
|
|
|
|
|
|
|
indexes => $self->indexes, |
84
|
0
|
0
|
|
|
|
|
( $link->supports_helper_write_concern ? ( @{ $self->write_concern->as_args } ) : () ), |
|
0
|
0
|
|
|
|
|
|
85
|
|
|
|
|
|
|
(defined($self->max_time_ms) |
86
|
|
|
|
|
|
|
? (maxTimeMS => $self->max_time_ms) |
87
|
|
|
|
|
|
|
: () |
88
|
|
|
|
|
|
|
), |
89
|
|
|
|
|
|
|
], |
90
|
|
|
|
|
|
|
query_flags => {}, |
91
|
|
|
|
|
|
|
bson_codec => $self->bson_codec, |
92
|
|
|
|
|
|
|
monitoring_callback => $self->monitoring_callback, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $res = $op->execute( $link ); |
96
|
0
|
|
|
|
|
|
$res->assert_no_write_concern_error; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return $res; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _legacy_index_insert { |
102
|
0
|
|
|
0
|
|
|
my ( $self, $link, $op_doc ) = @_; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# construct docs for an insert many op |
105
|
0
|
|
|
|
|
|
my $ns = join( ".", $self->db_name, $self->coll_name ); |
106
|
|
|
|
|
|
|
my $indexes = [ |
107
|
|
|
|
|
|
|
map { |
108
|
0
|
|
|
|
|
|
{ %$_, ns => $ns } |
109
|
0
|
|
|
|
|
|
} @{ $self->indexes } |
|
0
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
]; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $op = MongoDB::Op::_BatchInsert->_new( |
113
|
|
|
|
|
|
|
db_name => $self->db_name, |
114
|
|
|
|
|
|
|
coll_name => "system.indexes", |
115
|
|
|
|
|
|
|
full_name => ( join ".", $self->db_name, "system.indexes" ), |
116
|
|
|
|
|
|
|
documents => $indexes, |
117
|
|
|
|
|
|
|
write_concern => $self->write_concern, |
118
|
|
|
|
|
|
|
bson_codec => $self->bson_codec, |
119
|
|
|
|
|
|
|
check_keys => 0, |
120
|
|
|
|
|
|
|
ordered => 1, |
121
|
|
|
|
|
|
|
monitoring_callback => $self->monitoring_callback, |
122
|
|
|
|
|
|
|
); |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return $op->execute($link); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |