]> git.kaiwu.me - nginx.git/commitdiff
proxy_cache_use_stale/fastcgi_cache_use_stale updating
authorIgor Sysoev <igor@sysoev.ru>
Sat, 6 Jun 2009 18:49:47 +0000 (18:49 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Sat, 6 Jun 2009 18:49:47 +0000 (18:49 +0000)
src/http/modules/ngx_http_fastcgi_module.c
src/http/modules/ngx_http_proxy_module.c
src/http/ngx_http_cache.h
src/http/ngx_http_file_cache.c
src/http/ngx_http_upstream.c
src/http/ngx_http_upstream.h

index 2373d7cdfc878aff7672b10428d9856143b366de..abf02720a7a66f48863223656018e32f0884352a 100644 (file)
@@ -178,6 +178,7 @@ static ngx_conf_bitmask_t  ngx_http_fastcgi_next_upstream_masks[] = {
     { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 },
     { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
     { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
+    { ngx_string("updating"), NGX_HTTP_UPSTREAM_FT_UPDATING },
     { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
     { ngx_null_string, 0 }
 };
index 6d7350176cb162fd56dee67e14c9088c3a4a9270..5f48a0c82ff84a57af64449e1ee59b68de255ae9 100644 (file)
@@ -167,6 +167,7 @@ static ngx_conf_bitmask_t  ngx_http_proxy_next_upstream_masks[] = {
     { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
     { ngx_string("http_504"), NGX_HTTP_UPSTREAM_FT_HTTP_504 },
     { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
+    { ngx_string("updating"), NGX_HTTP_UPSTREAM_FT_UPDATING },
     { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
     { ngx_null_string, 0 }
 };
index ed5ec24999f3e5ab0aaddd2a844cbdcc796f4d2c..cf909cc3d03239c5cdeac2c858dbf5716245e1d3 100644 (file)
@@ -14,6 +14,7 @@
 
 
 #define NGX_HTTP_CACHE_STALE         1
+#define NGX_HTTP_CACHE_UPDATING      2
 
 #define NGX_HTTP_CACHE_KEY_LEN       16
 
@@ -36,7 +37,8 @@ typedef struct {
     unsigned                         valid_msec:10;
     unsigned                         error:10;
     unsigned                         exists:1;
-                                     /* 13 unused bits */
+    unsigned                         updating:1;
+                                     /* 12 unused bits */
 
     ngx_file_uniq_t                  uniq;
     time_t                           expire;
index 8c944aed34daf47d07b0f91992c7c5bad6fd1c25..248cd9455669936b4165cfb5bd84b10c03fe47c1 100644 (file)
@@ -331,10 +331,23 @@ ngx_http_file_cache_open(ngx_http_request_t *r)
 
     if (c->valid_sec < now) {
 
-        ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                       "http file cache expired: %T %T", c->valid_sec, now);
+        ngx_shmtx_lock(&cache->shpool->mutex);
+
+        if (c->node->updating) {
+            rc = NGX_HTTP_CACHE_UPDATING;
+
+        } else {
+            c->node->updating = 1;
+            rc = NGX_HTTP_CACHE_STALE;
+        }
 
-        return NGX_HTTP_CACHE_STALE;
+        ngx_shmtx_unlock(&cache->shpool->mutex);
+
+        ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                       "http file cache expired: %i %T %T",
+                       rc, c->valid_sec, now);
+
+        return rc;
     }
 
     return NGX_OK;
@@ -648,6 +661,8 @@ ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf)
         c->node->exists = 1;
     }
 
+    c->node->updating = 0;
+
     ngx_shmtx_unlock(&cache->shpool->mutex);
 }
 
@@ -730,6 +745,8 @@ ngx_http_file_cache_free(ngx_http_request_t *r, ngx_temp_file_t *tf)
         c->node->error = c->error;
     }
 
+    c->node->updating = 0;
+
     ngx_shmtx_unlock(&cache->shpool->mutex);
 
     if (c->temp_file) {
index f360e841e13620ae28de47aa3ce5ff22b4e9beab..747084528a0e1f9d5f6692327d5a7b810ba1c913 100644 (file)
@@ -580,6 +580,15 @@ ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                    "http upstream cache: %i", rc);
 
+    if (rc == NGX_HTTP_CACHE_UPDATING) {
+        if (u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) {
+            rc = NGX_OK;
+
+        } else {
+            rc = NGX_HTTP_CACHE_STALE;
+        }
+    }
+
     if (rc == NGX_OK) {
 
         rc = ngx_http_upstream_cache_send(r, u);
index 488aed5a8783e272d8baca45e7556f380ec3322b..eb97d3989ea294a00f5ed543ff52884fad1f7a40 100644 (file)
@@ -24,8 +24,9 @@
 #define NGX_HTTP_UPSTREAM_FT_HTTP_503        0x00000040
 #define NGX_HTTP_UPSTREAM_FT_HTTP_504        0x00000080
 #define NGX_HTTP_UPSTREAM_FT_HTTP_404        0x00000100
-#define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK       0x00000200
-#define NGX_HTTP_UPSTREAM_FT_MAX_WAITING     0x00000400
+#define NGX_HTTP_UPSTREAM_FT_UPDATING        0x00000200
+#define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK       0x00000400
+#define NGX_HTTP_UPSTREAM_FT_MAX_WAITING     0x00000800
 #define NGX_HTTP_UPSTREAM_FT_NOLIVE          0x40000000
 #define NGX_HTTP_UPSTREAM_FT_OFF             0x80000000