| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Licensed to Elasticsearch B.V. under one or more contributor |
|
2
|
|
|
|
|
|
|
# license agreements. See the NOTICE file distributed with |
|
3
|
|
|
|
|
|
|
# this work for additional information regarding copyright |
|
4
|
|
|
|
|
|
|
# ownership. Elasticsearch B.V. licenses this file to you under |
|
5
|
|
|
|
|
|
|
# the Apache License, Version 2.0 (the "License"); you may |
|
6
|
|
|
|
|
|
|
# not use this file except in compliance with the License. |
|
7
|
|
|
|
|
|
|
# You may obtain a copy of the License at |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
|
|
|
|
# |
|
11
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, |
|
12
|
|
|
|
|
|
|
# software distributed under the License is distributed on an |
|
13
|
|
|
|
|
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|
14
|
|
|
|
|
|
|
# KIND, either express or implied. See the License for the |
|
15
|
|
|
|
|
|
|
# specific language governing permissions and limitations |
|
16
|
|
|
|
|
|
|
# under the License. |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Search::Elasticsearch::Transport::Async; |
|
19
|
|
|
|
|
|
|
$Search::Elasticsearch::Transport::Async::VERSION = '7.717'; |
|
20
|
50
|
|
|
50
|
|
727796
|
use Moo; |
|
|
50
|
|
|
|
|
129
|
|
|
|
50
|
|
|
|
|
266
|
|
|
21
|
|
|
|
|
|
|
with 'Search::Elasticsearch::Role::Is_Async', |
|
22
|
|
|
|
|
|
|
'Search::Elasticsearch::Role::Transport'; |
|
23
|
|
|
|
|
|
|
|
|
24
|
50
|
|
|
50
|
|
13630
|
use Time::HiRes qw(time); |
|
|
50
|
|
|
|
|
100
|
|
|
|
50
|
|
|
|
|
336
|
|
|
25
|
50
|
|
|
50
|
|
4916
|
use Search::Elasticsearch::Util qw(upgrade_error); |
|
|
50
|
|
|
|
|
122
|
|
|
|
50
|
|
|
|
|
355
|
|
|
26
|
50
|
|
|
50
|
|
13169
|
use Promises qw(deferred); |
|
|
50
|
|
|
|
|
99
|
|
|
|
50
|
|
|
|
|
294
|
|
|
27
|
50
|
|
|
50
|
|
9519
|
use namespace::clean; |
|
|
50
|
|
|
|
|
93
|
|
|
|
50
|
|
|
|
|
320
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#=================================== |
|
30
|
|
|
|
|
|
|
sub perform_request { |
|
31
|
|
|
|
|
|
|
#=================================== |
|
32
|
160
|
|
|
160
|
1
|
115979
|
my $self = shift; |
|
33
|
160
|
|
|
|
|
569
|
my $params = $self->tidy_request(@_); |
|
34
|
160
|
|
|
|
|
3600
|
my $pool = $self->cxn_pool; |
|
35
|
160
|
|
|
|
|
363
|
my $logger = $self->logger; |
|
36
|
|
|
|
|
|
|
|
|
37
|
160
|
|
|
|
|
449
|
my $deferred = deferred; |
|
38
|
|
|
|
|
|
|
|
|
39
|
160
|
|
|
|
|
1884
|
my ( $start, $cxn ); |
|
40
|
|
|
|
|
|
|
$pool->next_cxn |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# perform request |
|
43
|
|
|
|
|
|
|
->then( |
|
44
|
|
|
|
|
|
|
sub { |
|
45
|
148
|
|
|
148
|
|
11423
|
$cxn = shift; |
|
46
|
148
|
|
|
|
|
383
|
$start = time(); |
|
47
|
148
|
|
|
|
|
2838
|
$cxn->perform_request($params); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
) |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# log request regardless of success/failure |
|
52
|
160
|
|
|
160
|
|
56613
|
->finally( sub { $logger->trace_request( $cxn, $params ) } ) |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
->done( |
|
55
|
|
|
|
|
|
|
# request succeeded |
|
56
|
|
|
|
|
|
|
sub { |
|
57
|
114
|
|
|
114
|
|
17270
|
my ( $code, $response ) = @_; |
|
58
|
114
|
|
|
|
|
409
|
$pool->request_ok($cxn); |
|
59
|
114
|
|
|
|
|
4426
|
$logger->trace_response( $cxn, $code, $response, |
|
60
|
|
|
|
|
|
|
time() - $start ); |
|
61
|
114
|
|
|
|
|
4660
|
$deferred->resolve($response); |
|
62
|
|
|
|
|
|
|
}, |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# request failed |
|
65
|
|
|
|
|
|
|
sub { |
|
66
|
46
|
|
|
46
|
|
6300
|
my $error = upgrade_error( shift(), { request => $params } ); |
|
67
|
46
|
100
|
|
|
|
464
|
if ( $pool->request_failed( $cxn, $error ) ) { |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# log failed, then retry |
|
70
|
19
|
|
|
|
|
3485
|
$logger->debugf( "[%s] %s", $cxn->stringify, "$error" ); |
|
71
|
19
|
|
|
|
|
1092
|
$logger->info('Retrying request on a new cxn'); |
|
72
|
|
|
|
|
|
|
return $self->perform_request($params)->done( |
|
73
|
9
|
|
|
|
|
368
|
sub { $deferred->resolve(@_) }, |
|
74
|
10
|
|
|
|
|
399
|
sub { $deferred->reject(@_) } |
|
75
|
19
|
|
|
|
|
445
|
); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
27
|
100
|
|
|
|
2436
|
if ($cxn) { |
|
78
|
15
|
|
|
|
|
88
|
$logger->trace_request( $cxn, $params ); |
|
79
|
15
|
|
|
|
|
587
|
$logger->trace_error( $cxn, $error ); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
27
|
100
|
|
|
|
592
|
$error->is('NoNodes') |
|
82
|
|
|
|
|
|
|
? $logger->critical($error) |
|
83
|
|
|
|
|
|
|
: $logger->error($error); |
|
84
|
27
|
|
|
|
|
1190
|
$deferred->reject($error); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
160
|
|
|
|
|
1311
|
); |
|
87
|
160
|
|
|
|
|
5456
|
return $deferred->promise; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#ABSTRACT: Provides async interface between the client class and the Elasticsearch cluster |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |