Skip to content

Commit 0061e0b

Browse files
author
vogelor
committed
fixed a bug in clearing the syslog. This bug only appears at "low used" systems
1 parent 01d1205 commit 0061e0b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

server/cron_daily.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,32 @@ function setConfigVar( $filename, $varName, $varValue ) {
231231
* actually in the system (and will be insered in 3 days or so).
232232
* 2) We have to keey ALL entries which are not actually precessed by the
233233
* server never mind how old they are!
234+
* 3) We have to keep the entry with the highest autoinc-id, because mysql calculates the
235+
* autoinc-id as "new value = max(row) +1" and does not store this in a separate table.
236+
* This means, if we delete to entry with the highest autoinc-value then this value is
237+
* reused as autoinc and so there are more than one entries with the same value (over
238+
* for example 4 Weeks). This is confusing for our system.
239+
* ATTENTION 2) and 3) is in some case NOT the same! so we have to check both!
234240
*/
235241

236242
/* First we need all servers and the last sys_datalog-id they processed */
237243
$sql = "SELECT server_id, updated FROM server ORDER BY server_id";
238244
$records = $app->dbmaster->queryAllRecords($sql);
239245

246+
/* Then we need the highest value ever */
247+
$sql = "SELECT max(datalog_id) FROM sys_datalog";
248+
$res = $app->dbmaster->queryOneRecord($sql);
249+
$maxId = $res['max(datalog_id)'];
250+
240251
/* Then delete server by server */
241252
foreach($records as $server) {
242253
$tmp_server_id = intval($server['server_id']);
243254
if($tmp_server_id > 0) {
244-
$sql = "DELETE FROM sys_datalog WHERE tstamp < " . $tstamp .
255+
$sql = "DELETE FROM sys_datalog " .
256+
"WHERE tstamp < " . $tstamp .
245257
" AND server_id = " . intval($server['server_id']) .
246-
" AND datalog_id < " . intval($server['updated']);
258+
" AND datalog_id < " . intval($server['updated']) .
259+
" AND datalog_id < " . intval($maxId);
247260
}
248261
// echo $sql . "\n";
249262
$app->dbmaster->query($sql);

0 commit comments

Comments
 (0)