Welcome! Log In Create A New Profile

Advanced

[PATCH 05 of 15] http upstream & file_cache: store temp file number and length in tf_node

Jiří Setnička via nginx-devel
January 28, 2022 11:46AM
# HG changeset patch
# User Jiří Setnička <jiri.setnicka@cdn77.com>
# Date 1643385660 -3600
# Fri Jan 28 17:01:00 2022 +0100
# Node ID 76c1a836b1de47cb16b636b585526e25574e0f58
# Parent 2488cf77a1cc6c7f48696816f085c71e49355b72
http upstream & file_cache: store temp file number and length in tf_node
Number could be used to construct name of the tempfile, length is used
by secondary requests to read the tempfile.

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
@@ -59,6 +59,7 @@ typedef struct {
size_t body_start;
off_t fs_size;
ngx_msec_t lock_time;
+ uint32_t tf_number; /* 0 = no temp file exists */
} ngx_http_file_cache_node_t;

typedef struct {
@@ -211,6 +212,8 @@ struct ngx_http_file_cache_s {
ngx_int_t ngx_http_file_cache_new(ngx_http_request_t *r);
ngx_int_t ngx_http_file_cache_create(ngx_http_request_t *r);
void ngx_http_file_cache_create_key(ngx_http_request_t *r);
+void ngx_http_file_cache_update_tf(ngx_http_request_t *r,
+ ngx_http_cache_t *c, uint32_t tf_number, off_t length);
ngx_int_t ngx_http_file_cache_open(ngx_http_request_t *r);
ngx_int_t ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf);
void ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf);
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
@@ -319,6 +319,45 @@ ngx_http_file_cache_create_key(ngx_http_
ngx_memcpy(c->main, c->key, NGX_HTTP_CACHE_KEY_LEN);
}

+void
+ngx_http_file_cache_update_tf(ngx_http_request_t *r, ngx_http_cache_t *c,
+ uint32_t tf_number, off_t length)
+{
+ ngx_http_file_cache_t *cache;
+
+ if (!c->node) {
+ return;
+ }
+
+ cache = c->file_cache;
+
+ ngx_shmtx_lock(&cache->shpool->mutex);
+
+ if (c->tf_node == NULL) {
+ c->node->tf_number = tf_number;
+ c->tf_node = ngx_slab_calloc_locked(cache->tf_shpool,
+ sizeof(ngx_http_file_cache_tf_node_t));
+ if (c->tf_node == NULL) {
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
+ "could not allocate tf node%s", cache->shpool->log_ctx);
+ return;
+ }
+
+ cache->tf_sh->count++;
+
+ c->tf_node->node.key = tf_number;
+
+ ngx_rbtree_insert(&cache->tf_sh->rbtree, &c->tf_node->node);
+
+ c->tf_node->updated = 0;
+ c->tf_node->count = 1;
+ }
+
+ c->tf_node->length = length;
+
+ ngx_shmtx_unlock(&cache->shpool->mutex);
+}
+

ngx_int_t
ngx_http_file_cache_open(ngx_http_request_t *r)
@@ -971,6 +1010,7 @@ renew:
fcn->uniq = 0;
fcn->body_start = 0;
fcn->fs_size = 0;
+ fcn->tf_number = 0;

done:

@@ -1547,6 +1587,7 @@ ngx_http_file_cache_update(ngx_http_requ
}

c->node->updating = 0;
+ c->node->tf_number = 0;

ngx_shmtx_unlock(&cache->shpool->mutex);
}
@@ -1759,6 +1800,7 @@ ngx_http_file_cache_free(ngx_http_cache_

if (c->updating && fcn->lock_time == c->lock_time) {
fcn->updating = 0;
+ fcn->tf_number = 0;
}

if (c->tf_node != NULL) {
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -4069,6 +4069,14 @@ ngx_http_upstream_process_upstream(ngx_h
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
return;
}
+
+#if (NGX_HTTP_CACHE)
+ if (u->cacheable && r->cache) {
+ ngx_http_file_cache_update_tf(r, r->cache,
+ p->temp_file->suffix_number,
+ p->temp_file->offset);
+ }
+#endif
}

ngx_http_upstream_process_request(r, u);
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[PATCH 00 of 15] Serve all requests from single tempfile

Jiří Setnička via nginx-devel 468 January 28, 2022 11:36AM

[PATCH 01 of 15] ngx core - obtain number appended to the temp file name

Jiří Setnička via nginx-devel 133 January 28, 2022 11:38AM

[PATCH 02 of 15] ngx core - ensure that tempfile number never be 0

Jiří Setnička via nginx-devel 141 January 28, 2022 11:40AM

[PATCH 03 of 15] Cache: Shared memory for tempfile nodes

Jiří Setnička via nginx-devel 280 January 28, 2022 11:42AM

[PATCH 04 of 15] Cache: tf_node for tracking opened tempfile

Jiří Setnička via nginx-devel 130 January 28, 2022 11:44AM

[PATCH 05 of 15] http upstream & file_cache: store temp file number and length in tf_node

Jiří Setnička via nginx-devel 141 January 28, 2022 11:46AM

[PATCH 07 of 15] Tempfiles: Wait handlers

Jiří Setnička via nginx-devel 122 January 28, 2022 11:48AM

[PATCH 06 of 15] Configuration for tempfiles serving

Jiří Setnička via nginx-devel 163 January 28, 2022 11:50AM

[PATCH 09 of 15] Tempfiles: Sending data from tempfile

Jiří Setnička via nginx-devel 127 January 28, 2022 11:52AM

[PATCH 08 of 15] Tempfiles: Mechanism of opening tempfiles used for serving paralell requests

Jiří Setnička via nginx-devel 131 January 28, 2022 11:54AM

[PATCH 10 of 15] Tempfiles: Setup event handlers in ngx_http_upstream.c

Jiří Setnička via nginx-devel 143 January 28, 2022 11:56AM

[PATCH 11 of 15] Tempfiles: reset c->body_start when updating a tempfile

Jiří Setnička via nginx-devel 149 January 28, 2022 11:58AM

[PATCH 12 of 15] Tempfiles: Expired tempfiles

Jiří Setnička via nginx-devel 153 January 28, 2022 12:00PM

[PATCH 13 of 15] Tempfiles: Skip cached file if there is already newer tempfile

Jiří Setnička via nginx-devel 248 January 28, 2022 12:02PM

Re: [PATCH 13 of 15] Tempfiles: Skip cached file if there is already newer tempfile

Vadim Fedorenko 151 January 30, 2022 07:38PM

Re: [PATCH 13 of 15] Tempfiles: Skip cached file if there is already newer tempfile

Jiří Setnička via nginx-devel 142 February 07, 2022 06:22AM

[PATCH 14 of 15] Tempfiles: Set send_timeout inside ngx_http_cache_send

Jiří Setnička via nginx-devel 158 January 28, 2022 12:04PM

[PATCH 15 of 15] Use cache status UPDATING when serving from tempfile

Jiří Setnička via nginx-devel 131 January 28, 2022 12:06PM

Re: [PATCH 00 of 15] Serve all requests from single tempfile

Jiří Setnička via nginx-devel 127 February 07, 2022 06:18AM

Re: [PATCH 00 of 15] Serve all requests from single tempfile

Roman Arutyunyan 143 February 07, 2022 06:32AM

Re: [PATCH 00 of 15] Serve all requests from single tempfile

Jiří Setnička via nginx-devel 165 February 07, 2022 07:30AM

Re: [PATCH 00 of 15] Serve all requests from single tempfile

Roman Arutyunyan 180 February 08, 2022 06:20AM



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

Online Users

Guests: 274
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready