Mercurial > hg > nginx-quic
comparison src/http/ngx_http_file_cache.c @ 3711:ce6ba077c270
several changes in cache cleanup handling:
*) now ngx_http_file_cache_cleanup() uses ngx_http_file_cache_free()
*) ngx_http_file_cache_free() interface has been changed to accept r->cache
ngx_http_file_cache_cleanup() must use r->cache, but not r, because
there can be several r->cache's during request processing, r->cache may
be NULL at request finalising, etc.
*) test if updating request does not complete correctly
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 28 Jul 2010 15:49:34 +0000 |
parents | 5f63b6ab4d4b |
children | f0b62d1ac7af |
comparison
equal
deleted
inserted
replaced
3710:5f63b6ab4d4b | 3711:ce6ba077c270 |
---|---|
428 if (c->node->updating) { | 428 if (c->node->updating) { |
429 rc = NGX_HTTP_CACHE_UPDATING; | 429 rc = NGX_HTTP_CACHE_UPDATING; |
430 | 430 |
431 } else { | 431 } else { |
432 c->node->updating = 1; | 432 c->node->updating = 1; |
433 c->updating = 1; | |
433 rc = NGX_HTTP_CACHE_STALE; | 434 rc = NGX_HTTP_CACHE_STALE; |
434 } | 435 } |
435 | 436 |
436 ngx_shmtx_unlock(&cache->shpool->mutex); | 437 ngx_shmtx_unlock(&cache->shpool->mutex); |
437 | 438 |
791 | 792 |
792 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 793 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
793 "http file cache update"); | 794 "http file cache update"); |
794 | 795 |
795 c->updated = 1; | 796 c->updated = 1; |
797 c->updating = 0; | |
796 | 798 |
797 cache = c->file_cache; | 799 cache = c->file_cache; |
798 | 800 |
799 uniq = 0; | 801 uniq = 0; |
800 length = 0; | 802 length = 0; |
900 return ngx_http_output_filter(r, &out); | 902 return ngx_http_output_filter(r, &out); |
901 } | 903 } |
902 | 904 |
903 | 905 |
904 void | 906 void |
905 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) |
906 { | 908 { |
907 ngx_http_cache_t *c; | |
908 ngx_http_file_cache_t *cache; | 909 ngx_http_file_cache_t *cache; |
909 ngx_http_file_cache_node_t *fcn; | 910 ngx_http_file_cache_node_t *fcn; |
910 | 911 |
911 c = r->cache; | |
912 | |
913 if (c->updated) { | 912 if (c->updated) { |
914 return; | 913 return; |
915 } | 914 } |
916 | 915 |
917 c->updated = 1; | |
918 | |
919 cache = c->file_cache; | 916 cache = c->file_cache; |
920 | 917 |
921 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 918 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->file.log, 0, |
922 "http file cache free"); | 919 "http file cache free"); |
923 | 920 |
924 ngx_shmtx_lock(&cache->shpool->mutex); | 921 ngx_shmtx_lock(&cache->shpool->mutex); |
925 | 922 |
926 fcn = c->node; | 923 fcn = c->node; |
927 fcn->count--; | 924 fcn->count--; |
928 fcn->updating = 0; | 925 |
926 if (c->updating) { | |
927 fcn->updating = 0; | |
928 } | |
929 | 929 |
930 if (c->error) { | 930 if (c->error) { |
931 fcn->valid_sec = c->valid_sec; | 931 fcn->valid_sec = c->valid_sec; |
932 fcn->valid_msec = c->valid_msec; | 932 fcn->valid_msec = c->valid_msec; |
933 fcn->error = c->error; | 933 fcn->error = c->error; |
939 c->node = NULL; | 939 c->node = NULL; |
940 } | 940 } |
941 | 941 |
942 ngx_shmtx_unlock(&cache->shpool->mutex); | 942 ngx_shmtx_unlock(&cache->shpool->mutex); |
943 | 943 |
944 c->updated = 1; | |
945 c->updating = 0; | |
946 | |
944 if (c->temp_file) { | 947 if (c->temp_file) { |
945 if (tf && tf->file.fd != NGX_INVALID_FILE) { | 948 if (tf && tf->file.fd != NGX_INVALID_FILE) { |
946 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 949 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->file.log, 0, |
947 "http file cache incomplete: \"%s\"", | 950 "http file cache incomplete: \"%s\"", |
948 tf->file.name.data); | 951 tf->file.name.data); |
949 | 952 |
950 if (ngx_delete_file(tf->file.name.data) == NGX_FILE_ERROR) { | 953 if (ngx_delete_file(tf->file.name.data) == NGX_FILE_ERROR) { |
951 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, | 954 ngx_log_error(NGX_LOG_CRIT, c->file.log, ngx_errno, |
952 ngx_delete_file_n " \"%s\" failed", | 955 ngx_delete_file_n " \"%s\" failed", |
953 tf->file.name.data); | 956 tf->file.name.data); |
954 } | 957 } |
955 } | 958 } |
956 } | 959 } |
960 static void | 963 static void |
961 ngx_http_file_cache_cleanup(void *data) | 964 ngx_http_file_cache_cleanup(void *data) |
962 { | 965 { |
963 ngx_http_cache_t *c = data; | 966 ngx_http_cache_t *c = data; |
964 | 967 |
965 ngx_http_file_cache_t *cache; | |
966 | |
967 if (c->updated) { | 968 if (c->updated) { |
968 return; | 969 return; |
969 } | 970 } |
970 | 971 |
971 c->updated = 1; | |
972 | |
973 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->file.log, 0, | 972 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->file.log, 0, |
974 "http file cache cleanup"); | 973 "http file cache cleanup"); |
975 | 974 |
976 if (c->error) { | 975 if (c->updating) { |
977 return; | 976 ngx_log_error(NGX_LOG_ALERT, c->file.log, 0, |
978 } | 977 "stalled cache updating, error:%ui", c->error); |
979 | 978 } |
980 cache = c->file_cache; | 979 |
981 | 980 ngx_http_file_cache_free(c, NULL); |
982 ngx_shmtx_lock(&cache->shpool->mutex); | |
983 | |
984 c->node->count--; | |
985 | |
986 ngx_shmtx_unlock(&cache->shpool->mutex); | |
987 } | 981 } |
988 | 982 |
989 | 983 |
990 static time_t | 984 static time_t |
991 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) |