rrs-commit: r61 - trunk

decibel at decibel.org decibel at decibel.org
Wed Mar 30 23:02:34 GMT 2005


Author: decibel
Date: Wed Mar 30 23:02:33 2005
New Revision: 61

Modified:
   trunk/rrs_functions.sql
Log:
We don't insert into the source table.

Modified: trunk/rrs_functions.sql
==============================================================================
--- trunk/rrs_functions.sql	(original)
+++ trunk/rrs_functions.sql	Wed Mar 30 23:02:33 2005
@@ -20,6 +20,8 @@
     v_start_time rrs.history.start_time%TYPE;
     v_run_time interval;
     v_my_oid oid;
+
+    v_max_source_interval rrs.history_data_interval_run_time_v.next_data_interval%TYPE;
 BEGIN
     -- Figure out our OID and try to aquire a lock
     SELECT ''rrs.update()''::regprocedure::oid
@@ -34,6 +36,10 @@
     -- remember when we started for later
     v_start_time := rrs.tod();
 
+    --  Calculate max amount of source data to process for any source
+    v_max_source_interval := calculate_source_interval();
+
+    -- TODO nuke
     -- make sure all the buckets are up to date
     v_total_rows := rrs.update_buckets( v_start_time );
 
@@ -44,11 +50,25 @@
         -- Run through all the RRDs
         FOR v_rrs IN SELECT * FROM rrs.rrs ORDER BY coalesce( parent, -1 ), rrs_id
         LOOP
+            -- IF parent IS NULL
+                -- find first bucket time to process
+                    -- same as current
+                -- find last bucket time to process
+                    -- max(timestamp) from source table where timestamp < min( current_timestamp, v_first_bucket_time + v_max_source_interval )
+                -- update_bucket_source( v_first_bucket_time, v_last_bucket_time )
+                -- update_rrs_source( v_first_bucket_time, v_last_bucket_time )
+                    -- including updating first and last bucket times in source_status
+            -- ELSE
+                -- update_bucket
+                -- update_rrs
+
+            -- TODO nuke
             v_total_rows := v_total_rows + update_source_rrs(v_source.source_id, v_rrs.rrs_id);
             --debug.f(''alert_rrs %s rows added for rrs_id %s'', v_rows, v_rrs.rrs_id);
         END LOOP;
     END LOOP;
 
+    -- TODO When we log runtime, also log the average amount of input data processed for each source, if we limited it
     v_run_time := rrs.log_time( v_start_time );
     RAISE INFO ''% rows updated in %'', v_total_rows, v_run_time;
 
@@ -106,7 +126,7 @@
         IF v_last_end_time = v_max_end_time THEN
             RAISE INFO ''Nothing to do for % rrs_id %, skipping...'', v_source.source_name, v_rrs.rrs_id;
         ELSE
-            RAISE INFO ''Inserting into % for rrs_id % from % to %'', v_source.source_name, v_rrs.rrs_id, v_last_end_time, v_max_end_time;
+            RAISE INFO ''Inserting into % for rrs_id % from % to %'', v_source.insert_table, v_rrs.rrs_id, v_last_end_time, v_max_end_time;
             IF v_rrs.parent IS NULL THEN
                 v_sql :=
                 ''INSERT INTO '' || v_source.insert_table || ''
@@ -416,6 +436,98 @@
     LANGUAGE plpgsql;
 
 
