Browse code

- add fetch_result support to carrierroute routing rules loading - related to feature request #1876664 - needs this capability in the database, otherwise the "old" logic will be used - number of routing rules fetchs is configurable as module parameter

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4876 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 10/09/2008 16:51:11
Showing 5 changed files
... ...
@@ -14,8 +14,8 @@ Henning Westerholt
14 14
 
15 15
    Copyright � 2007 1&1 Internet AG
16 16
    Revision History
17
-   Revision $Revision: 4838 $ $Date: 2008-09-04 15:53:32 +0200
18
-                              (Do, 04 Sep 2008) $
17
+   Revision $Revision: 4872 $ $Date: 2008-09-09 17:39:38 +0200
18
+                              (Di, 09 Sep 2008) $
19 19
      __________________________________________________________
20 20
 
21 21
    Table of Contents
... ...
@@ -39,6 +39,7 @@ Henning Westerholt
39 39
               1.3.7. default_tree (string)
40 40
               1.3.8. use_domain (int)
41 41
               1.3.9. fallback_default (int)
42
+              1.3.10. fetch_rows (integer)
42 43
 
43 44
         1.4. Exported Functions
44 45
 
... ...
@@ -110,23 +111,24 @@ Henning Westerholt
110 110
    1.7. Set default_tree parameter
111 111
    1.8. Set use_domain parameter
112 112
    1.9. Set fallback_default parameter
113
-   1.10. cr_replace_host usage
114
-   1.11. cr_deactivate_host usage
115
-   1.12. cr_activate_host usage
116
-   1.13. cr_add_host usage
117
-   1.14. cr_delete_host usage
118
-   1.15. Configuration example - Routing to default tree
119
-   1.16. Configuration example - Routing to user tree
120
-   1.17. Configuration example - module configuration
121
-   1.18. Example database content - carrierroute table
122
-   1.19. Example database content - simple carrierfailureroute
113
+   1.10. Set fetch_rows parameter
114
+   1.11. cr_replace_host usage
115
+   1.12. cr_deactivate_host usage
116
+   1.13. cr_activate_host usage
117
+   1.14. cr_add_host usage
118
+   1.15. cr_delete_host usage
119
+   1.16. Configuration example - Routing to default tree
120
+   1.17. Configuration example - Routing to user tree
121
+   1.18. Configuration example - module configuration
122
+   1.19. Example database content - carrierroute table
123
+   1.20. Example database content - simple carrierfailureroute
123 124
           table
124 125
 
125
-   1.20. Example database content - more complex
126
+   1.21. Example database content - more complex
126 127
           carrierfailureroute table
127 128
 
128
-   1.21. Example database content - route_tree table
129
-   1.22. Necessary extensions for the user table
129
+   1.22. Example database content - route_tree table
130
+   1.23. Necessary extensions for the user table
130 131
    2.1. Set db_url parameter
131 132
    2.2. Set carrierroute_table parameter
132 133
    2.3. Set carrierroute_id_col parameter
... ...
@@ -348,6 +350,21 @@ modparam("carrierroute", "use_domain", 0)
348 348
 modparam("carrierroute", "fallback_default", 1)
349 349
 ...
350 350
 
351
+1.3.10. fetch_rows (integer)
352
+
353
+   The number of the rows to be fetched at once from database when
354
+   loading the routing data. This value can be used to tune the
355
+   load time at startup. For 1MB of private memory (default) it
356
+   should be below 3750. The database driver must support the
357
+   fetch_result() capability.
358
+
359
+   Default value is "2000".
360
+
361
+   Example 1.10. Set fetch_rows parameter
362
+...
363
+modparam("carrierroute", "fetch_rows", 3000)
364
+...
365
+
351 366
 1.4. Exported Functions
352 367
 
353 368
    Previous versions of carriertree had some more function. All
... ...
@@ -532,7 +549,7 @@ reply_code, dstavp)
532 532
 
533 533
    Use the "null" prefix to specify an empty prefix.
534 534
 
535
-   Example 1.10. cr_replace_host usage
535
+   Example 1.11. cr_replace_host usage
536 536
 ...
537 537
 kamctl fifo cr_replace_host "-d proxy -p 49 -h proxy1 -t proxy2"
538 538
 ...
... ...
@@ -554,7 +571,7 @@ kamctl fifo cr_replace_host "-d proxy -p 49 -h proxy1 -t proxy2"
554 554
 
555 555
    Use the "null" prefix to specify an empty prefix.
556 556
 
557
-   Example 1.11. cr_deactivate_host usage
557
+   Example 1.12. cr_deactivate_host usage
558 558
 ...
559 559
 kamctl fifo cr_deactivate_host "-d proxy -p 49 -h proxy1"
