Ver Fonte

siptrace: new parameter to allow the option of doing delayed insert to db

- if 'trace_delayed' parameter is set to 1, insert to database table is
  done delayed, when the db server has support for it
Daniel-Constantin Mierla há 13 anos atrás
pai
commit
d85c6b9037

+ 23 - 7
modules_k/siptrace/README

@@ -16,9 +16,9 @@ Daniel-Constantin Mierla
 
 
    <[email protected]>
    <[email protected]>
 
 
-   Copyright © 2010 asipto.com
+   Copyright © 2010 asipto.com
 
 
-   Copyright © 2006 voice-system.ro
+   Copyright © 2006 voice-system.ro
      __________________________________________________________________
      __________________________________________________________________
 
 
    Table of Contents
    Table of Contents
@@ -48,6 +48,7 @@ Daniel-Constantin Mierla
               3.13. hep_mode_on (integer)
               3.13. hep_mode_on (integer)
               3.14. hep_version (integer)
               3.14. hep_version (integer)
               3.15. hep_capture_id (integer)
               3.15. hep_capture_id (integer)
+              3.16. trace_delayed (integer)
 
 
         4. Functions
         4. Functions
 
 
@@ -77,7 +78,8 @@ Daniel-Constantin Mierla
    1.13. Set hep_mode_on parameter
    1.13. Set hep_mode_on parameter
    1.14. Set hep_version parameter
    1.14. Set hep_version parameter
    1.15. Set hep_capture_id parameter
    1.15. Set hep_capture_id parameter
-   1.16. sip_trace() usage
+   1.16. Set trace_delayed parameter
+   1.17. sip_trace() usage
 
 
 Chapter 1. Admin Guide
 Chapter 1. Admin Guide
 
 
@@ -106,6 +108,7 @@ Chapter 1. Admin Guide
         3.13. hep_mode_on (integer)
         3.13. hep_mode_on (integer)
         3.14. hep_version (integer)
         3.14. hep_version (integer)
         3.15. hep_capture_id (integer)
         3.15. hep_capture_id (integer)
+        3.16. trace_delayed (integer)
 
 
    4. Functions
    4. Functions
 
 
@@ -174,6 +177,7 @@ Chapter 1. Admin Guide
    3.13. hep_mode_on (integer)
    3.13. hep_mode_on (integer)
    3.14. hep_version (integer)
    3.14. hep_version (integer)
    3.15. hep_capture_id (integer)
    3.15. hep_capture_id (integer)
+   3.16. trace_delayed (integer)
 
 
 3.1. db_url (str)
 3.1. db_url (str)
 
 
@@ -380,11 +384,23 @@ modparam("siptrace", "hep_version", 2)
 modparam("siptrace", "hep_capture_id", 234)
 modparam("siptrace", "hep_capture_id", 234)
 ...
 ...
 
 
+3.16. trace_delayed (integer)
+
+   Use 'INSERT DELAYED' to store to database when it is available, instead
+   of 'INSERT'.
+
+   Default value is 0 (off).
+
+   Example 1.16. Set trace_delayed parameter
+...
+modparam("siptrace", "trace_delayed", 1)
+...
+
 4. Functions
 4. Functions
 
 
    4.1. sip_trace()
    4.1. sip_trace()
 
 
-4.1.  sip_trace()
+4.1. sip_trace()
 
 
    Store current processed SIP message in database. It is stored in the
    Store current processed SIP message in database. It is stored in the
    form prior applying chages made to it.
    form prior applying chages made to it.
@@ -392,7 +408,7 @@ modparam("siptrace", "hep_capture_id", 234)
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
    ONREPLY_ROUTE, BRANCH_ROUTE.
    ONREPLY_ROUTE, BRANCH_ROUTE.
 
 
-   Example 1.16. sip_trace() usage
+   Example 1.17. sip_trace() usage
 ...
 ...
 sip_trace();
 sip_trace();
 ...
 ...
@@ -401,7 +417,7 @@ sip_trace();
 
 
    5.1. sip_trace
    5.1. sip_trace
 
 
-5.1.  sip_trace
+5.1. sip_trace
 
 
    Name: sip_trace
    Name: sip_trace
 
 
@@ -410,7 +426,7 @@ sip_trace();
           + on
           + on
           + off
           + off
        The parameter is optional - if missing, the command will return the
        The parameter is optional - if missing, the command will return the
-       status of the SIP message tracing (as string “on� or “off� )
+       status of the SIP message tracing (as string "on" or "off" )
        without changing anything.
        without changing anything.
 
 
    MI FIFO Command Format:
    MI FIFO Command Format:

+ 19 - 0
modules_k/siptrace/doc/siptrace_admin.xml

@@ -428,6 +428,25 @@ modparam("siptrace", "hep_version", 2)
 ...
 ...
 modparam("siptrace", "hep_capture_id", 234)
 modparam("siptrace", "hep_capture_id", 234)
 ...
 ...
