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:
Remi Tricot-Le Breton 2023-11-16 17:38:18 +01:00 committed by William Lallemand
parent 0dfb57bbf9
commit bd24118212

View File

@ -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);
shctx_lock(shctx_ptr(cache));
cache_wrlock(cache);
cache_rdlock(cache);
res = entry_exist(cache, s->txn->cache_hash, 0);
/* 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
@ -1860,7 +1860,7 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p
struct appctx *appctx;
entry_block = block_ptr(res);
shctx_row_inc_hot(shctx_ptr(cache), entry_block);
cache_wrunlock(cache);
cache_rdunlock(cache);
shctx_unlock(shctx_ptr(cache));
/* 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 (!http_request_build_secondary_key(s, res->secondary_key_signature)) {
shctx_lock(shctx_ptr(cache));
cache_wrlock(cache);
cache_rdlock(cache);
sec_entry = secondary_entry_exist(cache, res,
s->txn->cache_secondary_hash, 0);
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);
}
res = sec_entry;
cache_wrunlock(cache);
cache_rdunlock(cache);
shctx_unlock(shctx_ptr(cache));
}
else
@ -1922,7 +1922,7 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p
return ACT_RET_CONT;
}
}
cache_wrunlock(cache);
cache_rdunlock(cache);
shctx_unlock(shctx_ptr(cache));
/* Shared context does not need to be locked while we calculate the