aboutsummaryrefslogtreecommitdiff
path: root/src/http/ngx_http_file_cache.c
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2016-11-03 17:10:29 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2016-11-03 17:10:29 +0300
commitf3093695b9e3069ef4c525cf24b5ddda8ae5f83a (patch)
tree08012d22b81dc36e4d8f3262f62654b564ec40cb /src/http/ngx_http_file_cache.c
parent5eac3bca41bcf4d75d0da2fe88e72516e889779d (diff)
downloadnginx-f3093695b9e3069ef4c525cf24b5ddda8ae5f83a.tar.gz
nginx-f3093695b9e3069ef4c525cf24b5ddda8ae5f83a.zip
Cache: prefix-based temporary files.
On Linux, the rename syscall can be slow due to a global file system lock, acquired for the entire rename operation, unless both old and new files are in the same directory. To address this temporary files are now created in the same directory as the expected resulting cache file when using the "use_temp_path=off" parameter. This change mostly reverts 99639bfdfa2a and 3281de8142f5, restoring the behaviour as of a9138c35120d (with minor changes).
Diffstat (limited to 'src/http/ngx_http_file_cache.c')
-rw-r--r--src/http/ngx_http_file_cache.c45
1 files changed, 13 insertions, 32 deletions
diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c
index ac5c10374..3c8ad7dab 100644
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -2112,6 +2112,17 @@ ngx_http_file_cache_add_file(ngx_tree_ctx_t *ctx, ngx_str_t *name)
return NGX_ERROR;
}
+ /*
+ * Temporary files in cache have a suffix consisting of a dot
+ * followed by 10 digits.
+ */
+
+ if (name->len >= 2 * NGX_HTTP_CACHE_KEY_LEN + 1 + 10
+ && name->data[name->len - 10 - 1] == '.')
+ {
+ return NGX_OK;
+ }
+
if (ctx->size < (off_t) sizeof(ngx_http_file_cache_header_t)) {
ngx_log_error(NGX_LOG_CRIT, ctx->log, 0,
"cache file \"%s\" is too small", name->data);
@@ -2256,7 +2267,6 @@ ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
off_t max_size;
u_char *last, *p;
time_t inactive;
- size_t len;
ssize_t size;
ngx_str_t s, name, *value;
ngx_int_t loader_files, manager_files;
@@ -2529,37 +2539,6 @@ ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
- if (!use_temp_path) {
- cache->temp_path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t));
- if (cache->temp_path == NULL) {
- return NGX_CONF_ERROR;
- }
-
- len = cache->path->name.len + sizeof("/temp") - 1;
-
- p = ngx_pnalloc(cf->pool, len + 1);
- if (p == NULL) {
- return NGX_CONF_ERROR;
- }
-
- cache->temp_path->name.len = len;
- cache->temp_path->name.data = p;
-
- p = ngx_cpymem(p, cache->path->name.data, cache->path->name.len);
- ngx_memcpy(p, "/temp", sizeof("/temp"));
-
- ngx_memcpy(&cache->temp_path->level, &cache->path->level,
- NGX_MAX_PATH_LEVEL * sizeof(size_t));
-
- cache->temp_path->len = cache->path->len;
- cache->temp_path->conf_file = cf->conf_file->file.name.data;
- cache->temp_path->line = cf->conf_file->line;
-
- if (ngx_add_path(cf, &cache->temp_path) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
- }
-
cache->shm_zone = ngx_shared_memory_add(cf, &name, size, cmd->post);
if (cache->shm_zone == NULL) {
return NGX_CONF_ERROR;
@@ -2575,6 +2554,8 @@ ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
cache->shm_zone->init = ngx_http_file_cache_init;
cache->shm_zone->data = cache;
+ cache->use_temp_path = use_temp_path;
+
cache->inactive = inactive;
cache->max_size = max_size;