Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/MirrorCache/Schema/ResultSet/Server.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2020-2023 SUSE LLC
# Copyright (C) 2020-2025 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -258,26 +258,30 @@ END_SQL
}

sub server_projects {
my ($self) = @_;
my ($self, $region) = @_;
my $rsource = $self->result_source;
my $schema = $rsource->schema;
my $dbh = $schema->storage->dbh;
my $condition_our_regions = $schema->condition_our_regions;
my $condirion_region = "";
$region = '' unless $region;

my $sql = <<"END_SQL";
select concat(s.id, '::', p.id) as _key,
s.id as server_id,
p.id as project_id,
CASE WHEN coalesce(scf.server_id, 0) > 0 THEN 'https' ELSE 'http' END as protocol,
concat(CASE WHEN length(s.hostname_vpn)>0 THEN s.hostname_vpn ELSE s.hostname END,s.urldir, p.path) as uri,
sp.server_id as mirror_id,
coalesce(sp.state, -2) oldstate
from project p
join server s on s.enabled
join server s on s.enabled and (? = '' or s.region = ?)
left join server_project sp on sp.server_id = s.id and sp.project_id = p.id
left join server_capability_force scf on scf.server_id = s.id and capability = 'http'
where
coalesce(sp.state,0) > -1 $condition_our_regions
END_SQL
return $dbh->selectall_hashref($sql, '_key', {});
return $dbh->selectall_hashref($sql, '_key', {}, $region, $region);
}

sub log_project_probe_outcome {
Expand Down
6 changes: 4 additions & 2 deletions lib/MirrorCache/Task/Cleanup.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2021 SUSE LLC
# Copyright (C) 2021-2025 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -33,7 +33,9 @@ sub _run {
unless my $guard = $minion->guard('cleanup', 120);

my $schema = $app->schema;
$minion->enqueue('mirror_probe_projects');
for my $region ('eu', 'na', 'sa', 'af', 'as', 'oc') {
$minion->enqueue('mirror_probe_projects' => [$region]);
}
$minion->enqueue('cleanup_agg_download_pkg');

# detect stalled backstage jobs
Expand Down
15 changes: 8 additions & 7 deletions lib/MirrorCache/Task/MirrorProbe.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2020 SUSE LLC
# Copyright (C) 2020-2025 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -123,16 +123,16 @@ sub _probe_capability {
}

sub _probe_projects {
my ($app, $job, $country) = @_;
$country = '' unless $country;
my ($app, $job, $region) = @_;
$region = '' unless $region;

my $minion = $app->minion;
return $job->finish("Previous projects probe job is still active")
unless my $guard = $minion->guard('mirror_probe_projects', 6000);
unless my $guard = $minion->guard('mirror_probe_projects' . $region, 6000);

my $schema = $app->schema;
my $rs = $schema->resultset('Server');
my $href = $rs->server_projects();
my $href = $rs->server_projects($region);

my %count;
my @keys = sort keys %$href;
Expand All @@ -144,9 +144,10 @@ sub _probe_projects {
my $success = 1;
my $code = -1;
eval {
$code = Mojo::UserAgent->new->max_redirects(5)->head($data->{uri}, {'User-Agent' => 'MirrorCache/probe_projects'})->result->code;
my $url = ( $data->{protocol} // 'https' ) . '://' . $data->{uri};
$code = Mojo::UserAgent->new->max_redirects(5)->head($url, {'User-Agent' => 'MirrorCache/probe_projects'})->result->code;
};
$success = 0 if $code ne 200;
$success = 0 if ($code < 200 || $code >= 400) and $code != 403;

$count{$code} = 0 unless $count{$code};
$count{$code}++;
Expand Down
2 changes: 2 additions & 0 deletions lib/MirrorCache/resources/migrations/Pg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,5 @@ create index if not exists stat_dt_pkg_folder_id_country_idx on stat(dt, pkg, fo
create index if not exists agg_download_pkg_period_metapkg_id_dt_idx on agg_download_pkg(period, metapkg_id, dt);
-- 45 up
alter table project add column if not exists shard varchar(32);
-- 46 up
-- noop
4 changes: 4 additions & 0 deletions lib/MirrorCache/resources/migrations/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,7 @@ create index if not exists i_stat_dt_pkg_folder_id_country on stat(dt, pkg, fold
create index if not exists i_agg_download_pkg_period_metapkg_id_dt on agg_download_pkg(period, metapkg_id, dt);
-- 45 up
alter table project add column if not exists shard varchar(32);
-- 46 up
-- delete duplicate rows and add PR to server_project
delete from server_project where (server_id, project_id, dt) in (select x.server_id, x.project_id, x.dt from server_project x join server_project y on (y.server_id, y.project_id) = (x.server_id, x.project_id) and x.dt < y.dt);
alter table server_project add primary key if not exists (server_id, project_id);