[sr-dev] git:master: sr-oob.cfg: Automatic reload of global attributes.

Jan Janak jan at ryngle.com
Tue Oct 20 21:47:57 CEST 2009


Module: sip-router
Branch: master
Commit: 6351694a00c4b305bdfe80a33b9597a09c727bcc
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6351694a00c4b305bdfe80a33b9597a09c727bcc

Author: Jan Janak <jan at ryngle.com>
Committer: Jan Janak <jan at ryngle.com>
Date:   Tue Oct 20 21:45:04 2009 +0200

sr-oob.cfg: Automatic reload of global attributes.

This patch creates a new attribute called gattr_timestamp. The
attribute is stored in global_attrs table and contains the timestamp
of the last modification of the contents of the table. It can be
updated by applications like serweb whenever they update any of the
attributes in that table.

In the configuration file sr-oob.cfg we check the value stored in that
attribute and if its value indicates that it has been modified within
last two minutes, the script initiates a reload of the global_attr
memory cache.

The mechanism is the same as for the domain_attrs table reload that
is present in the same route section.

This patch also contains an unrelated small fix that correct the path
to the root directory in lib/srdb2/schema/Makefile. The root path
there was incorrect as result of the merge.

---

 etc/sip-router-oob.cfg             |    9 ++++++++
 lib/srdb2/schema/Makefile          |    2 +-
 lib/srdb2/schema/global_attrs.xml  |    7 ++++++
 scripts/dbtext/ser_db/global_attrs |    1 +
 scripts/mysql/my_create.sql        |   38 ++++++++++++++++++------------------
 scripts/mysql/my_data.sql          |    2 +
 scripts/oracle/or_data.sql         |    2 +
 scripts/postgres/pg_data.sql       |    2 +
 8 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/etc/sip-router-oob.cfg b/etc/sip-router-oob.cfg
index 145541f..2d593b3 100644
--- a/etc/sip-router-oob.cfg
+++ b/etc/sip-router-oob.cfg
@@ -512,6 +512,7 @@ modparam("timer", "declare_timer",
 # -- db_ops --
 
 modparam("db_ops", "declare_handle", "reload")
+modparam("db_ops", "declare_handle", "gattr_reload")
 
 
 # -------------------------  Request Routing Logic --------------------------
@@ -1575,5 +1576,13 @@ route[ON_1MIN_TIMER] {
 		exec_msg("sercmd domain.reload");
 	}
 	db_close("reload");
+
+	# Reload global attributes (they are cached in memory) if the contents of
+	# the global_attrs table has been changed recently.
+	db_query("select value from global_attrs where name='gattr_timestamp' and type=0 and cast(value as unsigned int) between unix_timestamp(now())-120 and unix_timestamp(now())", "gattr_reload");
+	if (@db.fetch.gattr_reload.count=="1") {
+	   exec_msg("sercmd global.reload");
+	}
+	db_close("gattr_reload");
 }
 
diff --git a/lib/srdb2/schema/Makefile b/lib/srdb2/schema/Makefile
index f6b8d76..f501031 100644
--- a/lib/srdb2/schema/Makefile
+++ b/lib/srdb2/schema/Makefile
@@ -5,7 +5,7 @@
 # File containing SER database description
 DOC_ROOT = ser.xml
 
-ROOT=../..
+ROOT=../../..
 STYLESHEETS=$(ROOT)/doc/stylesheets/dbschema/xsl
 
 # Stylesheet used to generate MySQL database schema
diff --git a/lib/srdb2/schema/global_attrs.xml b/lib/srdb2/schema/global_attrs.xml
index 96f9bb3..1d1beb3 100644
--- a/lib/srdb2/schema/global_attrs.xml
+++ b/lib/srdb2/schema/global_attrs.xml
@@ -224,6 +224,13 @@
     <value col="global_attrs.value">0</value>
     <value col="global_attrs.flags">33</value>
   </row>
+
+  <row vendor-controlled="1">
+    <value col="global_attrs.name">gattr_timestamp</value>
+    <value col="global_attrs.type">0</value>
+    <value col="global_attrs.value">0</value>
+    <value col="global_attrs.flags">33</value>
+  </row>
   
   <row>
 	<value col="global_attrs.name">sw_show_status</value>
diff --git a/scripts/dbtext/ser_db/global_attrs b/scripts/dbtext/ser_db/global_attrs
index 91711ef..91a514e 100644
--- a/scripts/dbtext/ser_db/global_attrs
+++ b/scripts/dbtext/ser_db/global_attrs
@@ -4,6 +4,7 @@ sw_credential_default_flags:0:33:32
 sw_uri_default_flags:0:57:32
 sw_uname_assign_mode:2:fcfs:32
 domain_data_version:0:0:33
+gattr_timestamp:0:0:33
 sw_show_status:0:1:32
 sw_require_conf:0:1:32
 lang:2:en:33
