Skip to content

Commit de068b5

Browse files
committed
Post internal error / disable judgedaemon on low disk space.
Fixes #186.
1 parent 9d29074 commit de068b5

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

judge/judgedaemon.main.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,29 @@ function fetch_executable($workdirpath, $execid, $md5sum)
400400
$currentEndpoint = 0;
401401
while ( TRUE ) {
402402

403+
// Check for available disk space
404+
$free_space = disk_free_space(JUDGEDIR);
405+
$total_space = disk_total_space(JUDGEDIR);
406+
$free_perc = (100.*$free_space) / $total_space;
407+
408+
$allowed_free_perc = dbconfig_get_rest('diskspace_error_perc');
409+
$allowed_free_abs = dbconfig_get_rest('diskspace_error_abs'); // in kB
410+
if ( $free_perc < $allowed_free_perc || $free_space < 1024*$allowed_free_abs ) {
411+
$free_perc = sprintf("%01.2f%%", $free_perc);
412+
$free_abs = sprintf("%01.2fGB", $free_space / (1024*1024*1024));
413+
logmsg(LOG_ERR, "Low on disk space: $free_perc available, i.e. $free_abs");
414+
415+
$disabled = json_encode(array(
416+
'kind' => 'judgehost',
417+
'hostname' => $myhost));
418+
$judgehostlog = read_judgehostlog();
419+
$error_id = request('internal_error', 'POST',
420+
'description=' . urlencode("low on disk space on $myhost") .
421+
'&judgehostlog=' . urlencode(base64_encode($judgehostlog)) .
422+
'&disabled=' . urlencode($disabled));
423+
logmsg(LOG_ERR, "=> internal error " . $error_id);
424+
}
425+
403426
// If all endpoints are waiting, sleep for a bit
404427
$dosleep = TRUE;
405428
foreach ($endpoints as $id=>$endpoint) {
@@ -451,11 +474,11 @@ function fetch_executable($workdirpath, $execid, $md5sum)
451474

452475
judge($row);
453476

454-
// Check if we were interrupted while judging, if so, exit(to avoid sleeping)
455-
if ($exitsignalled) {
456-
logmsg(LOG_NOTICE, "Received signal, exiting.");
477+
// Check if we were interrupted while judging, if so, exit(to avoid sleeping)
478+
if ($exitsignalled) {
479+
logmsg(LOG_NOTICE, "Received signal, exiting.");
457480
exit;
458-
}
481+
}
459482

460483
// restart the judging loop
461484
}
@@ -587,7 +610,7 @@ function judge($row)
587610
'&description=' . urlencode("no test cases found") .
588611
'&judgehostlog=' . urlencode(base64_encode($judgehostlog)) .
589612
'&disabled=' . urlencode($disabled));
590-
logmsg(LOG_WARNING, "No testcases found for p$row[probid] => internal error " . $error_id);
613+
logmsg(LOG_ERR, "No testcases found for p$row[probid] => internal error " . $error_id);
591614
break;
592615
}
593616
$tc = dj_json_decode($testcase);

lib/www/common.jury.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,12 @@ function set_internal_error($disabled, $cid, $value) {
625625
WHERE cid=%i AND probid=%i',
626626
$value, $cid, $disabled['probid']);
627627
break;
628+
case 'judgehost':
629+
$DB->q('RETURNAFFECTED UPDATE judgehost
630+
SET active=%i
631+
WHERE hostname=%s',
632+
$value, $disabled['hostname']);
633+
break;
628634
default:
629635
$api->createError("unknown internal error kind '" . $disabled['kind'] . "'");
630636
}

sql/mysql_db_defaultdata.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ INSERT INTO `configuration` (`name`, `value`, `type`, `description`) VALUES
3939
('allow_registration', '0', 'bool', 'Allow users to register themselves with the system?'),
4040
('judgehost_warning', '30', 'int', 'Time in seconds after a judgehost last checked in before showing its status as "warning".'),
4141
('judgehost_critical', '120', 'int', 'Time in seconds after a judgehost last checked in before showing its status as "critical".'),
42-
('thumbnail_size', '128', 'int', 'Maximum width/height of a thumbnail for uploaded testcase images.');
42+
('thumbnail_size', '128', 'int', 'Maximum width/height of a thumbnail for uploaded testcase images.'),
43+
('diskspace_error_perc', '5', 'int', 'Minimum percentage of free disk space on judgehosts.'),
44+
('diskspace_error_abs', '1048576', 'int', 'Minimum absolute free disk space (in kB) on judgehosts.');
4345

4446
--
4547
-- Dumping data for table `executable`

sql/upgrade/upgrade_5.1.0_5.2.0DEV.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ UPDATE `judging` SET `judgehost` = 'host-created-by-SQL-upgrade' WHERE `judgehos
7878
--
7979
-- Add/remove sample/initial contents
8080
--
81+
INSERT INTO `configuration` (`name`, `value`, `type`, `description`) VALUES
82+
('diskspace_error_perc', '5', 'int', 'Minimum percentage of free disk space on judgehosts.'),
83+
('diskspace_error_abs', '1048576', 'int', 'Minimum absolute free disk space (in kB) on judgehosts.');
8184

8285
--
8386
-- Finally remove obsolete structures after moving data

www/api/index.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,8 +1299,11 @@ function internal_error_POST($args)
12991299
$disabled = dj_json_decode($args['disabled']);
13001300
// disable what needs to be disabled
13011301
set_internal_error($disabled, $args['cid'], 0);
1302-
$submitid = $DB->q('VALUE SELECT submitid FROM judging WHERE judgingid = %i', $args['judgingid']);
1303-
give_back_judging($args['judgingid'], $submitid);
1302+
if ( $disabled['kind'] == 'problem' ) {
1303+
// give back judging if we have to
1304+
$submitid = $DB->q('VALUE SELECT submitid FROM judging WHERE judgingid = %i', $args['judgingid']);
1305+
give_back_judging($args['judgingid'], $submitid);
1306+
}
13041307

13051308
return $errorid;
13061309
}

0 commit comments

Comments
 (0)