From d17c4be4a5e905ead2b02c54b2c67cb27509b767 Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Fri, 18 Jun 2021 14:29:42 +0200 Subject: [PATCH] TT#121250 improve sip_lcr_reload and sip_domain_reload * sip_lcr_reload is now called after "commit" in all API endpoints, to correctly reflect updated DB changes. It was correct in /api/peeringrules POST but not correct in DELETE, as well as also not correct in /api/peeringservers and /api/peeringgroups * sip_domain_reload does not check if the domain is successfully reload in kamailio proxy as is logic is redundant, it fails however if domain reload XMLRPC request failed on any available proxy servers. Another reason is by default tcp_conn_wq_max in kamailio-proxy is 32KB by default and that causes an impact when domain.dump XMLRPC is used on very large domain sets (600+), as well as sip_domain_reload has improved performance with the removed XMLRPC domain.dump body parsing. Change-Id: I17c5718198b06b1ce78b2654f3d7c3bd2830f60b --- .../Panel/Controller/API/PeeringGroups.pm | 7 +-- .../Panel/Controller/API/PeeringGroupsItem.pm | 7 +-- lib/NGCP/Panel/Controller/API/PeeringRules.pm | 1 + .../Panel/Controller/API/PeeringRulesItem.pm | 7 +-- .../Panel/Controller/API/PeeringServers.pm | 4 +- .../Controller/API/PeeringServersItem.pm | 17 ++++--- lib/NGCP/Panel/Utils/XMLDispatcher.pm | 44 +++---------------- 7 files changed, 33 insertions(+), 54 deletions(-) diff --git a/lib/NGCP/Panel/Controller/API/PeeringGroups.pm b/lib/NGCP/Panel/Controller/API/PeeringGroups.pm index 3d993d0894..beb3d0c47e 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringGroups.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringGroups.pm @@ -99,13 +99,13 @@ sub POST :Allow { my $guard = $c->model('DB')->txn_scope_guard; { my $resource = $self->get_valid_post_data( - c => $c, + c => $c, media_type => 'application/json', ); last unless $resource; my $form = $self->get_form($c); - + last unless $self->validate_form( c => $c, resource => $resource, @@ -125,7 +125,6 @@ sub POST :Allow { try { $item = $c->model('DB')->resultset('voip_peer_groups')->create($resource); - NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); } catch($e){ $c->log->error("failed to create peering group: $e"); # TODO: user, message, trace, ... $self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to create peering group."); @@ -134,6 +133,8 @@ sub POST :Allow { $guard->commit; + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); + $c->response->status(HTTP_CREATED); $c->response->header(Location => sprintf('/%s%d', $c->request->path, $item->id)); $c->response->body(q()); diff --git a/lib/NGCP/Panel/Controller/API/PeeringGroupsItem.pm b/lib/NGCP/Panel/Controller/API/PeeringGroupsItem.pm index 2f08fbdac9..f6e0de5f72 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringGroupsItem.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringGroupsItem.pm @@ -51,7 +51,7 @@ sub PATCH :Allow { last unless $preference; my $json = $self->get_valid_patch_data( - c => $c, + c => $c, id => $id, media_type => 'application/json-patch+json', ); @@ -66,7 +66,7 @@ sub PATCH :Allow { my $form = $self->get_form($c); $item = $self->update_item($c, $item, $old_resource, $resource, $form); last unless $item; - + $guard->commit; $self->return_representation($c, 'item' => $item, 'form' => $form, 'preference' => $preference ); @@ -95,7 +95,7 @@ sub PUT :Allow { $item = $self->update_item($c, $item, $old_resource, $resource, $form); last unless $item; - $guard->commit; + $guard->commit; $self->return_representation($c, 'item' => $item, 'form' => $form, 'preference' => $preference ); } @@ -124,6 +124,7 @@ sub DELETE :Allow { } $item->delete; $guard->commit; + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); $c->response->status(HTTP_NO_CONTENT); diff --git a/lib/NGCP/Panel/Controller/API/PeeringRules.pm b/lib/NGCP/Panel/Controller/API/PeeringRules.pm index 4abacf6600..f175741ca4 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringRules.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringRules.pm @@ -161,6 +161,7 @@ sub POST :Allow { } $guard->commit; + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); $c->response->status(HTTP_CREATED); diff --git a/lib/NGCP/Panel/Controller/API/PeeringRulesItem.pm b/lib/NGCP/Panel/Controller/API/PeeringRulesItem.pm index 5865275e43..c8671fb157 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringRulesItem.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringRulesItem.pm @@ -63,7 +63,7 @@ sub PATCH :Allow { last unless $preference; my $json = $self->get_valid_patch_data( - c => $c, + c => $c, id => $id, media_type => 'application/json-patch+json', ); @@ -78,7 +78,7 @@ sub PATCH :Allow { my $form = $self->get_form($c); $item = $self->update_item($c, $item, $old_resource, $resource, $form); last unless $item; - + $guard->commit; $self->return_representation($c, 'item' => $item, 'form' => $form, 'preference' => $preference ); @@ -121,9 +121,10 @@ sub DELETE :Allow { my $item = $self->item_by_id($c, $id); last unless $self->resource_exists($c, peeringrule => $item); $item->delete; - NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); $guard->commit; + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); + $c->response->status(HTTP_NO_CONTENT); $c->response->body(q()); } diff --git a/lib/NGCP/Panel/Controller/API/PeeringServers.pm b/lib/NGCP/Panel/Controller/API/PeeringServers.pm index 7ee6feb643..a83f71fd7b 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringServers.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringServers.pm @@ -167,7 +167,6 @@ sub POST :Allow { try { $item = $c->model('DB')->resultset('voip_peer_hosts')->create($resource); - NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); if($resource->{probe}) { NGCP::Panel::Utils::Peering::_sip_dispatcher_reload(c => $c); } @@ -179,8 +178,9 @@ sub POST :Allow { $guard->commit; + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); + try { - NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); if($resource->{probe}) { NGCP::Panel::Utils::Peering::_sip_dispatcher_reload(c => $c); } diff --git a/lib/NGCP/Panel/Controller/API/PeeringServersItem.pm b/lib/NGCP/Panel/Controller/API/PeeringServersItem.pm index b25dba051f..2757942415 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringServersItem.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringServersItem.pm @@ -63,7 +63,7 @@ sub PATCH :Allow { last unless $preference; my $json = $self->get_valid_patch_data( - c => $c, + c => $c, id => $id, media_type => 'application/json-patch+json', ); @@ -78,11 +78,12 @@ sub PATCH :Allow { my $form = $self->get_form($c); $item = $self->update_item($c, $item, $old_resource, $resource, $form); last unless $item; - + $guard->commit; + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); + try { - NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); if (($item->probe && $old_resource->{enabled} && !$item->enabled) || ($old_resource->{probe} && !$item->probe)) { NGCP::Panel::Utils::Peering::_sip_delete_probe( c => $c, @@ -136,9 +137,11 @@ sub PUT :Allow { $item = $self->update_item($c, $item, $old_resource, $resource, $form); last unless $item; - $guard->commit; + $guard->commit; + + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); + try { - NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); if (($item->probe && $old_resource->{enabled} && !$item->enabled) || ($old_resource->{probe} && !$item->probe)) { NGCP::Panel::Utils::Peering::_sip_delete_probe( c => $c, @@ -181,8 +184,10 @@ sub DELETE :Allow { my $probe = $item->probe; $item->delete; $guard->commit; + + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); + try { - NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); if($probe) { NGCP::Panel::Utils::Peering::_sip_delete_probe( c => $c, diff --git a/lib/NGCP/Panel/Utils/XMLDispatcher.pm b/lib/NGCP/Panel/Utils/XMLDispatcher.pm index e7c65cc054..52bc66e755 100644 --- a/lib/NGCP/Panel/Utils/XMLDispatcher.pm +++ b/lib/NGCP/Panel/Utils/XMLDispatcher.pm @@ -70,7 +70,7 @@ sub dispatch { } # failure - + $c->log->info("failure: $@"); $all or next; @@ -147,10 +147,6 @@ sub _unqueue { sub sip_domain_reload { my ($c, $domain_name) = @_; - my $NUM_TRIES = 3; - my $SLEEP_BEFORE_RETRY = 1; - my $res; - my $reload_command = < @@ -159,41 +155,15 @@ sub sip_domain_reload { EOF - my $dump_command = < - -domain.dump - - -EOF + my @ret = dispatch($c, "proxy-ng", 1, 1, $reload_command); # we're only checking first host here - for (my $i = 0; $i < $NUM_TRIES; $i++) { - sleep $SLEEP_BEFORE_RETRY if ($i > 0); - - ($res) = dispatch($c, "proxy-ng", 1, 1, $reload_command); # we're only checking first host here - if ($res->[1] == 0) { - die "couldn't reload domains"; - } - return () unless $domain_name; - my @replies = dispatch($c, "proxy-ng", 1, 1, $dump_command); - my $all_successful = 1; - for my $reply (@replies) { - if ($reply->[1] == -1) { - # skip inactive host - } elsif ($reply->[1] && $reply->[2] =~ m/$domain_name/) { - # successful - } else { - $c->log->debug("Domain not loaded. Retrying..."); - $all_successful = 0; - } - } - if ($all_successful) { - $c->log->debug("Domain successfully loaded in all active proxies"); - return; - } + if (grep { $_->[1] == 0 } @ret) { + die "Couldn't reload domain"; } - die "couldn't load domain into all proxies. Tried $NUM_TRIES times."; + $c->log->debug("Domain successfully loaded in all active proxies"); + + return; }