annotate src/http/ngx_http_file_cache.c @ 5929:f436e9a60b8f

Cache: proper wakeup of subrequests. In case of a cache lock timeout and in the aio handler we now call r->write_event_handler() instead of a connection write handler, to make sure to run appropriate subrequest. Previous code failed to run inactive subrequests and hence resulted in suboptimal behaviour, see report by Yichun Zhang: http://mailman.nginx.org/pipermail/nginx-devel/2013-October/004435.html (Infinite hang claimed in the report seems impossible without 3rd party modules, as subrequests will be eventually woken up by the postpone filter.)
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 02 Dec 2014 05:54:56 +0300
parents 8dfee01ff0bd
children 1573fc7875fa
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);
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
17 static void ngx_http_file_cache_lock_wait(ngx_http_request_t *r,
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
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
26 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
27 ngx_http_cache_t *c);
3696
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
28 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
29 ngx_path_t *path);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
30 static ngx_http_file_cache_node_t *
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
31 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
32 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
33 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
34 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
35 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
36 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
37 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
38 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
39 ngx_http_cache_t *c);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
40 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
41 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
42 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
43 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
44 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
45 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
46 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
47 ngx_str_t *path);
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
48 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
49 ngx_str_t *path);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
50 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
51 ngx_str_t *path);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
52 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
53 ngx_http_cache_t *c);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
54 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
55 ngx_str_t *path);
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
58 ngx_str_t ngx_http_cache_status[] = {
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
59 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
60 ngx_string("BYPASS"),
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
61 ngx_string("EXPIRED"),
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
62 ngx_string("STALE"),
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
63 ngx_string("UPDATING"),
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
64 ngx_string("REVALIDATED"),
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
65 ngx_string("HIT")
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
66 };
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
67
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2935
diff changeset
68
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
69 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
70
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
72 static ngx_int_t
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
73 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
74 {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
75 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
76
2611
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
77 size_t len;
3017
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
78 ngx_uint_t n;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
79 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
80
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
81 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
82
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
83 if (ocache) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
84 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
85 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
86 "cache \"%V\" uses the \"%V\" cache path "
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
87 "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
88 &shm_zone->shm.name, &cache->path->name,
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
89 &ocache->path->name);
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 return NGX_ERROR;
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93
3017
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
94 for (n = 0; n < 3; n++) {
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
95 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
96 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
97 "cache \"%V\" had previously different levels",
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
98 &shm_zone->shm.name);
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
99 return NGX_ERROR;
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
100 }
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
101 }
c466605d9426 test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
102
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
103 cache->sh = ocache->sh;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
104
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
105 cache->shpool = ocache->shpool;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
106 cache->bsize = ocache->bsize;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
107
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
108 cache->max_size /= cache->bsize;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
109
3018
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
110 if (!cache->sh->cold || cache->sh->loading) {
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
111 cache->path->loader = NULL;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
112 }
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
113
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
114 return NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
115 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
116
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
117 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
118
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
119 if (shm_zone->shm.exists) {
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
120 cache->sh = cache->shpool->data;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
121 cache->bsize = ngx_fs_bsize(cache->path->name.data);
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
122
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
123 return NGX_OK;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
124 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
125
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
126 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
127 if (cache->sh == NULL) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
128 return NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
129 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
130
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
131 cache->shpool->data = cache->sh;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
132
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
133 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
134 ngx_http_file_cache_rbtree_insert_value);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
135
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
136 ngx_queue_init(&cache->sh->queue);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
137
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
138 cache->sh->cold = 1;
3018
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
139 cache->sh->loading = 0;
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
140 cache->sh->size = 0;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
141
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
142 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
143
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
144 cache->max_size /= cache->bsize;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
145
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
146 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
147
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
148 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
149 if (cache->shpool->log_ctx == NULL) {
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
150 return NGX_ERROR;
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
151 }
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
152
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
153 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
154 &shm_zone->shm.name);
2611
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2606
diff changeset
155
5822
063f7e75f9ef Upstream: suppressed the file cache slab allocator error messages.
Roman Arutyunyan <arut@nginx.com>
parents: 5737
diff changeset
156 cache->shpool->log_nomem = 0;
063f7e75f9ef Upstream: suppressed the file cache slab allocator error messages.
Roman Arutyunyan <arut@nginx.com>
parents: 5737
diff changeset
157
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
158 return NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
159 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
160
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
161
3697
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
162 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
163 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
164 {
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
165 ngx_http_cache_t *c;
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
166
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
167 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
168 if (c == NULL) {
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
169 return NGX_ERROR;
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
170 }
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
171
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
172 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
173 return NGX_ERROR;
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
174 }
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
175
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
176 r->cache = c;
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
177 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
178 c->file.fd = NGX_INVALID_FILE;
3697
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 return NGX_OK;
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
181 }
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
182
3c442bd5597b ngx_http_file_cache_create()
Igor Sysoev <igor@sysoev.ru>
parents: 3696
diff changeset
183
3699
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
184 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
185 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
186 {
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
187 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
188 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
189 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
190
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
191 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
192 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
193
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
194 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
195 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
196 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
197 }
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
198
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
199 cln->handler = ngx_http_file_cache_cleanup;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
200 cln->data = c;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
201
3699
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
202 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
203 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
204 }
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
205
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
206 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
207 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
208 }
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
209
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
210 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
211 }
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
212
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
213
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
214 void
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
215 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
216 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
217 size_t len;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
218 ngx_str_t *key;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
219 ngx_uint_t i;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
220 ngx_md5_t md5;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
221 ngx_http_cache_t *c;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
222
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
223 c = r->cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
224
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
225 len = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
226
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
227 ngx_crc32_init(c->crc32);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
228 ngx_md5_init(&md5);
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 key = c->keys.elts;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
231 for (i = 0; i < c->keys.nelts; i++) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
232 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
233 "http cache key: \"%V\"", &key[i]);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
234
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
235 len += key[i].len;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
236
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
237 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
238 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
239 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
240
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
241 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
242 + sizeof(ngx_http_file_cache_key) + len + 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
243
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
244 ngx_crc32_final(c->crc32);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
245 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
246
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
247 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
248 }
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
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
251 ngx_int_t
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
252 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
253 {
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
254 ngx_int_t rc, rv;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
255 ngx_uint_t cold, test;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
256 ngx_http_cache_t *c;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
257 ngx_pool_cleanup_t *cln;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
258 ngx_open_file_info_t of;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
259 ngx_http_file_cache_t *cache;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
260 ngx_http_core_loc_conf_t *clcf;
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 c = r->cache;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
263
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
264 if (c->waiting) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
265 return NGX_AGAIN;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
266 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
267
5879
c525c0454aa5 Cache: c->reading flag introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5878
diff changeset
268 if (c->reading) {
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
269 return ngx_http_file_cache_read(r, c);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
270 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
271
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
272 cache = c->file_cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
273
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
274 if (c->node == NULL) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
275 cln = ngx_pool_cleanup_add(r->pool, 0);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
276 if (cln == NULL) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
277 return NGX_ERROR;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
278 }
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 cln->handler = ngx_http_file_cache_cleanup;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
281 cln->data = c;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
282 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
283
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
284 rc = ngx_http_file_cache_exists(cache, c);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
285
2926
80a314b63c56 delete useless r->cache->uses
Igor Sysoev <igor@sysoev.ru>
parents: 2925
diff changeset
286 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
287 "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
288
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
289 if (rc == NGX_ERROR) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
290 return rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
291 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
292
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
293 if (rc == NGX_AGAIN) {
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
294 return NGX_HTTP_CACHE_SCARCE;
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
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
297 cold = cache->sh->cold;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
298
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
299 if (rc == NGX_OK) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
300
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
301 if (c->error) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
302 return c->error;
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
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
305 c->temp_file = 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
306 test = c->exists ? 1 : 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
307 rv = NGX_DECLINED;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
308
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
309 } else { /* rc == NGX_DECLINED */
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 if (c->min_uses > 1) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
312
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
313 if (!cold) {
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
314 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
315 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
316
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
317 test = 1;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
318 rv = NGX_HTTP_CACHE_SCARCE;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
319
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
320 } else {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
321 c->temp_file = 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
322 test = cold ? 1 : 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
323 rv = NGX_DECLINED;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
324 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
325 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
326
3696
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
327 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
328 return NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
329 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
330
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
331 if (!test) {
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
332 goto done;
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
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
335 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
336
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
337 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
338
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
339 of.uniq = c->uniq;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
340 of.valid = clcf->open_file_cache_valid;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
341 of.min_uses = clcf->open_file_cache_min_uses;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
342 of.events = clcf->open_file_cache_events;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
343 of.directio = NGX_OPEN_FILE_DIRECTIO_OFF;
3178
975f0558aab3 read_ahead
Igor Sysoev <igor@sysoev.ru>
parents: 3136
diff changeset
344 of.read_ahead = clcf->read_ahead;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
345
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
346 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
347 != NGX_OK)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
348 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
349 switch (of.err) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
350
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
351 case 0:
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
352 return NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
353
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
354 case NGX_ENOENT:
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
355 case NGX_ENOTDIR:
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
356 goto done;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
357
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
358 default:
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
359 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
360 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
361 return NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
362 }
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
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
365 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
366 "http file cache fd: %d", of.fd);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
367
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
368 c->file.fd = of.fd;
2603
f9bd7999eb08 fix segfault if ngx_read_file() will fail
Igor Sysoev <igor@sysoev.ru>
parents: 2600
diff changeset
369 c->file.log = r->connection->log;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
370 c->uniq = of.uniq;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
371 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
372 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
373
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
374 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
375 if (c->buf == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
376 return NGX_ERROR;
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
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
379 return ngx_http_file_cache_read(r, c);
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
380
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
381 done:
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
382
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
383 if (rv == NGX_DECLINED) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
384 return ngx_http_file_cache_lock(r, c);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
385 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
386
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
387 return rv;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
388 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
389
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
390
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
391 static ngx_int_t
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
392 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
393 {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
394 ngx_msec_t now, timer;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
395 ngx_http_file_cache_t *cache;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
396
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
397 if (!c->lock) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
398 return NGX_DECLINED;
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
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
401 now = ngx_current_msec;
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
402
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
403 cache = c->file_cache;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
404
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
405 ngx_shmtx_lock(&cache->shpool->mutex);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
406
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
407 timer = c->node->lock_time - now;
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
408
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
409 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
410 c->node->updating = 1;
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
411 c->node->lock_time = now + c->lock_age;
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
412 c->updating = 1;
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
413 c->lock_time = c->node->lock_time;
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
414 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
415
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
416 ngx_shmtx_unlock(&cache->shpool->mutex);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
417
4387
e8181eeddaf8 Fixed build without debug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4385
diff changeset
418 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
419 "http file cache lock u:%d wt:%M",
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
420 c->updating, c->wait_time);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
421
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
422 if (c->updating) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
423 return NGX_DECLINED;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
424 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
425
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
426 if (c->lock_timeout == 0) {
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
427 return NGX_HTTP_CACHE_SCARCE;
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
428 }
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
429
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
430 c->waiting = 1;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
431
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
432 if (c->wait_time == 0) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
433 c->wait_time = now + c->lock_timeout;
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 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
436 c->wait_event.data = r;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
437 c->wait_event.log = r->connection->log;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
438 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
439
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
440 timer = c->wait_time - now;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
441
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
442 ngx_add_timer(&c->wait_event, (timer > 500) ? 500 : timer);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
443
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
444 r->main->blocked++;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
445
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
446 return NGX_AGAIN;
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
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
449
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
450 static void
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
451 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
452 {
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
453 ngx_connection_t *c;
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
454 ngx_http_request_t *r;
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
455
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
456 r = ev->data;
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
457 c = r->connection;
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
458
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
459 ngx_http_set_log_request(c->log, r);
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
460
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
461 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
462 "http file cache wait: \"%V?%V\"", &r->uri, &r->args);
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
463
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
464 ngx_http_file_cache_lock_wait(r, r->cache);
5929
f436e9a60b8f Cache: proper wakeup of subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5928
diff changeset
465
f436e9a60b8f Cache: proper wakeup of subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5928
diff changeset
466 ngx_http_run_posted_requests(c);
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
467 }
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
468
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
469
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
470 static void
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
471 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
472 {
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
473 ngx_uint_t wait;
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
474 ngx_msec_t now, timer;
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
475 ngx_http_file_cache_t *cache;
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
476
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
477 now = ngx_current_msec;
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
478
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
479 timer = c->wait_time - now;
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
480
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
481 if ((ngx_msec_int_t) timer <= 0) {
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
482 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
483 "cache lock timeout");
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
484 c->lock_timeout = 0;
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
485 goto wakeup;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
486 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
487
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
488 cache = c->file_cache;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
489 wait = 0;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
490
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
491 ngx_shmtx_lock(&cache->shpool->mutex);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
492
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
493 timer = c->node->lock_time - now;
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
494
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
495 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
496 wait = 1;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
497 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
498
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
499 ngx_shmtx_unlock(&cache->shpool->mutex);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
500
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
501 if (wait) {
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
502 ngx_add_timer(&c->wait_event, (timer > 500) ? 500 : timer);
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
503 return;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
504 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
505
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
506 wakeup:
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
507
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
508 c->waiting = 0;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
509 r->main->blocked--;
5929
f436e9a60b8f Cache: proper wakeup of subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5928
diff changeset
510 r->write_event_handler(r);
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
511 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
512
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
513
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
514 static ngx_int_t
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
515 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
516 {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
517 time_t now;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
518 ssize_t n;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
519 ngx_int_t rc;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
520 ngx_http_file_cache_t *cache;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
521 ngx_http_file_cache_header_t *h;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
522
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
523 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
524
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
525 if (n < 0) {
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
526 return n;
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
527 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
528
3369
479468a7d982 fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
529 if ((size_t) n < c->header_start) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
530 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
531 "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
532 return NGX_DECLINED;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
533 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
534
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
535 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
536
5736
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
537 if (h->version != NGX_HTTP_CACHE_VERSION) {
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
538 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
539 "cache file \"%s\" version mismatch", c->file.name.data);
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
540 return NGX_DECLINED;
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
541 }
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
542
3460
bbea0b19b608 fix cached FastCGI response with large stderr output before header
Igor Sysoev <igor@sysoev.ru>
parents: 3400
diff changeset
543 if (h->crc32 != c->crc32) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
544 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
545 "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
546 return NGX_DECLINED;
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
547 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
548
5359
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5341
diff changeset
549 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
550 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
551 "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
552 c->file.name.data);
6f97afc238de Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4338
diff changeset
553 return NGX_DECLINED;
6f97afc238de Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4338
diff changeset
554 }
6f97afc238de Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4338
diff changeset
555
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
556 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
557 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
558 "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
559 c->file.name.data);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
560 return NGX_DECLINED;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
561 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
562
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
563 if (h->vary_len) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
564 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
565
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
566 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
567 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
568 "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
569 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
570 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
571 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
572
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
573 c->buf->last += n;
477
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
574
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
575 c->valid_sec = h->valid_sec;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
576 c->last_modified = h->last_modified;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
577 c->date = h->date;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
578 c->valid_msec = h->valid_msec;
3460
bbea0b19b608 fix cached FastCGI response with large stderr output before header
Igor Sysoev <igor@sysoev.ru>
parents: 3400
diff changeset
579 c->header_start = h->header_start;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
580 c->body_start = h->body_start;
5737
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
581 c->etag.len = h->etag_len;
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
582 c->etag.data = h->etag;
477
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
583
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
584 r->cached = 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
585
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
586 cache = c->file_cache;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
587
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
588 if (cache->sh->cold) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
589
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
590 ngx_shmtx_lock(&cache->shpool->mutex);
477
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
591
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
592 if (!c->node->exists) {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
593 c->node->uses = 1;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
594 c->node->body_start = c->body_start;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
595 c->node->exists = 1;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
596 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
597 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
598
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
599 cache->sh->size += c->fs_size;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
600 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
601
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
602 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
603 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
604
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
605 now = ngx_time();
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
606
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
607 if (c->valid_sec < now) {
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
608
2927
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
609 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
610
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
611 if (c->node->updating) {
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
612 rc = NGX_HTTP_CACHE_UPDATING;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
613
2927
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
614 } else {
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
615 c->node->updating = 1;
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
616 c->updating = 1;
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
617 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
618 rc = NGX_HTTP_CACHE_STALE;
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
619 }
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
620
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
621 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
622
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
623 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
624 "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
625 rc, c->valid_sec, now);
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
626
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
627 return rc;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
628 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
629
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
630 return NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
631 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
632
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
633
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
634 static ssize_t
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
635 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
636 {
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
637 #if (NGX_HAVE_FILE_AIO)
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
638 ssize_t n;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
639 ngx_http_core_loc_conf_t *clcf;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
640
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
641 if (!ngx_file_aio) {
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
642 goto noaio;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
643 }
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
644
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
645 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
646
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
647 if (!clcf->aio) {
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
648 goto noaio;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
649 }
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
650
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
651 n = ngx_file_aio_read(&c->file, c->buf->pos, c->body_start, 0, r->pool);
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
652
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
653 if (n != NGX_AGAIN) {
5879
c525c0454aa5 Cache: c->reading flag introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5878
diff changeset
654 c->reading = 0;
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
655 return n;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
656 }
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
657
5879
c525c0454aa5 Cache: c->reading flag introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5878
diff changeset
658 c->reading = 1;
c525c0454aa5 Cache: c->reading flag introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5878
diff changeset
659
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
660 c->file.aio->data = r;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
661 c->file.aio->handler = ngx_http_cache_aio_event_handler;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
662
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
663 r->main->blocked++;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
664 r->aio = 1;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
665
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
666 return NGX_AGAIN;
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
667
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
668 noaio:
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
669
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
670 #endif
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
671
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
672 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
673 }
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
674
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
675
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3195
diff changeset
676 #if (NGX_HAVE_FILE_AIO)
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
677
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
678 static void
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
679 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
680 {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
681 ngx_event_aio_t *aio;
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
682 ngx_connection_t *c;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
683 ngx_http_request_t *r;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
684
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
685 aio = ev->data;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
686 r = aio->data;
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
687 c = r->connection;
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
688
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
689 ngx_http_set_log_request(c->log, r);
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
690
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
691 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5905
diff changeset
692 "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
693
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
694 r->main->blocked--;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
695 r->aio = 0;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
696
5929
f436e9a60b8f Cache: proper wakeup of subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5928
diff changeset
697 r->write_event_handler(r);
f436e9a60b8f Cache: proper wakeup of subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5928
diff changeset
698
f436e9a60b8f Cache: proper wakeup of subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5928
diff changeset
699 ngx_http_run_posted_requests(c);
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
700 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
701
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
702 #endif
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
703
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
704
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
705 static ngx_int_t
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
706 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
707 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
708 ngx_int_t rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
709 ngx_http_file_cache_node_t *fcn;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
710
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
711 ngx_shmtx_lock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
712
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
713 fcn = c->node;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
714
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
715 if (fcn == NULL) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
716 fcn = ngx_http_file_cache_lookup(cache, c->key);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
717 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
718
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
719 if (fcn) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
720 ngx_queue_remove(&fcn->queue);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
721
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
722 if (c->node == NULL) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
723 fcn->uses++;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
724 fcn->count++;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
725 }
3724
e9f0a2497d3c count cache key node usage for cached error statuses
Igor Sysoev <igor@sysoev.ru>
parents: 3723
diff changeset
726
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
727 if (fcn->error) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
728
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
729 if (fcn->valid_sec < ngx_time()) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
730 goto renew;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
731 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
732
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
733 rc = NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
734
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
735 goto done;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
736 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
737
3966
9c425f22ea36 fuse two if's in one condition
Igor Sysoev <igor@sysoev.ru>
parents: 3965
diff changeset
738 if (fcn->exists || fcn->uses >= c->min_uses) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
739
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
740 c->exists = fcn->exists;
3969
3ea15c6b16da fix r3968
Igor Sysoev <igor@sysoev.ru>
parents: 3968
diff changeset
741 if (fcn->body_start) {
3967
83e41f6f6d96 The cache loader performs two tasks: inserting cache objects in inactivity
Igor Sysoev <igor@sysoev.ru>
parents: 3966
diff changeset
742 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
743 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
744
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
745 rc = NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
746
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
747 goto done;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
748 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
749
3966
9c425f22ea36 fuse two if's in one condition
Igor Sysoev <igor@sysoev.ru>
parents: 3965
diff changeset
750 rc = NGX_AGAIN;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
751
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
752 goto done;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
753 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
754
5726
25ade23cf281 Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents: 5679
diff changeset
755 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
756 sizeof(ngx_http_file_cache_node_t));
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
757 if (fcn == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
758 ngx_shmtx_unlock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
759
2693
197cda0e767e style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2671
diff changeset
760 (void) ngx_http_file_cache_forced_expire(cache);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
761
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
762 ngx_shmtx_lock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
763
5726
25ade23cf281 Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents: 5679
diff changeset
764 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
765 sizeof(ngx_http_file_cache_node_t));
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
766 if (fcn == NULL) {
5822
063f7e75f9ef Upstream: suppressed the file cache slab allocator error messages.
Roman Arutyunyan <arut@nginx.com>
parents: 5737
diff changeset
767 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
768 "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
769 rc = NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
770 goto failed;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
771 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
772 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
773
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
774 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
775
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
776 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
777 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
778
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
779 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
780
3724
e9f0a2497d3c count cache key node usage for cached error statuses
Igor Sysoev <igor@sysoev.ru>
parents: 3723
diff changeset
781 fcn->uses = 1;
e9f0a2497d3c count cache key node usage for cached error statuses
Igor Sysoev <igor@sysoev.ru>
parents: 3723
diff changeset
782 fcn->count = 1;
e9f0a2497d3c count cache key node usage for cached error statuses
Igor Sysoev <igor@sysoev.ru>
parents: 3723
diff changeset
783
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
784 renew:
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
785
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
786 rc = NGX_DECLINED;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
787
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
788 fcn->valid_msec = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
789 fcn->error = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
790 fcn->exists = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
791 fcn->valid_sec = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
792 fcn->uniq = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
793 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
794 fcn->fs_size = 0;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
795
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
796 done:
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
797
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
798 fcn->expire = ngx_time() + cache->inactive;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
799
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
800 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
801
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
802 c->uniq = fcn->uniq;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
803 c->error = fcn->error;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
804 c->node = fcn;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
805
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
806 failed:
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
807
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
808 ngx_shmtx_unlock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
809
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
810 return rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
811 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
812
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
813
3696
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
814 static ngx_int_t
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
815 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
816 {
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
817 u_char *p;
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
818 ngx_http_cache_t *c;
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
819
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
820 c = r->cache;
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
821
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
822 if (c->file.name.len) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
823 return NGX_OK;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
824 }
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
825
3696
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
826 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
827 + 2 * NGX_HTTP_CACHE_KEY_LEN;
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
828
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
829 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
830 if (c->file.name.data == NULL) {
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
831 return NGX_ERROR;
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
832 }
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
833
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
834 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
835
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
836 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
837 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
838 *p = '\0';
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
839
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
840 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
841
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
842 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
843 "cache file: \"%s\"", c->file.name.data);
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
844
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
845 return NGX_OK;
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
846 }
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
847
29fcf794c082 ngx_http_file_cache_name()
Igor Sysoev <igor@sysoev.ru>
parents: 3695
diff changeset
848
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
849 static ngx_http_file_cache_node_t *
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
850 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
851 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
852 ngx_int_t rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
853 ngx_rbtree_key_t node_key;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
854 ngx_rbtree_node_t *node, *sentinel;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
855 ngx_http_file_cache_node_t *fcn;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
856
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
857 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
858
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
859 node = cache->sh->rbtree.root;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
860 sentinel = cache->sh->rbtree.sentinel;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
861
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
862 while (node != sentinel) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
863
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
864 if (node_key < node->key) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
865 node = node->left;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
866 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
867 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
868
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
869 if (node_key > node->key) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
870 node = node->right;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
871 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
872 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
873
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
874 /* node_key == node->key */
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
875
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4474
diff changeset
876 fcn = (ngx_http_file_cache_node_t *) node;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
877
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4474
diff changeset
878 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
879 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
880
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4474
diff changeset
881 if (rc == 0) {
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4474
diff changeset
882 return fcn;
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4474
diff changeset
883 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
884
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4474
diff changeset
885 node = (rc < 0) ? node->left : node->right;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
886 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
887
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
888 /* not found */
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
889
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
890 return NULL;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
891 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
892
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 static void
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
895 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
896 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
897 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
898 ngx_rbtree_node_t **p;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
899 ngx_http_file_cache_node_t *cn, *cnt;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
900
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
901 for ( ;; ) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
902
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
903 if (node->key < temp->key) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
904
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
905 p = &temp->left;
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 } else if (node->key > temp->key) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
908
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
909 p = &temp->right;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
910
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
911 } else { /* node->key == temp->key */
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
912
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
913 cn = (ngx_http_file_cache_node_t *) node;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
914 cnt = (ngx_http_file_cache_node_t *) temp;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
915
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
916 p = (ngx_memcmp(cn->key, cnt->key,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
917 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
918 < 0)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
919 ? &temp->left : &temp->right;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
920 }
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 if (*p == sentinel) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
923 break;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
924 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
925
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
926 temp = *p;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
927 }
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 *p = node;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
930 node->parent = temp;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
931 node->left = sentinel;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
932 node->right = sentinel;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
933 ngx_rbt_red(node);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
934 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
935
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
936
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
937 static void
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
938 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
939 u_char *hash)
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
940 {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
941 u_char *p, *last;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
942 ngx_str_t name;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
943 ngx_md5_t md5;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
944 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
945
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
946 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
947 "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
948
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
949 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
950 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
951
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
952 ngx_strlow(buf, vary, len);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
953
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
954 p = buf;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
955 last = buf + len;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
956
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
957 while (p < last) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
958
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
959 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
960
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
961 name.data = p;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
962
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
963 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
964
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
965 name.len = p - name.data;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
966
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
967 if (name.len == 0) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
968 break;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
969 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
970
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
971 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
972 "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
973
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
974 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
975 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
976
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
977 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
978
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
979 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
980 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
981
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
982 ngx_md5_final(hash, &md5);
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
983 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
984
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
985
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
986 static void
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
987 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
988 ngx_str_t *name)
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
989 {
5881
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
990 size_t len;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
991 u_char *p, *start, *last;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
992 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
993 ngx_list_part_t *part;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
994 ngx_table_elt_t *header;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
995
5881
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
996 multiple = 0;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
997 normalize = 0;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
998
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
999 if (name->len == sizeof("Accept-Charset") - 1
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1000 && ngx_strncasecmp(name->data, (u_char *) "Accept-Charset",
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1001 sizeof("Accept-Charset") - 1) == 0)
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1002 {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1003 normalize = 1;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1004
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1005 } else if (name->len == sizeof("Accept-Encoding") - 1
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1006 && ngx_strncasecmp(name->data, (u_char *) "Accept-Encoding",
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1007 sizeof("Accept-Encoding") - 1) == 0)
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1008 {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1009 normalize = 1;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1010
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1011 } else if (name->len == sizeof("Accept-Language") - 1
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1012 && ngx_strncasecmp(name->data, (u_char *) "Accept-Language",
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1013 sizeof("Accept-Language") - 1) == 0)
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1014 {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1015 normalize = 1;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1016 }
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1017
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1018 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
1019 header = part->elts;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1020
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1021 for (i = 0; /* void */ ; i++) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1022
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1023 if (i >= part->nelts) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1024 if (part->next == NULL) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1025 break;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1026 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1027
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1028 part = part->next;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1029 header = part->elts;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1030 i = 0;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1031 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1032
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1033 if (header[i].hash == 0) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1034 continue;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1035 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1036
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1037 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
1038 continue;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1039 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1040
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1041 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
1042 continue;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1043 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1044
5881
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1045 if (!normalize) {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1046
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1047 if (multiple) {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1048 ngx_md5_update(md5, (u_char *) ",", sizeof(",") - 1);
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1049 }
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1050
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1051 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
1052
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1053 multiple = 1;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1054
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1055 continue;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1056 }
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1057
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1058 /* normalize spaces */
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1059
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1060 p = header[i].value.data;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1061 last = p + header[i].value.len;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1062
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1063 while (p < last) {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1064
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1065 while (p < last && (*p == ' ' || *p == ',')) { p++; }
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1066
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1067 start = p;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1068
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1069 while (p < last && *p != ',' && *p != ' ') { p++; }
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1070
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1071 len = p - start;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1072
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1073 if (len == 0) {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1074 break;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1075 }
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1076
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1077 if (multiple) {
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1078 ngx_md5_update(md5, (u_char *) ",", sizeof(",") - 1);
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1079 }
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1080
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1081 ngx_md5_update(md5, start, len);
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1082
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1083 multiple = 1;
ee9230cd4bda Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5880
diff changeset
1084 }
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1085 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1086 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1087
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1088
5880
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1089 static ngx_int_t
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1090 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
1091 {
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1092 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
1093
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1094 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
1095 "http file cache reopen");
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1096
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1097 if (c->secondary) {
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1098 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
1099 "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
1100 c->file.name.data);
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1101 return NGX_DECLINED;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1102 }
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1103
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1104 cache = c->file_cache;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1105
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1106 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
1107
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1108 c->node->count--;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1109 c->node = NULL;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1110
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1111 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
1112
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1113 c->secondary = 1;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1114 c->file.name.len = 0;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1115 c->body_start = c->buf->end - c->buf->start;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1116
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1117 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
1118
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1119 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
1120 }
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1121
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1122
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1123 void
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1124 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
1125 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1126 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
1127
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1128 u_char *p;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1129 ngx_str_t *key;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1130 ngx_uint_t i;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1131 ngx_http_cache_t *c;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1132
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1133 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
1134 "http file cache set header");
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1135
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1136 c = r->cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1137
5245
711fa02afae8 Valgrind: supressed complaints about uninitialized bytes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5077
diff changeset
1138 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
1139
5736
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
1140 h->version = NGX_HTTP_CACHE_VERSION;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1141 h->valid_sec = c->valid_sec;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1142 h->last_modified = c->last_modified;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1143 h->date = c->date;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1144 h->crc32 = c->crc32;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1145 h->valid_msec = (u_short) c->valid_msec;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1146 h->header_start = (u_short) c->header_start;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1147 h->body_start = (u_short) c->body_start;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1148
5737
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
1149 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
1150 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
1151 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
1152 }
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
1153
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1154 if (c->vary.len) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1155 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
1156 /* should not happen */
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1157 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
1158 }
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 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
1161 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
1162
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1163 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
1164 ngx_memcpy(h->variant, c->variant, NGX_HTTP_CACHE_KEY_LEN);
5880
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1165
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1166 } else {
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1167 ngx_memzero(c->variant, 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
1168 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1169
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1170 p = buf + sizeof(ngx_http_file_cache_header_t);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1171
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1172 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
1173
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1174 key = c->keys.elts;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1175 for (i = 0; i < c->keys.nelts; i++) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1176 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
1177 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1178
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1179 *p = LF;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1180 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1181
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1182
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1183 void
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1184 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
1185 {
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
1186 off_t fs_size;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1187 ngx_int_t rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1188 ngx_file_uniq_t uniq;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1189 ngx_file_info_t fi;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1190 ngx_http_cache_t *c;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1191 ngx_ext_rename_file_t ext;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1192 ngx_http_file_cache_t *cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1193
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1194 c = r->cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1195
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1196 if (c->updated) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1197 return;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1198 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1199
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1200 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
1201 "http file cache update");
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1202
5880
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1203 cache = c->file_cache;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1204
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1205 if (c->secondary
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1206 && ngx_memcmp(c->variant, c->key, NGX_HTTP_CACHE_KEY_LEN) != 0)
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1207 {
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1208 /*
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1209 * if the variant hash doesn't match one we used as a secondary
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1210 * cache key, switch back to the original key
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1211 */
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1212
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1213 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1214 "http file cache main key");
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1215
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1216 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
1217
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1218 c->node->count--;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1219 c->node->updating = 0;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1220 c->node = NULL;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1221
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1222 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
1223
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1224 c->file.name.len = 0;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1225
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1226 ngx_memcpy(c->key, c->main, 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
1227
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1228 if (ngx_http_file_cache_exists(cache, c) == NGX_ERROR) {
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1229 return;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1230 }
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1231
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1232 if (ngx_http_file_cache_name(r, cache->path) != NGX_OK) {
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1233 return;
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1234 }
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1235 }
78c49e243848 Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5879
diff changeset
1236
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1237 c->updated = 1;
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1238 c->updating = 0;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1239
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1240 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
1241 fs_size = 0;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1242
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1243 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
1244 "http file cache rename: \"%s\" to \"%s\"",
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1245 tf->file.name.data, c->file.name.data);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1246
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1247 ext.access = NGX_FILE_OWNER_ACCESS;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1248 ext.path_access = NGX_FILE_OWNER_ACCESS;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1249 ext.time = -1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1250 ext.create_path = 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1251 ext.delete_file = 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1252 ext.log = r->connection->log;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1253
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1254 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
1255
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1256 if (rc == NGX_OK) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1257
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1258 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
1259 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
1260 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
1261
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1262 rc = NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1263
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1264 } else {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1265 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
1266 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
1267 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1268 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1269
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1270 ngx_shmtx_lock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1271
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1272 c->node->count--;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1273 c->node->uniq = uniq;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1274 c->node->body_start = c->body_start;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1275
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
1276 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
1277 c->node->fs_size = fs_size;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1278
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1279 if (rc == NGX_OK) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1280 c->node->exists = 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1281 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1282
2927
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
1283 c->node->updating = 0;
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
1284
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1285 ngx_shmtx_unlock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1286 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1287
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1288
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1289 void
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1290 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
1291 {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1292 ssize_t n;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1293 ngx_err_t err;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1294 ngx_file_t file;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1295 ngx_file_info_t fi;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1296 ngx_http_cache_t *c;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1297 ngx_http_file_cache_header_t h;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1298
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1299 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
1300 "http file cache update header");
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1301
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1302 c = r->cache;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1303
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1304 ngx_memzero(&file, sizeof(ngx_file_t));
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1305
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1306 file.name = c->file.name;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1307 file.log = r->connection->log;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1308 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
1309
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1310 if (file.fd == NGX_INVALID_FILE) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1311 err = ngx_errno;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1312
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1313 /* cache file may have been deleted */
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1314
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1315 if (err == NGX_ENOENT) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1316 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
1317 "http file cache \"%s\" not found",
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1318 file.name.data);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1319 return;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1320 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1321
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1322 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
1323 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
1324 return;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1325 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1326
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1327 /*
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1328 * make sure cache file wasn't replaced;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1329 * if it was, do nothing
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1330 */
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1331
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1332 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
1333 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
1334 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
1335 goto done;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1336 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1337
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1338 if (c->uniq != ngx_file_uniq(&fi)
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1339 || c->length != ngx_file_size(&fi))
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1340 {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1341 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
1342 "http file cache \"%s\" changed",
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1343 file.name.data);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1344 goto done;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1345 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1346
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1347 n = ngx_read_file(&file, (u_char *) &h,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1348 sizeof(ngx_http_file_cache_header_t), 0);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1349
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1350 if (n == NGX_ERROR) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1351 goto done;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1352 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1353
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1354 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
1355 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
1356 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
1357 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
1358 goto done;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1359 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1360
5736
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
1361 if (h.version != NGX_HTTP_CACHE_VERSION
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
1362 || h.last_modified != c->last_modified
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1363 || h.crc32 != c->crc32
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1364 || h.header_start != c->header_start
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1365 || h.body_start != c->body_start)
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1366 {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1367 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
1368 "http file cache \"%s\" content changed",
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1369 file.name.data);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1370 goto done;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1371 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1372
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1373 /*
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1374 * update cache file header with new data,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1375 * notably h.valid_sec and h.date
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1376 */
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1377
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1378 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
1379
5736
2fe1967f8854 Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5726
diff changeset
1380 h.version = NGX_HTTP_CACHE_VERSION;
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1381 h.valid_sec = c->valid_sec;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1382 h.last_modified = c->last_modified;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1383 h.date = c->date;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1384 h.crc32 = c->crc32;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1385 h.valid_msec = (u_short) c->valid_msec;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1386 h.header_start = (u_short) c->header_start;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1387 h.body_start = (u_short) c->body_start;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1388
5737
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
1389 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
1390 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
1391 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
1392 }
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5736
diff changeset
1393
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1394 if (c->vary.len) {
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1395 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
1396 /* should not happen */
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1397 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
1398 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1399
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1400 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
1401 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
1402
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1403 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
1404 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
1405 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5822
diff changeset
1406
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1407 (void) ngx_write_file(&file, (u_char *) &h,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1408 sizeof(ngx_http_file_cache_header_t), 0);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1409
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1410 done:
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1411
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1412 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
1413 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
1414 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
1415 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1416 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1417
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5359
diff changeset
1418
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1419 ngx_int_t
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1420 ngx_http_cache_send(ngx_http_request_t *r)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1421 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1422 ngx_int_t rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1423 ngx_buf_t *b;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1424 ngx_chain_t out;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1425 ngx_http_cache_t *c;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1426
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1427 c = r->cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1428
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1429 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3965
90b0487fba44 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 3942
diff changeset
1430 "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
1431
4150
b9ee14871bf1 Cache: fix for sending of empty responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4034
diff changeset
1432 if (r != r->main && c->length - c->body_start == 0) {
b9ee14871bf1 Cache: fix for sending of empty responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4034
diff changeset
1433 return ngx_http_send_header(r);
b9ee14871bf1 Cache: fix for sending of empty responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4034
diff changeset
1434 }
b9ee14871bf1 Cache: fix for sending of empty responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4034
diff changeset
1435
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1436 /* 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
1437
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1438 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1439 if (b == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1440 return NGX_HTTP_INTERNAL_SERVER_ERROR;
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
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1443 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
1444 if (b->file == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1445 return NGX_HTTP_INTERNAL_SERVER_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1446 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1447
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1448 rc = ngx_http_send_header(r);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1449
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1450 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
1451 return rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1452 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1453
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1454 b->file_pos = c->body_start;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1455 b->file_last = c->length;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1456
4150
b9ee14871bf1 Cache: fix for sending of empty responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4034
diff changeset
1457 b->in_file = (c->length - c->body_start) ? 1: 0;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1458 b->last_buf = (r == r->main) ? 1: 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1459 b->last_in_chain = 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1460
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1461 b->file->fd = c->file.fd;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1462 b->file->name = c->file.name;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1463 b->file->log = r->connection->log;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1464
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1465 out.buf = b;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1466 out.next = NULL;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1467
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1468 return ngx_http_output_filter(r, &out);
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 void
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1473 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
1474 {
3694
dfb17155eca9 delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents: 3526
diff changeset
1475 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
1476 ngx_http_file_cache_node_t *fcn;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1477
3917
2a70484a6580 fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents: 3899
diff changeset
1478 if (c->updated || c->node == NULL) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1479 return;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1480 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1481
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1482 cache = c->file_cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1483
3713
f0b62d1ac7af move debug logging inside ngx_http_file_cache_free()
Igor Sysoev <igor@sysoev.ru>
parents: 3711
diff changeset
1484 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
1485 "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
1486
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1487 ngx_shmtx_lock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1488
3694
dfb17155eca9 delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents: 3526
diff changeset
1489 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
1490 fcn->count--;
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1491
5905
2f7e557eab5b Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5898
diff changeset
1492 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
1493 fcn->updating = 0;
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1494 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1495
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1496 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
1497 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
1498
3743
c469ffeab569 error status codes could be cached for next request only,
Igor Sysoev <igor@sysoev.ru>
parents: 3732
diff changeset
1499 if (c->valid_sec) {
c469ffeab569 error status codes could be cached for next request only,
Igor Sysoev <igor@sysoev.ru>
parents: 3732
diff changeset
1500 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
1501 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
1502 }
c469ffeab569 error status codes could be cached for next request only,
Igor Sysoev <igor@sysoev.ru>
parents: 3732
diff changeset
1503
3723
14ad3210fc73 do not free unused cache node if cache min_uses > 1,
Igor Sysoev <igor@sysoev.ru>
parents: 3713
diff changeset
1504 } 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
1505 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
1506 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
1507 ngx_slab_free_locked(cache->shpool, fcn);
dfb17155eca9 delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents: 3526
diff changeset
1508 c->node = NULL;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1509 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1510
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1511 ngx_shmtx_unlock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1512
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1513 c->updated = 1;
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1514 c->updating = 0;
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1515
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1516 if (c->temp_file) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1517 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
1518 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
1519 "http file cache incomplete: \"%s\"",
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1520 tf->file.name.data);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1521
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1522 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
1523 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
1524 ngx_delete_file_n " \"%s\" failed",
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1525 tf->file.name.data);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1526 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1527 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1528 }
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
1529
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
1530 if (c->wait_event.timer_set) {
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
1531 ngx_del_timer(&c->wait_event);
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4340
diff changeset
1532 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1533 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1534
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1535
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1536 static void
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1537 ngx_http_file_cache_cleanup(void *data)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1538 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1539 ngx_http_cache_t *c = data;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1540
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1541 if (c->updated) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1542 return;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1543 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1544
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1545 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
1546 "http file cache cleanup");
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1547
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1548 if (c->updating) {
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1549 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
1550 "stalled cache updating, error:%ui", c->error);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1551 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1552
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3710
diff changeset
1553 ngx_http_file_cache_free(c, NULL);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1554 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1555
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1556
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1557 static time_t
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1558 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
1559 {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1560 u_char *name;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1561 size_t len;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1562 time_t wait;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1563 ngx_uint_t tries;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1564 ngx_path_t *path;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1565 ngx_queue_t *q;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1566 ngx_http_file_cache_node_t *fcn;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1567
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1568 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
1569 "http file cache forced expire");
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1570
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1571 path = cache->path;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1572 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
1573
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1574 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
1575 if (name == NULL) {
2694
49a1382b249b set cache manager maximum sleep time to 10s
Igor Sysoev <igor@sysoev.ru>
parents: 2693
diff changeset
1576 return 10;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1577 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1578
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1579 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
1580
2694
49a1382b249b set cache manager maximum sleep time to 10s
Igor Sysoev <igor@sysoev.ru>
parents: 2693
diff changeset
1581 wait = 10;
3728
a29bb11f8c80 change logic slightly
Igor Sysoev <igor@sysoev.ru>
parents: 3727
diff changeset
1582 tries = 20;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1583
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1584 ngx_shmtx_lock(&cache->shpool->mutex);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1585
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
1586 for (q = ngx_queue_last(&cache->sh->queue);
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
1587 q != ngx_queue_sentinel(&cache->sh->queue);
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1588 q = ngx_queue_prev(q))
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1589 {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1590 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
1591
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1592 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
1593 "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
1594 fcn->count, fcn->exists,
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1595 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
1596
3727
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1597 if (fcn->count == 0) {
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1598 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
1599 wait = 0;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1600
3727
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1601 } else {
3728
a29bb11f8c80 change logic slightly
Igor Sysoev <igor@sysoev.ru>
parents: 3727
diff changeset
1602 if (--tries) {
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1603 continue;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1604 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1605
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1606 wait = 1;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1607 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1608
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1609 break;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1610 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1611
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1612 ngx_shmtx_unlock(&cache->shpool->mutex);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1613
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1614 ngx_free(name);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1615
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1616 return wait;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1617 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1618
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1619
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1620 static time_t
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1621 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
1622 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1623 u_char *name, *p;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1624 size_t len;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1625 time_t now, wait;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1626 ngx_path_t *path;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1627 ngx_queue_t *q;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1628 ngx_http_file_cache_node_t *fcn;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1629 u_char key[2 * NGX_HTTP_CACHE_KEY_LEN];
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1630
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1631 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
1632 "http file cache expire");
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 path = cache->path;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1635 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
1636
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1637 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
1638 if (name == NULL) {
2694
49a1382b249b set cache manager maximum sleep time to 10s
Igor Sysoev <igor@sysoev.ru>
parents: 2693
diff changeset
1639 return 10;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1640 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1641
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1642 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
1643
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1644 now = ngx_time();
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1645
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1646 ngx_shmtx_lock(&cache->shpool->mutex);
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 for ( ;; ) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1649
5679
5748ce74c1cc Cache: added ngx_quit check to ngx_http_file_cache_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5441
diff changeset
1650 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
1651 wait = 1;
5748ce74c1cc Cache: added ngx_quit check to ngx_http_file_cache_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5441
diff changeset
1652 break;
5748ce74c1cc Cache: added ngx_quit check to ngx_http_file_cache_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5441
diff changeset
1653 }
5748ce74c1cc Cache: added ngx_quit check to ngx_http_file_cache_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5441
diff changeset
1654
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
1655 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
1656 wait = 10;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1657 break;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1658 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1659
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
1660 q = ngx_queue_last(&cache->sh->queue);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1661
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1662 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
1663
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1664 wait = fcn->expire - now;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1665
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1666 if (wait > 0) {
2694
49a1382b249b set cache manager maximum sleep time to 10s
Igor Sysoev <igor@sysoev.ru>
parents: 2693
diff changeset
1667 wait = wait > 10 ? 10 : wait;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1668 break;
2592
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
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1671 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
1672 "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
1673 fcn->count, fcn->exists,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1674 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
1675
3727
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1676 if (fcn->count == 0) {
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1677 ngx_http_file_cache_delete(cache, q, name);
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1678 continue;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1679 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1680
3755
76e3a93821b1 fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents: 3744
diff changeset
1681 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
1682 wait = 1;
2e8dbd773d63 fix r3756: release lock to allow other process to delete cache node
Igor Sysoev <igor@sysoev.ru>
parents: 3917
diff changeset
1683 break;
3755
76e3a93821b1 fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents: 3744
diff changeset
1684 }
76e3a93821b1 fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents: 3744
diff changeset
1685
3727
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1686 p = ngx_hex_dump(key, (u_char *) &fcn->node.key,
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1687 sizeof(ngx_rbtree_key_t));
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1688 len = NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t);
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1689 (void) ngx_hex_dump(p, fcn->key, len);
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1690
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1691 /*
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1692 * abnormally exited workers may leave locked cache entries,
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1693 * 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
1694 * 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
1695 */
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1696
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1697 ngx_queue_remove(q);
4340
4533d7684e14 Cache: only complain on long locked entries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4339
diff changeset
1698 fcn->expire = ngx_time() + cache->inactive;
4533d7684e14 Cache: only complain on long locked entries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4339
diff changeset
1699 ngx_queue_insert_head(&cache->sh->queue, &fcn->queue);
3727
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1700
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1701 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1702 "ignore long locked inactive cache entry %*s, count:%d",
fd2bb219de22 change order
Igor Sysoev <igor@sysoev.ru>
parents: 3726
diff changeset
1703 2 * NGX_HTTP_CACHE_KEY_LEN, key, fcn->count);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1704 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1705
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1706 ngx_shmtx_unlock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1707
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1708 ngx_free(name);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1709
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1710 return wait;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1711 }
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
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1714 static void
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1715 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
1716 u_char *name)
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1717 {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1718 u_char *p;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1719 size_t len;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1720 ngx_path_t *path;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1721 ngx_http_file_cache_node_t *fcn;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1722
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1723 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
1724
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1725 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
1726 cache->sh->size -= fcn->fs_size;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1727
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1728 path = cache->path;
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1729 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
1730 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
1731 sizeof(ngx_rbtree_key_t));
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1732 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
1733 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
1734 *p = '\0';
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1735
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1736 fcn->count++;
3755
76e3a93821b1 fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents: 3744
diff changeset
1737 fcn->deleting = 1;
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1738 ngx_shmtx_unlock(&cache->shpool->mutex);
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1739
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1740 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
1741 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
1742
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1743 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
1744 "http file cache expire: \"%s\"", name);
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1745
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1746 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
1747 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
1748 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
1749 }
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1750
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1751 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
1752 fcn->count--;
3755
76e3a93821b1 fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents: 3744
diff changeset
1753 fcn->deleting = 0;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1754 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1755
3726
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1756 if (fcn->count == 0) {
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1757 ngx_queue_remove(q);
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1758 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
1759 ngx_slab_free_locked(cache->shpool, fcn);
282ddd49f925 *) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents: 3724
diff changeset
1760 }
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1761 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1762
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1763
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1764 static time_t
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1765 ngx_http_file_cache_manager(void *data)
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1766 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1767 ngx_http_file_cache_t *cache = data;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1768
3018
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1769 off_t size;
3885
46938b7418c6 fix CPU hog in cache manager
Igor Sysoev <igor@sysoev.ru>
parents: 3755
diff changeset
1770 time_t next, wait;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1771
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1772 next = ngx_http_file_cache_expire(cache);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1773
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1774 cache->last = ngx_current_msec;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1775 cache->files = 0;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1776
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1777 for ( ;; ) {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1778 ngx_shmtx_lock(&cache->shpool->mutex);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1779
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
1780 size = cache->sh->size;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1781
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1782 ngx_shmtx_unlock(&cache->shpool->mutex);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1783
2631
73571521c2eb add debug logging
Igor Sysoev <igor@sysoev.ru>
parents: 2626
diff changeset
1784 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
73571521c2eb add debug logging
Igor Sysoev <igor@sysoev.ru>
parents: 2626
diff changeset
1785 "http file cache size: %O", size);
73571521c2eb add debug logging
Igor Sysoev <igor@sysoev.ru>
parents: 2626
diff changeset
1786
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1787 if (size < cache->max_size) {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1788 return next;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1789 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1790
3885
46938b7418c6 fix CPU hog in cache manager
Igor Sysoev <igor@sysoev.ru>
parents: 3755
diff changeset
1791 wait = ngx_http_file_cache_forced_expire(cache);
46938b7418c6 fix CPU hog in cache manager
Igor Sysoev <igor@sysoev.ru>
parents: 3755
diff changeset
1792
46938b7418c6 fix CPU hog in cache manager
Igor Sysoev <igor@sysoev.ru>
parents: 3755
diff changeset
1793 if (wait > 0) {
46938b7418c6 fix CPU hog in cache manager
Igor Sysoev <igor@sysoev.ru>
parents: 3755
diff changeset
1794 return wait;
46938b7418c6 fix CPU hog in cache manager
Igor Sysoev <igor@sysoev.ru>
parents: 3755
diff changeset
1795 }
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1796
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
1797 if (ngx_quit || ngx_terminate) {
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1798 return next;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1799 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1800 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1801 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1802
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1803
3018
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1804 static void
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1805 ngx_http_file_cache_loader(void *data)
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1806 {
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1807 ngx_http_file_cache_t *cache = data;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1808
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1809 ngx_tree_ctx_t tree;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1810
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1811 if (!cache->sh->cold || cache->sh->loading) {
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1812 return;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1813 }
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1814
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1815 if (!ngx_atomic_cmp_set(&cache->sh->loading, 0, ngx_pid)) {
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1816 return;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1817 }
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1818
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1819 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1820 "http file cache loader");
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1821
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1822 tree.init_handler = NULL;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1823 tree.file_handler = ngx_http_file_cache_manage_file;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1824 tree.pre_tree_handler = ngx_http_file_cache_noop;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1825 tree.post_tree_handler = ngx_http_file_cache_noop;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1826 tree.spec_handler = ngx_http_file_cache_delete_file;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1827 tree.data = cache;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1828 tree.alloc = 0;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1829 tree.log = ngx_cycle->log;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1830
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1831 cache->last = ngx_current_msec;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1832 cache->files = 0;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1833
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1834 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
1835 cache->sh->loading = 0;
3018
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1836 return;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1837 }
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1838
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1839 cache->sh->cold = 0;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1840 cache->sh->loading = 0;
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1841
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1842 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1843 "http file cache: %V %.3fM, bsize: %uz",
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1844 &cache->path->name,
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1845 ((double) cache->sh->size * cache->bsize) / (1024 * 1024),
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1846 cache->bsize);
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1847 }
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1848
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
1849
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1850 static ngx_int_t
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1851 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
1852 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1853 return NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1854 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1855
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1856
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1857 static ngx_int_t
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1858 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
1859 {
4018
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1860 ngx_msec_t elapsed;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1861 ngx_http_file_cache_t *cache;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1862
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1863 cache = ctx->data;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1864
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1865 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
1866 (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
1867 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1868
4018
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1869 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
1870 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
1871
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1872 } else {
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1873 ngx_time_update();
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1874
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1875 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
1876
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1877 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
1878 "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
1879
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1880 if (elapsed >= cache->loader_threshold) {
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1881 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
1882 }
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1883 }
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1884
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1885 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
1886 }
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1887
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1888
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1889 static void
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1890 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
1891 {
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1892 ngx_msleep(cache->loader_sleep);
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1893
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1894 ngx_time_update();
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1895
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1896 cache->last = ngx_current_msec;
5e544655d97b The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents: 3974
diff changeset
1897 cache->files = 0;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1898 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1899
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1900
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1901 static ngx_int_t
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1902 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
1903 {
3970
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
1904 u_char *p;
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
1905 ngx_int_t n;
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
1906 ngx_uint_t i;
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
1907 ngx_http_cache_t c;
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
1908 ngx_http_file_cache_t *cache;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1909
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1910 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
1911 return NGX_ERROR;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1912 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1913
3970
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
1914 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
1915 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
1916 "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
1917 return NGX_ERROR;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1918 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1919
3970
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
1920 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
1921 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
1922
3970
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
1923 c.length = ctx->size;
2d05952a324d elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents: 3969
diff changeset
1924 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
1925
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1926 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
1927
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1928 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
1929 n = ngx_hextoi(p, 2);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1930
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1931 if (n == NGX_ERROR) {
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1932 return NGX_ERROR;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1933 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1934
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1935 p += 2;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1936
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1937 c.key[i] = (u_char) n;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1938 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1939
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1940 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
1941 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1942
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1943
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1944 static ngx_int_t
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1945 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
1946 {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1947 ngx_http_file_cache_node_t *fcn;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1948
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1949 ngx_shmtx_lock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1950
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1951 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
1952
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1953 if (fcn == NULL) {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1954
5726
25ade23cf281 Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents: 5679
diff changeset
1955 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
1956 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
1957 if (fcn == NULL) {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1958 ngx_shmtx_unlock(&cache->shpool->mutex);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1959 return NGX_ERROR;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1960 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1961
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1962 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
1963
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1964 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
1965 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
1966
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
1967 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
1968
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1969 fcn->uses = 1;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1970 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
1971 fcn->fs_size = c->fs_size;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1972
3899
e7cd13b7f759 Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents: 3885
diff changeset
1973 cache->sh->size += c->fs_size;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1974
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1975 } else {
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1976 ngx_queue_remove(&fcn->queue);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1977 }
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->expire = ngx_time() + cache->inactive;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1980
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
1981 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
1982
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1983 ngx_shmtx_unlock(&cache->shpool->mutex);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1984
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1985 return NGX_OK;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1986 }
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1987
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1988
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1989 static ngx_int_t
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
1990 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
1991 {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1992 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
1993 "http file cache delete: \"%s\"", path->data);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1994
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1995 if (ngx_delete_file(path->data) == NGX_FILE_ERROR) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1996 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
1997 ngx_delete_file_n " \"%s\" failed", path->data);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
1998 }
477
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
1999
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2000 return NGX_OK;
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2001 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2002
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2003
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2004 time_t
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2005 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
2006 {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2007 ngx_uint_t i;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2008 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
2009
2626
b0cfe5f66e8d fix segfault introduced in r2602 if there is 502/504 error
Igor Sysoev <igor@sysoev.ru>
parents: 2616
diff changeset
2010 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
2011 return 0;
b0cfe5f66e8d fix segfault introduced in r2602 if there is 502/504 error
Igor Sysoev <igor@sysoev.ru>
parents: 2616
diff changeset
2012 }
b0cfe5f66e8d fix segfault introduced in r2602 if there is 502/504 error
Igor Sysoev <igor@sysoev.ru>
parents: 2616
diff changeset
2013
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2014 valid = cache_valid->elts;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2015 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
2016
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2017 if (valid[i].status == 0) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2018 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
2019 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2020
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2021 if (valid[i].status == status) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2022 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
2023 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2024 }
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2025
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2026 return 0;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2027 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2028
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2029
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2030 char *
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2031 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
2032 {
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2033 off_t max_size;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2034 u_char *last, *p;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2035 time_t inactive;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2036 ssize_t size;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2037 ngx_str_t s, name, *value;
4474
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2038 ngx_int_t loader_files;
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2039 ngx_msec_t loader_sleep, loader_threshold;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2040 ngx_uint_t i, n;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2041 ngx_http_file_cache_t *cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2042
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2043 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
2044 if (cache == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2045 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2046 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2047
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2048 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
2049 if (cache->path == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2050 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2051 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2052
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2053 inactive = 600;
3974
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2054 loader_files = 100;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2055 loader_sleep = 50;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2056 loader_threshold = 200;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2057
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2058 name.len = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2059 size = 0;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2060 max_size = NGX_MAX_OFF_T_VALUE;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2061
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2062 value = cf->args->elts;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2063
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2064 cache->path->name = value[1];
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2065
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2066 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
2067 cache->path->name.len--;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2068 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2069
5330
314c3d7cc3a5 Backed out f1a91825730a and 7094bd12c1ff.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5317
diff changeset
2070 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
2071 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2072 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2073
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2074 for (i = 2; i < cf->args->nelts; i++) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2075
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2076 if (ngx_strncmp(value[i].data, "levels=", 7) == 0) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2077
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2078 p = value[i].data + 7;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2079 last = value[i].data + value[i].len;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2080
2671
627dee566f6c fix cache path slot
Igor Sysoev <igor@sysoev.ru>
parents: 2632
diff changeset
2081 for (n = 0; n < 3 && p < last; n++) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2082
2671
627dee566f6c fix cache path slot
Igor Sysoev <igor@sysoev.ru>
parents: 2632
diff changeset
2083 if (*p > '0' && *p < '3') {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2084
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2085 cache->path->level[n] = *p++ - '0';
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2086 cache->path->len += cache->path->level[n] + 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2087
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2088 if (p == last) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2089 break;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2090 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2091
2671
627dee566f6c fix cache path slot
Igor Sysoev <igor@sysoev.ru>
parents: 2632
diff changeset
2092 if (*p++ == ':' && n < 2 && p != last) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2093 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2094 }
2671
627dee566f6c fix cache path slot
Igor Sysoev <igor@sysoev.ru>
parents: 2632
diff changeset
2095
627dee566f6c fix cache path slot
Igor Sysoev <igor@sysoev.ru>
parents: 2632
diff changeset
2096 goto invalid_levels;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2097 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2098
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2099 goto invalid_levels;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2100 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2101
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2102 if (cache->path->len < 10 + 3) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2103 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2104 }
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 invalid_levels:
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2107
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2108 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2109 "invalid \"levels\" \"%V\"", &value[i]);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2110 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2111 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2112
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2113 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
2114
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2115 name.data = value[i].data + 10;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2116
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2117 p = (u_char *) ngx_strchr(name.data, ':');
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2118
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2119 if (p) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2120 name.len = p - name.data;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2121
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2122 p++;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2123
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2124 s.len = value[i].data + value[i].len - p;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2125 s.data = p;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2126
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2127 size = ngx_parse_size(&s);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2128 if (size > 8191) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2129 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2130 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2131 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2132
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2133 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2134 "invalid keys zone size \"%V\"", &value[i]);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2135 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2136 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2137
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2138 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2139
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2140 s.len = value[i].len - 9;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2141 s.data = value[i].data + 9;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2142
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2143 inactive = ngx_parse_time(&s, 1);
4474
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2144 if (inactive == (time_t) NGX_ERROR) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2145 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2146 "invalid inactive value \"%V\"", &value[i]);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2147 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2148 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2149
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2150 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2151 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2152
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2153 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
2154
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2155 s.len = value[i].len - 9;
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2156 s.data = value[i].data + 9;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2157
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2158 max_size = ngx_parse_offset(&s);
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2159 if (max_size < 0) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2160 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
2161 "invalid max_size value \"%V\"", &value[i]);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2162 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2163 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2164
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2165 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2166 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2167
3974
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2168 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
2169
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2170 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
2171 if (loader_files == NGX_ERROR) {
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2172 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
2173 "invalid loader_files value \"%V\"", &value[i]);
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2174 return NGX_CONF_ERROR;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2175 }
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2176
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2177 continue;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2178 }
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2179
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2180 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
2181
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2182 s.len = value[i].len - 13;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2183 s.data = value[i].data + 13;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2184
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2185 loader_sleep = ngx_parse_time(&s, 0);
4474
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2186 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
2187 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
2188 "invalid loader_sleep value \"%V\"", &value[i]);
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2189 return NGX_CONF_ERROR;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2190 }
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2191
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2192 continue;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2193 }
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2194
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2195 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
2196
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2197 s.len = value[i].len - 17;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2198 s.data = value[i].data + 17;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2199
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2200 loader_threshold = ngx_parse_time(&s, 0);
4474
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2201 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
2202 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
2203 "invalid loader_threshold value \"%V\"", &value[i]);
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2204 return NGX_CONF_ERROR;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2205 }
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2206
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2207 continue;
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2208 }
d10bcb07d9d4 loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents: 3973
diff changeset
2209
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2210 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2211 "invalid parameter \"%V\"", &value[i]);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2212 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2213 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2214
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2215 if (name.len == 0 || size == 0) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2216 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2217 "\"%V\" must have \"keys_zone\" parameter",
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2218 &cmd->name);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2219 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2220 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2221
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2222 cache->path->manager = ngx_http_file_cache_manager;
3018
8fc7b94f647b cache loader process
Igor Sysoev <igor@sysoev.ru>
parents: 3017
diff changeset
2223 cache->path->loader = ngx_http_file_cache_loader;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2224 cache->path->data = cache;
3973
9d6f21415231 set correct configuration file values while adding path
Igor Sysoev <igor@sysoev.ru>
parents: 3972
diff changeset
2225 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
2226 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
2227 cache->loader_files = loader_files;
4474
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2228 cache->loader_sleep = loader_sleep;
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2229 cache->loader_threshold = loader_threshold;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2230
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2231 if (ngx_add_path(cf, &cache->path) != NGX_OK) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2232 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2233 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2234
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2235 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
2236 if (cache->shm_zone == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2237 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2238 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2239
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2240 if (cache->shm_zone->data) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2241 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2242 "duplicate zone \"%V\"", &name);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2243 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2244 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2245
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2246
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2247 cache->shm_zone->init = ngx_http_file_cache_init;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2248 cache->shm_zone->data = cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2249
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2250 cache->inactive = inactive;
2616
d19979e0d980 introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents: 2611
diff changeset
2251 cache->max_size = max_size;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2252
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2253 return NGX_CONF_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2254 }
477
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
2255
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
2256
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2257 char *
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2258 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
2259 void *conf)
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2260 {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2261 char *p = conf;
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2262
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2263 time_t valid;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2264 ngx_str_t *value;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2265 ngx_uint_t i, n, status;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2266 ngx_array_t **a;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2267 ngx_http_cache_valid_t *v;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2268 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
2269
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2270 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
2271
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2272 if (*a == NGX_CONF_UNSET_PTR) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2273 *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
2274 if (*a == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2275 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2276 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2277 }
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2278
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2279 value = cf->args->elts;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2280 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
2281
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2282 valid = ngx_parse_time(&value[n], 1);
4474
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2283 if (valid == (time_t) NGX_ERROR) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2284 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2285 "invalid time value \"%V\"", &value[n]);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2286 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
2287 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2288
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2289 if (n == 1) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2290
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2291 for (i = 0; i < 3; i++) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2292 v = ngx_array_push(*a);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2293 if (v == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2294 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2295 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2296
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2297 v->status = statuses[i];
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2298 v->valid = valid;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2299 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2300
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2301 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
2302 }
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2303
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2304 for (i = 1; i < n; i++) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2305
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2306 if (ngx_strcmp(value[i].data, "any") == 0) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2307
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2308 status = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2309
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2310 } else {
202
74994aeef848 nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2311
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2312 status = ngx_atoi(value[i].data, value[i].len);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2313 if (status < 100) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2314 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2315 "invalid status \"%V\"", &value[i]);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2316 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2317 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2318 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2319
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2320 v = ngx_array_push(*a);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2321 if (v == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2322 return NGX_CONF_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2323 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2324
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2325 v->status = status;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2326 v->valid = valid;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2327 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2328
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
2329 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
2330 }