comparison src/http/ngx_http_file_cache.c @ 502:89dc5654117c NGINX_0_7_63

nginx 0.7.63 *) Security: now "/../" are disabled in "Destination" request header line. *) Change: minimum supported OpenSSL version is 0.9.7. *) Change: the "ask" parameter of the "ssl_verify_client" directive was changed to the "optional" parameter and now it checks a client certificate if it was offered. Thanks to Brice Figureau. *) Feature: now the "-V" switch shows TLS SNI support. *) Feature: the $ssl_client_verify variable. Thanks to Brice Figureau. *) Feature: the "ssl_crl" directive. Thanks to Brice Figureau. *) Bugfix: the $ssl_client_cert variable usage corrupted memory; the bug had appeared in 0.7.7. Thanks to Sergey Zhuravlev. *) Feature: now the start cache loader runs in a separate process; this should improve large caches handling. *) Feature: now temporary files and permanent storage area may reside at different file systems. *) Bugfix: nginx counted incorrectly disk cache size. *) Change: now directive "gzip_disable msie6" does not disable gzipping for MSIE 6.0 SV1. *) Bugfix: nginx always added "Vary: Accept-Encoding" response header line, if both "gzip_static" and "gzip_vary" were on. *) Feature: the "proxy" parameter of the "geo" directive. *) Feature: the ngx_http_geoip_module. *) Feature: the "limit_rate_after" directive. Thanks to Ivan Debnar. *) Feature: the "limit_req_log_level" and "limit_conn_log_level" directives. *) Bugfix: now "limit_req" directive conforms to the leaky bucket algorithm. Thanks to Maxim Dounin. *) Bugfix: in ngx_http_limit_req_module. Thanks to Maxim Dounin. *) Bugfix: now nginx allows underscores in a request method. *) Bugfix: "proxy_pass_header" and "fastcgi_pass_header" directives did not pass to a client the "X-Accel-Redirect", "X-Accel-Limit-Rate", "X-Accel-Buffering", and "X-Accel-Charset" lines from backend response header. Thanks to Maxim Dounin. *) Bugfix: in handling "Last-Modified" and "Accept-Ranges" backend response header lines; the bug had appeared in 0.7.44. Thanks to Maxim Dounin. *) Feature: the "image_filter_transparency" directive. *) Feature: the "image_filter" directive supports variables for setting size. *) Bugfix: in PNG alpha-channel support in the ngx_http_image_filter_module. *) Bugfix: in transparency support in the ngx_http_image_filter_module. *) Feature: now several "perl_modules" directives may be used. *) Bugfix: ngx_http_perl_module responses did not work in subrequests. *) Bugfix: nginx sent '\0' in a "Location" response header line on MKCOL request. Thanks to Xie Zhenye. *) Bugfix: an "error_page" directive did not redirect a 413 error; the bug had appeared in 0.6.10. *) Bugfix: in memory allocation error handling. Thanks to Maxim Dounin and Kirill A. Korinskiy.
author Igor Sysoev <http://sysoev.ru>
date Mon, 26 Oct 2009 00:00:00 +0300
parents ed3d382670c7
children b9fdcaf2062b
comparison
equal deleted inserted replaced
501:dc87c92181c7 502:89dc5654117c
51 ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data) 51 ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data)
52 { 52 {
53 ngx_http_file_cache_t *ocache = data; 53 ngx_http_file_cache_t *ocache = data;
54 54
55 size_t len; 55 size_t len;
56 ngx_uint_t n;
56 ngx_http_file_cache_t *cache; 57 ngx_http_file_cache_t *cache;
57 58
58 cache = shm_zone->data; 59 cache = shm_zone->data;
59 60
60 if (ocache) { 61 if (ocache) {
66 &ocache->path->name); 67 &ocache->path->name);
67 68
68 return NGX_ERROR; 69 return NGX_ERROR;
69 } 70 }
70 71
72 for (n = 0; n < 3; n++) {
73 if (cache->path->level[n] != ocache->path->level[n]) {
74 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
75 "cache \"%V\" had previously different levels",
76 &shm_zone->shm.name);
77 return NGX_ERROR;
78 }
79 }
80
71 cache->sh = ocache->sh; 81 cache->sh = ocache->sh;
72 82
73 cache->shpool = ocache->shpool; 83 cache->shpool = ocache->shpool;
74 cache->bsize = ocache->bsize; 84 cache->bsize = ocache->bsize;
75 85
76 cache->max_size /= cache->bsize; 86 cache->max_size /= cache->bsize;
87
88 if (!cache->sh->cold || cache->sh->loading) {
89 cache->path->loader = NULL;
90 }
77 91
78 return NGX_OK; 92 return NGX_OK;
79 } 93 }
80 94
81 cache->shpool = (ngx_slab_pool_t *) shm_zone->shm.addr; 95 cache->shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
98 ngx_http_file_cache_rbtree_insert_value); 112 ngx_http_file_cache_rbtree_insert_value);
99 113
100 ngx_queue_init(&cache->sh->queue); 114 ngx_queue_init(&cache->sh->queue);
101 115
102 cache->sh->cold = 1; 116 cache->sh->cold = 1;
117 cache->sh->loading = 0;
103 cache->sh->size = 0; 118 cache->sh->size = 0;
104 119
105 cache->bsize = ngx_fs_bsize(cache->path->name.data); 120 cache->bsize = ngx_fs_bsize(cache->path->name.data);
106 121
107 cache->max_size /= cache->bsize; 122 cache->max_size /= cache->bsize;
601 616
602 617
603 void 618 void
604 ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf) 619 ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf)
605 { 620 {
606 off_t size; 621 off_t size, length;
607 ngx_int_t rc; 622 ngx_int_t rc;
608 ngx_file_uniq_t uniq; 623 ngx_file_uniq_t uniq;
609 ngx_file_info_t fi; 624 ngx_file_info_t fi;
610 ngx_http_cache_t *c; 625 ngx_http_cache_t *c;
611 ngx_ext_rename_file_t ext; 626 ngx_ext_rename_file_t ext;
623 c->updated = 1; 638 c->updated = 1;
624 639
625 cache = c->file_cache; 640 cache = c->file_cache;
626 641
627 uniq = 0; 642 uniq = 0;
643 length = 0;
628 644
629 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 645 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
630 "http file cache rename: \"%s\" to \"%s\"", 646 "http file cache rename: \"%s\" to \"%s\"",
631 tf->file.name.data, c->file.name.data); 647 tf->file.name.data, c->file.name.data);
632 648
633 ext.access = NGX_FILE_OWNER_ACCESS; 649 ext.access = NGX_FILE_OWNER_ACCESS;
634 ext.path_access = NGX_FILE_OWNER_ACCESS; 650 ext.path_access = NGX_FILE_OWNER_ACCESS;
635 ext.time = -1; 651 ext.time = -1;
636 ext.create_path = 1; 652 ext.create_path = 1;
637 ext.delete_file = 1; 653 ext.delete_file = 1;
638 ext.log_rename_error = 1;
639 ext.log = r->connection->log; 654 ext.log = r->connection->log;
640 655
641 rc = ngx_ext_rename_file(&tf->file.name, &c->file.name, &ext); 656 rc = ngx_ext_rename_file(&tf->file.name, &c->file.name, &ext);
642 657
643 if (rc == NGX_OK) { 658 if (rc == NGX_OK) {
648 663
649 rc = NGX_ERROR; 664 rc = NGX_ERROR;
650 665
651 } else { 666 } else {
652 uniq = ngx_file_uniq(&fi); 667 uniq = ngx_file_uniq(&fi);
653 } 668 length = ngx_file_size(&fi);
654 } 669 }
655 670 }
656 size = (c->length + cache->bsize - 1) / cache->bsize; 671
672 size = (length + cache->bsize - 1) / cache->bsize;
657 673
658 ngx_shmtx_lock(&cache->shpool->mutex); 674 ngx_shmtx_lock(&cache->shpool->mutex);
659 675
660 c->node->count--; 676 c->node->count--;
661 c->node->uniq = uniq; 677 c->node->uniq = uniq;
662 c->node->body_start = c->body_start; 678 c->node->body_start = c->body_start;
663 679
664 size = size - (c->node->length + cache->bsize - 1) / cache->bsize; 680 size = size - (c->node->length + cache->bsize - 1) / cache->bsize;
665 681
666 c->node->length = c->length; 682 c->node->length = length;
667 683
668 cache->sh->size += size; 684 cache->sh->size += size;
669 685
670 if (rc == NGX_OK) { 686 if (rc == NGX_OK) {
671 c->node->exists = 1; 687 c->node->exists = 1;
1024 static time_t 1040 static time_t
1025 ngx_http_file_cache_manager(void *data) 1041 ngx_http_file_cache_manager(void *data)
1026 { 1042 {
1027 ngx_http_file_cache_t *cache = data; 1043 ngx_http_file_cache_t *cache = data;
1028 1044
1029 off_t size; 1045 off_t size;
1030 time_t next; 1046 time_t next;
1031 ngx_tree_ctx_t tree;
1032
1033 if (cache->sh->cold) {
1034
1035 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
1036 "http file cache manager update");
1037
1038 tree.init_handler = NULL;
1039 tree.file_handler = ngx_http_file_cache_manage_file;
1040 tree.pre_tree_handler = ngx_http_file_cache_noop;
1041 tree.post_tree_handler = ngx_http_file_cache_noop;
1042 tree.spec_handler = ngx_http_file_cache_delete_file;
1043 tree.data = cache;
1044 tree.alloc = 0;
1045 tree.log = ngx_cycle->log;
1046
1047 cache->last = ngx_current_msec;
1048 cache->files = 0;
1049
1050 if (ngx_walk_tree(&tree, &cache->path->name) == NGX_ABORT) {
1051 return 10;
1052 }
1053
1054 cache->sh->cold = 0;
1055
1056 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,
1057 "http file cache: %V %.3fM, bsize: %uz",
1058 &cache->path->name,
1059 ((double) cache->sh->size * cache->bsize) / (1024 * 1024),
1060 cache->bsize);
1061 }
1062 1047
1063 next = ngx_http_file_cache_expire(cache); 1048 next = ngx_http_file_cache_expire(cache);
1064 1049
1065 cache->last = ngx_current_msec; 1050 cache->last = ngx_current_msec;
1066 cache->files = 0; 1051 cache->files = 0;
1083 1068
1084 if (ngx_http_file_cache_manager_sleep(cache) != NGX_OK) { 1069 if (ngx_http_file_cache_manager_sleep(cache) != NGX_OK) {
1085 return next; 1070 return next;
1086 } 1071 }
1087 } 1072 }
1073 }
1074
1075
1076 static void
1077 ngx_http_file_cache_loader(void *data)
1078 {
1079 ngx_http_file_cache_t *cache = data;
1080
1081 ngx_tree_ctx_t tree;
1082
1083 if (!cache->sh->cold || cache->sh->loading) {
1084 return;
1085 }
1086
1087 if (!ngx_atomic_cmp_set(&cache->sh->loading, 0, ngx_pid)) {
1088 return;
1089 }
1090
1091 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
1092 "http file cache loader");
1093
1094 tree.init_handler = NULL;
1095 tree.file_handler = ngx_http_file_cache_manage_file;
1096 tree.pre_tree_handler = ngx_http_file_cache_noop;
1097 tree.post_tree_handler = ngx_http_file_cache_noop;
1098 tree.spec_handler = ngx_http_file_cache_delete_file;
1099 tree.data = cache;
1100 tree.alloc = 0;
1101 tree.log = ngx_cycle->log;
1102
1103 cache->last = ngx_current_msec;
1104 cache->files = 0;
1105
1106 if (ngx_walk_tree(&tree, &cache->path->name) == NGX_ABORT) {
1107 cache->sh->loading = 0;
1108 return;
1109 }
1110
1111 cache->sh->cold = 0;
1112 cache->sh->loading = 0;
1113
1114 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,
1115 "http file cache: %V %.3fM, bsize: %uz",
1116 &cache->path->name,
1117 ((double) cache->sh->size * cache->bsize) / (1024 * 1024),
1118 cache->bsize);
1088 } 1119 }
1089 1120
1090 1121
1091 static ngx_int_t 1122 static ngx_int_t
1092 ngx_http_file_cache_manager_sleep(ngx_http_file_cache_t *cache) 1123 ngx_http_file_cache_manager_sleep(ngx_http_file_cache_t *cache)
1466 &cmd->name); 1497 &cmd->name);
1467 return NGX_CONF_ERROR; 1498 return NGX_CONF_ERROR;
1468 } 1499 }
1469 1500
1470 cache->path->manager = ngx_http_file_cache_manager; 1501 cache->path->manager = ngx_http_file_cache_manager;
1502 cache->path->loader = ngx_http_file_cache_loader;
1471 cache->path->data = cache; 1503 cache->path->data = cache;
1472 1504
1473 if (ngx_add_path(cf, &cache->path) != NGX_OK) { 1505 if (ngx_add_path(cf, &cache->path) != NGX_OK) {
1474 return NGX_CONF_ERROR; 1506 return NGX_CONF_ERROR;
1475 } 1507 }