annotate src/http/ngx_http_file_cache.c @ 9256:43fe0edddba1

Request body: block reading when returning errors. If reading is not blocked, additional client activity can result in undefined behaviour, including segfaults, as seen with proxying with proxy_ignore_client_abort before 4072:cf334deeea66. While unlikely with low-level errors being returned when reading the request body, it might be the case, for example, when chunked transfer encoding is used, and error_page 400 (or 413) is proxied with proxy_ignore_client_abort.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 27 Apr 2024 18:20:17 +0300
parents 0de20f43db25
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 265
diff changeset
1
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 265
diff changeset
2 /*
444
42d11f017717 nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents: 441
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 4387
diff changeset
4 * Copyright (C) Nginx, Inc.
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 265
diff changeset
5 */
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 265
diff changeset
6
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_config.h>
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_core.h>
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10 #include <ngx_http.h>
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
11 #include <ngx_md5.h>
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
14 static ngx_int_t ngx_http_file_cache_lock(ngx_http_request_t *r,
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
15 ngx_http_cache_t *c);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
16 static void ngx_http_file_cache_lock_wait_handler(ngx_event_t *ev);
9203
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
17 static ngx_int_t ngx_http_file_cache_lock_wait(ngx_http_request_t *r,
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
18 ngx_http_cache_t *c);
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
19 static ngx_int_t ngx_http_file_cache_read(ngx_http_request_t *r,
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
20 ngx_http_cache_t *c);
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
21 static ssize_t ngx_http_file_cache_aio_read(ngx_http_request_t *r,
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
22 ngx_http_cache_t *c);
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
23 #if (NGX_HAVE_FILE_AIO)
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
24 static void ngx_http_cache_aio_event_handler(ngx_event_t *ev);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
25 #endif
6063
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
26 #if (NGX_THREADS)
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
27 static ngx_int_t ngx_http_cache_thread_handler(ngx_thread_task_t *task,
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
28 ngx_file_t *file);
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
29 static void ngx_http_cache_thread_event_handler(ngx_event_t *ev);
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
30 #endif
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
31 static ngx_int_t ngx_http_file_cache_exists(ngx_http_file_cache_t *cache,
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
32 ngx_http_cache_t *c);
3696
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
33 static ngx_int_t ngx_http_file_cache_name(ngx_http_request_t *r,
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
34 ngx_path_t *path);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
35 static ngx_http_file_cache_node_t *
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
36 ngx_http_file_cache_lookup(ngx_http_file_cache_t *cache, u_char *key);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
37 static void ngx_http_file_cache_rbtree_insert_value(ngx_rbtree_node_t *temp,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
38 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
39 static void ngx_http_file_cache_vary(ngx_http_request_t *r, u_char *vary,
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
40 size_t len, u_char *hash);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
41 static void ngx_http_file_cache_vary_header(ngx_http_request_t *r,
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
42 ngx_md5_t *md5, ngx_str_t *name);
5880
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
43 static ngx_int_t ngx_http_file_cache_reopen(ngx_http_request_t *r,
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
44 ngx_http_cache_t *c);
5959
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
45 static ngx_int_t ngx_http_file_cache_update_variant(ngx_http_request_t *r,
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
46 ngx_http_cache_t *c);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
47 static void ngx_http_file_cache_cleanup(void *data);
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
48 static time_t ngx_http_file_cache_forced_expire(ngx_http_file_cache_t *cache);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
49 static time_t ngx_http_file_cache_expire(ngx_http_file_cache_t *cache);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
50 static void ngx_http_file_cache_delete(ngx_http_file_cache_t *cache,
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
51 ngx_queue_t *q, u_char *name);
4018
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
52 static void ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache);
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
53 static ngx_int_t ngx_http_file_cache_noop(ngx_tree_ctx_t *ctx,
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
54 ngx_str_t *path);
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
55 static ngx_int_t ngx_http_file_cache_manage_file(ngx_tree_ctx_t *ctx,
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
56 ngx_str_t *path);
5968
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
57 static ngx_int_t ngx_http_file_cache_manage_directory(ngx_tree_ctx_t *ctx,
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
58 ngx_str_t *path);
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
59 static ngx_int_t ngx_http_file_cache_add_file(ngx_tree_ctx_t *ctx,
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
60 ngx_str_t *path);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
61 static ngx_int_t ngx_http_file_cache_add(ngx_http_file_cache_t *cache,
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
62 ngx_http_cache_t *c);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
63 static ngx_int_t ngx_http_file_cache_delete_file(ngx_tree_ctx_t *ctx,
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
64 ngx_str_t *path);
6445
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
65 static void ngx_http_file_cache_set_watermark(ngx_http_file_cache_t *cache);
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
66
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
67
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
68 ngx_str_t ngx_http_cache_status[] = {
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
69 ngx_string("MISS"),
3699
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
70 ngx_string("BYPASS"),
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
71 ngx_string("EXPIRED"),
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
72 ngx_string("STALE"),
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
73 ngx_string("UPDATING"),
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
74 ngx_string("REVALIDATED"),
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
75 ngx_string("HIT")
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
76 };
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
77
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
78
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
79 static u_char ngx_http_file_cache_key[] = { LF, 'K', 'E', 'Y', ':', ' ' };
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
82 static ngx_int_t
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
83 ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data)
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
85 ngx_http_file_cache_t *ocache = data;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86
2611
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
87 size_t len;
3017
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
88 ngx_uint_t n;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
89 ngx_http_file_cache_t *cache;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
91 cache = shm_zone->data;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
93 if (ocache) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
94 if (ngx_strcmp(cache->path->name.data, ocache->path->name.data) != 0) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
95 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
96 "cache \"%V\" uses the \"%V\" cache path "
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
97 "while previously it used the \"%V\" cache path",
2716
d5896f6608e8 move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2694
diff changeset
98 &shm_zone->shm.name, &cache->path->name,
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
99 &ocache->path->name);
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 return NGX_ERROR;
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
102 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103
6617
8bf484eef9ab Use NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents: 6539
diff changeset
104 for (n = 0; n < NGX_MAX_PATH_LEVEL; n++) {
3017
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
105 if (cache->path->level[n] != ocache->path->level[n]) {
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
106 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
107 "cache \"%V\" had previously different levels",
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
108 &shm_zone->shm.name);
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
109 return NGX_ERROR;
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
110 }
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
111 }
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
112
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
113 cache->sh = ocache->sh;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
114
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
115 cache->shpool = ocache->shpool;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
116 cache->bsize = ocache->bsize;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
117
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
118 cache->max_size /= cache->bsize;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
119
3018
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
120 if (!cache->sh->cold || cache->sh->loading) {
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
121 cache->path->loader = NULL;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
122 }
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
123
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
124 return NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
125 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
126
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
127 cache->shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
128
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
129 if (shm_zone->shm.exists) {
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
130 cache->sh = cache->shpool->data;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
131 cache->bsize = ngx_fs_bsize(cache->path->name.data);
7075
72d3aefc2993 Cache: fixed max_size on win32.
Ruslan Ermilov <ru@nginx.com>
parents: 7002
diff changeset
132 cache->max_size /= cache->bsize;
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
133
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
134 return NGX_OK;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
135 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
136
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
137 cache->sh = ngx_slab_alloc(cache->shpool, sizeof(ngx_http_file_cache_sh_t));
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
138 if (cache->sh == NULL) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
139 return NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
140 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
141
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
142 cache->shpool->data = cache->sh;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
143
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
144 ngx_rbtree_init(&cache->sh->rbtree, &cache->sh->sentinel,
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
145 ngx_http_file_cache_rbtree_insert_value);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
146
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
147 ngx_queue_init(&cache->sh->queue);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
148
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
149 cache->sh->cold = 1;
3018
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
150 cache->sh->loading = 0;
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
151 cache->sh->size = 0;
6445
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
152 cache->sh->count = 0;
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
153 cache->sh->watermark = (ngx_uint_t) -1;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
154
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
155 cache->bsize = ngx_fs_bsize(cache->path->name.data);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
156
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
157 cache->max_size /= cache->bsize;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
158
2716
d5896f6608e8 move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2694
diff changeset
159 len = sizeof(" in cache keys zone \"\"") + shm_zone->shm.name.len;
2611
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
160
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
161 cache->shpool->log_ctx = ngx_slab_alloc(cache->shpool, len);
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
162 if (cache->shpool->log_ctx == NULL) {
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
163 return NGX_ERROR;
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
164 }
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
165
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
166 ngx_sprintf(cache->shpool->log_ctx, " in cache keys zone \"%V\"%Z",
2716
d5896f6608e8 move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2694
diff changeset
167 &shm_zone->shm.name);
2611
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
168
5822
063f7e75f9ef Upstream: suppressed the file cache slab allocator error messages.
Roman Arutyunyan <arut@nginx.com>
parents: 5737
diff changeset
169 cache->shpool->log_nomem = 0;
063f7e75f9ef Upstream: suppressed the file cache slab allocator error messages.
Roman Arutyunyan <arut@nginx.com>
parents: 5737
diff changeset
170
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
171 return NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
172 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
173
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
174
3697
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
175 ngx_int_t
3698
d11227f0107f rename ngx_http_file_cache_create() to ngx_http_file_cache_new()
Igor Sysoev <igor@sysoev.ru>
parents: 3697
diff changeset
176 ngx_http_file_cache_new(ngx_http_request_t *r)
3697
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
177 {
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
178 ngx_http_cache_t *c;
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
179
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
180 c = ngx_pcalloc(r->pool, sizeof(ngx_http_cache_t));
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
181 if (c == NULL) {
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
182 return NGX_ERROR;
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
183 }
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
184
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
185 if (ngx_array_init(&c->keys, r->pool, 4, sizeof(ngx_str_t)) != NGX_OK) {
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
186 return NGX_ERROR;
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
187 }
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
188
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
189 r->cache = c;
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
190 c->file.log = r->connection->log;
3704
f220e5a5fb5e initialize r->cache->file.fd with NGX_INVALID_FILE
Igor Sysoev <igor@sysoev.ru>
parents: 3699
diff changeset
191 c->file.fd = NGX_INVALID_FILE;
3697
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
192
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
193 return NGX_OK;
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
194 }
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
195
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
196
3699
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
197 ngx_int_t
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
198 ngx_http_file_cache_create(ngx_http_request_t *r)
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
199 {
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
200 ngx_http_cache_t *c;
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
201 ngx_pool_cleanup_t *cln;
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
202 ngx_http_file_cache_t *cache;
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
203
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
204 c = r->cache;
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
205 cache = c->file_cache;
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
206
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
207 cln = ngx_pool_cleanup_add(r->pool, 0);
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
208 if (cln == NULL) {
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
209 return NGX_ERROR;
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
210 }
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
211
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
212 cln->handler = ngx_http_file_cache_cleanup;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
213 cln->data = c;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
214
3699
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
215 if (ngx_http_file_cache_exists(cache, c) == NGX_ERROR) {
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
216 return NGX_ERROR;
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
217 }
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
218
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
219 if (ngx_http_file_cache_name(r, cache->path) != NGX_OK) {
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
220 return NGX_ERROR;
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
221 }
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
222
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
223 return NGX_OK;
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
224 }
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
225
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
226
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
227 void
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
228 ngx_http_file_cache_create_key(ngx_http_request_t *r)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
229 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
230 size_t len;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
231 ngx_str_t *key;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
232 ngx_uint_t i;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
233 ngx_md5_t md5;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
234 ngx_http_cache_t *c;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
235
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
236 c = r->cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
237
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
238 len = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
239
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
240 ngx_crc32_init(c->crc32);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
241 ngx_md5_init(&md5);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
242
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
243 key = c->keys.elts;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
244 for (i = 0; i < c->keys.nelts; i++) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
245 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
246 "http cache key: \"%V\"", &key[i]);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
247
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
248 len += key[i].len;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
249
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
250 ngx_crc32_update(&c->crc32, key[i].data, key[i].len);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
251 ngx_md5_update(&md5, key[i].data, key[i].len);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
252 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
253
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
254 c->header_start = sizeof(ngx_http_file_cache_header_t)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
255 + sizeof(ngx_http_file_cache_key) + len + 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
256
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
257 ngx_crc32_final(c->crc32);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
258 ngx_md5_final(c->key, &md5);
5880
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
259
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
260 ngx_memcpy(c->main, c->key, NGX_HTTP_CACHE_KEY_LEN);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
261 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
262
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
263
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
264 ngx_int_t
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
265 ngx_http_file_cache_open(ngx_http_request_t *r)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
266 {
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
267 ngx_int_t rc, rv;
5984
3f568dd68af1 Cache: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5968
diff changeset
268 ngx_uint_t test;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
269 ngx_http_cache_t *c;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
270 ngx_pool_cleanup_t *cln;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
271 ngx_open_file_info_t of;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
272 ngx_http_file_cache_t *cache;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
273 ngx_http_core_loc_conf_t *clcf;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
274
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
275 c = r->cache;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
276
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
277 if (c->waiting) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
278 return NGX_AGAIN;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
279 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
280
5879
c525c0454aa5 Cache: c->reading flag introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5878
diff changeset
281 if (c->reading) {
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
282 return ngx_http_file_cache_read(r, c);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
283 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
284
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
285 cache = c->file_cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
286
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
287 if (c->node == NULL) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
288 cln = ngx_pool_cleanup_add(r->pool, 0);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
289 if (cln == NULL) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
290 return NGX_ERROR;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
291 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
292
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
293 cln->handler = ngx_http_file_cache_cleanup;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
294 cln->data = c;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
295 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
296
7704
847fd35f94de Cache: reset c->body_start when reading a variant on Vary mismatch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7670
diff changeset
297 c->buffer_size = c->body_start;
847fd35f94de Cache: reset c->body_start when reading a variant on Vary mismatch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7670
diff changeset
298
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
299 rc = ngx_http_file_cache_exists(cache, c);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
300
2926
80a314b63c56 delete useless r->cache->uses
Igor Sysoev <igor@sysoev.ru>
parents: 2925
diff changeset
301 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
80a314b63c56 delete useless r->cache->uses
Igor Sysoev <igor@sysoev.ru>
parents: 2925
diff changeset
302 "http file cache exists: %i e:%d", rc, c->exists);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
303
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
304 if (rc == NGX_ERROR) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
305 return rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
306 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
307
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
308 if (rc == NGX_AGAIN) {
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
309 return NGX_HTTP_CACHE_SCARCE;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
310 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
311
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
312 if (rc == NGX_OK) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
313
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
314 if (c->error) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
315 return c->error;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
316 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
317
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
318 c->temp_file = 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
319 test = c->exists ? 1 : 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
320 rv = NGX_DECLINED;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
321
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
322 } else { /* rc == NGX_DECLINED */
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
323
5984
3f568dd68af1 Cache: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5968
diff changeset
324 test = cache->sh->cold ? 1 : 0;
3f568dd68af1 Cache: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5968
diff changeset
325
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
326 if (c->min_uses > 1) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
327
5984
3f568dd68af1 Cache: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5968
diff changeset
328 if (!test) {
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
329 return NGX_HTTP_CACHE_SCARCE;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
330 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
331
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
332 rv = NGX_HTTP_CACHE_SCARCE;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
333
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
334 } else {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
335 c->temp_file = 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
336 rv = NGX_DECLINED;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
337 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
338 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
339
3696
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
340 if (ngx_http_file_cache_name(r, cache->path) != NGX_OK) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
341 return NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
342 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
343
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
344 if (!test) {
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
345 goto done;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
346 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
347
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
348 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
349
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
350 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
351
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
352 of.uniq = c->uniq;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
353 of.valid = clcf->open_file_cache_valid;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
354 of.min_uses = clcf->open_file_cache_min_uses;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
355 of.events = clcf->open_file_cache_events;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
356 of.directio = NGX_OPEN_FILE_DIRECTIO_OFF;
3178
975f0558aab3 read_ahead
Igor Sysoev <igor@sysoev.ru>
parents: 3136
diff changeset
357 of.read_ahead = clcf->read_ahead;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
358
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
359 if (ngx_open_cached_file(clcf->open_file_cache, &c->file.name, &of, r->pool)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
360 != NGX_OK)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
361 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
362 switch (of.err) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
363
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
364 case 0:
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
365 return NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
366
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
367 case NGX_ENOENT:
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
368 case NGX_ENOTDIR:
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
369 goto done;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
370
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
371 default:
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
372 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
373 ngx_open_file_n " \"%s\" failed", c->file.name.data);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
374 return NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
375 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
376 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
377
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
378 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
379 "http file cache fd: %d", of.fd);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
380
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
381 c->file.fd = of.fd;
2603
f9bd7999eb08 fix segfault if ngx_read_file() will fail
Igor Sysoev <igor@sysoev.ru>
parents: 2600
diff changeset
382 c->file.log = r->connection->log;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
383 c->uniq = of.uniq;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
384 c->length = of.size;
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
385 c->fs_size = (of.fs_size + cache->bsize - 1) / cache->bsize;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
386
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
387 c->buf = ngx_create_temp_buf(r->pool, c->body_start);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
388 if (c->buf == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
389 return NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
390 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
391
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
392 return ngx_http_file_cache_read(r, c);
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
393
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
394 done:
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
395
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
396 if (rv == NGX_DECLINED) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
397 return ngx_http_file_cache_lock(r, c);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
398 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
399
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
400 return rv;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
401 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
402
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
403
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
404 static ngx_int_t
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
405 ngx_http_file_cache_lock(ngx_http_request_t *r, ngx_http_cache_t *c)
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
406 {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
407 ngx_msec_t now, timer;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
408 ngx_http_file_cache_t *cache;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
409
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
410 if (!c->lock) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
411 return NGX_DECLINED;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
412 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
413
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
414 now = ngx_current_msec;
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
415
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
416 cache = c->file_cache;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
417
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
418 ngx_shmtx_lock(&cache->shpool->mutex);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
419
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
420 timer = c->node->lock_time - now;
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
421
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
422 if (!c->node->updating || (ngx_msec_int_t) timer <= 0) {
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
423 c->node->updating = 1;
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
424 c->node->lock_time = now + c->lock_age;
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
425 c->updating = 1;
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
426 c->lock_time = c->node->lock_time;
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
427 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
428
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
429 ngx_shmtx_unlock(&cache->shpool->mutex);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
430
4387
e8181eeddaf8 Fixed build without debug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4385
diff changeset
431 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
432 "http file cache lock u:%d wt:%M",
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
433 c->updating, c->wait_time);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
434
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
435 if (c->updating) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
436 return NGX_DECLINED;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
437 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
438
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
439 if (c->lock_timeout == 0) {
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
440 return NGX_HTTP_CACHE_SCARCE;
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
441 }
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
442
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
443 c->waiting = 1;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
444
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
445 if (c->wait_time == 0) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
446 c->wait_time = now + c->lock_timeout;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
447
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
448 c->wait_event.handler = ngx_http_file_cache_lock_wait_handler;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
449 c->wait_event.data = r;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
450 c->wait_event.log = r->connection->log;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
451 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
452
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
453 timer = c->wait_time - now;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
454
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
455 ngx_add_timer(&c->wait_event, (timer > 500) ? 500 : timer);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
456
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
457 r->main->blocked++;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
458
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
459 return NGX_AGAIN;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
460 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
461
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
462
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
463 static void
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
464 ngx_http_file_cache_lock_wait_handler(ngx_event_t *ev)
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
465 {
9203
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
466 ngx_int_t rc;
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
467 ngx_connection_t *c;
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
468 ngx_http_request_t *r;
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
469
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
470 r = ev->data;
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
471 c = r->connection;
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
472
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
473 ngx_http_set_log_request(c->log, r);
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
474
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
475 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
476 "http file cache wait: \"%V?%V\"", &r->uri, &r->args);
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
477
9203
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
478 rc = ngx_http_file_cache_lock_wait(r, r->cache);
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
479
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
480 if (rc == NGX_AGAIN) {
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
481 return;
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
482 }
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
483
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
484 r->cache->waiting = 0;
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
485 r->main->blocked--;
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
486
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
487 if (r->main->terminated) {
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
488 /*
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
489 * trigger connection event handler if the request was
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
490 * terminated
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
491 */
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
492
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
493 c->write->handler(c->write);
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
494
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
495 } else {
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
496 r->write_event_handler(r);
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
497 ngx_http_run_posted_requests(c);
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
498 }
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
499 }
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
500
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
501
9203
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
502 static ngx_int_t
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
503 ngx_http_file_cache_lock_wait(ngx_http_request_t *r, ngx_http_cache_t *c)
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
504 {
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
505 ngx_uint_t wait;
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
506 ngx_msec_t now, timer;
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
507 ngx_http_file_cache_t *cache;
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
508
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
509 now = ngx_current_msec;
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
510
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
511 timer = c->wait_time - now;
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
512
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
513 if ((ngx_msec_int_t) timer <= 0) {
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
514 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
515 "cache lock timeout");
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
516 c->lock_timeout = 0;
9203
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
517 return NGX_OK;
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
518 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
519
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
520 cache = c->file_cache;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
521 wait = 0;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
522
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
523 ngx_shmtx_lock(&cache->shpool->mutex);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
524
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
525 timer = c->node->lock_time - now;
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
526
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
527 if (c->node->updating && (ngx_msec_int_t) timer > 0) {
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
528 wait = 1;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
529 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
530
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
531 ngx_shmtx_unlock(&cache->shpool->mutex);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
532
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
533 if (wait) {
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
534 ngx_add_timer(&c->wait_event, (timer > 500) ? 500 : timer);
9203
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
535 return NGX_AGAIN;
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
536 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
537
9203
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
538 return NGX_OK;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
539 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
540
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
541
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
542 static ngx_int_t
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
543 ngx_http_file_cache_read(ngx_http_request_t *r, ngx_http_cache_t *c)
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
544 {
6243
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
545 u_char *p;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
546 time_t now;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
547 ssize_t n;
6243
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
548 ngx_str_t *key;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
549 ngx_int_t rc;
6243
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
550 ngx_uint_t i;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
551 ngx_http_file_cache_t *cache;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
552 ngx_http_file_cache_header_t *h;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
553
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
554 n = ngx_http_file_cache_aio_read(r, c);
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
555
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
556 if (n < 0) {
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
557 return n;
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
558 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
559
3369
479468a7d982 fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
560 if ((size_t) n < c->header_start) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
561 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
477
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
562 "cache file \"%s\" is too small", c->file.name.data);
3971
44f4fc874b2f do not close connection if cache file is too small: replace it with valid one
Igor Sysoev <igor@sysoev.ru>
parents: 3970
diff changeset
563 return NGX_DECLINED;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
564 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
565
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
566 h = (ngx_http_file_cache_header_t *) c->buf->pos;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
567
5736
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
568 if (h->version != NGX_HTTP_CACHE_VERSION) {
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
569 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
570 "cache file \"%s\" version mismatch", c->file.name.data);
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
571 return NGX_DECLINED;
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
572 }
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
573
6860
f18c285c2e59 Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6795
diff changeset
574 if (h->crc32 != c->crc32 || (size_t) h->header_start != c->header_start) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
575 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
576 "cache file \"%s\" has md5 collision", c->file.name.data);
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
577 return NGX_DECLINED;
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
578 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
579
6243
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
580 p = c->buf->pos + sizeof(ngx_http_file_cache_header_t)
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
581 + sizeof(ngx_http_file_cache_key);
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
582
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
583 key = c->keys.elts;
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
584 for (i = 0; i < c->keys.nelts; i++) {
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
585 if (ngx_memcmp(p, key[i].data, key[i].len) != 0) {
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
586 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
587 "cache file \"%s\" has md5 collision",
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
588 c->file.name.data);
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
589 return NGX_DECLINED;
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
590 }
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
591
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
592 p += key[i].len;
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
593 }
4821fc788c12 Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6063
diff changeset
594
5359
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5341
diff changeset
595 if ((size_t) h->body_start > c->body_start) {
4339
6f97afc238de Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4338
diff changeset
596 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
6f97afc238de Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4338
diff changeset
597 "cache file \"%s\" has too long header",
6f97afc238de Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4338
diff changeset
598 c->file.name.data);
6f97afc238de Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4338
diff changeset
599 return NGX_DECLINED;
6f97afc238de Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4338
diff changeset
600 }
6f97afc238de Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4338
diff changeset
601
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
602 if (h->vary_len > NGX_HTTP_CACHE_VARY_LEN) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
603 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
604 "cache file \"%s\" has incorrect vary length",
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
605 c->file.name.data);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
606 return NGX_DECLINED;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
607 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
608
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
609 if (h->vary_len) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
610 ngx_http_file_cache_vary(r, h->vary, h->vary_len, c->variant);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
611
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
612 if (ngx_memcmp(c->variant, h->variant, NGX_HTTP_CACHE_KEY_LEN) != 0) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
613 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
614 "http file cache vary mismatch");
5880
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
615 return ngx_http_file_cache_reopen(r, c);
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
616 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
617 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
618
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
619 c->buf->last += n;
477
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
620
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
621 c->valid_sec = h->valid_sec;
6905
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6860
diff changeset
622 c->updating_sec = h->updating_sec;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6860
diff changeset
623 c->error_sec = h->error_sec;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
624 c->last_modified = h->last_modified;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
625 c->date = h->date;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
626 c->valid_msec = h->valid_msec;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
627 c->body_start = h->body_start;
5737
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
628 c->etag.len = h->etag_len;
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
629 c->etag.data = h->etag;
477
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
630
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
631 r->cached = 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
632
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
633 cache = c->file_cache;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
634
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
635 if (cache->sh->cold) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
636
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
637 ngx_shmtx_lock(&cache->shpool->mutex);
477
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
638
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
639 if (!c->node->exists) {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
640 c->node->uses = 1;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
641 c->node->body_start = c->body_start;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
642 c->node->exists = 1;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
643 c->node->uniq = c->uniq;
4034
e2c075e774b6 Cache size accounting fix: actual cache size on disk was less than
Igor Sysoev <igor@sysoev.ru>
parents: 4018
diff changeset
644 c->node->fs_size = c->fs_size;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
645
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
646 cache->sh->size += c->fs_size;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
647 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
648
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
649 ngx_shmtx_unlock(&cache->shpool->mutex);
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
650 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
651
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
652 now = ngx_time();
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
653
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
654 if (c->valid_sec < now) {
6905
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6860
diff changeset
655 c->stale_updating = c->valid_sec + c->updating_sec >= now;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6860
diff changeset
656 c->stale_error = c->valid_sec + c->error_sec >= now;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
657
2927
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
658 ngx_shmtx_lock(&cache->shpool->mutex);
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
659
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
660 if (c->node->updating) {
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
661 rc = NGX_HTTP_CACHE_UPDATING;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
662
2927
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
663 } else {
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
664 c->node->updating = 1;
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
665 c->updating = 1;
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
666 c->lock_time = c->node->lock_time;
2927
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
667 rc = NGX_HTTP_CACHE_STALE;
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
668 }
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
669
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
670 ngx_shmtx_unlock(&cache->shpool->mutex);
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
671
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
672 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
673 "http file cache expired: %i %T %T",
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
674 rc, c->valid_sec, now);
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
675
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
676 return rc;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
677 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
678
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
679 return NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
680 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
681
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
682
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
683 static ssize_t
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
684 ngx_http_file_cache_aio_read(ngx_http_request_t *r, ngx_http_cache_t *c)
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
685 {
6063
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
686 #if (NGX_HAVE_FILE_AIO || NGX_THREADS)
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
687 ssize_t n;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
688 ngx_http_core_loc_conf_t *clcf;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
689
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
690 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
6063
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
691 #endif
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
692
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
693 #if (NGX_HAVE_FILE_AIO)
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
694
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
695 if (clcf->aio == NGX_HTTP_AIO_ON && ngx_file_aio) {
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
696 n = ngx_file_aio_read(&c->file, c->buf->pos, c->body_start, 0, r->pool);
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
697
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
698 if (n != NGX_AGAIN) {
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
699 c->reading = 0;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
700 return n;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
701 }
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
702
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
703 c->reading = 1;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
704
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
705 c->file.aio->data = r;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
706 c->file.aio->handler = ngx_http_cache_aio_event_handler;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
707
9202
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
708 ngx_add_timer(&c->file.aio->event, 60000);
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
709
6063
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
710 r->main->blocked++;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
711 r->aio = 1;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
712
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
713 return NGX_AGAIN;
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
714 }
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
715
6063
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
716 #endif
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
717
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
718 #if (NGX_THREADS)
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
719
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
720 if (clcf->aio == NGX_HTTP_AIO_THREADS) {
6441
9fd738b85fad Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6243
diff changeset
721 c->file.thread_task = c->thread_task;
6063
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
722 c->file.thread_handler = ngx_http_cache_thread_handler;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
723 c->file.thread_ctx = r;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
724
6441
9fd738b85fad Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6243
diff changeset
725 n = ngx_thread_read(&c->file, c->buf->pos, c->body_start, 0, r->pool);
9fd738b85fad Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6243
diff changeset
726
9fd738b85fad Threads: task pointer stored in ngx_file_t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6243
diff changeset
727 c->thread_task = c->file.thread_task;
6063
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
728 c->reading = (n == NGX_AGAIN);
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
729
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
730 return n;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
731 }
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
732
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
733 #endif
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
734
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
735 return ngx_read_file(&c->file, c->buf->pos, c->body_start, 0);
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
736 }
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
737
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
738
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
739 #if (NGX_HAVE_FILE_AIO)
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
740
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
741 static void
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
742 ngx_http_cache_aio_event_handler(ngx_event_t *ev)
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
743 {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
744 ngx_event_aio_t *aio;
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
745 ngx_connection_t *c;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
746 ngx_http_request_t *r;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
747
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
748 aio = ev->data;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
749 r = aio->data;
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
750 c = r->connection;
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
751
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
752 ngx_http_set_log_request(c->log, r);
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
753
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
754 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
755 "http file cache aio: \"%V?%V\"", &r->uri, &r->args);
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
756
9202
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
757 if (ev->timedout) {
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
758 ngx_log_error(NGX_LOG_ALERT, c->log, 0,
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
759 "aio operation took too long");
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
760 ev->timedout = 0;
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
761 return;
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
762 }
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
763
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
764 if (ev->timer_set) {
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
765 ngx_del_timer(ev);
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
766 }
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
767
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
768 r->main->blocked--;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
769 r->aio = 0;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
770
9203
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
771 if (r->main->terminated) {
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
772 /*
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
773 * trigger connection event handler if the request was
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
774 * terminated
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
775 */
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
776
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
777 c->write->handler(c->write);
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
778
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
779 } else {
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
780 r->write_event_handler(r);
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
781 ngx_http_run_posted_requests(c);
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
782 }
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
783 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
784
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
785 #endif
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
786
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
787
6063
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
788 #if (NGX_THREADS)
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
789
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
790 static ngx_int_t
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
791 ngx_http_cache_thread_handler(ngx_thread_task_t *task, ngx_file_t *file)
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
792 {
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
793 ngx_str_t name;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
794 ngx_thread_pool_t *tp;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
795 ngx_http_request_t *r;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
796 ngx_http_core_loc_conf_t *clcf;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
797
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
798 r = file->thread_ctx;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
799
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
800 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
801 tp = clcf->thread_pool;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
802
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
803 if (tp == NULL) {
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
804 if (ngx_http_complex_value(r, clcf->thread_pool_value, &name)
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
805 != NGX_OK)
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
806 {
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
807 return NGX_ERROR;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
808 }
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
809
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
810 tp = ngx_thread_pool_get((ngx_cycle_t *) ngx_cycle, &name);
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
811
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
812 if (tp == NULL) {
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
813 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
814 "thread pool \"%V\" not found", &name);
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
815 return NGX_ERROR;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
816 }
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
817 }
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
818
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
819 task->event.data = r;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
820 task->event.handler = ngx_http_cache_thread_event_handler;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
821
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
822 if (ngx_thread_task_post(tp, task) != NGX_OK) {
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
823 return NGX_ERROR;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
824 }
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
825
9202
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
826 ngx_add_timer(&task->event, 60000);
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
827
6063
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
828 r->main->blocked++;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
829 r->aio = 1;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
830
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
831 return NGX_OK;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
832 }
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
833
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
834
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
835 static void
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
836 ngx_http_cache_thread_event_handler(ngx_event_t *ev)
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
837 {
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
838 ngx_connection_t *c;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
839 ngx_http_request_t *r;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
840
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
841 r = ev->data;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
842 c = r->connection;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
843
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
844 ngx_http_set_log_request(c->log, r);
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
845
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
846 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
847 "http file cache thread: \"%V?%V\"", &r->uri, &r->args);
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
848
9202
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
849 if (ev->timedout) {
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
850 ngx_log_error(NGX_LOG_ALERT, c->log, 0,
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
851 "thread operation took too long");
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
852 ev->timedout = 0;
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
853 return;
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
854 }
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
855
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
856 if (ev->timer_set) {
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
857 ngx_del_timer(ev);
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
858 }
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8124
diff changeset
859
6063
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
860 r->main->blocked--;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
861 r->aio = 0;
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
862
9203
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
863 if (r->main->terminated) {
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
864 /*
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
865 * trigger connection event handler if the request was
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
866 * terminated
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
867 */
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
868
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
869 c->write->handler(c->write);
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
870
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
871 } else {
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
872 r->write_event_handler(r);
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
873 ngx_http_run_posted_requests(c);
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
874 }
6063
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
875 }
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
876
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
877 #endif
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
878
d698c300b9ff Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
879
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
880 static ngx_int_t
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
881 ngx_http_file_cache_exists(ngx_http_file_cache_t *cache, ngx_http_cache_t *c)
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
882 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
883 ngx_int_t rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
884 ngx_http_file_cache_node_t *fcn;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
885
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
886 ngx_shmtx_lock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
887
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
888 fcn = c->node;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
889
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
890 if (fcn == NULL) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
891 fcn = ngx_http_file_cache_lookup(cache, c->key);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
892 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
893
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
894 if (fcn) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
895 ngx_queue_remove(&fcn->queue);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
896
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
897 if (c->node == NULL) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
898 fcn->uses++;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
899 fcn->count++;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
900 }
3724
e9f0a2497d3c count cache key node usage for cached error statuses
Igor Sysoev <igor@sysoev.ru>
parents: 3723
diff changeset
901
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
902 if (fcn->error) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
903
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
904 if (fcn->valid_sec < ngx_time()) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
905 goto renew;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
906 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
907
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
908 rc = NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
909
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
910 goto done;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
911 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
912
3966
9c425f22ea36 fuse two if's in one condition
Igor Sysoev <igor@sysoev.ru>
parents: 3965
diff changeset
913 if (fcn->exists || fcn->uses >= c->min_uses) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
914
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
915 c->exists = fcn->exists;
7705
3781de64e747 Cache: keep c->body_start when Vary changes (ticket #2029).
Sergey Kandaurov <pluknet@nginx.com>
parents: 7704
diff changeset
916 if (fcn->body_start && !c->update_variant) {
3967
83e41f6f6d96 The cache loader performs two tasks: inserting cache objects in inactivity
Igor Sysoev <igor@sysoev.ru>
parents: 3966
diff changeset
917 c->body_start = fcn->body_start;
83e41f6f6d96 The cache loader performs two tasks: inserting cache objects in inactivity
Igor Sysoev <igor@sysoev.ru>
parents: 3966
diff changeset
918 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
919
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
920 rc = NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
921
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
922 goto done;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
923 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
924
3966
9c425f22ea36 fuse two if's in one condition
Igor Sysoev <igor@sysoev.ru>
parents: 3965
diff changeset
925 rc = NGX_AGAIN;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
926
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
927 goto done;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
928 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
929
5726
25ade23cf281 Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents: 5679
diff changeset
930 fcn = ngx_slab_calloc_locked(cache->shpool,
25ade23cf281 Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents: 5679
diff changeset
931 sizeof(ngx_http_file_cache_node_t));
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
932 if (fcn == NULL) {
6445
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
933 ngx_http_file_cache_set_watermark(cache);
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
934
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
935 ngx_shmtx_unlock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
936
2693
197cda0e767e style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2671
diff changeset
937 (void) ngx_http_file_cache_forced_expire(cache);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
938
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
939 ngx_shmtx_lock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
940
5726
25ade23cf281 Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents: 5679
diff changeset
941 fcn = ngx_slab_calloc_locked(cache->shpool,
25ade23cf281 Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents: 5679
diff changeset
942 sizeof(ngx_http_file_cache_node_t));
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
943 if (fcn == NULL) {
5822
063f7e75f9ef Upstream: suppressed the file cache slab allocator error messages.
Roman Arutyunyan <arut@nginx.com>
parents: 5737
diff changeset
944 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
063f7e75f9ef Upstream: suppressed the file cache slab allocator error messages.
Roman Arutyunyan <arut@nginx.com>
parents: 5737
diff changeset
945 "could not allocate node%s", cache->shpool->log_ctx);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
946 rc = NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
947 goto failed;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
948 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
949 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
950
6445
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
951 cache->sh->count++;
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
952
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
953 ngx_memcpy((u_char *) &fcn->node.key, c->key, sizeof(ngx_rbtree_key_t));
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
954
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
955 ngx_memcpy(fcn->key, &c->key[sizeof(ngx_rbtree_key_t)],
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
956 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t));
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
957
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
958 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
959
3724
e9f0a2497d3c count cache key node usage for cached error statuses
Igor Sysoev <igor@sysoev.ru>
parents: 3723
diff changeset
960 fcn->uses = 1;
e9f0a2497d3c count cache key node usage for cached error statuses
Igor Sysoev <igor@sysoev.ru>
parents: 3723
diff changeset
961 fcn->count = 1;
e9f0a2497d3c count cache key node usage for cached error statuses
Igor Sysoev <igor@sysoev.ru>
parents: 3723
diff changeset
962
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
963 renew:
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
964
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
965 rc = NGX_DECLINED;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
966
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
967 fcn->valid_msec = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
968 fcn->error = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
969 fcn->exists = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
970 fcn->valid_sec = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
971 fcn->uniq = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
972 fcn->body_start = 0;
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
973 fcn->fs_size = 0;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
974
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
975 done:
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
976
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
977 fcn->expire = ngx_time() + cache->inactive;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
978
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
979 ngx_queue_insert_head(&cache->sh->queue, &fcn->queue);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
980
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
981 c->uniq = fcn->uniq;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
982 c->error = fcn->error;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
983 c->node = fcn;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
984
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
985 failed:
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
986
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
987 ngx_shmtx_unlock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
988
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
989 return rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
990 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
991
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
992
3696
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
993 static ngx_int_t
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
994 ngx_http_file_cache_name(ngx_http_request_t *r, ngx_path_t *path)
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
995 {
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
996 u_char *p;
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
997 ngx_http_cache_t *c;
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
998
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
999 c = r->cache;
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1000
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
1001 if (c->file.name.len) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
1002 return NGX_OK;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
1003 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
1004
3696
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1005 c->file.name.len = path->name.len + 1 + path->len
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1006 + 2 * NGX_HTTP_CACHE_KEY_LEN;
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1007
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1008 c->file.name.data = ngx_pnalloc(r->pool, c->file.name.len + 1);
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1009 if (c->file.name.data == NULL) {
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1010 return NGX_ERROR;
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1011 }
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1012
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1013 ngx_memcpy(c->file.name.data, path->name.data, path->name.len);
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1014
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1015 p = c->file.name.data + path->name.len + 1 + path->len;
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1016 p = ngx_hex_dump(p, c->key, NGX_HTTP_CACHE_KEY_LEN);
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1017 *p = '\0';
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1018
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1019 ngx_create_hashed_filename(path, c->file.name.data, c->file.name.len);
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1020
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1021 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1022 "cache file: \"%s\"", c->file.name.data);
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1023
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1024 return NGX_OK;
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1025 }
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1026
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
1027
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1028 static ngx_http_file_cache_node_t *
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1029 ngx_http_file_cache_lookup(ngx_http_file_cache_t *cache, u_char *key)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1030 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1031 ngx_int_t rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1032 ngx_rbtree_key_t node_key;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1033 ngx_rbtree_node_t *node, *sentinel;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1034 ngx_http_file_cache_node_t *fcn;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1035
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1036 ngx_memcpy((u_char *) &node_key, key, sizeof(ngx_rbtree_key_t));
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1037
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
1038 node = cache->sh->rbtree.root;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
1039 sentinel = cache->sh->rbtree.sentinel;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1040
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1041 while (node != sentinel) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1042
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1043 if (node_key < node->key) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1044 node = node->left;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1045 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1046 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1047
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1048 if (node_key > node->key) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1049 node = node->right;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1050 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1051 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1052
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1053 /* node_key == node->key */
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1054
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4474
diff changeset
1055 fcn = (ngx_http_file_cache_node_t *) node;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1056
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4474
diff changeset
1057 rc = ngx_memcmp(&key[sizeof(ngx_rbtree_key_t)], fcn->key,
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4474
diff changeset
1058 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t));
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1059
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4474
diff changeset
1060 if (rc == 0) {
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4474
diff changeset
1061 return fcn;
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4474
diff changeset
1062 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1063
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4474
diff changeset
1064 node = (rc < 0) ? node->left : node->right;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1065 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1066
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1067 /* not found */
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1068
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1069 return NULL;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1070 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1071
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1072
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1073 static void
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1074 ngx_http_file_cache_rbtree_insert_value(ngx_rbtree_node_t *temp,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1075 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1076 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1077 ngx_rbtree_node_t **p;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1078 ngx_http_file_cache_node_t *cn, *cnt;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1079
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1080 for ( ;; ) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1081
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1082 if (node->key < temp->key) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1083
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1084 p = &temp->left;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1085
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1086 } else if (node->key > temp->key) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1087
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1088 p = &temp->right;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1089
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1090 } else { /* node->key == temp->key */
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1091
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1092 cn = (ngx_http_file_cache_node_t *) node;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1093 cnt = (ngx_http_file_cache_node_t *) temp;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1094
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1095 p = (ngx_memcmp(cn->key, cnt->key,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1096 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t))
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1097 < 0)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1098 ? &temp->left : &temp->right;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1099 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1100
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1101 if (*p == sentinel) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1102 break;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1103 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1104
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1105 temp = *p;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1106 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1107
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1108 *p = node;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1109 node->parent = temp;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1110 node->left = sentinel;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1111 node->right = sentinel;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1112 ngx_rbt_red(node);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1113 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1114
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1115
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1116 static void
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1117 ngx_http_file_cache_vary(ngx_http_request_t *r, u_char *vary, size_t len,
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1118 u_char *hash)
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1119 {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1120 u_char *p, *last;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1121 ngx_str_t name;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1122 ngx_md5_t md5;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1123 u_char buf[NGX_HTTP_CACHE_VARY_LEN];
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1124
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1125 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1126 "http file cache vary: \"%*s\"", len, vary);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1127
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1128 ngx_md5_init(&md5);
5880
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1129 ngx_md5_update(&md5, r->cache->main, NGX_HTTP_CACHE_KEY_LEN);
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1130
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1131 ngx_strlow(buf, vary, len);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1132
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1133 p = buf;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1134 last = buf + len;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1135
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1136 while (p < last) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1137
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1138 while (p < last && (*p == ' ' || *p == ',')) { p++; }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1139
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1140 name.data = p;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1141
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1142 while (p < last && *p != ',' && *p != ' ') { p++; }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1143
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1144 name.len = p - name.data;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1145
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1146 if (name.len == 0) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1147 break;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1148 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1149
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1150 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1151 "http file cache vary: %V", &name);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1152
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1153 ngx_md5_update(&md5, name.data, name.len);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1154 ngx_md5_update(&md5, (u_char *) ":", sizeof(":") - 1);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1155
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1156 ngx_http_file_cache_vary_header(r, &md5, &name);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1157
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1158 ngx_md5_update(&md5, (u_char *) CRLF, sizeof(CRLF) - 1);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1159 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1160
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1161 ngx_md5_final(hash, &md5);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1162 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1163
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1164
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1165 static void
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1166 ngx_http_file_cache_vary_header(ngx_http_request_t *r, ngx_md5_t *md5,
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1167 ngx_str_t *name)
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1168 {
5881
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1169 size_t len;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1170 u_char *p, *start, *last;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1171 ngx_uint_t i, multiple, normalize;
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1172 ngx_list_part_t *part;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1173 ngx_table_elt_t *header;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1174
5881
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1175 multiple = 0;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1176 normalize = 0;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1177
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1178 if (name->len == sizeof("Accept-Charset") - 1
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1179 && ngx_strncasecmp(name->data, (u_char *) "Accept-Charset",
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1180 sizeof("Accept-Charset") - 1) == 0)
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1181 {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1182 normalize = 1;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1183
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1184 } else if (name->len == sizeof("Accept-Encoding") - 1
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1185 && ngx_strncasecmp(name->data, (u_char *) "Accept-Encoding",
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1186 sizeof("Accept-Encoding") - 1) == 0)
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1187 {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1188 normalize = 1;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1189
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1190 } else if (name->len == sizeof("Accept-Language") - 1
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1191 && ngx_strncasecmp(name->data, (u_char *) "Accept-Language",
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1192 sizeof("Accept-Language") - 1) == 0)
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1193 {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1194 normalize = 1;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1195 }
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1196
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1197 part = &r->headers_in.headers.part;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1198 header = part->elts;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1199
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1200 for (i = 0; /* void */ ; i++) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1201
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1202 if (i >= part->nelts) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1203 if (part->next == NULL) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1204 break;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1205 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1206
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1207 part = part->next;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1208 header = part->elts;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1209 i = 0;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1210 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1211
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1212 if (header[i].hash == 0) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1213 continue;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1214 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1215
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1216 if (header[i].key.len != name->len) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1217 continue;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1218 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1219
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1220 if (ngx_strncasecmp(header[i].key.data, name->data, name->len) != 0) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1221 continue;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1222 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1223
5881
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1224 if (!normalize) {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1225
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1226 if (multiple) {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1227 ngx_md5_update(md5, (u_char *) ",", sizeof(",") - 1);
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1228 }
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1229
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1230 ngx_md5_update(md5, header[i].value.data, header[i].value.len);
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1231
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1232 multiple = 1;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1233
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1234 continue;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1235 }
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1236
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1237 /* normalize spaces */
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1238
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1239 p = header[i].value.data;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1240 last = p + header[i].value.len;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1241
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1242 while (p < last) {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1243
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1244 while (p < last && (*p == ' ' || *p == ',')) { p++; }
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1245
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1246 start = p;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1247
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1248 while (p < last && *p != ',' && *p != ' ') { p++; }
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1249
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1250 len = p - start;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1251
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1252 if (len == 0) {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1253 break;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1254 }
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1255
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1256 if (multiple) {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1257 ngx_md5_update(md5, (u_char *) ",", sizeof(",") - 1);
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1258 }
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1259
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1260 ngx_md5_update(md5, start, len);
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1261
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1262 multiple = 1;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1263 }
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1264 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1265 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1266
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1267
5880
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1268 static ngx_int_t
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1269 ngx_http_file_cache_reopen(ngx_http_request_t *r, ngx_http_cache_t *c)
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1270 {
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1271 ngx_http_file_cache_t *cache;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1272
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1273 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->file.log, 0,
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1274 "http file cache reopen");
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1275
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1276 if (c->secondary) {
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1277 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1278 "cache file \"%s\" has incorrect vary hash",
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1279 c->file.name.data);
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1280 return NGX_DECLINED;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1281 }
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1282
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1283 cache = c->file_cache;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1284
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1285 ngx_shmtx_lock(&cache->shpool->mutex);
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1286
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1287 c->node->count--;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1288 c->node = NULL;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1289
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1290 ngx_shmtx_unlock(&cache->shpool->mutex);
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1291
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1292 c->secondary = 1;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1293 c->file.name.len = 0;
7704
847fd35f94de Cache: reset c->body_start when reading a variant on Vary mismatch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7670
diff changeset
1294 c->body_start = c->buffer_size;
5880
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1295
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1296 ngx_memcpy(c->key, c->variant, NGX_HTTP_CACHE_KEY_LEN);
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1297
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1298 return ngx_http_file_cache_open(r);
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1299 }
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1300
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1301
5959
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1302 ngx_int_t
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1303 ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1304 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1305 ngx_http_file_cache_header_t *h = (ngx_http_file_cache_header_t *) buf;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1306
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1307 u_char *p;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1308 ngx_str_t *key;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1309 ngx_uint_t i;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1310 ngx_http_cache_t *c;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1311
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1312 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1313 "http file cache set header");
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1314
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1315 c = r->cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1316
5245
711fa02afae8 Valgrind: supressed complaints about uninitialized bytes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5077
diff changeset
1317 ngx_memzero(h, sizeof(ngx_http_file_cache_header_t));
711fa02afae8 Valgrind: supressed complaints about uninitialized bytes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5077
diff changeset
1318
5736
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
1319 h->version = NGX_HTTP_CACHE_VERSION;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1320 h->valid_sec = c->valid_sec;
6905
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6860
diff changeset
1321 h->updating_sec = c->updating_sec;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6860
diff changeset
1322 h->error_sec = c->error_sec;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1323 h->last_modified = c->last_modified;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1324 h->date = c->date;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1325 h->crc32 = c->crc32;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1326 h->valid_msec = (u_short) c->valid_msec;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1327 h->header_start = (u_short) c->header_start;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1328 h->body_start = (u_short) c->body_start;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1329
5737
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
1330 if (c->etag.len <= NGX_HTTP_CACHE_ETAG_LEN) {
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
1331 h->etag_len = (u_char) c->etag.len;
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
1332 ngx_memcpy(h->etag, c->etag.data, c->etag.len);
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
1333 }
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
1334
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1335 if (c->vary.len) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1336 if (c->vary.len > NGX_HTTP_CACHE_VARY_LEN) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1337 /* should not happen */
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1338 c->vary.len = NGX_HTTP_CACHE_VARY_LEN;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1339 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1340
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1341 h->vary_len = (u_char) c->vary.len;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1342 ngx_memcpy(h->vary, c->vary.data, c->vary.len);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1343
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1344 ngx_http_file_cache_vary(r, c->vary.data, c->vary.len, c->variant);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1345 ngx_memcpy(h->variant, c->variant, NGX_HTTP_CACHE_KEY_LEN);
5959
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1346 }
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1347
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1348 if (ngx_http_file_cache_update_variant(r, c) != NGX_OK) {
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1349 return NGX_ERROR;
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1350 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1351
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1352 p = buf + sizeof(ngx_http_file_cache_header_t);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1353
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1354 p = ngx_cpymem(p, ngx_http_file_cache_key, sizeof(ngx_http_file_cache_key));
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1355
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1356 key = c->keys.elts;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1357 for (i = 0; i < c->keys.nelts; i++) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1358 p = ngx_copy(p, key[i].data, key[i].len);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1359 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1360
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1361 *p = LF;
5959
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1362
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1363 return NGX_OK;
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1364 }
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1365
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1366
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1367 static ngx_int_t
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1368 ngx_http_file_cache_update_variant(ngx_http_request_t *r, ngx_http_cache_t *c)
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1369 {
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1370 ngx_http_file_cache_t *cache;
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1371
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1372 if (!c->secondary) {
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1373 return NGX_OK;
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1374 }
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1375
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1376 if (c->vary.len
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1377 && ngx_memcmp(c->variant, c->key, NGX_HTTP_CACHE_KEY_LEN) == 0)
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1378 {
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1379 return NGX_OK;
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1380 }
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1381
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1382 /*
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1383 * if the variant hash doesn't match one we used as a secondary
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1384 * cache key, switch back to the original key
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1385 */
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1386
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1387 cache = c->file_cache;
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1388
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1389 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1390 "http file cache main key");
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1391
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1392 ngx_shmtx_lock(&cache->shpool->mutex);
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1393
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1394 c->node->count--;
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1395 c->node->updating = 0;
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1396 c->node = NULL;
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1397
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1398 ngx_shmtx_unlock(&cache->shpool->mutex);
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1399
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1400 c->file.name.len = 0;
7705
3781de64e747 Cache: keep c->body_start when Vary changes (ticket #2029).
Sergey Kandaurov <pluknet@nginx.com>
parents: 7704
diff changeset
1401 c->update_variant = 1;
5959
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1402
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1403 ngx_memcpy(c->key, c->main, NGX_HTTP_CACHE_KEY_LEN);
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1404
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1405 if (ngx_http_file_cache_exists(cache, c) == NGX_ERROR) {
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1406 return NGX_ERROR;
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1407 }
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1408
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1409 if (ngx_http_file_cache_name(r, cache->path) != NGX_OK) {
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1410 return NGX_ERROR;
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1411 }
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1412
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
1413 return NGX_OK;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1414 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1415
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1416
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1417 void
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1418 ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1419 {
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
1420 off_t fs_size;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1421 ngx_int_t rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1422 ngx_file_uniq_t uniq;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1423 ngx_file_info_t fi;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1424 ngx_http_cache_t *c;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1425 ngx_ext_rename_file_t ext;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1426 ngx_http_file_cache_t *cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1427
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1428 c = r->cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1429
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1430 if (c->updated) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1431 return;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1432 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1433
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1434 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1435 "http file cache update");
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1436
5880
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1437 cache = c->file_cache;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1438
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1439 c->updated = 1;
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1440 c->updating = 0;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1441
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1442 uniq = 0;
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
1443 fs_size = 0;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1444
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1445 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1446 "http file cache rename: \"%s\" to \"%s\"",
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1447 tf->file.name.data, c->file.name.data);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1448
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1449 ext.access = NGX_FILE_OWNER_ACCESS;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1450 ext.path_access = NGX_FILE_OWNER_ACCESS;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1451 ext.time = -1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1452 ext.create_path = 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1453 ext.delete_file = 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1454 ext.log = r->connection->log;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1455
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1456 rc = ngx_ext_rename_file(&tf->file.name, &c->file.name, &ext);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1457
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1458 if (rc == NGX_OK) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1459
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1460 if (ngx_fd_info(tf->file.fd, &fi) == NGX_FILE_ERROR) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1461 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1462 ngx_fd_info_n " \"%s\" failed", tf->file.name.data);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1463
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1464 rc = NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1465
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1466 } else {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1467 uniq = ngx_file_uniq(&fi);
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
1468 fs_size = (ngx_file_fs_size(&fi) + cache->bsize - 1) / cache->bsize;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1469 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1470 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1471
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1472 ngx_shmtx_lock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1473
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1474 c->node->count--;
6539
d94f57990492 Cache: fixed updating bypassed cached errors (ticket #827).
Maxim Dounin <mdounin@mdounin.ru>
parents: 6478
diff changeset
1475 c->node->error = 0;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1476 c->node->uniq = uniq;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1477 c->node->body_start = c->body_start;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1478
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
1479 cache->sh->size += fs_size - c->node->fs_size;
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
1480 c->node->fs_size = fs_size;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1481
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1482 if (rc == NGX_OK) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1483 c->node->exists = 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1484 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1485
2927
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
1486 c->node->updating = 0;
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
1487
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1488 ngx_shmtx_unlock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1489 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1490
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1491
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1492 void
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1493 ngx_http_file_cache_update_header(ngx_http_request_t *r)
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1494 {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1495 ssize_t n;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1496 ngx_err_t err;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1497 ngx_file_t file;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1498 ngx_file_info_t fi;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1499 ngx_http_cache_t *c;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1500 ngx_http_file_cache_header_t h;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1501
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1502 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1503 "http file cache update header");
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1504
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1505 c = r->cache;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1506
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1507 ngx_memzero(&file, sizeof(ngx_file_t));
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1508
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1509 file.name = c->file.name;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1510 file.log = r->connection->log;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1511 file.fd = ngx_open_file(file.name.data, NGX_FILE_RDWR, NGX_FILE_OPEN, 0);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1512
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1513 if (file.fd == NGX_INVALID_FILE) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1514 err = ngx_errno;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1515
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1516 /* cache file may have been deleted */
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1517
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1518 if (err == NGX_ENOENT) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1519 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1520 "http file cache \"%s\" not found",
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1521 file.name.data);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1522 return;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1523 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1524
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1525 ngx_log_error(NGX_LOG_CRIT, r->connection->log, err,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1526 ngx_open_file_n " \"%s\" failed", file.name.data);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1527 return;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1528 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1529
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1530 /*
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1531 * make sure cache file wasn't replaced;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1532 * if it was, do nothing
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1533 */
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1534
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1535 if (ngx_fd_info(file.fd, &fi) == NGX_FILE_ERROR) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1536 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1537 ngx_fd_info_n " \"%s\" failed", file.name.data);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1538 goto done;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1539 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1540
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1541 if (c->uniq != ngx_file_uniq(&fi)
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1542 || c->length != ngx_file_size(&fi))
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1543 {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1544 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1545 "http file cache \"%s\" changed",
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1546 file.name.data);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1547 goto done;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1548 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1549
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1550 n = ngx_read_file(&file, (u_char *) &h,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1551 sizeof(ngx_http_file_cache_header_t), 0);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1552
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1553 if (n == NGX_ERROR) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1554 goto done;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1555 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1556
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1557 if ((size_t) n != sizeof(ngx_http_file_cache_header_t)) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1558 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1559 ngx_read_file_n " read only %z of %z from \"%s\"",
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1560 n, sizeof(ngx_http_file_cache_header_t), file.name.data);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1561 goto done;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1562 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1563
5736
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
1564 if (h.version != NGX_HTTP_CACHE_VERSION
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
1565 || h.last_modified != c->last_modified
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1566 || h.crc32 != c->crc32
6860
f18c285c2e59 Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6795
diff changeset
1567 || (size_t) h.header_start != c->header_start
f18c285c2e59 Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6795
diff changeset
1568 || (size_t) h.body_start != c->body_start)
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1569 {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1570 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1571 "http file cache \"%s\" content changed",
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1572 file.name.data);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1573 goto done;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1574 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1575
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1576 /*
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1577 * update cache file header with new data,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1578 * notably h.valid_sec and h.date
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1579 */
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1580
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1581 ngx_memzero(&h, sizeof(ngx_http_file_cache_header_t));
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1582
5736
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
1583 h.version = NGX_HTTP_CACHE_VERSION;
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1584 h.valid_sec = c->valid_sec;
6905
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6860
diff changeset
1585 h.updating_sec = c->updating_sec;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6860
diff changeset
1586 h.error_sec = c->error_sec;
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1587 h.last_modified = c->last_modified;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1588 h.date = c->date;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1589 h.crc32 = c->crc32;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1590 h.valid_msec = (u_short) c->valid_msec;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1591 h.header_start = (u_short) c->header_start;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1592 h.body_start = (u_short) c->body_start;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1593
5737
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
1594 if (c->etag.len <= NGX_HTTP_CACHE_ETAG_LEN) {
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
1595 h.etag_len = (u_char) c->etag.len;
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
1596 ngx_memcpy(h.etag, c->etag.data, c->etag.len);
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
1597 }
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
1598
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1599 if (c->vary.len) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1600 if (c->vary.len > NGX_HTTP_CACHE_VARY_LEN) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1601 /* should not happen */
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1602 c->vary.len = NGX_HTTP_CACHE_VARY_LEN;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1603 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1604
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1605 h.vary_len = (u_char) c->vary.len;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1606 ngx_memcpy(h.vary, c->vary.data, c->vary.len);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1607
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1608 ngx_http_file_cache_vary(r, c->vary.data, c->vary.len, c->variant);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1609 ngx_memcpy(h.variant, c->variant, NGX_HTTP_CACHE_KEY_LEN);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1610 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1611
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1612 (void) ngx_write_file(&file, (u_char *) &h,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1613 sizeof(ngx_http_file_cache_header_t), 0);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1614
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1615 done:
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1616
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1617 if (ngx_close_file(file.fd) == NGX_FILE_ERROR) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1618 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1619 ngx_close_file_n " \"%s\" failed", file.name.data);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1620 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1621 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1622
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1623
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1624 ngx_int_t
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1625 ngx_http_cache_send(ngx_http_request_t *r)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1626 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1627 ngx_int_t rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1628 ngx_buf_t *b;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1629 ngx_chain_t out;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1630 ngx_http_cache_t *c;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1631
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1632 c = r->cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1633
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1634 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3965
90b0487fba44 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 3942
diff changeset
1635 "http file cache send: %s", c->file.name.data);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1636
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1637 /* we need to allocate all before the header would be sent */
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1638
6973
99934aade555 Use ngx_calloc_buf() where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents: 6906
diff changeset
1639 b = ngx_calloc_buf(r->pool);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1640 if (b == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1641 return NGX_HTTP_INTERNAL_SERVER_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1642 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1643
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1644 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1645 if (b->file == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1646 return NGX_HTTP_INTERNAL_SERVER_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1647 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1648
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1649 rc = ngx_http_send_header(r);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1650
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1651 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1652 return rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1653 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1654
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1655 b->file_pos = c->body_start;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1656 b->file_last = c->length;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1657
8123
Maxim Dounin <mdounin@mdounin.ru>
parents: 8005
diff changeset
1658 b->in_file = (c->length - c->body_start) ? 1 : 0;
Maxim Dounin <mdounin@mdounin.ru>
parents: 8005
diff changeset
1659 b->last_buf = (r == r->main) ? 1 : 0;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1660 b->last_in_chain = 1;
8124
f5515e727656 Fixed "zero size buf" alerts with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8123
diff changeset
1661 b->sync = (b->last_buf || b->in_file) ? 0 : 1;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1662
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1663 b->file->fd = c->file.fd;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1664 b->file->name = c->file.name;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1665 b->file->log = r->connection->log;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1666
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1667 out.buf = b;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1668 out.next = NULL;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1669
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1670 return ngx_http_output_filter(r, &out);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1671 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1672
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1673
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1674 void
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1675 ngx_http_file_cache_free(ngx_http_cache_t *c, ngx_temp_file_t *tf)
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1676 {
3694
dfb17155eca9 delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents: 3526
diff changeset
1677 ngx_http_file_cache_t *cache;
dfb17155eca9 delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents: 3526
diff changeset
1678 ngx_http_file_cache_node_t *fcn;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1679
3917
2a70484a6580 fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents: 3899
diff changeset
1680 if (c->updated || c->node == NULL) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1681 return;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1682 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1683
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1684 cache = c->file_cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1685
3713
f0b62d1ac7af move debug logging inside ngx_http_file_cache_free()
Igor Sysoev <igor@sysoev.ru>
parents: 3711
diff changeset
1686 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->file.log, 0,
f0b62d1ac7af move debug logging inside ngx_http_file_cache_free()
Igor Sysoev <igor@sysoev.ru>
parents: 3711
diff changeset
1687 "http file cache free, fd: %d", c->file.fd);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1688
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1689 ngx_shmtx_lock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1690
3694
dfb17155eca9 delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents: 3526
diff changeset
1691 fcn = c->node;
dfb17155eca9 delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents: 3526
diff changeset
1692 fcn->count--;
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1693
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
1694 if (c->updating && fcn->lock_time == c->lock_time) {
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1695 fcn->updating = 0;
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1696 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1697
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1698 if (c->error) {
3694
dfb17155eca9 delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents: 3526
diff changeset
1699 fcn->error = c->error;
dfb17155eca9 delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents: 3526
diff changeset
1700
3743
c469ffeab569 error status codes could be cached for next request only,
Igor Sysoev <igor@sysoev.ru>
parents: 3732
diff changeset
1701 if (c->valid_sec) {
c469ffeab569 error status codes could be cached for next request only,
Igor Sysoev <igor@sysoev.ru>
parents: 3732
diff changeset
1702 fcn->valid_sec = c->valid_sec;
c469ffeab569 error status codes could be cached for next request only,
Igor Sysoev <igor@sysoev.ru>
parents: 3732
diff changeset
1703 fcn->valid_msec = c->valid_msec;
c469ffeab569 error status codes could be cached for next request only,
Igor Sysoev <igor@sysoev.ru>
parents: 3732
diff changeset
1704 }
c469ffeab569 error status codes could be cached for next request only,
Igor Sysoev <igor@sysoev.ru>
parents: 3732
diff changeset
1705
3723
14ad3210fc73 do not free unused cache node if cache min_uses > 1,
Igor Sysoev <igor@sysoev.ru>
parents: 3713
diff changeset
1706 } else if (!fcn->exists && fcn->count == 0 && c->min_uses == 1) {
3694
dfb17155eca9 delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents: 3526
diff changeset
1707 ngx_queue_remove(&fcn->queue);
dfb17155eca9 delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents: 3526
diff changeset
1708 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
dfb17155eca9 delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents: 3526
diff changeset
1709 ngx_slab_free_locked(cache->shpool, fcn);
6445
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
1710 cache->sh->count--;
3694
dfb17155eca9 delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents: 3526
diff changeset
1711 c->node = NULL;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1712 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1713
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1714 ngx_shmtx_unlock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1715
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1716 c->updated = 1;
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1717 c->updating = 0;
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1718
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1719 if (c->temp_file) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1720 if (tf && tf->file.fd != NGX_INVALID_FILE) {
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1721 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->file.log, 0,
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1722 "http file cache incomplete: \"%s\"",
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1723 tf->file.name.data);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1724
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1725 if (ngx_delete_file(tf->file.name.data) == NGX_FILE_ERROR) {
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1726 ngx_log_error(NGX_LOG_CRIT, c->file.log, ngx_errno,
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1727 ngx_delete_file_n " \"%s\" failed",
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1728 tf->file.name.data);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1729 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1730 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1731 }
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
1732
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
1733 if (c->wait_event.timer_set) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
1734 ngx_del_timer(&c->wait_event);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
1735 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1736 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1737
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1738
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1739 static void
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1740 ngx_http_file_cache_cleanup(void *data)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1741 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1742 ngx_http_cache_t *c = data;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1743
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1744 if (c->updated) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1745 return;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1746 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1747
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1748 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->file.log, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1749 "http file cache cleanup");
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1750
6906
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1751 if (c->updating && !c->background) {
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1752 ngx_log_error(NGX_LOG_ALERT, c->file.log, 0,
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1753 "stalled cache updating, error:%ui", c->error);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1754 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1755
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1756 ngx_http_file_cache_free(c, NULL);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1757 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1758
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1759
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1760 static time_t
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1761 ngx_http_file_cache_forced_expire(ngx_http_file_cache_t *cache)
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1762 {
7002
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1763 u_char *name, *p;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1764 size_t len;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1765 time_t wait;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1766 ngx_uint_t tries;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1767 ngx_path_t *path;
7002
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1768 ngx_queue_t *q, *sentinel;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1769 ngx_http_file_cache_node_t *fcn;
7002
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1770 u_char key[2 * NGX_HTTP_CACHE_KEY_LEN];
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1771
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1772 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1773 "http file cache forced expire");
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1774
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1775 path = cache->path;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1776 len = path->name.len + 1 + path->len + 2 * NGX_HTTP_CACHE_KEY_LEN;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1777
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1778 name = ngx_alloc(len + 1, ngx_cycle->log);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1779 if (name == NULL) {
2694
49a1382b249b set cache manager maximum sleep time to 10s
Igor Sysoev <igor@sysoev.ru>
parents: 2693
diff changeset
1780 return 10;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1781 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1782
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1783 ngx_memcpy(name, path->name.data, path->name.len);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1784
2694
49a1382b249b set cache manager maximum sleep time to 10s
Igor Sysoev <igor@sysoev.ru>
parents: 2693
diff changeset
1785 wait = 10;
3728
a29bb11f8c80 change logic slightly
Igor Sysoev <igor@sysoev.ru>
parents: 3727
diff changeset
1786 tries = 20;
7002
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1787 sentinel = NULL;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1788
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1789 ngx_shmtx_lock(&cache->shpool->mutex);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1790
7002
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1791 for ( ;; ) {
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1792 if (ngx_queue_empty(&cache->sh->queue)) {
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1793 break;
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1794 }
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1795
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1796 q = ngx_queue_last(&cache->sh->queue);
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1797
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1798 if (q == sentinel) {
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1799 break;
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1800 }
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1801
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1802 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1803
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1804 ngx_log_debug6(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1805 "http file cache forced expire: #%d %d %02xd%02xd%02xd%02xd",
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1806 fcn->count, fcn->exists,
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1807 fcn->key[0], fcn->key[1], fcn->key[2], fcn->key[3]);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1808
3727
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1809 if (fcn->count == 0) {
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1810 ngx_http_file_cache_delete(cache, q, name);
3885
46938b7418c6 fix CPU hog in cache manager
Igor Sysoev <igor@sysoev.ru>
parents: 3755
diff changeset
1811 wait = 0;
7002
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1812 break;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1813 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1814
8005
dd718d1cef3c Cache: fixed race in ngx_http_file_cache_forced_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7705
diff changeset
1815 if (fcn->deleting) {
dd718d1cef3c Cache: fixed race in ngx_http_file_cache_forced_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7705
diff changeset
1816 wait = 1;
dd718d1cef3c Cache: fixed race in ngx_http_file_cache_forced_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7705
diff changeset
1817 break;
dd718d1cef3c Cache: fixed race in ngx_http_file_cache_forced_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7705
diff changeset
1818 }
dd718d1cef3c Cache: fixed race in ngx_http_file_cache_forced_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7705
diff changeset
1819
7002
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1820 p = ngx_hex_dump(key, (u_char *) &fcn->node.key,
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1821 sizeof(ngx_rbtree_key_t));
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1822 len = NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t);
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1823 (void) ngx_hex_dump(p, fcn->key, len);
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1824
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1825 /*
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1826 * abnormally exited workers may leave locked cache entries,
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1827 * and although it may be safe to remove them completely,
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1828 * we prefer to just move them to the top of the inactive queue
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1829 */
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1830
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1831 ngx_queue_remove(q);
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1832 fcn->expire = ngx_time() + cache->inactive;
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1833 ngx_queue_insert_head(&cache->sh->queue, &fcn->queue);
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1834
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1835 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1836 "ignore long locked inactive cache entry %*s, count:%d",
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1837 (size_t) 2 * NGX_HTTP_CACHE_KEY_LEN, key, fcn->count);
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1838
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1839 if (sentinel == NULL) {
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1840 sentinel = q;
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1841 }
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1842
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1843 if (--tries) {
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1844 continue;
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1845 }
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1846
ab199f0eb8e8 Cache: ignore long locked entries during forced expire.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6973
diff changeset
1847 wait = 1;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1848 break;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1849 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1850
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1851 ngx_shmtx_unlock(&cache->shpool->mutex);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1852
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1853 ngx_free(name);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1854
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1855 return wait;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1856 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1857
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1858
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1859 static time_t
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1860 ngx_http_file_cache_expire(ngx_http_file_cache_t *cache)
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1861 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1862 u_char *name, *p;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1863 size_t len;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1864 time_t now, wait;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1865 ngx_path_t *path;
6727
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1866 ngx_msec_t elapsed;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1867 ngx_queue_t *q;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1868 ngx_http_file_cache_node_t *fcn;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1869 u_char key[2 * NGX_HTTP_CACHE_KEY_LEN];
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1870
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1871 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1872 "http file cache expire");
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1873
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1874 path = cache->path;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1875 len = path->name.len + 1 + path->len + 2 * NGX_HTTP_CACHE_KEY_LEN;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1876
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1877 name = ngx_alloc(len + 1, ngx_cycle->log);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1878 if (name == NULL) {
2694
49a1382b249b set cache manager maximum sleep time to 10s
Igor Sysoev <igor@sysoev.ru>
parents: 2693
diff changeset
1879 return 10;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1880 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1881
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1882 ngx_memcpy(name, path->name.data, path->name.len);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1883
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1884 now = ngx_time();
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1885
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1886 ngx_shmtx_lock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1887
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1888 for ( ;; ) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1889
5679
5748ce74c1cc Cache: added ngx_quit check to ngx_http_file_cache_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5441
diff changeset
1890 if (ngx_quit || ngx_terminate) {
5748ce74c1cc Cache: added ngx_quit check to ngx_http_file_cache_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5441
diff changeset
1891 wait = 1;
5748ce74c1cc Cache: added ngx_quit check to ngx_http_file_cache_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5441
diff changeset
1892 break;
5748ce74c1cc Cache: added ngx_quit check to ngx_http_file_cache_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5441
diff changeset
1893 }
5748ce74c1cc Cache: added ngx_quit check to ngx_http_file_cache_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5441
diff changeset
1894
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
1895 if (ngx_queue_empty(&cache->sh->queue)) {
2694
49a1382b249b set cache manager maximum sleep time to 10s
Igor Sysoev <igor@sysoev.ru>
parents: 2693
diff changeset
1896 wait = 10;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1897 break;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1898 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1899
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
1900 q = ngx_queue_last(&cache->sh->queue);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1901
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1902 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1903
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1904 wait = fcn->expire - now;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1905
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1906 if (wait > 0) {
2694
49a1382b249b set cache manager maximum sleep time to 10s
Igor Sysoev <igor@sysoev.ru>
parents: 2693
diff changeset
1907 wait = wait > 10 ? 10 : wait;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1908 break;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1909 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1910
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1911 ngx_log_debug6(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1912 "http file cache expire: #%d %d %02xd%02xd%02xd%02xd",
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1913 fcn->count, fcn->exists,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1914 fcn->key[0], fcn->key[1], fcn->key[2], fcn->key[3]);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1915
3727
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1916 if (fcn->count == 0) {
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1917 ngx_http_file_cache_delete(cache, q, name);
6727
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1918 goto next;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1919 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1920
3755
76e3a93821b1 fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents: 3744
diff changeset
1921 if (fcn->deleting) {
3942
2e8dbd773d63 fix r3756: release lock to allow other process to delete cache node
Igor Sysoev <igor@sysoev.ru>
parents: 3917
diff changeset
1922 wait = 1;
2e8dbd773d63 fix r3756: release lock to allow other process to delete cache node
Igor Sysoev <igor@sysoev.ru>
parents: 3917
diff changeset
1923 break;
3755
76e3a93821b1 fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents: 3744
diff changeset
1924 }
76e3a93821b1 fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents: 3744
diff changeset
1925
3727
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1926 p = ngx_hex_dump(key, (u_char *) &fcn->node.key,
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1927 sizeof(ngx_rbtree_key_t));
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1928 len = NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t);
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1929 (void) ngx_hex_dump(p, fcn->key, len);
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1930
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1931 /*
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1932 * abnormally exited workers may leave locked cache entries,
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1933 * and although it may be safe to remove them completely,
4340
4533d7684e14 Cache: only complain on long locked entries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4339
diff changeset
1934 * we prefer to just move them to the top of the inactive queue
3727
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1935 */
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1936
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1937 ngx_queue_remove(q);
4340
4533d7684e14 Cache: only complain on long locked entries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4339
diff changeset
1938 fcn->expire = ngx_time() + cache->inactive;
4533d7684e14 Cache: only complain on long locked entries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4339
diff changeset
1939 ngx_queue_insert_head(&cache->sh->queue, &fcn->queue);
3727
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1940
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1941 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1942 "ignore long locked inactive cache entry %*s, count:%d",
6478
3ef7bb882ad4 Fixed logging with variable field width.
Sergey Kandaurov <pluknet@nginx.com>
parents: 6450
diff changeset
1943 (size_t) 2 * NGX_HTTP_CACHE_KEY_LEN, key, fcn->count);
6727
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1944
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1945 next:
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1946
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1947 if (++cache->files >= cache->manager_files) {
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1948 wait = 0;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1949 break;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1950 }
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1951
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1952 ngx_time_update();
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1953
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1954 elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last));
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1955
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1956 if (elapsed >= cache->manager_threshold) {
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1957 wait = 0;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1958 break;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
1959 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1960 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1961
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1962 ngx_shmtx_unlock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1963
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1964 ngx_free(name);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1965
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1966 return wait;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1967 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1968
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1969
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1970 static void
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1971 ngx_http_file_cache_delete(ngx_http_file_cache_t *cache, ngx_queue_t *q,
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1972 u_char *name)
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1973 {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1974 u_char *p;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1975 size_t len;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1976 ngx_path_t *path;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1977 ngx_http_file_cache_node_t *fcn;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1978
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1979 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1980
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1981 if (fcn->exists) {
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
1982 cache->sh->size -= fcn->fs_size;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1983
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1984 path = cache->path;
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1985 p = name + path->name.len + 1 + path->len;
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1986 p = ngx_hex_dump(p, (u_char *) &fcn->node.key,
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1987 sizeof(ngx_rbtree_key_t));
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1988 len = NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t);
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1989 p = ngx_hex_dump(p, fcn->key, len);
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1990 *p = '\0';
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1991
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1992 fcn->count++;
3755
76e3a93821b1 fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents: 3744
diff changeset
1993 fcn->deleting = 1;
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1994 ngx_shmtx_unlock(&cache->shpool->mutex);
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1995
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1996 len = path->name.len + 1 + path->len + 2 * NGX_HTTP_CACHE_KEY_LEN;
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1997 ngx_create_hashed_filename(path, name, len);
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1998
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1999 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
2000 "http file cache expire: \"%s\"", name);
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2001
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
2002 if (ngx_delete_file(name) == NGX_FILE_ERROR) {
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
2003 ngx_log_error(NGX_LOG_CRIT, ngx_cycle->log, ngx_errno,
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
2004 ngx_delete_file_n " \"%s\" failed", name);
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
2005 }
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2006
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
2007 ngx_shmtx_lock(&cache->shpool->mutex);
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
2008 fcn->count--;
3755
76e3a93821b1 fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents: 3744
diff changeset
2009 fcn->deleting = 0;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2010 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2011
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
2012 if (fcn->count == 0) {
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
2013 ngx_queue_remove(q);
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
2014 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
2015 ngx_slab_free_locked(cache->shpool, fcn);
6445
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2016 cache->sh->count--;
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
2017 }
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2018 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2019
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2020
6727
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2021 static ngx_msec_t
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2022 ngx_http_file_cache_manager(void *data)
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2023 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2024 ngx_http_file_cache_t *cache = data;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2025
7670
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2026 off_t size, free;
6742
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2027 time_t wait;
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2028 ngx_msec_t elapsed, next;
6445
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2029 ngx_uint_t count, watermark;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2030
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2031 cache->last = ngx_current_msec;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2032 cache->files = 0;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2033
6742
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2034 next = (ngx_msec_t) ngx_http_file_cache_expire(cache) * 1000;
6727
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2035
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2036 if (next == 0) {
6742
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2037 next = cache->manager_sleep;
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2038 goto done;
6727
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2039 }
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2040
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2041 for ( ;; ) {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2042 ngx_shmtx_lock(&cache->shpool->mutex);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2043
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
2044 size = cache->sh->size;
6445
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2045 count = cache->sh->count;
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2046 watermark = cache->sh->watermark;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2047
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2048 ngx_shmtx_unlock(&cache->shpool->mutex);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2049
6445
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2050 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2051 "http file cache size: %O c:%ui w:%i",
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2052 size, count, (ngx_int_t) watermark);
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2053
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2054 if (size < cache->max_size && count < watermark) {
7670
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2055
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2056 if (!cache->min_free) {
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2057 break;
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2058 }
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2059
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2060 free = ngx_fs_available(cache->path->name.data);
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2061
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2062 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2063 "http file cache free: %O", free);
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2064
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2065 if (free > cache->min_free) {
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2066 break;
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2067 }
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2068 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2069
3885
46938b7418c6 fix CPU hog in cache manager
Igor Sysoev <igor@sysoev.ru>
parents: 3755
diff changeset
2070 wait = ngx_http_file_cache_forced_expire(cache);
46938b7418c6 fix CPU hog in cache manager
Igor Sysoev <igor@sysoev.ru>
parents: 3755
diff changeset
2071
46938b7418c6 fix CPU hog in cache manager
Igor Sysoev <igor@sysoev.ru>
parents: 3755
diff changeset
2072 if (wait > 0) {
6742
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2073 next = (ngx_msec_t) wait * 1000;
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2074 break;
3885
46938b7418c6 fix CPU hog in cache manager
Igor Sysoev <igor@sysoev.ru>
parents: 3755
diff changeset
2075 }
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2076
3972
c1a69e03bdf2 rename ngx_http_file_cache_manager_sleep() to ngx_http_file_cache_loader_sleep()
Igor Sysoev <igor@sysoev.ru>
parents: 3971
diff changeset
2077 if (ngx_quit || ngx_terminate) {
6742
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2078 break;
6727
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2079 }
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2080
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2081 if (++cache->files >= cache->manager_files) {
6742
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2082 next = cache->manager_sleep;
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2083 break;
6727
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2084 }
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2085
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2086 ngx_time_update();
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2087
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2088 elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last));
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2089
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2090 if (elapsed >= cache->manager_threshold) {
6742
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2091 next = cache->manager_sleep;
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2092 break;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2093 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2094 }
6742
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2095
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2096 done:
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2097
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2098 elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last));
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2099
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2100 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2101 "http file cache manager: %ui e:%M n:%M",
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2102 cache->files, elapsed, next);
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2103
3fbb3bdff824 Cache: cache manager debugging.
Ruslan Ermilov <ru@nginx.com>
parents: 6727
diff changeset
2104 return next;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2105 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2106
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2107
3018
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2108 static void
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2109 ngx_http_file_cache_loader(void *data)
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2110 {
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2111 ngx_http_file_cache_t *cache = data;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2112
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2113 ngx_tree_ctx_t tree;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2114
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2115 if (!cache->sh->cold || cache->sh->loading) {
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2116 return;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2117 }
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2118
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2119 if (!ngx_atomic_cmp_set(&cache->sh->loading, 0, ngx_pid)) {
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2120 return;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2121 }
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2122
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2123 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2124 "http file cache loader");
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2125
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2126 tree.init_handler = NULL;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2127 tree.file_handler = ngx_http_file_cache_manage_file;
5968
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
2128 tree.pre_tree_handler = ngx_http_file_cache_manage_directory;
3018
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2129 tree.post_tree_handler = ngx_http_file_cache_noop;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2130 tree.spec_handler = ngx_http_file_cache_delete_file;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2131 tree.data = cache;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2132 tree.alloc = 0;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2133 tree.log = ngx_cycle->log;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2134
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2135 cache->last = ngx_current_msec;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2136 cache->files = 0;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2137
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2138 if (ngx_walk_tree(&tree, &cache->path->name) == NGX_ABORT) {
3020
364ea8f54a2f unlock incompletely loaded cache
Igor Sysoev <igor@sysoev.ru>
parents: 3018
diff changeset
2139 cache->sh->loading = 0;
3018
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2140 return;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2141 }
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2142
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2143 cache->sh->cold = 0;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2144 cache->sh->loading = 0;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2145
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2146 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2147 "http file cache: %V %.3fM, bsize: %uz",
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2148 &cache->path->name,
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2149 ((double) cache->sh->size * cache->bsize) / (1024 * 1024),
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2150 cache->bsize);
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2151 }
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2152
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2153
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2154 static ngx_int_t
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2155 ngx_http_file_cache_noop(ngx_tree_ctx_t *ctx, ngx_str_t *path)
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2156 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2157 return NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2158 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2159
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2160
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2161 static ngx_int_t
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2162 ngx_http_file_cache_manage_file(ngx_tree_ctx_t *ctx, ngx_str_t *path)
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2163 {
4018
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2164 ngx_msec_t elapsed;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2165 ngx_http_file_cache_t *cache;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2166
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2167 cache = ctx->data;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2168
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2169 if (ngx_http_file_cache_add_file(ctx, path) != NGX_OK) {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2170 (void) ngx_http_file_cache_delete_file(ctx, path);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2171 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2172
4018
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2173 if (++cache->files >= cache->loader_files) {
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2174 ngx_http_file_cache_loader_sleep(cache);
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2175
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2176 } else {
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2177 ngx_time_update();
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2178
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2179 elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last));
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2180
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2181 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2182 "http file cache loader time elapsed: %M", elapsed);
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2183
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2184 if (elapsed >= cache->loader_threshold) {
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2185 ngx_http_file_cache_loader_sleep(cache);
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2186 }
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2187 }
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2188
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2189 return (ngx_quit || ngx_terminate) ? NGX_ABORT : NGX_OK;
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2190 }
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2191
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2192
5968
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
2193 static ngx_int_t
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
2194 ngx_http_file_cache_manage_directory(ngx_tree_ctx_t *ctx, ngx_str_t *path)
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
2195 {
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
2196 if (path->len >= 5
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
2197 && ngx_strncmp(path->data + path->len - 5, "/temp", 5) == 0)
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
2198 {
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
2199 return NGX_DECLINED;
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
2200 }
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
2201
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
2202 return NGX_OK;
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
2203 }
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
2204
99639bfdfa2a Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents: 5960
diff changeset
2205
4018
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2206 static void
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2207 ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache)
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2208 {
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2209 ngx_msleep(cache->loader_sleep);
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2210
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2211 ngx_time_update();
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2212
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2213 cache->last = ngx_current_msec;
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
2214 cache->files = 0;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2215 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2216
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2217
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2218 static ngx_int_t
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2219 ngx_http_file_cache_add_file(ngx_tree_ctx_t *ctx, ngx_str_t *name)
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2220 {
3970
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
2221 u_char *p;
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
2222 ngx_int_t n;
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
2223 ngx_uint_t i;
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
2224 ngx_http_cache_t c;
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
2225 ngx_http_file_cache_t *cache;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2226
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2227 if (name->len < 2 * NGX_HTTP_CACHE_KEY_LEN) {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2228 return NGX_ERROR;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2229 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2230
6795
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6742
diff changeset
2231 /*
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6742
diff changeset
2232 * Temporary files in cache have a suffix consisting of a dot
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6742
diff changeset
2233 * followed by 10 digits.
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6742
diff changeset
2234 */
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6742
diff changeset
2235
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6742
diff changeset
2236 if (name->len >= 2 * NGX_HTTP_CACHE_KEY_LEN + 1 + 10
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6742
diff changeset
2237 && name->data[name->len - 10 - 1] == '.')
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6742
diff changeset
2238 {
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6742
diff changeset
2239 return NGX_OK;
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6742
diff changeset
2240 }
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6742
diff changeset
2241
3970
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
2242 if (ctx->size < (off_t) sizeof(ngx_http_file_cache_header_t)) {
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2243 ngx_log_error(NGX_LOG_CRIT, ctx->log, 0,
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2244 "cache file \"%s\" is too small", name->data);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2245 return NGX_ERROR;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2246 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2247
3970
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
2248 ngx_memzero(&c, sizeof(ngx_http_cache_t));
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
2249 cache = ctx->data;
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
2250
3970
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
2251 c.length = ctx->size;
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
2252 c.fs_size = (ctx->fs_size + cache->bsize - 1) / cache->bsize;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2253
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2254 p = &name->data[name->len - 2 * NGX_HTTP_CACHE_KEY_LEN];
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2255
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2256 for (i = 0; i < NGX_HTTP_CACHE_KEY_LEN; i++) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2257 n = ngx_hextoi(p, 2);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2258
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2259 if (n == NGX_ERROR) {
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2260 return NGX_ERROR;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2261 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2262
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2263 p += 2;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2264
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2265 c.key[i] = (u_char) n;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2266 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2267
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2268 return ngx_http_file_cache_add(cache, &c);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2269 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2270
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2271
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2272 static ngx_int_t
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2273 ngx_http_file_cache_add(ngx_http_file_cache_t *cache, ngx_http_cache_t *c)
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2274 {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2275 ngx_http_file_cache_node_t *fcn;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2276
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2277 ngx_shmtx_lock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2278
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2279 fcn = ngx_http_file_cache_lookup(cache, c->key);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2280
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2281 if (fcn == NULL) {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2282
5726
25ade23cf281 Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents: 5679
diff changeset
2283 fcn = ngx_slab_calloc_locked(cache->shpool,
25ade23cf281 Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents: 5679
diff changeset
2284 sizeof(ngx_http_file_cache_node_t));
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2285 if (fcn == NULL) {
6445
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2286 ngx_http_file_cache_set_watermark(cache);
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2287
6444
043914d19be8 Cache: report error if slab allocator fails during cache loading.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6441
diff changeset
2288 if (cache->fail_time != ngx_time()) {
043914d19be8 Cache: report error if slab allocator fails during cache loading.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6441
diff changeset
2289 cache->fail_time = ngx_time();
043914d19be8 Cache: report error if slab allocator fails during cache loading.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6441
diff changeset
2290 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
043914d19be8 Cache: report error if slab allocator fails during cache loading.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6441
diff changeset
2291 "could not allocate node%s", cache->shpool->log_ctx);
043914d19be8 Cache: report error if slab allocator fails during cache loading.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6441
diff changeset
2292 }
043914d19be8 Cache: report error if slab allocator fails during cache loading.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6441
diff changeset
2293
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2294 ngx_shmtx_unlock(&cache->shpool->mutex);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2295 return NGX_ERROR;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2296 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2297
6450
22c32937a41f Cache: fixed slots accounting error introduced in c9d680b00744.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6445
diff changeset
2298 cache->sh->count++;
22c32937a41f Cache: fixed slots accounting error introduced in c9d680b00744.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6445
diff changeset
2299
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2300 ngx_memcpy((u_char *) &fcn->node.key, c->key, sizeof(ngx_rbtree_key_t));
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2301
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2302 ngx_memcpy(fcn->key, &c->key[sizeof(ngx_rbtree_key_t)],
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2303 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t));
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2304
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
2305 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node);
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2306
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2307 fcn->uses = 1;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2308 fcn->exists = 1;
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
2309 fcn->fs_size = c->fs_size;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2310
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
2311 cache->sh->size += c->fs_size;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2312
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2313 } else {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2314 ngx_queue_remove(&fcn->queue);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2315 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2316
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2317 fcn->expire = ngx_time() + cache->inactive;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2318
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
2319 ngx_queue_insert_head(&cache->sh->queue, &fcn->queue);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2320
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2321 ngx_shmtx_unlock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2322
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2323 return NGX_OK;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2324 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2325
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2326
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2327 static ngx_int_t
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2328 ngx_http_file_cache_delete_file(ngx_tree_ctx_t *ctx, ngx_str_t *path)
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2329 {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2330 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->log, 0,
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2331 "http file cache delete: \"%s\"", path->data);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2332
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2333 if (ngx_delete_file(path->data) == NGX_FILE_ERROR) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2334 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2335 ngx_delete_file_n " \"%s\" failed", path->data);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2336 }
477
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
2337
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2338 return NGX_OK;
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2339 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2340
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2341
6445
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2342 static void
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2343 ngx_http_file_cache_set_watermark(ngx_http_file_cache_t *cache)
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2344 {
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2345 cache->sh->watermark = cache->sh->count - cache->sh->count / 8;
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2346
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2347 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2348 "http file cache watermark: %ui", cache->sh->watermark);
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2349 }
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2350
c9d680b00744 Cache: added watermark to reduce IO load when keys_zone is full.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6444
diff changeset
2351
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2352 time_t
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2353 ngx_http_file_cache_valid(ngx_array_t *cache_valid, ngx_uint_t status)
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2354 {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2355 ngx_uint_t i;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2356 ngx_http_cache_valid_t *valid;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2357
2626
b0cfe5f66e8d fix segfault introduced in r2602 if there is 502/504 error
Igor Sysoev <igor@sysoev.ru>
parents: 2616
diff changeset
2358 if (cache_valid == NULL) {
b0cfe5f66e8d fix segfault introduced in r2602 if there is 502/504 error
Igor Sysoev <igor@sysoev.ru>
parents: 2616
diff changeset
2359 return 0;
b0cfe5f66e8d fix segfault introduced in r2602 if there is 502/504 error
Igor Sysoev <igor@sysoev.ru>
parents: 2616
diff changeset
2360 }
b0cfe5f66e8d fix segfault introduced in r2602 if there is 502/504 error
Igor Sysoev <igor@sysoev.ru>
parents: 2616
diff changeset
2361
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2362 valid = cache_valid->elts;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2363 for (i = 0; i < cache_valid->nelts; i++) {
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2364
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2365 if (valid[i].status == 0) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2366 return valid[i].valid;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2367 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2368
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2369 if (valid[i].status == status) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2370 return valid[i].valid;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2371 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2372 }
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2373
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2374 return 0;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2375 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2376
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2377
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2378 char *
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2379 ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2380 {
5951
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5935
diff changeset
2381 char *confp = conf;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5935
diff changeset
2382
7670
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2383 off_t max_size, min_free;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2384 u_char *last, *p;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2385 time_t inactive;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2386 ssize_t size;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2387 ngx_str_t s, name, *value;
6727
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2388 ngx_int_t loader_files, manager_files;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2389 ngx_msec_t loader_sleep, manager_sleep, loader_threshold,
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2390 manager_threshold;
5960
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2391 ngx_uint_t i, n, use_temp_path;
5951
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5935
diff changeset
2392 ngx_array_t *caches;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5935
diff changeset
2393 ngx_http_file_cache_t *cache, **ce;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2394
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2395 cache = ngx_pcalloc(cf->pool, sizeof(ngx_http_file_cache_t));
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2396 if (cache == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2397 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2398 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2399
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2400 cache->path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t));
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2401 if (cache->path == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2402 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2403 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2404
5960
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2405 use_temp_path = 1;
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2406
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2407 inactive = 600;
6727
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2408
3974
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2409 loader_files = 100;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2410 loader_sleep = 50;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2411 loader_threshold = 200;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2412
6727
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2413 manager_files = 100;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2414 manager_sleep = 50;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2415 manager_threshold = 200;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2416
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2417 name.len = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2418 size = 0;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2419 max_size = NGX_MAX_OFF_T_VALUE;
7670
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2420 min_free = 0;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2421
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2422 value = cf->args->elts;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2423
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2424 cache->path->name = value[1];
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2425
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2426 if (cache->path->name.data[cache->path->name.len - 1] == '/') {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2427 cache->path->name.len--;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2428 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2429
5330
314c3d7cc3a5 Backed out f1a91825730a and 7094bd12c1ff.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5317
diff changeset
2430 if (ngx_conf_full_name(cf->cycle, &cache->path->name, 0) != NGX_OK) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2431 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2432 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2433
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2434 for (i = 2; i < cf->args->nelts; i++) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2435
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2436 if (ngx_strncmp(value[i].data, "levels=", 7) == 0) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2437
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2438 p = value[i].data + 7;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2439 last = value[i].data + value[i].len;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2440
6617
8bf484eef9ab Use NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents: 6539
diff changeset
2441 for (n = 0; n < NGX_MAX_PATH_LEVEL && p < last; n++) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2442
2671
627dee566f6c fix cache path slot
Igor Sysoev <igor@sysoev.ru>
parents: 2632
diff changeset
2443 if (*p > '0' && *p < '3') {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2444
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2445 cache->path->level[n] = *p++ - '0';
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2446 cache->path->len += cache->path->level[n] + 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2447
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2448 if (p == last) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2449 break;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2450 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2451
6617
8bf484eef9ab Use NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents: 6539
diff changeset
2452 if (*p++ == ':' && n < NGX_MAX_PATH_LEVEL - 1 && p < last) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2453 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2454 }
2671
627dee566f6c fix cache path slot
Igor Sysoev <igor@sysoev.ru>
parents: 2632
diff changeset
2455
627dee566f6c fix cache path slot
Igor Sysoev <igor@sysoev.ru>
parents: 2632
diff changeset
2456 goto invalid_levels;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2457 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2458
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2459 goto invalid_levels;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2460 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2461
6617
8bf484eef9ab Use NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents: 6539
diff changeset
2462 if (cache->path->len < 10 + NGX_MAX_PATH_LEVEL) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2463 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2464 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2465
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2466 invalid_levels:
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2467
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2468 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2469 "invalid \"levels\" \"%V\"", &value[i]);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2470 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2471 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2472
5960
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2473 if (ngx_strncmp(value[i].data, "use_temp_path=", 14) == 0) {
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2474
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2475 if (ngx_strcmp(&value[i].data[14], "on") == 0) {
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2476 use_temp_path = 1;
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2477
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2478 } else if (ngx_strcmp(&value[i].data[14], "off") == 0) {
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2479 use_temp_path = 0;
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2480
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2481 } else {
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2482 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2483 "invalid use_temp_path value \"%V\", "
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2484 "it must be \"on\" or \"off\"",
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2485 &value[i]);
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2486 return NGX_CONF_ERROR;
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2487 }
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2488
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2489 continue;
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2490 }
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
2491
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2492 if (ngx_strncmp(value[i].data, "keys_zone=", 10) == 0) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2493
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2494 name.data = value[i].data + 10;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2495
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2496 p = (u_char *) ngx_strchr(name.data, ':');
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2497
7375
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2498 if (p == NULL) {
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2499 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2500 "invalid keys zone size \"%V\"", &value[i]);
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2501 return NGX_CONF_ERROR;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2502 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2503
7375
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2504 name.len = p - name.data;
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2505
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2506 s.data = p + 1;
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2507 s.len = value[i].data + value[i].len - s.data;
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2508
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2509 size = ngx_parse_size(&s);
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2510
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2511 if (size == NGX_ERROR) {
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2512 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2513 "invalid keys zone size \"%V\"", &value[i]);
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2514 return NGX_CONF_ERROR;
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2515 }
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2516
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2517 if (size < (ssize_t) (2 * ngx_pagesize)) {
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2518 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2519 "keys zone \"%V\" is too small", &value[i]);
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2520 return NGX_CONF_ERROR;
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2521 }
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2522
bddacdaaec9e Cache: improved keys zone size error reporting.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7374
diff changeset
2523 continue;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2524 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2525
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2526 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2527
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2528 s.len = value[i].len - 9;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2529 s.data = value[i].data + 9;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2530
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2531 inactive = ngx_parse_time(&s, 1);
4474
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2532 if (inactive == (time_t) NGX_ERROR) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2533 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2534 "invalid inactive value \"%V\"", &value[i]);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2535 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2536 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2537
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2538 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2539 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2540
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2541 if (ngx_strncmp(value[i].data, "max_size=", 9) == 0) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2542
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2543 s.len = value[i].len - 9;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2544 s.data = value[i].data + 9;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2545
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2546 max_size = ngx_parse_offset(&s);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2547 if (max_size < 0) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2548 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2549 "invalid max_size value \"%V\"", &value[i]);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2550 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2551 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2552
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2553 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2554 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2555
7670
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2556 if (ngx_strncmp(value[i].data, "min_free=", 9) == 0) {
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2557
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2558 #if (NGX_WIN32 || NGX_HAVE_STATFS || NGX_HAVE_STATVFS)
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2559
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2560 s.len = value[i].len - 9;
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2561 s.data = value[i].data + 9;
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2562
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2563 min_free = ngx_parse_offset(&s);
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2564 if (min_free < 0) {
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2565 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2566 "invalid min_free value \"%V\"", &value[i]);
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2567 return NGX_CONF_ERROR;
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2568 }
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2569
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2570 #else
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2571 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2572 "min_free is not supported "
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2573 "on this platform, ignored");
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2574 #endif
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2575
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2576 continue;
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2577 }
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2578
3974
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2579 if (ngx_strncmp(value[i].data, "loader_files=", 13) == 0) {
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2580
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2581 loader_files = ngx_atoi(value[i].data + 13, value[i].len - 13);
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2582 if (loader_files == NGX_ERROR) {
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2583 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2584 "invalid loader_files value \"%V\"", &value[i]);
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2585 return NGX_CONF_ERROR;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2586 }
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2587
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2588 continue;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2589 }
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2590
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2591 if (ngx_strncmp(value[i].data, "loader_sleep=", 13) == 0) {
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2592
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2593 s.len = value[i].len - 13;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2594 s.data = value[i].data + 13;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2595
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2596 loader_sleep = ngx_parse_time(&s, 0);
4474
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2597 if (loader_sleep == (ngx_msec_t) NGX_ERROR) {
3974
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2598 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2599 "invalid loader_sleep value \"%V\"", &value[i]);
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2600 return NGX_CONF_ERROR;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2601 }
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2602
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2603 continue;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2604 }
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2605
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2606 if (ngx_strncmp(value[i].data, "loader_threshold=", 17) == 0) {
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2607
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2608 s.len = value[i].len - 17;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2609 s.data = value[i].data + 17;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2610
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2611 loader_threshold = ngx_parse_time(&s, 0);
4474
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2612 if (loader_threshold == (ngx_msec_t) NGX_ERROR) {
3974
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2613 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2614 "invalid loader_threshold value \"%V\"", &value[i]);
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2615 return NGX_CONF_ERROR;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2616 }
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2617
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2618 continue;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2619 }
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2620
6727
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2621 if (ngx_strncmp(value[i].data, "manager_files=", 14) == 0) {
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2622
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2623 manager_files = ngx_atoi(value[i].data + 14, value[i].len - 14);
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2624 if (manager_files == NGX_ERROR) {
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2625 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2626 "invalid manager_files value \"%V\"", &value[i]);
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2627 return NGX_CONF_ERROR;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2628 }
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2629
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2630 continue;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2631 }
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2632
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2633 if (ngx_strncmp(value[i].data, "manager_sleep=", 14) == 0) {
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2634
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2635 s.len = value[i].len - 14;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2636 s.data = value[i].data + 14;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2637
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2638 manager_sleep = ngx_parse_time(&s, 0);
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2639 if (manager_sleep == (ngx_msec_t) NGX_ERROR) {
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2640 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2641 "invalid manager_sleep value \"%V\"", &value[i]);
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2642 return NGX_CONF_ERROR;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2643 }
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2644
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2645 continue;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2646 }
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2647
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2648 if (ngx_strncmp(value[i].data, "manager_threshold=", 18) == 0) {
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2649
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2650 s.len = value[i].len - 18;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2651 s.data = value[i].data + 18;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2652
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2653 manager_threshold = ngx_parse_time(&s, 0);
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2654 if (manager_threshold == (ngx_msec_t) NGX_ERROR) {
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2655 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2656 "invalid manager_threshold value \"%V\"", &value[i]);
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2657 return NGX_CONF_ERROR;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2658 }
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2659
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2660 continue;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2661 }
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2662
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2663 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2664 "invalid parameter \"%V\"", &value[i]);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2665 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2666 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2667
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2668 if (name.len == 0 || size == 0) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2669 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2670 "\"%V\" must have \"keys_zone\" parameter",
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2671 &cmd->name);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2672 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2673 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2674
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2675 cache->path->manager = ngx_http_file_cache_manager;
3018
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2676 cache->path->loader = ngx_http_file_cache_loader;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2677 cache->path->data = cache;
3973
9d6f21415231 set correct configuration file values while adding path
Igor Sysoev <igor@sysoev.ru>
parents: 3972
diff changeset
2678 cache->path->conf_file = cf->conf_file->file.name.data;
9d6f21415231 set correct configuration file values while adding path
Igor Sysoev <igor@sysoev.ru>
parents: 3972
diff changeset
2679 cache->path->line = cf->conf_file->line;
3974
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2680 cache->loader_files = loader_files;
4474
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2681 cache->loader_sleep = loader_sleep;
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2682 cache->loader_threshold = loader_threshold;
6727
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2683 cache->manager_files = manager_files;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2684 cache->manager_sleep = manager_sleep;
ca709bca4b77 Cache: cache manager limits.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6617
diff changeset
2685 cache->manager_threshold = manager_threshold;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2686
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2687 if (ngx_add_path(cf, &cache->path) != NGX_OK) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2688 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2689 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2690
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2691 cache->shm_zone = ngx_shared_memory_add(cf, &name, size, cmd->post);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2692 if (cache->shm_zone == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2693 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2694 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2695
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2696 if (cache->shm_zone->data) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2697 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2698 "duplicate zone \"%V\"", &name);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2699 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2700 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2701
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2702
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2703 cache->shm_zone->init = ngx_http_file_cache_init;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2704 cache->shm_zone->data = cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2705
6795
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6742
diff changeset
2706 cache->use_temp_path = use_temp_path;
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6742
diff changeset
2707
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2708 cache->inactive = inactive;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2709 cache->max_size = max_size;
7670
ccb5ff87ab3e Cache: introduced min_free cache clearing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7375
diff changeset
2710 cache->min_free = min_free;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2711
5951
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5935
diff changeset
2712 caches = (ngx_array_t *) (confp + cmd->offset);
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5935
diff changeset
2713
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5935
diff changeset
2714 ce = ngx_array_push(caches);
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5935
diff changeset
2715 if (ce == NULL) {
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5935
diff changeset
2716 return NGX_CONF_ERROR;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5935
diff changeset
2717 }
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5935
diff changeset
2718
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5935
diff changeset
2719 *ce = cache;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5935
diff changeset
2720
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2721 return NGX_CONF_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2722 }
477
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
2723
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
2724
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2725 char *
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2726 ngx_http_file_cache_valid_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2727 void *conf)
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2728 {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2729 char *p = conf;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2730
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2731 time_t valid;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2732 ngx_str_t *value;
7267
7c614ef3c6ea Cache: fixed cache valid slot to reject incorrect statuses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7075
diff changeset
2733 ngx_int_t status;
7c614ef3c6ea Cache: fixed cache valid slot to reject incorrect statuses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7075
diff changeset
2734 ngx_uint_t i, n;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2735 ngx_array_t **a;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2736 ngx_http_cache_valid_t *v;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2737 static ngx_uint_t statuses[] = { 200, 301, 302 };
477
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
2738
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2739 a = (ngx_array_t **) (p + cmd->offset);
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2740
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2741 if (*a == NGX_CONF_UNSET_PTR) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2742 *a = ngx_array_create(cf->pool, 1, sizeof(ngx_http_cache_valid_t));
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2743 if (*a == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2744 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2745 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2746 }
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2747
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2748 value = cf->args->elts;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2749 n = cf->args->nelts - 1;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2750
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2751 valid = ngx_parse_time(&value[n], 1);
4474
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2752 if (valid == (time_t) NGX_ERROR) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2753 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2754 "invalid time value \"%V\"", &value[n]);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2755 return NGX_CONF_ERROR;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2756 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2757
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2758 if (n == 1) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2759
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2760 for (i = 0; i < 3; i++) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2761 v = ngx_array_push(*a);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2762 if (v == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2763 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2764 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2765
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2766 v->status = statuses[i];
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2767 v->valid = valid;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2768 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2769
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2770 return NGX_CONF_OK;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2771 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2772
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2773 for (i = 1; i < n; i++) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2774
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2775 if (ngx_strcmp(value[i].data, "any") == 0) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2776
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2777 status = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2778
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2779 } else {
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2780
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2781 status = ngx_atoi(value[i].data, value[i].len);
7359
b5ea47df9bee Cache: status must be less then 599 in *_cache_valid directives.
Gena Makhomed <gmm@csdoc.com>
parents: 7267
diff changeset
2782 if (status < 100 || status > 599) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2783 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2784 "invalid status \"%V\"", &value[i]);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2785 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2786 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2787 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2788
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2789 v = ngx_array_push(*a);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2790 if (v == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2791 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2792 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2793
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2794 v->status = status;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2795 v->valid = valid;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2796 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2797
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2798 return NGX_CONF_OK;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2799 }