Skip to content

Commit e265dcb

Browse files
author
vogelor
committed
Fixed a bug in the jobqueue - viewer
Fixed a bug in deleting old record from the syslog and the sys_datalog
1 parent 5c49702 commit e265dcb

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

interface/web/monitor/datalog_list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
$sql = '(';
5252
foreach($servers as $s) {
53-
$sql .= " (datalog_id > ".$s['updated']." AND server_id = ".$s['server_id'].") AND ";
53+
$sql .= " (datalog_id > ".$s['updated']." AND server_id = ".$s['server_id'].") OR ";
5454
}
5555
$sql = substr($sql,0,-4);
5656
$sql .= ')';

server/cron_daily.php

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,45 @@
126126
}
127127

128128
#######################################################################################################
129-
// Cleanup logs in database
129+
// Cleanup logs in master database (only the "master-server")
130130
#######################################################################################################
131-
//* Keep 7 days in sys_log
132-
$tstamp = time() - (60*60*24*7);
133-
$sql = "DELETE FROM sys_log WHERE tstamp < $tstamp AND server_id != 0";
134-
$app->db->query($sql);
135-
136-
//* Keep 7 days in sys_datalog
137-
$tstamp = time() - (60*60*24*7);
138-
$sql = "DELETE FROM sys_datalog WHERE tstamp < $tstamp AND server_id != 0";
139-
$app->db->query($sql);
140131

132+
if ($app->dbmaster == $app->db) {
133+
/** 7 days */
134+
$tstamp = time() - (60*60*24*7);
135+
136+
/*
137+
* Keep 7 days in sys_log
138+
* (we can delete the old items, because if they are OK, they don't interrest anymore
139+
* if they are NOT ok, the server will try to process them in 1 minute and so the
140+
* error appears again after 1 minute. So it is no problem to delete the old one!
141+
*/
142+
$sql = "DELETE FROM sys_log WHERE tstamp < $tstamp AND server_id != 0";
143+
$app->dbmaster->query($sql);
144+
145+
/*
146+
* The sys_datalog is more difficult.
147+
* 1) We have to keet ALL entries with
148+
* server_id=0, because they depend on ALL servers (even if they are not
149+
* actually in the system (and will be insered in 3 days or so).
150+
* 2) We have to keey ALL entries which are not actually precessed by the
151+
* server never mind how old they are!
152+
*/
153+
154+
/* First we need all servers and the last sys_datalog-id they processed */
155+
$sql = "SELECT server_id, updated FROM server ORDER BY server_id";
156+
$records = $app->dbmaster->queryAllRecords($sql);
157+
158+
/* Then delete server by server */
159+
foreach($records as $server) {
160+
$sql = "DELETE FROM sys_datalog WHERE tstamp < " . $tstamp .
161+
" AND server_id != 0 " . // to be more secure!
162+
" AND server_id = " . intval($server['server_id']) .
163+
" AND datalog_id < " . intval($server['updated']);
164+
// echo $sql . "\n";
165+
$app->dbmaster->query($sql);
166+
}
167+
}
141168

142169
die("finished.\n");
143170
?>

0 commit comments

Comments
 (0)