summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2009-06-15 09:30:59 +0000
committerIgor Sysoev <igor@sysoev.ru>2009-06-15 09:30:59 +0000
commit47246d6a1d65bb11c6db7d074ed8d317813ccfdb (patch)
treef3e1310f363bded05528853d3195d0b33b486cba
parent2374ad792c1bf5c90ed90151dfee8d52408382b9 (diff)
downloadnginx-47246d6a1d65bb11c6db7d074ed8d317813ccfdb.tar.gz
nginx-47246d6a1d65bb11c6db7d074ed8d317813ccfdb.tar.bz2
merge r2895, r2896, r2926, r2927, r2928, r2930, and r2936:
various proxy/fastcgi cache features and fixes: *) report about proxy/fastcgi_store and proxy/fastcgi_cache incompatibility *) delete useless r->cache->uses *) proxy_cache_use_stale/fastcgi_cache_use_stale updating *) inherit proxy_set_header, proxy_hide_header, and fastcgi_hide_header only if cache settings are similar *) add response file uniq while loading cold cache on demand
-rw-r--r--src/http/modules/ngx_http_fastcgi_module.c28
-rw-r--r--src/http/modules/ngx_http_proxy_module.c32
-rw-r--r--src/http/ngx_http_cache.h11
-rw-r--r--src/http/ngx_http_file_cache.c32
-rw-r--r--src/http/ngx_http_upstream.c17
-rw-r--r--src/http/ngx_http_upstream.h5
6 files changed, 89 insertions, 36 deletions
diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c
index 83178dba6..f752398db 100644
--- a/src/http/modules/ngx_http_fastcgi_module.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -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 }
};
@@ -1911,7 +1912,7 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
if (conf->upstream.store != 0) {
ngx_conf_merge_value(conf->upstream.store,
- prev->upstream.store, 0);
+ prev->upstream.store, 0);
if (conf->upstream.store_lengths == NULL) {
conf->upstream.store_lengths = prev->upstream.store_lengths;
@@ -2541,20 +2542,31 @@ ngx_http_fastcgi_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_str_t *value;
ngx_http_script_compile_t sc;
- if (flcf->upstream.store != NGX_CONF_UNSET || flcf->upstream.store_lengths)
+ if (flcf->upstream.store != NGX_CONF_UNSET
+ || flcf->upstream.store_lengths)
{
return "is duplicate";
}
value = cf->args->elts;
- if (ngx_strcmp(value[1].data, "on") == 0) {
- flcf->upstream.store = 1;
+ if (ngx_strcmp(value[1].data, "off") == 0) {
+ flcf->upstream.store = 0;
return NGX_CONF_OK;
}
- if (ngx_strcmp(value[1].data, "off") == 0) {
- flcf->upstream.store = 0;
+#if (NGX_HTTP_CACHE)
+
+ if (flcf->upstream.cache != NGX_CONF_UNSET_PTR
+ && flcf->upstream.cache != NULL)
+ {
+ return "is incompatible with \"fastcgi_cache\"";
+ }
+
+#endif
+
+ if (ngx_strcmp(value[1].data, "on") == 0) {
+ flcf->upstream.store = 1;
return NGX_CONF_OK;
}
@@ -2599,6 +2611,10 @@ ngx_http_fastcgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_OK;
}
+ if (flcf->upstream.store > 0 || flcf->upstream.store_lengths) {
+ return "is incompatible with \"fastcgi_store\"";
+ }
+
flcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
&ngx_http_fastcgi_module);
if (flcf->upstream.cache == NULL) {
diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c
index 484694d14..6e2d230b2 100644
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -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 }
};
@@ -1973,7 +1974,7 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
if (conf->upstream.store != 0) {
ngx_conf_merge_value(conf->upstream.store,
- prev->upstream.store, 0);
+ prev->upstream.store, 0);
if (conf->upstream.store_lengths == NULL) {
conf->upstream.store_lengths = prev->upstream.store_lengths;
@@ -2341,7 +2342,9 @@ ngx_http_proxy_merge_headers(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *conf,
conf->headers_source = prev->headers_source;
}
- if (conf->headers_set_hash.buckets) {
+ if (conf->headers_set_hash.buckets
+ && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL)))
+ {
return NGX_OK;
}
@@ -2809,20 +2812,31 @@ ngx_http_proxy_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_str_t *value;
ngx_http_script_compile_t sc;
- if (plcf->upstream.store != NGX_CONF_UNSET || plcf->upstream.store_lengths)
+ if (plcf->upstream.store != NGX_CONF_UNSET
+ || plcf->upstream.store_lengths)
{
return "is duplicate";
}
value = cf->args->elts;
- if (ngx_strcmp(value[1].data, "on") == 0) {
- plcf->upstream.store = 1;
+ if (ngx_strcmp(value[1].data, "off") == 0) {
+ plcf->upstream.store = 0;
return NGX_CONF_OK;
}
- if (ngx_strcmp(value[1].data, "off") == 0) {
- plcf->upstream.store = 0;
+#if (NGX_HTTP_CACHE)
+
+ if (plcf->upstream.cache != NGX_CONF_UNSET_PTR
+ && plcf->upstream.cache != NULL)
+ {
+ return "is incompatible with \"proxy_cache\"";
+ }
+
+#endif
+
+ if (ngx_strcmp(value[1].data, "on") == 0) {
+ plcf->upstream.store = 1;
return NGX_CONF_OK;
}
@@ -2867,6 +2881,10 @@ ngx_http_proxy_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_OK;
}
+ if (plcf->upstream.store > 0 || plcf->upstream.store_lengths) {
+ return "is incompatible with \"proxy_store\"";
+ }
+
plcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
&ngx_http_proxy_module);
if (plcf->upstream.cache == NULL) {
diff --git a/src/http/ngx_http_cache.h b/src/http/ngx_http_cache.h
index 232f09674..cf909cc3d 100644
--- a/src/http/ngx_http_cache.h
+++ b/src/http/ngx_http_cache.h
@@ -13,11 +13,8 @@
#include <ngx_http.h>
-/**/
#define NGX_HTTP_CACHE_STALE 1
-#define NGX_HTTP_CACHE_AGED 2
-#define NGX_HTTP_CACHE_THE_SAME 3
-/**/
+#define NGX_HTTP_CACHE_UPDATING 2
#define NGX_HTTP_CACHE_KEY_LEN 16
@@ -28,8 +25,6 @@ typedef struct {
} ngx_http_cache_valid_t;
-/* ngx_http_file_cache_node_t takes exactly 64 bytes on FreeBSD/i386 */
-
typedef struct {
ngx_rbtree_node_t node;
ngx_queue_t queue;
@@ -41,8 +36,9 @@ typedef struct {
unsigned uses:10;
unsigned valid_msec:10;
unsigned error:10;
- /* 7 unused bits */
unsigned exists:1;
+ unsigned updating:1;
+ /* 12 unused bits */
ngx_file_uniq_t uniq;
time_t expire;
@@ -68,7 +64,6 @@ struct ngx_http_cache_s {
off_t length;
ngx_uint_t min_uses;
- ngx_uint_t uses;
ngx_uint_t error;
ngx_uint_t valid_msec;
diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c
index 23e3503e0..323358742 100644
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -172,9 +172,8 @@ ngx_http_file_cache_open(ngx_http_request_t *r)
rc = ngx_http_file_cache_exists(cache, c);
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http file cache exists: %i u:%ui e:%d",
- rc, c->uses, c->exists);
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "http file cache exists: %i e:%d", rc, c->exists);
if (rc == NGX_ERROR) {
return rc;
@@ -321,6 +320,7 @@ ngx_http_file_cache_open(ngx_http_request_t *r)
c->node->uses = 1;
c->node->body_start = c->body_start;
c->node->exists = 1;
+ c->node->uniq = of.uniq;
cache->sh->size += (c->length + cache->bsize - 1) / cache->bsize;
}
@@ -332,15 +332,24 @@ ngx_http_file_cache_open(ngx_http_request_t *r)
if (c->valid_sec < now) {
- c->uses = c->min_uses;
+ ngx_shmtx_lock(&cache->shpool->mutex);
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http file cache expired: %T %T", c->valid_sec, now);
+ 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);
- /* TODO: NGX_HTTP_CACHE_AGED */
+ return rc;
+ }
return NGX_OK;
}
@@ -442,7 +451,6 @@ done:
ngx_queue_insert_head(&cache->sh->queue, &fcn->queue);
c->uniq = fcn->uniq;
- c->uses = fcn->uses;
c->error = fcn->error;
c->node = fcn;
@@ -654,6 +662,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);
}
@@ -736,6 +746,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) {
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index eb839e11b..75f3641c4 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -577,8 +577,17 @@ ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
rc = ngx_http_file_cache_open(r);
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http upstream cache: %i u:%ui", rc, c->uses);
+ 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) {
@@ -4076,7 +4085,9 @@ ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
{
conf->hide_headers_hash = prev->hide_headers_hash;
- if (conf->hide_headers_hash.buckets) {
+ if (conf->hide_headers_hash.buckets
+ && ((conf->cache == NULL) == (prev->cache == NULL)))
+ {
return NGX_OK;
}
diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h
index 488aed5a8..eb97d3989 100644
--- a/src/http/ngx_http_upstream.h
+++ b/src/http/ngx_http_upstream.h
@@ -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