Skip to content

Commit 0da7483

Browse files
authored
Fix Cache Result Code of negative revalidation cases (#12824) (#12831)
* Add %<crc> logging verification to the negative revalidating AuTest * Fix crc for stale-if-error * Fix for conditional request Conflicts: src/proxy/http/HttpTransactHeaders.cc tests/gold_tests/autest-site/ats_replay.test.ext tests/gold_tests/cache/replay/negative-revalidating-enabled.replay.yaml
1 parent 914651f commit 0da7483

5 files changed

Lines changed: 89 additions & 2 deletions

File tree

src/proxy/http/HttpTransact.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4342,6 +4342,9 @@ HttpTransact::handle_cache_operation_on_forward_server_response(State *s)
43424342
base_response->set_expires(exp_time);
43434343

43444344
SET_VIA_STRING(VIA_CACHE_FILL_ACTION, VIA_CACHE_UPDATED);
4345+
SET_VIA_STRING(VIA_CACHE_RESULT, VIA_IN_CACHE_STALE);
4346+
// change VIA_SERVER_RESULT to ERROR because this status hit the negative_revalidating_list
4347+
SET_VIA_STRING(VIA_SERVER_RESULT, VIA_SERVER_ERROR);
43454348
Metrics::Counter::increment(http_rsb.cache_updates);
43464349

43474350
// unset Cache-control: "need-revalidate-once" (if it's set)

src/proxy/http/HttpTransactHeaders.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "proxy/PoolableSession.h"
3939

4040
#include "iocore/utils/Machine.h"
41+
#include "tsutil/DbgCtl.h"
4142

4243
using namespace std::literals;
4344

@@ -420,6 +421,8 @@ HttpTransactHeaders::downgrade_request(bool *origin_server_keep_alive, HTTPHdr *
420421
void
421422
HttpTransactHeaders::generate_and_set_squid_codes(HTTPHdr *header, char *via_string, HttpTransact::SquidLogInfo *squid_codes)
422423
{
424+
Dbg(dbg_ctl_http_transact_headers, "via_string=%s", via_string);
425+
423426
SquidLogCode log_code = SQUID_LOG_EMPTY;
424427
SquidHierarchyCode hier_code = SQUID_HIER_EMPTY;
425428
SquidHitMissCode hit_miss_code = SQUID_HIT_RESERVED;
@@ -477,6 +480,8 @@ HttpTransactHeaders::generate_and_set_squid_codes(HTTPHdr *header, char *via_str
477480
} else {
478481
if (via_string[VIA_CACHE_RESULT] == VIA_IN_CACHE_STALE && via_string[VIA_SERVER_RESULT] == VIA_SERVER_NOT_MODIFIED) {
479482
log_code = SQUID_LOG_TCP_REFRESH_HIT;
483+
} else if (via_string[VIA_CACHE_RESULT] == VIA_IN_CACHE_STALE && via_string[VIA_SERVER_RESULT] == VIA_SERVER_ERROR) {
484+
log_code = SQUID_LOG_TCP_REF_FAIL_HIT;
480485
} else {
481486
log_code = SQUID_LOG_TCP_IMS_MISS;
482487
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
11 TCP_MISS 200 200
2+
12 TCP_``HIT 200 000
3+
42 TCP_IMS_HIT 304 000
4+
13 TCP_REFRESH_FAIL_HIT 200 503
5+
43 TCP_REFRESH_FAIL_HIT 304 503
6+
14 TCP_``MISS 503 503
7+
21 TCP_MISS 200 200
8+
22 TCP_``HIT 200 000
9+
23 TCP_REFRESH_FAIL_HIT 200 503
10+
``

tests/gold_tests/cache/negative-revalidating.test.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# See the License for the specific language governing permissions and
1818
# limitations under the License.
1919

20+
import os
21+
2022
Test.Summary = '''
2123
Test the negative revalidating feature.
2224
'''
@@ -25,14 +27,17 @@
2527
class NegativeRevalidatingTest:
2628
_test_num: int = 0
2729

28-
def __init__(self, name: str, records_config: dict, replay_file: str):
30+
def __init__(self, name: str, records_config: dict, replay_file: str, gold_access_log=""):
2931
self._tr = Test.AddTestRun(name)
3032
self._replay_file = replay_file
3133

3234
self.__setupOriginServer()
3335
self.__setupTS(records_config)
3436
self.__setupClient()
3537

38+
if gold_access_log:
39+
self.__testAccessLog(gold_access_log)
40+
3641
NegativeRevalidatingTest._test_num += 1
3742

3843
def __setupClient(self):
@@ -46,6 +51,20 @@ def __setupTS(self, records_config):
4651
self._ts = Test.MakeATSProcess(f"ts-{NegativeRevalidatingTest._test_num}")
4752
self._ts.Disk.records_config.update(records_config)
4853
self._ts.Disk.remap_config.AddLine('map / http://127.0.0.1:{0}'.format(self._server.Variables.http_port))
54+
self._ts.Disk.logging_yaml.AddLines(
55+
'''
56+
logging:
57+
formats:
58+
- name: access
59+
format: '%<{uuid}cqh> %<crc> %<pssc> %<sssc>'
60+
logs:
61+
- filename: access
62+
format: access
63+
mode: ascii
64+
'''.split("\n"))
65+
66+
def __testAccessLog(self, gold_access_log):
67+
Test.Disk.File(os.path.join(self._ts.Variables.LOGDIR, 'access.log'), exists=True, content=gold_access_log)
4968

5069
def run(self):
5170
self._tr.Processes.Default.StartBefore(self._ts)
@@ -81,7 +100,8 @@ def run(self):
81100
# 'proxy.config.http.negative_revalidating_enabled': 1,
82101
'proxy.config.http.cache.max_stale_age': 6
83102
},
84-
"replay/negative-revalidating-enabled.replay.yaml").run()
103+
"replay/negative-revalidating-enabled.replay.yaml",
104+
"gold/negative-revalidating-enabled-access.gold").run()
85105

86106
#
87107
# Verify negative_revalidating list behavior.

tests/gold_tests/cache/replay/negative-revalidating-enabled.replay.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ sessions:
4747
fields:
4848
- [ Content-Length, 32 ]
4949
- [ Cache-Control, max-age=2 ]
50+
- [ ETag, C0FFEE ]
5051

5152
proxy-response:
5253
status: 200
@@ -77,6 +78,30 @@ sessions:
7778
proxy-response:
7879
status: 200
7980

81+
# Verify we serve the 304 Not Modified out of the cache with INM request
82+
- client-request:
83+
method: "GET"
84+
version: "1.1"
85+
scheme: "http"
86+
url: /path/reques_item
87+
headers:
88+
fields:
89+
- [ Host, example.com ]
90+
- [ uuid, 42 ]
91+
- [ If-None-Match, C0FFEE ]
92+
93+
# This should not reach the origin server.
94+
server-response:
95+
status: 503
96+
reason: "Service Unavailable"
97+
headers:
98+
fields:
99+
- [ Content-Length, 32 ]
100+
101+
# Again, we should serve this out of the cache.
102+
proxy-response:
103+
status: 304
104+
80105
# Verify that with negative_revalidating enabled, we serve the 200 OK out of
81106
# the cache even though it is stale (but younger than max-age + max_stale_age).
82107
- client-request:
@@ -104,6 +129,30 @@ sessions:
104129
proxy-response:
105130
status: 200
106131

132+
# Verify that we serve the 304 Not Modified out of the cache with INM request
133+
- client-request:
134+
method: "GET"
135+
version: "1.1"
136+
scheme: "http"
137+
url: /path/reques_item
138+
headers:
139+
fields:
140+
- [ Host, example.com ]
141+
- [ uuid, 43 ]
142+
- [ If-None-Match, C0FFEE ]
143+
144+
# This should not reach the origin server.
145+
server-response:
146+
status: 503
147+
reason: "Service Unavailable"
148+
headers:
149+
fields:
150+
- [ Content-Length, 32 ]
151+
152+
# Again, we should serve this out of the cache.
153+
proxy-response:
154+
status: 304
155+
107156
# Verify that max_stale_age is respected.
108157
- client-request:
109158
method: "GET"

0 commit comments

Comments
 (0)