annotate src/http/ngx_http_file_cache.c @ 5736:2fe1967f8854

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