Commit c01f7b3e authored by Leigh Stoller's avatar Leigh Stoller

Some changes to how log files are handled; this too way too long to

do!

The original operation was to save up every log file forever in the
work directory, and copy that out to both the user directory and the
info directory (long term archive). When I cleaned /proj on ops
yesterday of all this old cruft, I recoved 17GB of disk space. Yow!

So, the new operation is:

* Only files that end in .log are copied to the user directory. No
  longer copying out .top, .ptop, and a couple of other logs; 99% of
  users never look at these things. We still have them available to us
  though, on boss.

* At the beginning of each swap operation, clean out the work
  directory of all the old log files. These are named a variety of
  ways, so I use some pattern patches to do this.

* Jigger the names a little so that we do not name things in the form
  "$$.log", to avoid copying out different named files to the user
  directory each time; instead link the .log file to the real output
  file so that it gets overwritten each time, while still getting the
  per-swap files for long term storage.
parent d4881005
......@@ -914,8 +914,40 @@ sub SaveLogFiles($)
my $pid = $self->pid();
my $eid = $self->eid();
my $workdir = $self->WorkDir();
my $logdir = TBExptLogDir($pid, $eid);
# What the hell is this file! Very annoying.
if (-e "$workdir/.rnd") {
system("/bin/rm -f $workdir/.rnd");
}
system("/bin/cp -Rpf $workdir/ $logdir");
return 0;
}
#
# Remove old logfiles from the wordir.
#
sub CleanLogFiles($)
{
my ($self) = @_;
# Must be a real reference.
return -1
if (! ref($self));
my $workdir = $self->WorkDir();
my $files = "";
foreach my $ext ("log", "ptop", "top", "assign") {
$files = "$files $workdir/*.${ext}";
}
foreach my $prefix ("swap", "start", "cancel") {
$files = "$files $workdir/${prefix}*.*";
}
system("/bin/rm -f $files") == 0
or return -1;
TBSaveExpLogFiles($pid, $eid);
return 0;
}
......@@ -935,7 +967,7 @@ sub CopyLogFiles($)
my $workdir = $self->WorkDir();
my $userdir = $self->UserDir();
system("/bin/cp -Rfp $workdir/ $userdir/tbdata");
system("/bin/cp -Rfp $workdir/*.log $userdir/tbdata");
return 0;
}
......
......@@ -3162,9 +3162,11 @@ sub TBExptCreateLogFile($$$)
my($pid, $eid, $prefix) = @_;
my $logdir;
my $logname;
my $linkname;
$logdir = TBExptWorkDir($pid, $eid);
$logname = `mktemp $logdir/${prefix}.XXXXXX`;
$logdir = TBExptWorkDir($pid, $eid);
$linkname = "$logdir/${prefix}.log";
$logname = `mktemp $logdir/${prefix}.XXXXXX`;
if ($logname =~ /^([-\@\w\.\/]+)$/) {
$logname = $1;
......@@ -3178,6 +3180,16 @@ sub TBExptCreateLogFile($$$)
die("*** $0:\n".
" Could not chmod $logname to 0644: $!\n");
# Link it to $prefix.log so that the most recent is well know.
if (-e $linkname) {
die("*** $0:\n".
" CreateLogFile: $linkname already exists!\n");
}
if (! link($logname, $linkname)) {
die("*** $0:\n".
" CreateLogFile: Cannot link $logname,$linkname: $!\n");
}
return $logname;
}
......@@ -4850,7 +4862,7 @@ sub MapNodeOSID($$)
}
#
# Save off the log files for an experiment.
# Save off the log files for an experiment to long term storage.
#
sub TBSaveExpLogFiles($$)
{
......
......@@ -998,7 +998,9 @@ sub RunAssign ()
# Saving up assign.log coz each swapin/modify is
# different and it is nice to have every mapping
# for debugging and archiving purposes
system("/bin/cp assign.log assign-$pid-$eid-$$.log");
# We do not call it .log though, since we do not want it copied
# out to the user directory every swapin. See Experiment.pm
system("/bin/cp assign.log $pid-$eid-$$.assign");
if (!open(ASSIGNFP, "assign.log")) {
print("Could not open assign logfile!\n");
return -1;
......
......@@ -54,6 +54,7 @@ use lib "@prefix@/lib";
use libdb;
use libtestbed;
use Template;
use Experiment;
# Be careful not to exit on transient error; 0 means infinite retry.
$libdb::DBQUERY_MAXTRIES = 0;
......@@ -344,9 +345,16 @@ sub dosomething($$)
# Locals
my $creator = $exphash->{'expt_head_uid'};
my $experiment = Experiment->Lookup($pid, $eid);
if (! defined($experiment)) {
print "Could not find experiment object! Skipping ...\n";
return -1;
}
print "Doing a '$dowhat' to batch experiment $pid/$eid\n";
# Clean before starting.
$experiment->CleanLogFiles();
#
# Create a temporary name for a log file. We do this in the parent so
# we can remove it when the child ends. The child could remove it, but
......
......@@ -391,6 +391,10 @@ if (! UserDBInfo($expt_head_login, \$expt_head_name, \$expt_head_email)) {
# If not in batch mode, go into the background. Parent exits.
#
if (!$batch && !$template_mode) {
# Cleanup
$experiment->CleanLogFiles() == 0
or fatal("Could not clean up logfiles!");
if ($experiment->CreateLogFile("endexp", \$logname) != 0) {
fatal("Could not create logfile!");
}
......
......@@ -756,6 +756,10 @@ if ($inout eq "modify" && defined($modnsfile)) {
# If not in batch mode, go into the background. Parent exits.
#
if (! $batch && ! $template_mode) {
# Cleanup
$experiment->CleanLogFiles() == 0
or fatal("Could not clean up logfiles!");
if ($experiment->CreateLogFile("swapexp", \$logname) != 0) {
fatal("Could not create logfile!");
}
......
......@@ -82,6 +82,7 @@ use libdb;
use libtestbed;
use libtblog;
use Template;
use Experiment;
# Be careful not to exit on transient error
$libdb::DBQUERY_MAXTRIES = 0;
......@@ -162,6 +163,12 @@ if (!defined($instance)) {
fatal(-1, "Could not get instance record for experiment $exptidx!");
}
# Grab the experiment record for below.
my $experiment = Experiment->Lookup($pid, $eid);
if (!defined($experiment)) {
fatal(-1, "Experiment $pid/$eid object could not be found!");
}
#
# At this point, we need to force a cleanup no matter how we exit.
# See the END block below.
......@@ -177,6 +184,10 @@ $SIG{TERM} = \&sighandler;
# If not in batch mode, go into the background. Parent exits.
#
if (! $batchmode) {
# Cleanup
$experiment->CleanLogFiles() == 0
or fatal("Could not clean up logfiles!");
$logname = TBExptCreateLogFile($pid, $eid, "swapout");
TBExptSetLogFile($pid, $eid, $logname);
TBExptOpenLogFile($pid, $eid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment