Maxim Dounin
June 25, 2014 06:42PM
details: http://hg.nginx.org/nginx/rev/2fe1967f8854
branches:
changeset: 5736:2fe1967f8854
user: Maxim Dounin <mdounin@mdounin.ru>
date: Thu Jun 26 02:27:21 2014 +0400
description:
Cache: version in cache files.

This allows to change the structure of cache files without spamming logs
with false alerts.

diffstat:

src/http/ngx_http_cache.h | 3 +++
src/http/ngx_http_file_cache.c | 11 ++++++++++-
2 files changed, 13 insertions(+), 1 deletions(-)

diffs (62 lines):

diff --git a/src/http/ngx_http_cache.h b/src/http/ngx_http_cache.h
--- a/src/http/ngx_http_cache.h
+++ b/src/http/ngx_http_cache.h
@@ -25,6 +25,8 @@

#define NGX_HTTP_CACHE_KEY_LEN 16

+#define NGX_HTTP_CACHE_VERSION 1
+

typedef struct {
ngx_uint_t status;
@@ -97,6 +99,7 @@ struct ngx_http_cache_s {


typedef struct {
+ ngx_uint_t version;
time_t valid_sec;
time_t last_modified;
time_t date;
diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -498,6 +498,12 @@ ngx_http_file_cache_read(ngx_http_reques

h = (ngx_http_file_cache_header_t *) c->buf->pos;

+ if (h->version != NGX_HTTP_CACHE_VERSION) {
+ ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+ "cache file \"%s\" version mismatch", c->file.name.data);
+ return NGX_DECLINED;
+ }
+
if (h->crc32 != c->crc32) {
ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
"cache file \"%s\" has md5 collision", c->file.name.data);
@@ -875,6 +881,7 @@ ngx_http_file_cache_set_header(ngx_http_

ngx_memzero(h, sizeof(ngx_http_file_cache_header_t));

+ h->version = NGX_HTTP_CACHE_VERSION;
h->valid_sec = c->valid_sec;
h->last_modified = c->last_modified;
h->date = c->date;
@@ -1042,7 +1049,8 @@ ngx_http_file_cache_update_header(ngx_ht
goto done;
}

- if (h.last_modified != c->last_modified
+ if (h.version != NGX_HTTP_CACHE_VERSION
+ || h.last_modified != c->last_modified
|| h.crc32 != c->crc32
|| h.header_start != c->header_start
|| h.body_start != c->body_start)
@@ -1060,6 +1068,7 @@ ngx_http_file_cache_update_header(ngx_ht

ngx_memzero(&h, sizeof(ngx_http_file_cache_header_t));

+ h.version = NGX_HTTP_CACHE_VERSION;
h.valid_sec = c->valid_sec;
h.last_modified = c->last_modified;
h.date = c->date;

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Cache: version in cache files.

Maxim Dounin 796 June 25, 2014 06:42PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 302
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready