Improved performance of processing log records
authorarjen <arjen>
Sat, 18 Jan 2003 08:48:43 +0000 (08:48 +0000)
committerarjen <arjen>
Sat, 18 Jan 2003 08:48:43 +0000 (08:48 +0000)
src/gcm_daemon/gcm_daemon.php

index 8d56920..5112e53 100755 (executable)
@@ -15,6 +15,7 @@
    
    * DATES * 
    First       : November 8th 2002
+   Gnucomo-0.0.3: December 6th 2002
 
 */
 
@@ -30,14 +31,19 @@ require_once "classes/gnucomo.process_log.php";
 // Set the standard variables //
 $project_name  = "gnucomo";    //name of the entire project
 $app_name      = "gcm_daemon"; //name of the application running
-$db_version    = 13;           //The db_version indicates what the level of 
+$developrelease = "FALSE";      //Indicates if special debug settings are needed
+$db_version    = 20;           //The db_version indicates what the level of 
                                //the database should be. If the database is 
                                //old an update will be generated.
-$gcmd_version   = 2;           //This value indicates the active version of the gcm_daemon,
+$gcmd_version   = 3;           //This value indicates the active version of the gcm_daemon,
                                //which is saved in the database. Log records that were not
                                //recognized before will now be recognized. The version doesn't
                                //mean anything in the overall gnucomo project.
 
+//Avoid time-limit issues
+set_time_limit(0);
+
+
 // Read the database settings //
 $class_settings = new gnucomo_config();
 $class_settings->read($project_name);
@@ -60,11 +66,12 @@ $dbms->db_connect();
 
 if ($dbms->have_db_connection() == "FALSE") {
   exit ("Database connection failed.");
+} else {
+  //The database connection has been made.
+  $dbms_working = copy_db_class($dbms);
 }
-//The database connection has been made.
-
 //Verify if the database is up-to-date by checking the versionnumber
-$local_sql = "SELECT setting_value FROM db_value WHERE setting = 'db_version'";
+$local_sql = "SELECT setting_value FROM db_value WHERE setting = 'db_version' ";
 $dbms->query($local_sql);
 
 if ($dbms->fetch_row() == "TRUE") {
@@ -88,7 +95,7 @@ $dbms->query($local_sql);
 if ($dbms->fetch_row() == "TRUE") {
    if ($dbms->db_result_row[0] < $gcmd_version) {
       //Reactive log-records that weren't understood earlier.
-      $local_sql = "UPDATE log SET processed = false WHERE recognized = false";
+      $local_sql = "UPDATE log SET processed = false WHERE logid NOT IN (SELECT DISTINCT logid FROM log_adv)";
       $dbms->query($local_sql);
 
       //Update de gcm_daemon version in the database
@@ -100,10 +107,16 @@ if ($dbms->fetch_row() == "TRUE") {
       
 }
 
+//Now we loop the tasks that we have to do.
+
+do {
+
+  //At this place we start processing new log-lines 
+  process_log ();
 
-  
-//At this place we start processing new log-lines 
-process_log ();
+  $keep_running = 'FALSE';
+
+} while ($keep_running == 'TRUE');
 
 //Tell the log that we're ending our efforts in a nice way
 syslog (LOG_INFO, "gcm_daemon ended nicely");
@@ -118,10 +131,26 @@ function process_log () {
   * OUTPUT : NONE
   */
   global $dbms;
-  
-  //Find open records.
-  $local_sql = "SELECT * FROM log WHERE processed = FALSE";
+  global $dbms_working;
+
+/*
+  //Start a transaction for the processing/
+  $local_sql_working = "BEGIN TRANSACTION";
+  $dbms_working->query($local_sql_working);
+*/  
+  //Find records in log that still have to be processed.
+
+  $local_sql = " SELECT setting_value FROM db_value WHERE setting = 'log_processing'";
   $dbms->query($local_sql);
+
+  if ($dbms->fetch_row() == "TRUE") {
+     $last_log = $dbms->db_result_row[0];
+  }
+
+
+  $local_sql = "SELECT * FROM log WHERE logid > CAST(".$last_log." AS BIGINT) order by logid";
+  $dbms->query($local_sql);
+
   $local_counter = 0;
 
   if ($dbms->num_rows() > 0) {
@@ -137,6 +166,7 @@ function process_log () {
        //Walk through all the log-records.
 
        while ($local_counter < $dbms->num_rows()) {
+
          $local_return_row = $dbms->fetch_row();
          if ($local_return_row == 'TRUE') {
             //Work on active rows
@@ -172,17 +202,10 @@ function process_log () {
                 syslog (LOG_INFO, "Couldn't find suitable OS for processing the logline");
                 break;
              }
-
-            //Now that the processing took place change the processing state if processing was
-            //completed successfully.
-            if ($local_process_return == 'TRUE') {
-               $local_sql_processed = "UPDATE log SET recognized = TRUE where logid = $local_log_id";
-               $dbms_changes->query($local_sql_processed);
+            
+            if ($local_process_return <> 'TRUE') {
+              $local_process_return = 'FALSE';
             }
-            //Change the status of the log-record to processed.
-            $local_sql_processed = "UPDATE log SET processed = TRUE WHERE logid = $local_log_id";
-            $dbms_changes->query($local_sql_processed);       
 
          } else {
 
@@ -191,11 +214,23 @@ function process_log () {
          }
          $local_counter++;
        } 
+
+       $local_sql = "UPDATE db_value SET setting_value = '".$local_log_id."' where setting = 'log_processing'";
+       $dbms->query($local_sql);
+       
+
      } else {
        syslog (LOG_INFO, "Couldn't clone database connection.");
        die ("Couldn't reconnect to the database.\n");
     }     
+   } else {
+     die ("done");
    }
+/*
+   //close the transaction
+   $local_working = "COMMIT";
+   $dbms_working->query($local_working);
+*/
 }
 
 ?>