diff --git a/scripts/mysql/my_create.sql b/scripts/mysql/my_create.sql
index fc27798..45f38e7 100644
--- a/scripts/mysql/my_create.sql
+++ b/scripts/mysql/my_create.sql
@@ -204,31 +204,31 @@ CREATE TABLE phonebook (
 );
 
 CREATE TABLE gw (
-    id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
-    lcr_id SMALLINT UNSIGNED NOT NULL DEFAULT 1,
     gw_name VARCHAR(128) NOT NULL,
-    grp_id INT UNSIGNED NOT NULL,
-    ip_addr VARCHAR(15) NOT NULL,
-    hostname VARCHAR(64),
+    ip_addr INT UNSIGNED NOT NULL,
     port SMALLINT UNSIGNED,
     uri_scheme TINYINT UNSIGNED,
-    transport TINYINT UNSIGNED,
-    strip TINYINT UNSIGNED,
-    tag VARCHAR(16) DEFAULT NULL,
-    weight INT UNSIGNED,
-    flags INT UNSIGNED DEFAULT 0 NOT NULL,
-    defunct INT UNSIGNED DEFAULT NULL,
-    CONSTRAINT lcr_id_gw_name_idx UNIQUE (lcr_id, gw_name)
+    transport SMALLINT UNSIGNED,
+    prefix VARCHAR(16) NOT NULL,
+    grp_id INT NOT NULL,
+    UNIQUE KEY gw_idx1 (gw_name),
+    KEY gw_idx2 (grp_id)
+);
+
+CREATE TABLE gw_grp (
+    grp_id INT AUTO_INCREMENT NOT NULL,
+    grp_name VARCHAR(64) NOT NULL,
+    UNIQUE KEY gwgrp_idx (grp_id)
 );
 
 CREATE TABLE lcr (
-    id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
-    lcr_id SMALLINT UNSIGNED NOT NULL DEFAULT 1,
-    prefix VARCHAR(16) DEFAULT NULL,
-    from_uri VARCHAR(64) DEFAULT NULL,
-    grp_id INT UNSIGNED NOT NULL,
-    priority TINYINT UNSIGNED NOT NULL,
-    INDEX lcr_id_idx (lcr_id)
+    prefix VARCHAR(16) NOT NULL,
+    from_uri VARCHAR(255) NOT NULL DEFAULT '%',
+    grp_id INT,
+    priority INT,
+    KEY lcr_idx1 (prefix),
+    KEY lcr_idx2 (from_uri),
+    KEY lcr_idx3 (grp_id)
 );
 
 CREATE TABLE grp (
diff --git a/scripts/mysql/my_data.sql b/scripts/mysql/my_data.sql
index 682852d..57cb18f 100644
--- a/scripts/mysql/my_data.sql
+++ b/scripts/mysql/my_data.sql
@@ -87,6 +87,8 @@ DELETE FROM global_attrs WHERE name='sw_uname_assign_mode';
 INSERT IGNORE INTO global_attrs (name, type, value, flags) VALUES ('sw_uname_assign_mode', '2', 'fcfs', '32');
 DELETE FROM global_attrs WHERE name='domain_data_version';
 INSERT IGNORE INTO global_attrs (name, type, value, flags) VALUES ('domain_data_version', '0', '0', '33');
+DELETE FROM global_attrs WHERE name='gattr_timestamp';
+INSERT IGNORE INTO global_attrs (name, type, value, flags) VALUES ('gattr_timestamp', '0', '0', '33');
 INSERT IGNORE INTO global_attrs (name, type, value, flags) VALUES ('sw_show_status', '0', '1', '32');
 INSERT IGNORE INTO global_attrs (name, type, value, flags) VALUES ('sw_require_conf', '0', '1', '32');
 INSERT IGNORE INTO global_attrs (name, type, value, flags) VALUES ('lang', '2', 'en', '33');
diff --git a/scripts/oracle/or_data.sql b/scripts/oracle/or_data.sql
index 6085ea4..83f3dff 100644
--- a/scripts/oracle/or_data.sql
+++ b/scripts/oracle/or_data.sql
@@ -87,6 +87,8 @@ DELETE FROM global_attrs WHERE name='sw_uname_assign_mode';
 INSERT IGNORE INTO global_attrs (name, type, value, flags) VALUES ('sw_uname_assign_mode', '2', 'fcfs', '32');
 DELETE FROM global_attrs WHERE name='domain_data_version';
 INSERT IGNORE INTO global_attrs (name, type, value, flags) VALUES ('domain_data_version', '0', '0', '33');
+DELETE FROM global_attrs WHERE name='gattr_timestamp';
+INSERT IGNORE INTO global_attrs (name, type, value, flags) VALUES ('gattr_timestamp', '0', '0', '33');
 INSERT IGNORE INTO global_attrs (name, type, value, flags) VALUES ('sw_show_status', '0', '1', '32');
 INSERT IGNORE INTO global_attrs (name, type, value, flags) VALUES ('sw_require_conf', '0', '1', '32');
 INSERT IGNORE INTO global_attrs (name, type, value, flags) VALUES ('lang', '2', 'en', '33');
diff --git a/scripts/postgres/pg_data.sql b/scripts/postgres/pg_data.sql
index 2c3d8cd..fc1585d 100644
--- a/scripts/postgres/pg_data.sql
+++ b/scripts/postgres/pg_data.sql
@@ -87,6 +87,8 @@ DELETE FROM global_attrs WHERE name='sw_uname_assign_mode';
 INSERT INTO global_attrs (name, type, value, flags) VALUES ('sw_uname_assign_mode', '2', 'fcfs', '32');
 DELETE FROM global_attrs WHERE name='domain_data_version';
 INSERT INTO global_attrs (name, type, value, flags) VALUES ('domain_data_version', '0', '0', '33');
+DELETE FROM global_attrs WHERE name='gattr_timestamp';
+INSERT INTO global_attrs (name, type, value, flags) VALUES ('gattr_timestamp', '0', '0', '33');
 INSERT INTO global_attrs (name, type, value, flags) VALUES ('sw_show_status', '0', '1', '32');
 INSERT INTO global_attrs (name, type, value, flags) VALUES ('sw_require_conf', '0', '1', '32');
 INSERT INTO global_attrs (name, type, value, flags) VALUES ('lang', '2', 'en', '33');




More information about the sr-dev mailing list