Browse code

dns_cache_del_nonexp configuration option is introduced: it allows deletion of non-expired records from the DNS cache when the cache becomes full. Disabled by default.

Miklos Tirpak authored on 21/08/2007 11:08:15
Showing 5 changed files
... ...
@@ -251,6 +251,7 @@ DNS_CACHE_MIN_TTL	dns_cache_min_ttl
251 251
 DNS_CACHE_MAX_TTL	dns_cache_max_ttl
252 252
 DNS_CACHE_MEM		dns_cache_mem
253 253
 DNS_CACHE_GC_INT	dns_cache_gc_interval
254
+DNS_CACHE_DEL_NONEXP	dns_cache_del_nonexp|dns_cache_delete_nonexpired
254 255
 /* blacklist */
255 256
 USE_DST_BLST		use_dst_blacklist
256 257
 DST_BLST_MEM		dst_blacklist_mem
... ...
@@ -496,6 +497,8 @@ EAT_ABLE	[\ \t\b\r]
496 497
 								return DNS_CACHE_MEM; }
497 498
 <INITIAL>{DNS_CACHE_GC_INT}	{ count(); yylval.strval=yytext;
498 499
 								return DNS_CACHE_GC_INT; }
500
+<INITIAL>{DNS_CACHE_DEL_NONEXP}	{ count(); yylval.strval=yytext;
501
+								return DNS_CACHE_DEL_NONEXP; }
499 502
 <INITIAL>{USE_DST_BLST}	{ count(); yylval.strval=yytext;
500 503
 								return USE_DST_BLST; }
501 504
 <INITIAL>{DST_BLST_MEM}	{ count(); yylval.strval=yytext;
... ...
@@ -290,6 +290,7 @@ static struct socket_id* mk_listen_id(char*, int, int);
290 290
 %token DNS_CACHE_MAX_TTL
291 291
 %token DNS_CACHE_MEM
292 292
 %token DNS_CACHE_GC_INT
293
+%token DNS_CACHE_DEL_NONEXP
293 294
 /*blacklist*/
294 295
 %token USE_DST_BLST
295 296
 %token DST_BLST_MEM
... ...
@@ -617,6 +618,8 @@ assign_stm:
617 618
 	| DNS_CACHE_MEM error { yyerror("boolean value expected"); }
618 619
 	| DNS_CACHE_GC_INT EQUAL NUMBER   { IF_DNS_CACHE(dns_timer_interval=$3); }
619 620
 	| DNS_CACHE_GC_INT error { yyerror("boolean value expected"); }
621
+	| DNS_CACHE_DEL_NONEXP EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_del_nonexp=$3); }
622
+	| DNS_CACHE_DEL_NONEXP error { yyerror("boolean value expected"); }
620 623
 	| USE_DST_BLST EQUAL NUMBER   { IF_DST_BLACKLIST(use_dst_blacklist=$3); }
621 624
 	| USE_DST_BLST error { yyerror("boolean value expected"); }
622 625
 	| DST_BLST_MEM EQUAL NUMBER   { IF_DST_BLACKLIST(blst_max_mem=$3); }
... ...
@@ -38,6 +38,7 @@
38 38
  *  2008-07-25  various rpc commands to manipulate the content
39 39
  *		of the cache (Miklos)
40 40
  *  2007-07-30  DNS cache measurements added (Gergo)
41
+ *  2007-08-17  dns_cache_del_nonexp config option is introduced (Miklos)
41 42
  */
42 43
 
43 44
 #ifdef USE_DNS_CACHE
... ...
@@ -98,6 +99,7 @@ unsigned int dns_timer_interval=DEFAULT_DNS_TIMER_INTERVAL; /* in s */
98 99
 int dns_flags=0; /* default flags used for the  dns_*resolvehost
99 100
                     (compatibility wrappers) */
100 101
 int dns_srv_lb=0; /* off by default */
102
+int dns_cache_del_nonexp=0; /* delete only expired entries by default */
101 103
 
102 104
 #ifdef USE_DNS_CACHE_STATS
103 105
 struct t_dns_cache_stats* dns_cache_stats=0;
... ...
@@ -717,7 +719,7 @@ inline static int dns_cache_add(struct dns_hash_entry* e)
717 719
 #endif
718 720
 		LOG(L_WARN, "WARNING: dns_cache_add: cache full, trying to free...\n");
719 721
 		/* free ~ 12% of the cache */
720
-		dns_cache_free_mem(*dns_cache_mem_used/16*14, 1);
722
+		dns_cache_free_mem(*dns_cache_mem_used/16*14, !dns_cache_del_nonexp);
721 723
 		if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
722 724
 			LOG(L_ERR, "ERROR: dns_cache_add: max. cache mem size exceeded\n");
723 725
 			return -1;
... ...
@@ -757,7 +759,7 @@ inline static int dns_cache_add_unsafe(struct dns_hash_entry* e)
757 759
 		LOG(L_WARN, "WARNING: dns_cache_add: cache full, trying to free...\n");
758 760
 		/* free ~ 12% of the cache */
759 761
 		UNLOCK_DNS_HASH();
760
-		dns_cache_free_mem(*dns_cache_mem_used/16*14, 1);
762
+		dns_cache_free_mem(*dns_cache_mem_used/16*14, !dns_cache_del_nonexp);
761 763
 		LOCK_DNS_HASH();
762 764
 		if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
763 765
 			LOG(L_ERR, "ERROR: dns_cache_add: max. cache mem size exceeded\n");
... ...
@@ -242,6 +242,12 @@ DNS Cache and Failover Config Variables
242 242
    dns_cache_gc_interval = how often (in s) the dns cache will be garbage 
243 243
       collected.
244 244
       Default:  120 s.
245
+      
246
+   dns_cache_del_nonexp = yes | no or
247
+   dns_cache_delete_nonexpired = yes | no - allow deletion of non-expired
248
+      records from the cache when there is no more space left for new
249
+      ones. The last-recently used entries are deleted first.
250
+      Default: no
245 251
 
246 252
 
247 253
 DNS Cache Compile Options
... ...
@@ -206,6 +206,7 @@ extern unsigned int dns_timer_interval; /* gc timer interval in s */
206 206
 extern int dns_flags; /* default flags used for the  dns_*resolvehost
207 207
                     (compatibility wrappers) */
208 208
 extern int dns_srv_lb; /* default SRV LB support value */
209
+extern int dns_cache_del_nonexp; /* delete non-expired values from the cache when it is full */
209 210
 
210 211
 #ifdef USE_DNS_CACHE_STATS
211 212
 struct t_dns_cache_stats{