rrs-commit: r11 - trunk

decibel at decibel.org decibel at decibel.org
Mon Jan 17 23:07:58 GMT 2005


Author: decibel
Date: Mon Jan 17 23:07:57 2005
New Revision: 11

Modified:
   trunk/rrs_functions.sql
   trunk/util_functions.sql
Log:
Add code to utilize user_lock if it's installed

Modified: trunk/rrs_functions.sql
==============================================================================
--- trunk/rrs_functions.sql	(original)
+++ trunk/rrs_functions.sql	Mon Jan 17 23:07:57 2005
@@ -25,8 +25,20 @@
     v_rrs rrs.rrs%ROWTYPE;
     v_source rrs.source%ROWTYPE;
     v_sql text;
+
+    v_my_oid oid;
 BEGIN
-    -- First, make sure all the buckets are up to date
+    -- Figure out our OID and try to aquire a lock
+    SELECT ''update()''::regprocedure::oid
+            INTO v_my_oid
+    ;
+    
+    IF update_lock(v_my_oid, 1) = 0 THEN
+        RAISE NOTICE ''rrs.update: unable to aquire lock'';
+        RETURN -1;
+    END IF;
+
+    -- make sure all the buckets are up to date
     v_total_rows := rrs.update_buckets();
 
     -- Run through each source, updating each RRD for each source
@@ -134,6 +146,7 @@
     END LOOP;
 
     --debug.f(''alert_rrs exit'');
+    update_lock(v_my_oid, 0);
     RETURN v_total_rows;
 END;
 '

Modified: trunk/util_functions.sql
==============================================================================
--- trunk/util_functions.sql	(original)
+++ trunk/util_functions.sql	Mon Jan 17 23:07:57 2005
@@ -3,6 +3,34 @@
 --
 -- $Id$
 
+CREATE OR REPLACE FUNCTION rrs.update_lock(oid, int) RETURNS int AS '
+DECLARE
+    -- Code to set or clear a userlock returns -1 if userlock code isn''t installed, 1 on sucess and 0 on failure
+
+    p_oid ALIAS FOR $1;
+    p_set ALIAS FOR $2;
+BEGIN
+    -- See if the locking code even exists
+    -- We can''t use regprocedure::oid because it will generate an error if the procedure doesn''t exist.
+    IF NOT EXISTS (
+            SELECT *
+                FROM pg_proc
+                WHERE proname=''user_write_lock_oid''
+                    AND pronargs = 1
+                    AND proargtypes=''26''
+        )
+    THEN
+        RETURN -1;
+    END IF;
+
+    IF p_set = 1 THEN
+        RETURN user_write_lock_oid(p_oid);
+    ELSE
+        RETURN user_write_unlock_oid(p_oid);
+    END IF;
+END;
+' LANGUAGE plpgsql;
+
 CREATE OR REPLACE FUNCTION rrs.min(timestamp with time zone, timestamp with time zone) RETURNS timestamp with time zone
     AS '
     SELECT CASE WHEN $1 < $2 THEN $1 ELSE $2 END


More information about the rrs-commit mailing list