560 560
 ...
... ...
@@ -570,7 +587,7 @@ kamctl fifo cr_deactivate_host "-d proxy -p 49 -h proxy1"
570 570
 
571 571
    Use the "null" prefix to specify an empty prefix.
572 572
 
573
-   Example 1.12. cr_activate_host usage
573
+   Example 1.13. cr_activate_host usage
574 574
 ...
575 575
 kamctl fifo cr_activate_host "-d proxy -p 49 -h proxy1"
576 576
 ...
... ...
@@ -590,7 +607,7 @@ kamctl fifo cr_activate_host "-d proxy -p 49 -h proxy1"
590 590
 
591 591
    Use the "null" prefix to specify an empty prefix.
592 592
 
593
-   Example 1.13. cr_add_host usage
593
+   Example 1.14. cr_add_host usage
594 594
 ...
595 595
 kamctl fifo cr_add_host "-d proxy -p 49 -h proxy1 -w 0.25"
596 596
 ...
... ...
@@ -611,14 +628,14 @@ kamctl fifo cr_add_host "-d proxy -p 49 -h proxy1 -w 0.25"
611 611
 
612 612
    Use the "null" prefix to specify an empty prefix.
613 613
 
614
-   Example 1.14. cr_delete_host usage
614
+   Example 1.15. cr_delete_host usage
615 615
 ...
616 616
 kamctl fifo cr_delete_host "-d proxy -p 49 -h proxy1 -w 0.25"
617 617
 ...
618 618
 
619 619
 1.6. Examples
620 620
 
621
-   Example 1.15. Configuration example - Routing to default tree
621
+   Example 1.16. Configuration example - Routing to default tree
622 622
 ...
