Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track mirror propagation using time of job #456

Merged
merged 1 commit into from
Mar 5, 2024
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
7 changes: 4 additions & 3 deletions lib/MirrorCache/Schema/ResultSet/Rollout.pm
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,19 @@ END_SQL
}

sub add_rollout_server {
my ($self, $rollout_id, $server_id) = @_;
my ($self, $rollout_id, $server_id, $dt) = @_;
my $dbh = $self->result_source->schema->storage->dbh;

my $sql = 'insert into rollout_server(rollout_id, server_id, dt) select ?, ?, now()';
my $sql = 'insert into rollout_server(rollout_id, server_id, dt, scan_dt) select ?, ?, to_timestamp(?), now()';

if ($dbh->{Driver}->{Name} eq 'Pg') {
$sql = $sql . ' on conflict do nothing';
} else {
$sql =~ s/to_timestamp/from_unixtime/g;
$sql = $sql . ' on duplicate key update server_id = server_id';
}

$dbh->prepare($sql)->execute($rollout_id, $server_id);
$dbh->prepare($sql)->execute($rollout_id, $server_id, $dt);
return 1;
}

Expand Down
12 changes: 7 additions & 5 deletions lib/MirrorCache/Task/MirrorScan.pm
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ sub _doscan {
my $count = 0;
my $perfect_count = 0;
my $proj = $schema->resultset('Rollout')->rollout_file_for_folder($path);
my $proj_rollout_filename = '';
$proj_rollout_filename = $proj->{filename} if $proj;
$job->note(rollout_filename => $proj_rollout_filename) if $proj_rollout_filename;
$job->note(rollout_id => ($proj->{rollout_id} // 'undef')) if $proj_rollout_filename;
my ($proj_rollout_filename, $rollout_server_dt) = ('', undef);
if ($proj) {
$proj_rollout_filename = $proj->{filename};
$rollout_server_dt = time;
$job->note(rollout_filename => $proj_rollout_filename, rollout_id => ($proj->{rollout_id} // 'undef'), dt => $rollout_server_dt);
}
for my $folder_on_mirror (@$folder_on_mirrors) {
my $server_id = $folder_on_mirror->{server_id};
my $url = $folder_on_mirror->{url} . '/';
Expand Down Expand Up @@ -161,7 +163,7 @@ unless ($hasall) {
my $rollout_res = 0;
my $rollout_err;
eval {
$rollout_res = $schema->resultset('Rollout')->add_rollout_server($proj->{rollout_id}, $server_id);
$rollout_res = $schema->resultset('Rollout')->add_rollout_server($proj->{rollout_id}, $server_id, $rollout_server_dt);
} or $rollout_err = $@ // 'no error';
print STDERR "Rollout error: $rollout_err\n\n" if $rollout_err;
$job->note(rollout_err => $rollout_err, at => datetime_now()) if $rollout_err;
Expand Down
3 changes: 2 additions & 1 deletion lib/MirrorCache/resources/migrations/Pg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,5 @@ create table rollout_server (
dt timestamp,
primary key(rollout_id, server_id)
);

-- 34 up
alter table rollout_server add column if not exists scan_dt timestamp;
2 changes: 2 additions & 0 deletions lib/MirrorCache/resources/migrations/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,5 @@ alter table rollout_server
add constraint `fk_rollout_server_server` FOREIGN KEY(server_id) references server(id) on delete cascade,
add constraint `fk_rollout_server_rollout` FOREIGN KEY(rollout_id) references rollout(id) on delete cascade;

-- 34 up
alter table rollout_server add column if not exists scan_dt timestamp;
Loading