+
+
+
+
+
+
+
+CREATE OR REPLACE FUNCTION calculate_source_interval ( ) RETURNS rrs.history_data_interval.data_interval%TYPE AS '
+DECLARE
+
+    r record;
+    v_desired_run_time interval;
+    v_last_start_time rrs.history.start_time%TYPE;
+    v_min_interval interval;
+    v_max_interval interval;
+    v_next_data_interval rrs.history_data_interval.data_interval%TYPE;
+    v_last_data_interval_secs double precision;
+    v_last_end_time rrs.bucket.end_time%TYPE;
+BEGIN
+    v_desired_run_time := rrs.setting_get(''desired run time'');
+    IF v_desired_run_time IS NULL THEN
+        v_desired_run_time := rrs.setting_set( ''desired run time'', ''30 seconds'' );
+        v_desired_run_time := rrs.setting_get(''desired run time'');
+        RAISE WARNING ''calculate_source_interval: WARNING desired run time not set, setting to %'', v_desired_run_time;
+    END IF;
+
+    v_min_interval = rrs.setting_get(''minimum data interval'');
+    IF v_min_interval IS NULL THEN
+        v_min_interval = rrs.setting_set(
+                                            ''minimum data interval''
+                                            , ( v_desired_run_time * 10 )::text
+                                        )
+        ;
+        v_min_interval = rrs.setting_get(''minimum data interval'');
+        RAISE WARNING ''calculate_source_interval: WARNING minimum data interval not set, setting to %'', v_min_interval;
+    END IF;
+
+    v_max_interval = rrs.setting_get(''maximum data interval'');
+    IF v_max_interval IS NULL THEN
+        v_max_interval = rrs.setting_set(
+                                            ''maximum data interval''
+                                            , ( v_min_interval * 100 )::text
+                                        )
+        ;
+        v_max_interval = rrs.setting_get(''maximum data interval'');
+        RAISE WARNING ''calculate_source_interval: WARNING maximum data interval not set, setting to %'', v_max_interval;
+    END IF;
+
+    IF v_max_interval < v_min_interval THEN
+        RAISE EXCEPTION ''calculate_source_interval: EXCEPTION! maximum data interval(%) < minimum data interval(%)'', v_max_interval, v_min_interval;
+    END IF;
+
+    RAISE DEBUG ''calculate_source_interval BEGIN: desired run time %, minimum data interval %, maximum data interval %'', v_desired_run_time, v_min_interval;
+
+    /*
+        For each row in history, calculate the ratio of desired runtime to actual, and apply that to the
+        data_interval that was used in that run. Take the average of those and use it for our value.
+    */
+    
+    SELECT INTO v_next_data_interval, v_last_start_time
+            avg(next_data_interval), max(start_time)
+        FROM rrs.history_data_interval_run_time_v
+        WHERE next_data_interval IS NOT NULL
+    ;
+    SELECT INTO v_last_data_interval_secs
+            rrs.interval_to_seconds(data_interval)
+        FROM rrs.history_data_interval
+        WHERE start_time = v_last_start_time
+    ;
+
+    IF v_next_data_interval IS NULL THEN
+        RAISE INFO ''calculate_source_interval: no data available, using minimum interval (%)'', v_min_interval;
+        v_next_data_interval := v_min_interval;
+    ELSE
+        IF rrs.interval_to_seconds(v_next_data_interval) > v_last_data_interval_secs * 3 THEN
+            RAISE INFO ''calculate_source_interval: maximum data interval slew exceeded, capping to 3x last setting'';
+            v_next_data_interval := rrs.seconds_to_interval( v_last_data_interval_secs * 3 );
+        END IF;
+    END IF;
+    IF v_next_data_interval < v_min_interval THEN
+        RAISE INFO ''v_next_data_interval % too low, forcing to minimum interval (%)'', v_next_data_interval, v_min_interval;
+        v_next_data_interval := v_min_interval;
+    END IF;
+    IF v_next_data_interval > v_max_interval THEN
+        RAISE INFO ''v_next_data_interval % too high, forcing to maximum interval (%)'', v_next_data_interval, v_max_interval;
+        v_next_data_interval := v_max_interval;
+    END IF;
+
+    RAISE INFO ''limiting bucket creation to %'', v_next_data_interval; 
+    RETURN v_next_data_interval;
+END;
+' LANGUAGE plpgsql;
 
 
 


More information about the rrs-commit mailing list