Fixed stucking cache status into UPDATING. #2162

u5h u5.horie at gmail.com
Sun Oct 1 22:58:49 UTC 2023


# HG changeset patch
# User Yugo Horie <u5.horie at gmail.com>
# Date 1696144340 -32400
#      Sun Oct 01 16:12:20 2023 +0900
# Node ID f8f6290d60615a4dfe2d8b26246891228f19aa5d
# Parent  3db945fda515014d220151046d02f3960bcfca0a
Fixed stucking cache status into UPDATING.

Fixed issue-2162's stucking cache status to
introduce `last_updating_time` to record at
the time to start the item last update.
https://trac.nginx.org/nginx/ticket/2162#comment:6

diff -r 3db945fda515 -r f8f6290d6061
src/http/modules/ngx_http_proxy_module.c
--- a/src/http/modules/ngx_http_proxy_module.c  Fri Sep 22 19:23:57 2023
+0400
+++ b/src/http/modules/ngx_http_proxy_module.c  Sun Oct 01 16:12:20 2023
+0900
@@ -564,6 +564,13 @@
       offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_use_stale),
       &ngx_http_proxy_next_upstream_masks },

+    { ngx_string("proxy_cache_updating_timeout"),
+
 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_msec_slot,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_updating_timeout),
+      NULL },
+
     { ngx_string("proxy_cache_methods"),

 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
       ngx_conf_set_bitmask_slot,
@@ -3388,6 +3395,7 @@
     conf->upstream.no_cache = NGX_CONF_UNSET_PTR;
     conf->upstream.cache_valid = NGX_CONF_UNSET_PTR;
     conf->upstream.cache_lock = NGX_CONF_UNSET;
+    conf->upstream.cache_updating_timeout = NGX_CONF_UNSET_MSEC;
     conf->upstream.cache_lock_timeout = NGX_CONF_UNSET_MSEC;
     conf->upstream.cache_lock_age = NGX_CONF_UNSET_MSEC;
     conf->upstream.cache_revalidate = NGX_CONF_UNSET;
diff -r 3db945fda515 -r f8f6290d6061 src/http/ngx_http_cache.h
--- a/src/http/ngx_http_cache.h Fri Sep 22 19:23:57 2023 +0400
+++ b/src/http/ngx_http_cache.h Sun Oct 01 16:12:20 2023 +0900
@@ -59,6 +59,7 @@
     size_t                           body_start;
     off_t                            fs_size;
     ngx_msec_t                       lock_time;
+    ngx_msec_t                       last_updating_time;
 } ngx_http_file_cache_node_t;


@@ -122,6 +123,8 @@

     unsigned                         stale_updating:1;
     unsigned                         stale_error:1;
+
+    ngx_msec_t                       updating_timeout;
 };
diff -r 3db945fda515 -r f8f6290d6061 src/http/ngx_http_file_cache.c
--- a/src/http/ngx_http_file_cache.c    Fri Sep 22 19:23:57 2023 +0400
+++ b/src/http/ngx_http_file_cache.c    Sun Oct 01 16:12:20 2023 +0900
@@ -643,6 +643,10 @@
         ngx_shmtx_lock(&cache->shpool->mutex);

         if (c->node->updating) {
+            if (c->updating_timeout != NGX_CONF_UNSET_MSEC
+                && ngx_current_msec - c->node->last_updating_time >
c->updating_
timeout) {
+                c->node->updating = 0;
+            }
             rc = NGX_HTTP_CACHE_UPDATING;

         } else {
@@ -1377,6 +1381,10 @@

     cache = c->file_cache;

+    ngx_shmtx_lock(&cache->shpool->mutex);
+    c->node->last_updating_time = ngx_current_msec;
+    ngx_shmtx_unlock(&cache->shpool->mutex);
+
     c->updated = 1;
     c->updating = 0;
diff -r 3db945fda515 -r f8f6290d6061 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c      Fri Sep 22 19:23:57 2023 +0400
+++ b/src/http/ngx_http_upstream.c      Sun Oct 01 16:12:20 2023 +0900
@@ -877,6 +877,7 @@
         c->body_start = u->conf->buffer_size;
         c->min_uses = u->conf->cache_min_uses;
         c->file_cache = cache;
+        c->updating_timeout = u->conf->cache_updating_timeout;

         switch (ngx_http_test_predicates(r, u->conf->cache_bypass)) {

diff -r 3db945fda515 -r f8f6290d6061 src/http/ngx_http_upstream.h
--- a/src/http/ngx_http_upstream.h      Fri Sep 22 19:23:57 2023 +0400
+++ b/src/http/ngx_http_upstream.h      Sun Oct 01 16:12:20 2023 +0900
@@ -199,6 +199,8 @@
     ngx_uint_t                       cache_use_stale;
     ngx_uint_t                       cache_methods;

+    ngx_msec_t                       cache_updating_timeout;
+
     off_t                            cache_max_range_offset;

     ngx_flag_t                       cache_lock;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20231002/ec1cb022/attachment.htm>


More information about the nginx-devel mailing list