Mercurial > hg > nginx-vendor-current
comparison src/http/ngx_http_file_cache.c @ 622:8dc007eddbcf NGINX_1_0_1
nginx 1.0.1
*) Change: now the "split_clients" directive uses MurmurHash2 algorithm
because of better distribution.
Thanks to Oleg Mamontov.
*) Change: now long strings starting with zero are not considered as
false values.
Thanks to Maxim Dounin.
*) Change: now nginx uses a default listen backlog value 511 on Linux.
*) Feature: the $upstream_... variables may be used in the SSI and perl
modules.
*) Bugfix: now nginx limits better disk cache size.
Thanks to Oleg Mamontov.
*) Bugfix: a segmentation fault might occur while parsing incorrect
IPv4 address; the bug had appeared in 0.9.3.
Thanks to Maxim Dounin.
*) Bugfix: nginx could not be built by gcc 4.6 without --with-debug
option.
*) Bugfix: nginx could not be built on Solaris 9 and earlier; the bug
had appeared in 0.9.3.
Thanks to Dagobert Michelsen.
*) Bugfix: $request_time variable had invalid values if subrequests
were used; the bug had appeared in 0.8.47.
Thanks to Igor A. Valcov.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Tue, 03 May 2011 00:00:00 +0400 |
parents | b4dcae568a2a |
children | a7a5fa2e395b |
comparison
equal
deleted
inserted
replaced
621:00d13b6d4ebd | 622:8dc007eddbcf |
---|---|
347 | 347 |
348 c->file.fd = of.fd; | 348 c->file.fd = of.fd; |
349 c->file.log = r->connection->log; | 349 c->file.log = r->connection->log; |
350 c->uniq = of.uniq; | 350 c->uniq = of.uniq; |
351 c->length = of.size; | 351 c->length = of.size; |
352 c->fs_size = (of.fs_size + cache->bsize - 1) / cache->bsize; | |
352 | 353 |
353 c->buf = ngx_create_temp_buf(r->pool, c->body_start); | 354 c->buf = ngx_create_temp_buf(r->pool, c->body_start); |
354 if (c->buf == NULL) { | 355 if (c->buf == NULL) { |
355 return NGX_ERROR; | 356 return NGX_ERROR; |
356 } | 357 } |
409 c->node->uses = 1; | 410 c->node->uses = 1; |
410 c->node->body_start = c->body_start; | 411 c->node->body_start = c->body_start; |
411 c->node->exists = 1; | 412 c->node->exists = 1; |
412 c->node->uniq = c->uniq; | 413 c->node->uniq = c->uniq; |
413 | 414 |
414 cache->sh->size += (c->length + cache->bsize - 1) / cache->bsize; | 415 cache->sh->size += c->fs_size; |
415 } | 416 } |
416 | 417 |
417 ngx_shmtx_unlock(&cache->shpool->mutex); | 418 ngx_shmtx_unlock(&cache->shpool->mutex); |
418 } | 419 } |
419 | 420 |
592 fcn->error = 0; | 593 fcn->error = 0; |
593 fcn->exists = 0; | 594 fcn->exists = 0; |
594 fcn->valid_sec = 0; | 595 fcn->valid_sec = 0; |
595 fcn->uniq = 0; | 596 fcn->uniq = 0; |
596 fcn->body_start = 0; | 597 fcn->body_start = 0; |
597 fcn->length = 0; | 598 fcn->fs_size = 0; |
598 | 599 |
599 done: | 600 done: |
600 | 601 |
601 fcn->expire = ngx_time() + cache->inactive; | 602 fcn->expire = ngx_time() + cache->inactive; |
602 | 603 |
775 | 776 |
776 | 777 |
777 void | 778 void |
778 ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf) | 779 ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf) |
779 { | 780 { |
780 off_t size, length; | 781 off_t fs_size; |
781 ngx_int_t rc; | 782 ngx_int_t rc; |
782 ngx_file_uniq_t uniq; | 783 ngx_file_uniq_t uniq; |
783 ngx_file_info_t fi; | 784 ngx_file_info_t fi; |
784 ngx_http_cache_t *c; | 785 ngx_http_cache_t *c; |
785 ngx_ext_rename_file_t ext; | 786 ngx_ext_rename_file_t ext; |
798 c->updating = 0; | 799 c->updating = 0; |
799 | 800 |
800 cache = c->file_cache; | 801 cache = c->file_cache; |
801 | 802 |
802 uniq = 0; | 803 uniq = 0; |
803 length = 0; | 804 fs_size = 0; |
804 | 805 |
805 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 806 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
806 "http file cache rename: \"%s\" to \"%s\"", | 807 "http file cache rename: \"%s\" to \"%s\"", |
807 tf->file.name.data, c->file.name.data); | 808 tf->file.name.data, c->file.name.data); |
808 | 809 |
823 | 824 |
824 rc = NGX_ERROR; | 825 rc = NGX_ERROR; |
825 | 826 |
826 } else { | 827 } else { |
827 uniq = ngx_file_uniq(&fi); | 828 uniq = ngx_file_uniq(&fi); |
828 length = ngx_file_size(&fi); | 829 fs_size = (ngx_file_fs_size(&fi) + cache->bsize - 1) / cache->bsize; |
829 } | 830 } |
830 } | 831 } |
831 | |
832 size = (length + cache->bsize - 1) / cache->bsize; | |
833 | 832 |
834 ngx_shmtx_lock(&cache->shpool->mutex); | 833 ngx_shmtx_lock(&cache->shpool->mutex); |
835 | 834 |
836 c->node->count--; | 835 c->node->count--; |
837 c->node->uniq = uniq; | 836 c->node->uniq = uniq; |
838 c->node->body_start = c->body_start; | 837 c->node->body_start = c->body_start; |
839 | 838 |
840 size = size - (c->node->length + cache->bsize - 1) / cache->bsize; | 839 cache->sh->size += fs_size - c->node->fs_size; |
841 | 840 c->node->fs_size = fs_size; |
842 c->node->length = length; | |
843 | |
844 cache->sh->size += size; | |
845 | 841 |
846 if (rc == NGX_OK) { | 842 if (rc == NGX_OK) { |
847 c->node->exists = 1; | 843 c->node->exists = 1; |
848 } | 844 } |
849 | 845 |
1146 ngx_http_file_cache_node_t *fcn; | 1142 ngx_http_file_cache_node_t *fcn; |
1147 | 1143 |
1148 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue); | 1144 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue); |
1149 | 1145 |
1150 if (fcn->exists) { | 1146 if (fcn->exists) { |
1151 cache->sh->size -= (fcn->length + cache->bsize - 1) / cache->bsize; | 1147 cache->sh->size -= fcn->fs_size; |
1152 | 1148 |
1153 path = cache->path; | 1149 path = cache->path; |
1154 p = name + path->name.len + 1 + path->len; | 1150 p = name + path->name.len + 1 + path->len; |
1155 p = ngx_hex_dump(p, (u_char *) &fcn->node.key, | 1151 p = ngx_hex_dump(p, (u_char *) &fcn->node.key, |
1156 sizeof(ngx_rbtree_key_t)); | 1152 sizeof(ngx_rbtree_key_t)); |
1369 ngx_log_error(NGX_LOG_CRIT, ctx->log, 0, | 1365 ngx_log_error(NGX_LOG_CRIT, ctx->log, 0, |
1370 "cache file \"%s\" is too small", name->data); | 1366 "cache file \"%s\" is too small", name->data); |
1371 return NGX_ERROR; | 1367 return NGX_ERROR; |
1372 } | 1368 } |
1373 | 1369 |
1370 cache = ctx->data; | |
1371 | |
1374 if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) { | 1372 if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) { |
1375 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, | 1373 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, |
1376 ngx_fd_info_n " \"%s\" failed", name->data); | 1374 ngx_fd_info_n " \"%s\" failed", name->data); |
1377 | 1375 |
1378 } else { | 1376 } else { |
1379 c.uniq = ngx_file_uniq(&fi); | 1377 c.uniq = ngx_file_uniq(&fi); |
1380 c.valid_sec = h.valid_sec; | 1378 c.valid_sec = h.valid_sec; |
1381 c.valid_msec = h.valid_msec; | 1379 c.valid_msec = h.valid_msec; |
1382 c.body_start = h.body_start; | 1380 c.body_start = h.body_start; |
1383 c.length = ngx_file_size(&fi); | 1381 c.length = ngx_file_size(&fi); |
1382 c.fs_size = (ngx_file_fs_size(&fi) + cache->bsize - 1) / cache->bsize; | |
1384 } | 1383 } |
1385 | 1384 |
1386 if (ngx_close_file(fd) == NGX_FILE_ERROR) { | 1385 if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
1387 ngx_log_error(NGX_LOG_ALERT, ctx->log, ngx_errno, | 1386 ngx_log_error(NGX_LOG_ALERT, ctx->log, ngx_errno, |
1388 ngx_close_file_n " \"%s\" failed", name->data); | 1387 ngx_close_file_n " \"%s\" failed", name->data); |
1403 | 1402 |
1404 p += 2; | 1403 p += 2; |
1405 | 1404 |
1406 c.key[i] = (u_char) n; | 1405 c.key[i] = (u_char) n; |
1407 } | 1406 } |
1408 | |
1409 cache = ctx->data; | |
1410 | 1407 |
1411 return ngx_http_file_cache_add(cache, &c); | 1408 return ngx_http_file_cache_add(cache, &c); |
1412 } | 1409 } |
1413 | 1410 |
1414 | 1411 |
1445 fcn->updating = 0; | 1442 fcn->updating = 0; |
1446 fcn->deleting = 0; | 1443 fcn->deleting = 0; |
1447 fcn->uniq = c->uniq; | 1444 fcn->uniq = c->uniq; |
1448 fcn->valid_sec = c->valid_sec; | 1445 fcn->valid_sec = c->valid_sec; |
1449 fcn->body_start = c->body_start; | 1446 fcn->body_start = c->body_start; |
1450 fcn->length = c->length; | 1447 fcn->fs_size = c->fs_size; |
1451 | 1448 |
1452 cache->sh->size += (c->length + cache->bsize - 1) / cache->bsize; | 1449 cache->sh->size += c->fs_size; |
1453 | 1450 |
1454 } else { | 1451 } else { |
1455 ngx_queue_remove(&fcn->queue); | 1452 ngx_queue_remove(&fcn->queue); |
1456 } | 1453 } |
1457 | 1454 |