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
This commit is contained in:
Igor Sysoev 2009-06-15 09:30:59 +00:00
parent 7a2e47f51d
commit ae6cd36c40
6 changed files with 89 additions and 36 deletions

View 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 }
};
@ -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) {

View 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 }
};
@ -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) {

View File

@ -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;

View File

@ -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,16 +332,25 @@ 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);
return rc;
}
/* TODO: NGX_HTTP_CACHE_AGED */
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) {

View File

@ -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;
}

View 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