comparison src/http/ngx_http_file_cache.c @ 590:cde3626b2d0d NGINX_0_8_47

nginx 0.8.47 *) Bugfix: $request_time variable had invalid values for subrequests. *) Bugfix: errors intercepted by error_page could be cached. *) Bugfix: a cache manager process my got caught in an endless loop, if max_size parameter was used; the bug had appeared in 0.8.46.
author Igor Sysoev <http://sysoev.ru>
date Wed, 28 Jul 2010 00:00:00 +0400
parents b6a5942a4e6a
children 09d5f308901f
comparison
equal deleted inserted replaced
589:5de4f69bbbab 590:cde3626b2d0d
159 return NGX_ERROR; 159 return NGX_ERROR;
160 } 160 }
161 161
162 r->cache = c; 162 r->cache = c;
163 c->file.log = r->connection->log; 163 c->file.log = r->connection->log;
164 c->file.fd = NGX_INVALID_FILE;
164 165
165 return NGX_OK; 166 return NGX_OK;
166 } 167 }
167 168
168 169
427 if (c->node->updating) { 428 if (c->node->updating) {
428 rc = NGX_HTTP_CACHE_UPDATING; 429 rc = NGX_HTTP_CACHE_UPDATING;
429 430
430 } else { 431 } else {
431 c->node->updating = 1; 432 c->node->updating = 1;
433 c->updating = 1;
432 rc = NGX_HTTP_CACHE_STALE; 434 rc = NGX_HTTP_CACHE_STALE;
433 } 435 }
434 436
435 ngx_shmtx_unlock(&cache->shpool->mutex); 437 ngx_shmtx_unlock(&cache->shpool->mutex);
436 438
790 792
791 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 793 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
792 "http file cache update"); 794 "http file cache update");
793 795
794 c->updated = 1; 796 c->updated = 1;
797 c->updating = 0;
795 798
796 cache = c->file_cache; 799 cache = c->file_cache;
797 800
798 uniq = 0; 801 uniq = 0;
799 length = 0; 802 length = 0;
899 return ngx_http_output_filter(r, &out); 902 return ngx_http_output_filter(r, &out);
900 } 903 }
901 904
902 905
903 void 906 void
904 ngx_http_file_cache_free(ngx_http_request_t *r, ngx_temp_file_t *tf) 907 ngx_http_file_cache_free(ngx_http_cache_t *c, ngx_temp_file_t *tf)
905 { 908 {
906 ngx_http_cache_t *c;
907 ngx_http_file_cache_t *cache; 909 ngx_http_file_cache_t *cache;
908 ngx_http_file_cache_node_t *fcn; 910 ngx_http_file_cache_node_t *fcn;
909 911
910 c = r->cache;
911
912 if (c->updated) { 912 if (c->updated) {
913 return; 913 return;
914 } 914 }
915 915
916 c->updated = 1;
917
918 cache = c->file_cache; 916 cache = c->file_cache;
919 917
920 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 918 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->file.log, 0,
921 "http file cache free"); 919 "http file cache free, fd: %d", c->file.fd);
922 920
923 ngx_shmtx_lock(&cache->shpool->mutex); 921 ngx_shmtx_lock(&cache->shpool->mutex);
924 922
925 fcn = c->node; 923 fcn = c->node;
926 fcn->count--; 924 fcn->count--;
927 fcn->updating = 0; 925
926 if (c->updating) {
927 fcn->updating = 0;
928 }
928 929
929 if (c->error) { 930 if (c->error) {
930 fcn->valid_sec = c->valid_sec; 931 fcn->valid_sec = c->valid_sec;
931 fcn->valid_msec = c->valid_msec; 932 fcn->valid_msec = c->valid_msec;
932 fcn->error = c->error; 933 fcn->error = c->error;
933 934
934 } else if (fcn->valid_msec == 0 && fcn->count == 0) { 935 } else if (!fcn->exists && fcn->count == 0) {
935 ngx_queue_remove(&fcn->queue); 936 ngx_queue_remove(&fcn->queue);
936 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node); 937 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
937 ngx_slab_free_locked(cache->shpool, fcn); 938 ngx_slab_free_locked(cache->shpool, fcn);
938 c->node = NULL; 939 c->node = NULL;
939 } 940 }
940 941
941 ngx_shmtx_unlock(&cache->shpool->mutex); 942 ngx_shmtx_unlock(&cache->shpool->mutex);
942 943
944 c->updated = 1;
945 c->updating = 0;
946
943 if (c->temp_file) { 947 if (c->temp_file) {
944 if (tf && tf->file.fd != NGX_INVALID_FILE) { 948 if (tf && tf->file.fd != NGX_INVALID_FILE) {
945 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 949 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->file.log, 0,
946 "http file cache incomplete: \"%s\"", 950 "http file cache incomplete: \"%s\"",
947 tf->file.name.data); 951 tf->file.name.data);
948 952
949 if (ngx_delete_file(tf->file.name.data) == NGX_FILE_ERROR) { 953 if (ngx_delete_file(tf->file.name.data) == NGX_FILE_ERROR) {
950 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, 954 ngx_log_error(NGX_LOG_CRIT, c->file.log, ngx_errno,
951 ngx_delete_file_n " \"%s\" failed", 955 ngx_delete_file_n " \"%s\" failed",
952 tf->file.name.data); 956 tf->file.name.data);
953 } 957 }
954 } 958 }
955 } 959 }
959 static void 963 static void
960 ngx_http_file_cache_cleanup(void *data) 964 ngx_http_file_cache_cleanup(void *data)
961 { 965 {
962 ngx_http_cache_t *c = data; 966 ngx_http_cache_t *c = data;
963 967
964 ngx_http_file_cache_t *cache;
965
966 if (c->updated) { 968 if (c->updated) {
967 return; 969 return;
968 } 970 }
969 971
970 c->updated = 1;
971
972 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->file.log, 0, 972 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->file.log, 0,
973 "http file cache cleanup"); 973 "http file cache cleanup");
974 974
975 if (c->error) { 975 if (c->updating) {
976 return; 976 ngx_log_error(NGX_LOG_ALERT, c->file.log, 0,
977 } 977 "stalled cache updating, error:%ui", c->error);
978 978 }
979 cache = c->file_cache; 979
980 980 ngx_http_file_cache_free(c, NULL);
981 ngx_shmtx_lock(&cache->shpool->mutex);
982
983 c->node->count--;
984
985 ngx_shmtx_unlock(&cache->shpool->mutex);
986 } 981 }
987 982
988 983
989 static time_t 984 static time_t
990 ngx_http_file_cache_forced_expire(ngx_http_file_cache_t *cache) 985 ngx_http_file_cache_forced_expire(ngx_http_file_cache_t *cache)