Mercurial > hg > nginx
comparison src/http/ngx_http_file_cache.c @ 3726:282ddd49f925
*) delete cache key node after a cache file removal
*) move fileless cache key node removal in ngx_http_file_cache_delete()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 02 Aug 2010 12:27:58 +0000 |
parents | e9f0a2497d3c |
children | fd2bb219de22 |
comparison
equal
deleted
inserted
replaced
3725:4954530db2af | 3726:282ddd49f925 |
---|---|
1031 wait = 1; | 1031 wait = 1; |
1032 | 1032 |
1033 break; | 1033 break; |
1034 } | 1034 } |
1035 | 1035 |
1036 if (!fcn->exists) { | |
1037 | |
1038 ngx_queue_remove(q); | |
1039 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node); | |
1040 ngx_slab_free_locked(cache->shpool, fcn); | |
1041 | |
1042 break; | |
1043 } | |
1044 | |
1045 ngx_http_file_cache_delete(cache, q, name); | 1036 ngx_http_file_cache_delete(cache, q, name); |
1046 | 1037 |
1047 break; | 1038 break; |
1048 } | 1039 } |
1049 | 1040 |
1129 2 * NGX_HTTP_CACHE_KEY_LEN, key, fcn->count); | 1120 2 * NGX_HTTP_CACHE_KEY_LEN, key, fcn->count); |
1130 | 1121 |
1131 continue; | 1122 continue; |
1132 } | 1123 } |
1133 | 1124 |
1134 if (!fcn->exists) { | |
1135 | |
1136 ngx_queue_remove(q); | |
1137 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node); | |
1138 ngx_slab_free_locked(cache->shpool, fcn); | |
1139 | |
1140 continue; | |
1141 } | |
1142 | |
1143 ngx_http_file_cache_delete(cache, q, name); | 1125 ngx_http_file_cache_delete(cache, q, name); |
1144 } | 1126 } |
1145 | 1127 |
1146 ngx_shmtx_unlock(&cache->shpool->mutex); | 1128 ngx_shmtx_unlock(&cache->shpool->mutex); |
1147 | 1129 |
1160 ngx_path_t *path; | 1142 ngx_path_t *path; |
1161 ngx_http_file_cache_node_t *fcn; | 1143 ngx_http_file_cache_node_t *fcn; |
1162 | 1144 |
1163 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue); | 1145 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue); |
1164 | 1146 |
1165 cache->sh->size -= (fcn->length + cache->bsize - 1) / cache->bsize; | 1147 if (fcn->exists) { |
1166 | 1148 cache->sh->size -= (fcn->length + cache->bsize - 1) / cache->bsize; |
1167 path = cache->path; | 1149 |
1168 | 1150 path = cache->path; |
1169 p = name + path->name.len + 1 + path->len; | 1151 p = name + path->name.len + 1 + path->len; |
1170 | 1152 p = ngx_hex_dump(p, (u_char *) &fcn->node.key, |
1171 p = ngx_hex_dump(p, (u_char *) &fcn->node.key, sizeof(ngx_rbtree_key_t)); | 1153 sizeof(ngx_rbtree_key_t)); |
1172 | 1154 len = NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t); |
1173 len = NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t); | 1155 p = ngx_hex_dump(p, fcn->key, len); |
1174 p = ngx_hex_dump(p, fcn->key, len); | 1156 *p = '\0'; |
1175 *p = '\0'; | 1157 |
1176 | 1158 fcn->count++; |
1177 ngx_queue_remove(q); | 1159 ngx_shmtx_unlock(&cache->shpool->mutex); |
1178 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node); | 1160 |
1179 ngx_slab_free_locked(cache->shpool, fcn); | 1161 len = path->name.len + 1 + path->len + 2 * NGX_HTTP_CACHE_KEY_LEN; |
1180 | 1162 ngx_create_hashed_filename(path, name, len); |
1181 ngx_shmtx_unlock(&cache->shpool->mutex); | 1163 |
1182 | 1164 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, |
1183 len = path->name.len + 1 + path->len + 2 * NGX_HTTP_CACHE_KEY_LEN; | 1165 "http file cache expire: \"%s\"", name); |
1184 | 1166 |
1185 ngx_create_hashed_filename(path, name, len); | 1167 if (ngx_delete_file(name) == NGX_FILE_ERROR) { |
1186 | 1168 ngx_log_error(NGX_LOG_CRIT, ngx_cycle->log, ngx_errno, |
1187 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, | 1169 ngx_delete_file_n " \"%s\" failed", name); |
1188 "http file cache expire: \"%s\"", name); | 1170 } |
1189 | 1171 |
1190 if (ngx_delete_file(name) == NGX_FILE_ERROR) { | 1172 ngx_shmtx_lock(&cache->shpool->mutex); |
1191 ngx_log_error(NGX_LOG_CRIT, ngx_cycle->log, ngx_errno, | 1173 fcn->count--; |
1192 ngx_delete_file_n " \"%s\" failed", name); | 1174 } |
1193 } | 1175 |
1194 | 1176 if (fcn->count == 0) { |
1195 ngx_shmtx_lock(&cache->shpool->mutex); | 1177 ngx_queue_remove(q); |
1178 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node); | |
1179 ngx_slab_free_locked(cache->shpool, fcn); | |
1180 } | |
1196 } | 1181 } |
1197 | 1182 |
1198 | 1183 |
1199 static time_t | 1184 static time_t |
1200 ngx_http_file_cache_manager(void *data) | 1185 ngx_http_file_cache_manager(void *data) |