# HG changeset patch # User Igor Sysoev # Date 1244314187 0 # Node ID 55ceaef03d34feae2e2608b1bd257c47d513c151 # Parent 80a314b63c56b4dfef024eab0bcec0599022b8cb proxy_cache_use_stale/fastcgi_cache_use_stale updating diff -r 80a314b63c56 -r 55ceaef03d34 src/http/modules/ngx_http_fastcgi_module.c --- a/src/http/modules/ngx_http_fastcgi_module.c Sat Jun 06 17:48:54 2009 +0000 +++ b/src/http/modules/ngx_http_fastcgi_module.c Sat Jun 06 18:49:47 2009 +0000 @@ -178,6 +178,7 @@ { 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 } }; diff -r 80a314b63c56 -r 55ceaef03d34 src/http/modules/ngx_http_proxy_module.c --- a/src/http/modules/ngx_http_proxy_module.c Sat Jun 06 17:48:54 2009 +0000 +++ b/src/http/modules/ngx_http_proxy_module.c Sat Jun 06 18:49:47 2009 +0000 @@ -167,6 +167,7 @@ { 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 } }; diff -r 80a314b63c56 -r 55ceaef03d34 src/http/ngx_http_cache.h --- a/src/http/ngx_http_cache.h Sat Jun 06 17:48:54 2009 +0000 +++ b/src/http/ngx_http_cache.h Sat Jun 06 18:49:47 2009 +0000 @@ -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 @@ 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; diff -r 80a314b63c56 -r 55ceaef03d34 src/http/ngx_http_file_cache.c --- a/src/http/ngx_http_file_cache.c Sat Jun 06 17:48:54 2009 +0000 +++ b/src/http/ngx_http_file_cache.c Sat Jun 06 18:49:47 2009 +0000 @@ -331,10 +331,23 @@ 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; - return NGX_HTTP_CACHE_STALE; + } else { + c->node->updating = 1; + rc = 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 @@ c->node->exists = 1; } + c->node->updating = 0; + ngx_shmtx_unlock(&cache->shpool->mutex); } @@ -730,6 +745,8 @@ c->node->error = c->error; } + c->node->updating = 0; + ngx_shmtx_unlock(&cache->shpool->mutex); if (c->temp_file) { diff -r 80a314b63c56 -r 55ceaef03d34 src/http/ngx_http_upstream.c --- a/src/http/ngx_http_upstream.c Sat Jun 06 17:48:54 2009 +0000 +++ b/src/http/ngx_http_upstream.c Sat Jun 06 18:49:47 2009 +0000 @@ -580,6 +580,15 @@ 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); diff -r 80a314b63c56 -r 55ceaef03d34 src/http/ngx_http_upstream.h --- a/src/http/ngx_http_upstream.h Sat Jun 06 17:48:54 2009 +0000 +++ b/src/http/ngx_http_upstream.h Sat Jun 06 18:49:47 2009 +0000 @@ -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