mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 15:47:01 +02:00
MEDIUM: cache: Use rdlock on cache in cache_use
When looking for a valid entry in the cache tree in http_action_req_cache_use, we do not need to delete an expired entry at once because even if an expired entry exists, since the request will be forwarded to the server, then the expired entry will be overwritten when the updated response is seen. We can then use a simpler rdlock during cache_use operation.
This commit is contained in:
parent
0dfb57bbf9
commit
bd24118212
10
src/cache.c
10
src/cache.c
@ -1851,7 +1851,7 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p
|
|||||||
_HA_ATOMIC_INC(&px->be_counters.p.http.cache_lookups);
|
_HA_ATOMIC_INC(&px->be_counters.p.http.cache_lookups);
|
||||||
|
|
||||||
shctx_lock(shctx_ptr(cache));
|
shctx_lock(shctx_ptr(cache));
|
||||||
cache_wrlock(cache);
|
cache_rdlock(cache);
|
||||||
res = entry_exist(cache, s->txn->cache_hash, 0);
|
res = entry_exist(cache, s->txn->cache_hash, 0);
|
||||||
/* We must not use an entry that is not complete but the check will be
|
/* We must not use an entry that is not complete but the check will be
|
||||||
* performed after we look for a potential secondary entry (in case of
|
* performed after we look for a potential secondary entry (in case of
|
||||||
@ -1860,7 +1860,7 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p
|
|||||||
struct appctx *appctx;
|
struct appctx *appctx;
|
||||||
entry_block = block_ptr(res);
|
entry_block = block_ptr(res);
|
||||||
shctx_row_inc_hot(shctx_ptr(cache), entry_block);
|
shctx_row_inc_hot(shctx_ptr(cache), entry_block);
|
||||||
cache_wrunlock(cache);
|
cache_rdunlock(cache);
|
||||||
shctx_unlock(shctx_ptr(cache));
|
shctx_unlock(shctx_ptr(cache));
|
||||||
|
|
||||||
/* In case of Vary, we could have multiple entries with the same
|
/* In case of Vary, we could have multiple entries with the same
|
||||||
@ -1869,7 +1869,7 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p
|
|||||||
if (res->secondary_key_signature) {
|
if (res->secondary_key_signature) {
|
||||||
if (!http_request_build_secondary_key(s, res->secondary_key_signature)) {
|
if (!http_request_build_secondary_key(s, res->secondary_key_signature)) {
|
||||||
shctx_lock(shctx_ptr(cache));
|
shctx_lock(shctx_ptr(cache));
|
||||||
cache_wrlock(cache);
|
cache_rdlock(cache);
|
||||||
sec_entry = secondary_entry_exist(cache, res,
|
sec_entry = secondary_entry_exist(cache, res,
|
||||||
s->txn->cache_secondary_hash, 0);
|
s->txn->cache_secondary_hash, 0);
|
||||||
if (sec_entry && sec_entry != res) {
|
if (sec_entry && sec_entry != res) {
|
||||||
@ -1879,7 +1879,7 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p
|
|||||||
shctx_row_inc_hot(shctx_ptr(cache), entry_block);
|
shctx_row_inc_hot(shctx_ptr(cache), entry_block);
|
||||||
}
|
}
|
||||||
res = sec_entry;
|
res = sec_entry;
|
||||||
cache_wrunlock(cache);
|
cache_rdunlock(cache);
|
||||||
shctx_unlock(shctx_ptr(cache));
|
shctx_unlock(shctx_ptr(cache));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1922,7 +1922,7 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p
|
|||||||
return ACT_RET_CONT;
|
return ACT_RET_CONT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cache_wrunlock(cache);
|
cache_rdunlock(cache);
|
||||||
shctx_unlock(shctx_ptr(cache));
|
shctx_unlock(shctx_ptr(cache));
|
||||||
|
|
||||||
/* Shared context does not need to be locked while we calculate the
|
/* Shared context does not need to be locked while we calculate the
|
||||||
|
Loading…
Reference in New Issue
Block a user