| 1 | # OpenSearch::Client is an unofficial client for OpenSearch. | ||||||||||
| 2 | # It is derived from Search::Elasticsearch version 7.714 | ||||||||||
| 3 | # License details from the original work are contained in the | ||||||||||
| 4 | # NOTICE file distributed with this work. | ||||||||||
| 5 | # | ||||||||||
| 6 | #----------------------------------------------------------------------- | ||||||||||
| 7 | # OpenSearch::Client | ||||||||||
| 8 | #----------------------------------------------------------------------- | ||||||||||
| 9 | # Copyright 2026 Mark Dootson | ||||||||||
| 10 | # | ||||||||||
| 11 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||
| 12 | # you may not use this file except in compliance with the License. | ||||||||||
| 13 | # You may obtain a copy of the License at | ||||||||||
| 14 | # | ||||||||||
| 15 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||
| 16 | # | ||||||||||
| 17 | # Unless required by applicable law or agreed to in writing, software | ||||||||||
| 18 | # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||
| 19 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||
| 20 | # See the License for the specific language governing permissions and | ||||||||||
| 21 | # limitations under the License. | ||||||||||
| 22 | |||||||||||
| 23 | package OpenSearch::Client::CxnPool::Sniff; | ||||||||||
| 24 | 11 | $OpenSearch::Client::CxnPool::Sniff::VERSION = '3.007011'; | |||||||||
| 25 | 11 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 11 | with 'OpenSearch::Client::Role::CxnPool::Sniff', | |||||||||
| 27 | 'OpenSearch::Client::Role::Is_Sync'; | ||||||||||
| 28 | |||||||||||
| 29 | 11 | ▶ | use OpenSearch::Client::Util qw(throw); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 11 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | |||||||||||
| 32 | #=================================== | ||||||||||
| 33 | 50 | ▶ | sub next_cxn { | ||||||||
|
Subroutine
next_cxn: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 34 | #=================================== | ||||||||||
| 35 | 50 | my ($self) = @_; | |||||||||
| 36 | |||||||||||
| 37 | 50 | ▶ | $self->sniff if $self->next_sniff <= time(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | |||||||||||
| 39 | 50 | my $cxns = $self->cxns; | |||||||||
| 40 | 50 | my $total = @$cxns; | |||||||||
| 41 | |||||||||||
| 42 | 50 | ▶ | while ( 0 < $total-- ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 49 | my $cxn = $cxns->[ $self->next_cxn_num ]; | |||||||||
| 44 | 49 | ▶ | return $cxn if $cxn->is_live; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 5 | throw( "NoNodes", | |||||||||
| 48 | "No nodes are available: [" . $self->cxns_seeds_str . ']' ); | ||||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | #=================================== | ||||||||||
| 52 | 29 | ▶ | sub sniff { | ||||||||
|
Subroutine
sniff: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||
| 53 | #=================================== | ||||||||||
| 54 | 29 | my $self = shift; | |||||||||
| 55 | |||||||||||
| 56 | 29 | my $cxns = $self->cxns; | |||||||||
| 57 | 29 | my $total = @$cxns; | |||||||||
| 58 | 29 | my @skipped; | |||||||||
| 59 | |||||||||||
| 60 | 29 | ▶ | while ( 0 < $total-- ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 19 | my $cxn = $cxns->[ $self->next_cxn_num ]; | |||||||||
| 62 | 19 | ▶ | if ( $cxn->is_dead ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 5 | push @skipped, $cxn; | |||||||||
| 64 | } | ||||||||||
| 65 | else { | ||||||||||
| 66 | 14 | ▶ | $self->sniff_cxn($cxn) and return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 1 | $cxn->mark_dead; | |||||||||
| 68 | } | ||||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 16 | for my $cxn (@skipped) { | |||||||||
| 72 | 4 | ▶ | $self->sniff_cxn($cxn) and return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 15 | $self->logger->info("No live nodes available. Trying seed nodes."); | |||||||||
| 76 | 15 | for my $seed ( @{ $self->seed_nodes } ) { | |||||||||
| 77 | 20 | my $cxn = $self->cxn_factory->new_cxn($seed); | |||||||||
| 78 | 20 | ▶ | $self->sniff_cxn($cxn) and return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | #=================================== | ||||||||||
| 84 | 38 | ▶ | sub sniff_cxn { | ||||||||
|
Subroutine
sniff_cxn: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 85 | #=================================== | ||||||||||
| 86 | 38 | my ( $self, $cxn ) = @_; | |||||||||
| 87 | 38 | return $self->parse_sniff( $cxn->sniff ); | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 11 | 1; | |||||||||
| 91 | |||||||||||
| 92 | __END__ | ||||||||||