Author: bsallen
Date: 2016-06-19 18:03:02 -0700 (Sun, 19 Jun 2016)
New Revision: 1994
Modified:
trunk/provision/cgi-bin/
vnfs.pl
Log:
Instead of a request that cannot get a lock falling through to 'Sending VNFS from the data store', return a 503. wwgetvnfs retries correctly until the vnfs is cached. This eliminates huge memory usage both on the wwmaster and backing mysqld as multiple nodes try to grab the same vnfs
Modified: trunk/provision/cgi-bin/
vnfs.pl
===================================================================
--- trunk/provision/cgi-bin/
vnfs.pl 2016-06-06 18:38:00 UTC (rev 1993)
+++ trunk/provision/cgi-bin/
vnfs.pl 2016-06-20 01:03:02 UTC (rev 1994)
@@ -71,6 +71,7 @@
my $vnfs_checksum = $obj->checksum();
my ($vnfs_nocache) = $obj->get("nocache");
my $use_cache;
+ my $cache_in_progress;
#&nprint("Sending VNFS '$vnfs_name' to node '$node_name'\n");
$q->print("Content-Type: application/octet-stream; name=\"vnfs.img\"\r\n");
@@ -93,18 +94,16 @@
if (! -d "$vnfs_cachedir/$vnfs_name") {
mkpath("$vnfs_cachedir/$vnfs_name");
}
-
+
my $lock_file = "$vnfs_cachedir/$vnfs_name/warewulf.cache.lock";
my $lock_fh;
-
+
if (! open($lock_fh, '>', $lock_file) || ! &lock($lock_fh)) {
+ $cache_in_progress = 1;
&eprint("Can't open VNFS cache. Locked by another request.\n");
- $q->print("Content-Type: application/octet-stream\r\n");
- $q->print("Status: 500\r\n");
- $q->print("\r\n");
} else {
&dprint("VNFS cache lock obtained.\n");
-
+
open($cache_fh, "> $vnfs_cachedir/$vnfs_name/image.$vnfs_checksum.$rand");
my $binstore = $db->binstore($obj->get("_id"));
@@ -147,12 +146,17 @@
$q->print("\r\n");
}
- } else {
+ } elsif(! $cache_in_progress) {
&dprint("Sending VNFS from the data store\n");
my $binstore = $db->binstore($obj->get("_id"));
while(my $buffer = $binstore->get_chunk()) {
$q->print($buffer);
}
+ } else {
+ &eprint("VNFS is being cached via a different request, try again.\n");
+ $q->print("Content-Type: application/octet-stream\r\n");
+ $q->print("Status: 503\r\n");
+ $q->print("\r\n");
}
} else {
@@ -187,4 +191,3 @@
}
# vim: filetype=perl:syntax=perl:expandtab:ts=4:sw=4:
-