summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2018-12-19 12:35:49 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2018-12-19 12:55:09 (GMT)
commitea2c058ce96484937fcfe52dc7382a461a9d72e3 (patch) (unidiff)
treeae86e1115c3ef91bc03d2cfcb7df4f7ff8d19ce9
parent249512af92d3f592ae683279c2cd1f54a7c1a726 (diff)
downloadglacier-ea2c058ce96484937fcfe52dc7382a461a9d72e3.tar.gz
glacier-ea2c058ce96484937fcfe52dc7382a461a9d72e3.tar.bz2
Bugfixes.
* lib/App/Glacier/Command.pm (option,check_job): New methods. * lib/App/Glacier/Command/Get.pm: Rewrite debug messages (fixes temporary solution in 6c6dab5d). * lib/App/Glacier/Command/Jobs.pm: Rewrite the db->foreach sub. * lib/App/Glacier/Command/Periodic.pm: Likewise. * lib/App/Glacier/DB/GDBM.pm (CLONE_SKIP): New method. * lib/App/Glacier/Job.pm: Overload the "" operator. * lib/App/Glacier/Roster.pm (foreach): Overload method.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/App/Glacier/Command.pm43
-rw-r--r--lib/App/Glacier/Command/Get.pm11
-rw-r--r--lib/App/Glacier/Command/Jobs.pm39
-rw-r--r--lib/App/Glacier/Command/Periodic.pm38
-rw-r--r--lib/App/Glacier/DB/GDBM.pm11
-rw-r--r--lib/App/Glacier/Job.pm5
-rw-r--r--lib/App/Glacier/Roster.pm9
7 files changed, 81 insertions, 75 deletions
diff --git a/lib/App/Glacier/Command.pm b/lib/App/Glacier/Command.pm
index 7178a75..1f9a130 100644
--- a/lib/App/Glacier/Command.pm
+++ b/lib/App/Glacier/Command.pm
@@ -164,2 +164,10 @@ sub clone {
164 164
165sub option {
166 my ($self, $opt, $val) = @_;
167 if (defined($val)) {
168 $self->{_options}{$opt} = $val;
169 }
170 return $self->{_options}{$opt};
171}
172
165sub touchdir { 173sub touchdir {
@@ -278,2 +286,37 @@ sub archive_cache_filename {
278 286
287sub check_job {
288 my ($self, $key, $descr, $vault) = @_;
289
290 $self->debug(2, "$descr->{JobId} $descr->{Action} $vault");
291 if ($descr->{StatusCode} eq 'Failed') {
292 $self->debug(1,
293 "deleting failed $key $vault "
294 . ($descr->{JobDescription} || $descr->{Action})
295 . ' '
296 . $descr->{JobId});
297 $self->jobdb()->delete($key) unless $self->dry_run;
298 return;
299 }
300
301 my $res = $self->glacier->Describe_job($vault, $descr->{JobId});
302 if ($self->glacier->lasterr) {
303 if ($self->glacier->lasterr('code') == 404) {
304 $self->debug(1,
305 "deleting expired $key $vault "
306 . ($descr->{JobDescription} || $descr->{Action})
307 . ' '
308 . $descr->{JobId});
309 App::Glacier::Job->fromdb($self, $vault, $key, $res)->delete()
310 unless $self->dry_run;
311 } else {
312 $self->error("can't describe job $descr->{JobId}: ",
313 $self->glacier->last_error_message);
314 }
315 return;
316 } elsif (ref($res) ne 'HASH') {
317 croak "describe_job returned wrong datatype (".ref($res).") for \"$descr->{JobId}\"";
318 }
319 return $res;
320}
321
2791; 3221;
diff --git a/lib/App/Glacier/Command/Get.pm b/lib/App/Glacier/Command/Get.pm
index 0d17659..82b32c8 100644
--- a/lib/App/Glacier/Command/Get.pm
+++ b/lib/App/Glacier/Command/Get.pm
@@ -162,2 +162,4 @@ sub run {
162 if (-f $cache_file) { 162 if (-f $cache_file) {
163 $self->debug(1, "$job: copying from $cache_file");
164 return if $self->dry_run;
163 unless (copy($cache_file, $localname)) { 165 unless (copy($cache_file, $localname)) {
@@ -195,2 +197,3 @@ sub download {
195 my ($self, $job, $localname) = @_; 197 my ($self, $job, $localname) = @_;
198
196 my $archive_size = $job->get('ArchiveSizeInBytes'); 199 my $archive_size = $job->get('ArchiveSizeInBytes');
@@ -216,5 +219,3 @@ sub _download_simple {
216 219
217 eval { # FIXME: file_name might be absent 220 $self->debug(1, "$job: downloading in single part");
218 $self->debug(1, "downloading", $job->file_name(1), "in single part");
219 };
220 return if $self->dry_run; 221 return if $self->dry_run;
@@ -258,4 +259,4 @@ sub _download_multipart {
258 259
259 $self->debug(1, 260 $self->debug(1, "$job: downloading in chunks of $part_size bytes, in $njobs jobs, with $job_parts parts per job");
260 "downloading", $job->file_name(1), "to $localname in chunks of $part_size bytes, in $njobs jobs, with $job_parts parts per job"); 261
261 return if $self->dry_run; 262 return if $self->dry_run;
diff --git a/lib/App/Glacier/Command/Jobs.pm b/lib/App/Glacier/Command/Jobs.pm
index 5a5f488..7dc5d06 100644
--- a/lib/App/Glacier/Command/Jobs.pm
+++ b/lib/App/Glacier/Command/Jobs.pm
@@ -118,5 +118,3 @@ sub list {
118 $db->foreach(sub { 118 $db->foreach(sub {
119 my ($key, $descr) = @_; 119 my ($key, $descr, $vault) = @_;
120 my $vault = $descr->{VaultARN};
121 $vault =~ s{.*:vaults/}{};
122 120
@@ -125,31 +123,8 @@ sub list {
125 unless ($self->{_options}{cached}) { 123 unless ($self->{_options}{cached}) {
126 if ($descr->{StatusCode} eq 'Failed') { 124 my $res = $self->check_job($key, $descr, $vault)
127 $self->debug(1, "deleting failed $key $vault " . 125 or return;
128 ($descr->{JobDescription} || $descr->{Action}) . 126 $res = timestamp_deserialize($res);
129 $descr->{JobId}); 127 $self->debug(2, $res->{StatusCode});
130 $db->delete($key) unless $self->dry_run; 128 $db->store($key, $res) unless $self->dry_run;
131 return; 129 $descr = $res;
132 }
133
134 my $res = $self->glacier->Describe_job($vault, $descr->{JobId});
135 if ($self->glacier->lasterr) {
136 if ($self->glacier->lasterr('code') == 404) {
137 $self->debug(1, "deleting expired $key $vault " .
138 ($descr->{JobDescription} || $descr->{Action}) .
139 $descr->{JobId});
140 App::Glacier::Job->fromdb($self, $vault, $key, $res)->delete()
141 unless $self->dry_run;
142 return;
143 } else {
144 $self->error("can't describe job $descr->{JobId}: ",
145 $self->glacier->last_error_message);
146 }
147 } elsif (ref($res) ne 'HASH') {
148 croak "describe_job returned wrong datatype (".ref($res).") for \"$descr->{JobId}\"";
149 } else {
150 $res = timestamp_deserialize($res);
151 $self->debug(2, $res->{StatusCode});
152 $db->store($key, $res) unless $self->dry_run;
153 $descr = $res;
154 }
155 } 130 }
diff --git a/lib/App/Glacier/Command/Periodic.pm b/lib/App/Glacier/Command/Periodic.pm
index 5a4dc2a..39a2d7a 100644
--- a/lib/App/Glacier/Command/Periodic.pm
+++ b/lib/App/Glacier/Command/Periodic.pm
@@ -9,2 +9,3 @@ use File::Basename;
9use App::Glacier::Job; 9use App::Glacier::Job;
10use App::Glacier::Command::Get;
10 11
@@ -40,35 +41,6 @@ sub run {
40 $db->foreach(sub { 41 $db->foreach(sub {
41 my ($key, $descr) = @_; 42 my ($key, $descr, $vault) = @_;
42 my $vault = $descr->{VaultARN};
43 $vault =~ s{.*:vaults/}{};
44 43
45 my $completed = $descr->{Completed}; 44 my $res = $self->check_job($key, $descr, $vault);
46 45 if ($res && $res->{Completed} ne $descr->{Completed}) {
47 $self->debug(2, "$descr->{JobId} $descr->{Action} $vault");
48 if ($descr->{StatusCode} eq 'Failed') {
49 $self->debug(1,
50 "deleting failed $key $vault "
51 . ($descr->{JobDescription} || $descr->{Action})
52 . ' '
53 . $descr->{JobId});
54 $db->delete($key) unless $self->dry_run;
55 }
56
57 my $res = $self->glacier->Describe_job($vault, $descr->{JobId});
58 if ($self->glacier->lasterr) {
59 if ($self->glacier->lasterr('code') == 404) {
60 $self->debug(1,
61 "deleting expired $key $vault "
62 . ($descr->{JobDescription} || $descr->{Action})
63 . ' '
64 . $descr->{JobId});
65 App::Glacier::Job->fromdb($self, $vault, $key, $res)->delete()
66 unless $self->dry_run;
67 } else {
68 $self->error("can't describe job $descr->{JobId}: ",
69 $self->glacier->last_error_message);
70 }
71 } elsif (ref($res) ne 'HASH') {
72 croak "describe_job returned wrong datatype (".ref($res).") for \"$descr->{JobId}\"";
73 } elsif ($res->{Completed} ne $completed) {
74 $self->debug(2, $res->{StatusCode}); 46 $self->debug(2, $res->{StatusCode});
@@ -88,4 +60,4 @@ sub run {
88 60
89 require App::Glacier::Command::Get;
90 my $get = clone App::Glacier::Command::Get($self); 61 my $get = clone App::Glacier::Command::Get($self);
62 $get->option(quiet => 1);
91 $get->download($job, $localname); 63 $get->download($job, $localname);
diff --git a/lib/App/Glacier/DB/GDBM.pm b/lib/App/Glacier/DB/GDBM.pm
index 0e14a65..f7cc29a 100644
--- a/lib/App/Glacier/DB/GDBM.pm
+++ b/lib/App/Glacier/DB/GDBM.pm
@@ -8,2 +8,6 @@ use File::Path qw(make_path);
8 8
9# Avoid coredumps in threaded code.
10# See https://rt.perl.org/Public/Bug/Display.html?id=61912.
11sub CLONE_SKIP { 1 }
12
9sub new { 13sub new {
@@ -54,7 +58,4 @@ sub configtest {
54 58
55# We can't tie the DB to $self->{_map} at once, in the new method, because 59# Tie in the database, run $code, and untie it again. Correctly handle
56# this will cause coredumps in threaded code (see 60# nested invocations to avoid deadlocking.
57# https://rt.perl.org/Public/Bug/Display.html?id=61912). So, the following
58# auxiliary method is used, which calls &$code with $self->{_map} tied
59# to the DB.
60sub _tied { 61sub _tied {
diff --git a/lib/App/Glacier/Job.pm b/lib/App/Glacier/Job.pm
index ae12b22..9478b20 100644
--- a/lib/App/Glacier/Job.pm
+++ b/lib/App/Glacier/Job.pm
@@ -110,2 +110,7 @@ sub get {
110 110
111sub as_string { shift->get('JobDescription') }
112
113use overload
114 '""' => \&as_string;
115
111sub is_finished { 116sub is_finished {
diff --git a/lib/App/Glacier/Roster.pm b/lib/App/Glacier/Roster.pm
index ee56ff5..32c2b08 100644
--- a/lib/App/Glacier/Roster.pm
+++ b/lib/App/Glacier/Roster.pm
@@ -3,2 +3,11 @@ use parent 'App::Glacier::DB';
3 3
4sub foreach {
5 my ($self, $fun) = @_;
6 $self->SUPER::foreach(sub {
7 my ($key, $descr) = @_;
8 (my $vault = $descr->{VaultARN}) =~ s{.*:vaults/}{};
9 &{$fun}($key, $descr, $vault);
10 });
11 }
12
41; 131;

Return to:

Send suggestions and report system problems to the System administrator.