+</programlisting>
+                </example>
+        </section>
+        <section>
+                <title><varname>trace_delayed</varname> (integer)</title>
+                <para>
+				Use 'INSERT DELAYED' to store to database when it is available,
+				instead of 'INSERT'.
+                </para>
+                <para>
+                Default value is <emphasis>0 (off)</emphasis>.
+                </para>
+                <example>
+                <title>Set <varname>trace_delayed</varname>
+                parameter</title>
+                <programlisting format="linespecific">
+...
+modparam("siptrace", "trace_delayed", 1)
+...
 </programlisting>
 </programlisting>
                 </example>
                 </example>
         </section>
         </section>

+ 36 - 10
modules_k/siptrace/siptrace.c

@@ -129,6 +129,7 @@ int trace_on   = 0;
 int trace_sl_acks = 1;
 int trace_sl_acks = 1;
 
 
 int trace_to_database = 1;
 int trace_to_database = 1;
+int trace_delayed = 0;
 
 
 int hep_version = 1;
 int hep_version = 1;
 int hep_capture_id = 1;
 int hep_capture_id = 1;
@@ -198,7 +199,8 @@ static param_export_t params[] = {
 	{"xheaders_read",      INT_PARAM, &xheaders_read        },
 	{"xheaders_read",      INT_PARAM, &xheaders_read        },
 	{"hep_mode_on",        INT_PARAM, &hep_mode_on          },	 
 	{"hep_mode_on",        INT_PARAM, &hep_mode_on          },	 
 	{"hep_version",        INT_PARAM, &hep_version          },
 	{"hep_version",        INT_PARAM, &hep_version          },
-        {"hep_capture_id",     INT_PARAM, &hep_capture_id       },	        
+	{"hep_capture_id",     INT_PARAM, &hep_capture_id       },	        
+	{"trace_delayed",      INT_PARAM, &trace_delayed        },
 	{0, 0, 0}
 	{0, 0, 0}
 };
 };
 
 
@@ -790,9 +792,17 @@ static int sip_trace_store_db(struct _siptrace_data *sto)
 		db_vals[9].val.str_val.len = 0;
 		db_vals[9].val.str_val.len = 0;
 
 
 		LM_DBG("storing info...\n");
 		LM_DBG("storing info...\n");
-		if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) {
-			LM_ERR("error storing trace\n");
-			goto error;
+		if(trace_delayed!=0 && db_funcs.insert_delayed!=NULL)
+		{
+			if(db_funcs.insert_delayed(db_con, db_keys, db_vals, NR_KEYS)<0) {
+				LM_ERR("error storing trace\n");
+				goto error;
+			}
+		} else {
+			if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) {
+				LM_ERR("error storing trace\n");
+				goto error;
+			}
 		}
 		}
 #ifdef STATISTICS
 #ifdef STATISTICS
 		update_stat(sto->stat, 1);
 		update_stat(sto->stat, 1);
@@ -805,9 +815,17 @@ static int sip_trace_store_db(struct _siptrace_data *sto)
 	db_vals[9].val.str_val = sto->avp_value.s;
 	db_vals[9].val.str_val = sto->avp_value.s;
 
 
 	LM_DBG("storing info...\n");
 	LM_DBG("storing info...\n");
-	if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) {
-		LM_ERR("error storing trace\n");
-		goto error;
+	if(trace_delayed!=0 && db_funcs.insert_delayed!=NULL)
+	{
+		if(db_funcs.insert_delayed(db_con, db_keys, db_vals, NR_KEYS) < 0) {
+			LM_ERR("error storing trace\n");
+			goto error;
+		}
+	} else {
+		if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) {
+			LM_ERR("error storing trace\n");
+			goto error;
+		}
 	}
 	}
 
 
 	sto->avp = search_next_avp(&sto->state, &sto->avp_value);
 	sto->avp = search_next_avp(&sto->state, &sto->avp_value);
@@ -815,9 +833,17 @@ static int sip_trace_store_db(struct _siptrace_data *sto)
 		db_vals[9].val.str_val = sto->avp_value.s;
 		db_vals[9].val.str_val = sto->avp_value.s;
 
 
 		LM_DBG("storing info...\n");
 		LM_DBG("storing info...\n");
-		if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) {
-			LM_ERR("error storing trace\n");
-			goto error;
+		if(trace_delayed!=0 && db_funcs.insert_delayed!=NULL)
+		{
+			if(db_funcs.insert_delayed(db_con, db_keys, db_vals, NR_KEYS) < 0) {
+				LM_ERR("error storing trace\n");
+				goto error;
+			}
+		} else {
+			if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) {
+				LM_ERR("error storing trace\n");
+				goto error;
+			}
 		}
 		}
 		sto->avp = search_next_avp(&sto->state, &sto->avp_value);
 		sto->avp = search_next_avp(&sto->state, &sto->avp_value);
 	}
 	}