623 623
 route {
624 624
         # route calls based on hash over callid
... ...
@@ -652,7 +669,7 @@ failure_route[2] {
652 652
 }
653 653
 
654 654
 
655
-   Example 1.16. Configuration example - Routing to user tree
655
+   Example 1.17. Configuration example - Routing to user tree
656 656
 ...
657 657
 route[1] {
658 658
         cr_user_carrier("$fU", "$fd", "$avp(s:carrier)");
... ...
@@ -692,7 +709,7 @@ failure_route[1] {
692 692
 }
693 693
 ...
694 694
 
695
-   Example 1.17. Configuration example - module configuration
695
+   Example 1.18. Configuration example - module configuration
696 696
 
697 697
    The following config file specifies within the default carrier
698 698
    two domains, each with an prefix that contains two hosts. It is
... ...
@@ -772,7 +789,7 @@ domain register {
772 772
    For a minimal configuration either use the config file given
773 773
    above, or insert some data into the tables of the module.
774 774
 
775
-   Example 1.18. Example database content - carrierroute table
775
+   Example 1.19. Example database content - carrierroute table
776 776
 ...
777 777
 +----+---------+--------+-------------+-------+------+---------------+
778 778
 | id | carrier | domain | scan_prefix | flags | prob | rewrite_host  |
... ...
@@ -811,7 +828,7 @@ domain register {
811 811
    this flags are not set, the other two rules are used. The
812 812
    "strip", "mask" and "comment" colums are omitted for brevity.
813 813
 
814
-   Example 1.19. Example database content - simple
814
+   Example 1.20. Example database content - simple
815 815
    carrierfailureroute table
816 816
 ...
817 817
 +----+---------+--------+---------------+------------+-------------+
... ...
@@ -833,7 +850,7 @@ domain register {
833 833
    corresponding entry in the carrierroute table, otherwise the
834 834
    module will not load the routing data.
835 835
 
836
-   Example 1.20. Example database content - more complex
836
+   Example 1.21. Example database content - more complex
837 837
    carrierfailureroute table
838 838
 ...
839 839
 +----+---------+-----------+------------+--------+-----+-------------+
... ...
@@ -860,7 +877,7 @@ domain register {
860 860
    holds domain entries for this routing rules. Not all table
861 861
    colums are show here for brevity.
862 862
 
863
-   Example 1.21. Example database content - route_tree table
863
+   Example 1.22. Example database content - route_tree table
864 864
 ...
865 865
 +----+----------+
866 866
 | id | carrier  |
... ...
@@ -879,7 +896,7 @@ domain register {
879 879
    that you specified as modul parameter) to choose the actual
880 880
    carrier for the users.
881 881
 
882
-   Example 1.22. Necessary extensions for the user table
882
+   Example 1.23. Necessary extensions for the user table
883 883
 
884 884
    Suggested changes:
885 885
 ...
... ...
@@ -79,6 +79,8 @@ int use_domain = 0;
79 79
 
80 80
 int fallback_default = 1;
81 81
 
82
+int cr_fetch_rows = 2000;
83
+
82 84
 
83 85
 /************* Declaration of Interface Functions **************************/
84 86
 static int mod_init(void);
... ...
@@ -122,6 +124,7 @@ static param_export_t params[]= {
122 122
 	{"config_file",                STR_PARAM, &config_file },
123 123
 	{"use_domain",                 INT_PARAM, &use_domain },
124 124
 	{"fallback_default",           INT_PARAM, &fallback_default },
125
+	{"fetch_result",               INT_PARAM, &cr_fetch_rows },
125 126
 	{0,0,0}
126 127
 };
127 128
 
... ...
@@ -62,6 +62,7 @@ extern const str SP_EMPTY_PREFIX;
62 62
 extern int mode;
63 63
 extern int use_domain;
64 64
 extern int fallback_default;
65
+extern int cr_fetch_rows;
65 66
 
66 67
 enum hash_algorithm {
67 68
 	alg_crc32 = 1, /*!< hashing algorithm is CRC32 */
... ...
@@ -286,6 +286,30 @@ modparam("carrierroute", "fallback_default", 1)
286 286
 		    </programlisting>
287 287
 	    </example>
288 288
     </section>
289
+		<section>
290
+		<title><varname>fetch_rows</varname> (integer)</title>
291
+		<para>
292
+		The number of the rows to be fetched at once from database
293
+		when loading the routing data. This value can be used to tune
294
+		the load time at startup. For 1MB of private memory (default)
295
+		it should be below 3750. The database driver must support the
296
+		fetch_result() capability.
297
+		</para>
298
+		<para>
299
+		<emphasis>
300
+			Default value is <quote>2000</quote>.
301
+		</emphasis>
302
+		</para>
303
+		<example>
304
+		<title>Set <varname>fetch_rows</varname> parameter</title>
305
+		<programlisting format="linespecific">
306
+...
307
+modparam("carrierroute", "fetch_rows", 3000)
308
+...
309
+</programlisting>
310
+		</example>
311
+	</section>
312
+
289 313
 </section>
290 314
     <section>
291 315
 	<title>Exported Functions</title>
... ...
@@ -210,51 +210,77 @@ int load_route_data(struct rewrite_data * rd) {
210 210
 		return -1;
211 211
 	}
212 212
 
213
-	if (carrierroute_dbf.query(carrierroute_dbh, NULL, NULL, NULL, (db_key_t *) columns, 0,
214
-				COLUMN_NUM, NULL, &res) < 0) {
215
-		LM_ERR("Failed to query database.\n");
216
-		return -1;
217
-	}
218
-	for (i = 0; i < RES_ROW_N(res); ++i) {
219
-		row = &RES_ROWS(res)[i];
220
-		tmp_domain.s=(char *)row->values[COL_DOMAIN].val.string_val;
221
-		tmp_scan_prefix.s=(char *)row->values[COL_SCAN_PREFIX].val.string_val;
222
-		tmp_rewrite_host.s=(char *)row->values[COL_REWRITE_HOST].val.string_val;
223
-		tmp_rewrite_prefix.s=(char *)row->values[COL_REWRITE_PREFIX].val.string_val;
224
-		tmp_rewrite_suffix.s=(char *)row->values[COL_REWRITE_SUFFIX].val.string_val;
225
-		tmp_comment.s=(char *)row->values[COL_COMMENT].val.string_val;
226
-		if (tmp_domain.s==NULL) tmp_domain.s="";
227
-		if (tmp_scan_prefix.s==NULL) tmp_scan_prefix.s="";
228
-		if (tmp_rewrite_host.s==NULL) tmp_rewrite_host.s="";
229
-		if (tmp_rewrite_prefix.s==NULL) tmp_rewrite_prefix.s="";
230
-		if (tmp_rewrite_suffix.s==NULL) tmp_rewrite_suffix.s="";
231
-		if (tmp_comment.s==NULL) tmp_comment.s="";
232
-		tmp_domain.len=strlen(tmp_domain.s);
233
-		tmp_scan_prefix.len=strlen(tmp_scan_prefix.s);
234
-		tmp_rewrite_host.len=strlen(tmp_rewrite_host.s);
235
-		tmp_rewrite_prefix.len=strlen(tmp_rewrite_prefix.s);
236
-		tmp_rewrite_suffix.len=strlen(tmp_rewrite_suffix.s);
237
-		tmp_comment.len=strlen(tmp_comment.s);
238
-		if (add_route(rd,
239
-				row->values[COL_CARRIER].val.int_val,
240
-				&tmp_domain,
241
-				&tmp_scan_prefix,
242
-				row->values[COL_FLAGS].val.int_val,
243
-				row->values[COL_MASK].val.int_val,
244
-				0,
245
-				row->values[COL_PROB].val.double_val,
246
-				&tmp_rewrite_host,
247
-				row->values[COL_STRIP].val.int_val,
248
-				&tmp_rewrite_prefix,
249
-				&tmp_rewrite_suffix,
250
-				1,
251
-				0,
252
-				-1,
253
-				NULL,
254
-				&tmp_comment) == -1) {
255
-			goto errout;
213
+	if (DB_CAPABILITY(carrierroute_dbf, DB_CAP_FETCH)) {
214
+		if (carrierroute_dbf.query(carrierroute_dbh, NULL, NULL, NULL, (db_key_t *) columns, 0,
215
+					COLUMN_NUM, NULL, NULL) < 0) {
216
+			LM_ERR("Failed to query database to prepare fetch row.\n");
217
+			return -1;
218
+		}
219
+		if(carrierroute_dbf.fetch_result(carrierroute_dbh, &res, cr_fetch_rows) < 0) {
220
+			LM_ERR("Fetching rows failed\n");
221
+			return -1;
222
+		}
223
+	} else {
224
+		if (carrierroute_dbf.query(carrierroute_dbh, NULL, NULL, NULL, (db_key_t *) columns, 0,
225
+					COLUMN_NUM, NULL, &res) < 0) {
226
+			LM_ERR("Failed to query database.\n");
227
+			return -1;
256 228
 		}
257 229
 	}
230
+	int n = 0;
231
+	do {
232
+		LM_DBG("loading, cycle %d", n++);
233
+		for (i = 0; i < RES_ROW_N(res); ++i) {
234
+			row = &RES_ROWS(res)[i];
235
+			tmp_domain.s=(char *)row->values[COL_DOMAIN].val.string_val;
236
+			tmp_scan_prefix.s=(char *)row->values[COL_SCAN_PREFIX].val.string_val;
237
+			tmp_rewrite_host.s=(char *)row->values[COL_REWRITE_HOST].val.string_val;
238
+			tmp_rewrite_prefix.s=(char *)row->values[COL_REWRITE_PREFIX].val.string_val;
239
+			tmp_rewrite_suffix.s=(char *)row->values[COL_REWRITE_SUFFIX].val.string_val;
240
+			tmp_comment.s=(char *)row->values[COL_COMMENT].val.string_val;
241
+			if (tmp_domain.s==NULL) tmp_domain.s="";
242
+			if (tmp_scan_prefix.s==NULL) tmp_scan_prefix.s="";
243
+			if (tmp_rewrite_host.s==NULL) tmp_rewrite_host.s="";
244
+			if (tmp_rewrite_prefix.s==NULL) tmp_rewrite_prefix.s="";
245
+			if (tmp_rewrite_suffix.s==NULL) tmp_rewrite_suffix.s="";
246
+			if (tmp_comment.s==NULL) tmp_comment.s="";
247
+			tmp_domain.len=strlen(tmp_domain.s);
248
+			tmp_scan_prefix.len=strlen(tmp_scan_prefix.s);
249
+			tmp_rewrite_host.len=strlen(tmp_rewrite_host.s);
250
+			tmp_rewrite_prefix.len=strlen(tmp_rewrite_prefix.s);
251
+			tmp_rewrite_suffix.len=strlen(tmp_rewrite_suffix.s);
252
+			tmp_comment.len=strlen(tmp_comment.s);
253
+			if (add_route(rd,
254
+					row->values[COL_CARRIER].val.int_val,
255
+					&tmp_domain,
256
+					&tmp_scan_prefix,
257
+					row->values[COL_FLAGS].val.int_val,
258
+					row->values[COL_MASK].val.int_val,
259
+					0,
260
+					row->values[COL_PROB].val.double_val,
261
+					&tmp_rewrite_host,
262
+					row->values[COL_STRIP].val.int_val,
263
+					&tmp_rewrite_prefix,
264
+					&tmp_rewrite_suffix,
265
+					1,
266
+					0,
267
+					-1,
268
+					NULL,
269
+					&tmp_comment) == -1) {
270
+				goto errout;
271
+			}
272
+		}
273
+		if (DB_CAPABILITY(carrierroute_dbf, DB_CAP_FETCH)) {
274
+			if(carrierroute_dbf.fetch_result(carrierroute_dbh, &res, cr_fetch_rows) < 0) {
275
+				LM_ERR("fetching rows failed\n");
276
+				carrierroute_dbf.free_result(carrierroute_dbh, res);
277
+				return -1;
278
+			}
279
+		} else {
280
+			break;
281
+		}
282
+	} while(RES_ROW_N(res) > 0);
283
+
258 284
 	carrierroute_dbf.free_result(carrierroute_dbh, res);
259 285
 	res = NULL;
260 286