Explorar el Código

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 hace 18 años
padre
commit
4136d1916a
Se han modificado 5 ficheros con 17 adiciones y 2 borrados
  1. 3 0
      cfg.lex
  2. 3 0
      cfg.y
  3. 4 2
      dns_cache.c
  4. 6 0
      doc/dns.txt
  5. 1 0
      globals.h

+ 3 - 0
cfg.lex

@@ -251,6 +251,7 @@ DNS_CACHE_MIN_TTL	dns_cache_min_ttl
 DNS_CACHE_MAX_TTL	dns_cache_max_ttl
 DNS_CACHE_MEM		dns_cache_mem
 DNS_CACHE_GC_INT	dns_cache_gc_interval
+DNS_CACHE_DEL_NONEXP	dns_cache_del_nonexp|dns_cache_delete_nonexpired
 /* blacklist */
 USE_DST_BLST		use_dst_blacklist
 DST_BLST_MEM		dst_blacklist_mem
@@ -496,6 +497,8 @@ EAT_ABLE	[\ \t\b\r]
 								return DNS_CACHE_MEM; }
 <INITIAL>{DNS_CACHE_GC_INT}	{ count(); yylval.strval=yytext;
 								return DNS_CACHE_GC_INT; }
+<INITIAL>{DNS_CACHE_DEL_NONEXP}	{ count(); yylval.strval=yytext;
+								return DNS_CACHE_DEL_NONEXP; }
 <INITIAL>{USE_DST_BLST}	{ count(); yylval.strval=yytext;
 								return USE_DST_BLST; }
 <INITIAL>{DST_BLST_MEM}	{ count(); yylval.strval=yytext;

+ 3 - 0
cfg.y

@@ -290,6 +290,7 @@ static struct socket_id* mk_listen_id(char*, int, int);
 %token DNS_CACHE_MAX_TTL
 %token DNS_CACHE_MEM
 %token DNS_CACHE_GC_INT
+%token DNS_CACHE_DEL_NONEXP
 /*blacklist*/
 %token USE_DST_BLST
 %token DST_BLST_MEM
@@ -617,6 +618,8 @@ assign_stm:
 	| DNS_CACHE_MEM error { yyerror("boolean value expected"); }
 	| DNS_CACHE_GC_INT EQUAL NUMBER   { IF_DNS_CACHE(dns_timer_interval=$3); }
 	| DNS_CACHE_GC_INT error { yyerror("boolean value expected"); }
+	| DNS_CACHE_DEL_NONEXP EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_del_nonexp=$3); }
+	| DNS_CACHE_DEL_NONEXP error { yyerror("boolean value expected"); }
 	| USE_DST_BLST EQUAL NUMBER   { IF_DST_BLACKLIST(use_dst_blacklist=$3); }
 	| USE_DST_BLST error { yyerror("boolean value expected"); }
 	| DST_BLST_MEM EQUAL NUMBER   { IF_DST_BLACKLIST(blst_max_mem=$3); }

+ 4 - 2
dns_cache.c

@@ -38,6 +38,7 @@
  *  2008-07-25  various rpc commands to manipulate the content
  *		of the cache (Miklos)
  *  2007-07-30  DNS cache measurements added (Gergo)
+ *  2007-08-17  dns_cache_del_nonexp config option is introduced (Miklos)
  */
 
 #ifdef USE_DNS_CACHE
@@ -98,6 +99,7 @@ unsigned int dns_timer_interval=DEFAULT_DNS_TIMER_INTERVAL; /* in s */
 int dns_flags=0; /* default flags used for the  dns_*resolvehost
                     (compatibility wrappers) */
 int dns_srv_lb=0; /* off by default */
+int dns_cache_del_nonexp=0; /* delete only expired entries by default */
 
 #ifdef USE_DNS_CACHE_STATS
 struct t_dns_cache_stats* dns_cache_stats=0;
@@ -717,7 +719,7 @@ inline static int dns_cache_add(struct dns_hash_entry* e)
 #endif
 		LOG(L_WARN, "WARNING: dns_cache_add: cache full, trying to free...\n");
 		/* free ~ 12% of the cache */
-		dns_cache_free_mem(*dns_cache_mem_used/16*14, 1);
+		dns_cache_free_mem(*dns_cache_mem_used/16*14, !dns_cache_del_nonexp);
 		if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
 			LOG(L_ERR, "ERROR: dns_cache_add: max. cache mem size exceeded\n");
 			return -1;
@@ -757,7 +759,7 @@ inline static int dns_cache_add_unsafe(struct dns_hash_entry* e)
 		LOG(L_WARN, "WARNING: dns_cache_add: cache full, trying to free...\n");
 		/* free ~ 12% of the cache */
 		UNLOCK_DNS_HASH();
-		dns_cache_free_mem(*dns_cache_mem_used/16*14, 1);
+		dns_cache_free_mem(*dns_cache_mem_used/16*14, !dns_cache_del_nonexp);
 		LOCK_DNS_HASH();
 		if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
 			LOG(L_ERR, "ERROR: dns_cache_add: max. cache mem size exceeded\n");

+ 6 - 0
doc/dns.txt

@@ -242,6 +242,12 @@ DNS Cache and Failover Config Variables
    dns_cache_gc_interval = how often (in s) the dns cache will be garbage 
       collected.
       Default:  120 s.
+      
+   dns_cache_del_nonexp = yes | no or
+   dns_cache_delete_nonexpired = yes | no - allow deletion of non-expired
+      records from the cache when there is no more space left for new
+      ones. The last-recently used entries are deleted first.
+      Default: no
 
 
 DNS Cache Compile Options

+ 1 - 0
globals.h

@@ -206,6 +206,7 @@ extern unsigned int dns_timer_interval; /* gc timer interval in s */
 extern int dns_flags; /* default flags used for the  dns_*resolvehost
                     (compatibility wrappers) */
 extern int dns_srv_lb; /* default SRV LB support value */
+extern int dns_cache_del_nonexp; /* delete non-expired values from the cache when it is full */
 
 #ifdef USE_DNS_CACHE_STATS
 struct t_dns_cache_stats{