[PATCH 1 of 1] Cache: move locked entries during forced expire to avoid overflow

Dmitry Volyntsev xeioex at nginx.com
Tue May 12 11:39:10 UTC 2015


# HG changeset patch
# User Dmitry Volyntsev <xeioex at nginx.com>
# Date 1431103222 -10800
#      Fri May 08 19:40:22 2015 +0300
# Branch se
# Node ID bbdd30b83a35a68c60ee69fea68530ef5e6560fd
# Parent  079711e9b729d175c84fa58a959d786f5dc890f3
Cache: move locked entries during forced expire to avoid overflow.

diff -r 079711e9b729 -r bbdd30b83a35 src/http/ngx_http_file_cache.c
--- a/src/http/ngx_http_file_cache.c	Thu Apr 23 14:10:42 2015 +0300
+++ b/src/http/ngx_http_file_cache.c	Fri May 08 19:40:22 2015 +0300
@@ -1769,13 +1769,14 @@ ngx_http_file_cache_cleanup(void *data)
 static time_t
 ngx_http_file_cache_forced_expire(ngx_http_file_cache_t *cache)
 {
-    u_char                      *name;
+    u_char                      *name, *p;
     size_t                       len;
     time_t                       wait;
     ngx_uint_t                   tries;
     ngx_path_t                  *path;
     ngx_queue_t                 *q;
     ngx_http_file_cache_node_t  *fcn;
+    u_char                       key[2 * NGX_HTTP_CACHE_KEY_LEN];
 
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
                    "http file cache forced expire");
@@ -1790,15 +1791,19 @@ ngx_http_file_cache_forced_expire(ngx_ht
 
     ngx_memcpy(name, path->name.data, path->name.len);
 
-    wait = 10;
     tries = 20;
 
     ngx_shmtx_lock(&cache->shpool->mutex);
 
-    for (q = ngx_queue_last(&cache->sh->queue);
-         q != ngx_queue_sentinel(&cache->sh->queue);
-         q = ngx_queue_prev(q))
-    {
+    for ( ;; ) {
+
+        if (ngx_queue_empty(&cache->sh->queue)) {
+            wait = 10;
+            break;
+        }
+
+        q = ngx_queue_last(&cache->sh->queue);
+
         fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue);
 
         ngx_log_debug6(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
@@ -1811,6 +1816,18 @@ ngx_http_file_cache_forced_expire(ngx_ht
             wait = 0;
 
         } else {
+            p = ngx_hex_dump(key, (u_char *) &fcn->node.key,
+                             sizeof(ngx_rbtree_key_t));
+            len = NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t);
+            (void) ngx_hex_dump(p, fcn->key, len);
+
+            ngx_queue_remove(q);
+            ngx_queue_insert_head(&cache->sh->queue, &fcn->queue);
+
+            ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
+                          "ignore long locked excess cache entry %*s, count:%d",
+                          2 * NGX_HTTP_CACHE_KEY_LEN, key, fcn->count);
+
             if (--tries) {
                 continue;
             }



Подробная информация о списке рассылки nginx-ru