Skip to content

Commit bfc2ef4

Browse files
committed
Cleanup serving stale while origin server down
1 parent da39efa commit bfc2ef4

3 files changed

Lines changed: 172 additions & 16 deletions

File tree

src/proxy/http/HttpTransact.cc

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,23 +2902,10 @@ HttpTransact::HandleCacheOpenReadHit(State *s)
29022902

29032903
find_server_and_update_current_info(s);
29042904

2905-
// We do not want to try to revalidate documents if we think
2906-
// the server is down due to the something report problem
2907-
//
2908-
// Note: we only want to skip origin servers because 1)
2909-
// parent proxies have their own negative caching
2910-
// scheme & 2) If we skip down parents, every page
2911-
// we serve is potentially stale
2912-
//
2913-
if (s->current.request_to == ResolveInfo::ORIGIN_SERVER && is_server_negative_cached(s) && response_returnable == true &&
2914-
is_stale_cache_response_returnable(s) == true) {
2915-
server_up = false;
2916-
update_current_info(&s->current, nullptr, ResolveInfo::UNDEFINED_LOOKUP, true);
2917-
TxnDbg(dbg_ctl_http_trans, "CacheOpenReadHit - server_down, returning stale document");
2918-
}
2919-
// a parent lookup could come back as ParentResultType::FAIL if in parent.config, go_direct == false and
2905+
// For origin servers (ResolveInfo::ORIGIN_SERVER): OSDNSLookup handles serving stale when all origin servers are down.
2906+
// For parent proxies: a parent lookup could come back as ParentResultType::FAIL if in parent.config, go_direct == false and
29202907
// there are no available parents (all down).
2921-
else if (s->current.request_to == ResolveInfo::HOST_NONE && s->parent_result.result == ParentResultType::FAIL) {
2908+
if (s->current.request_to == ResolveInfo::HOST_NONE && s->parent_result.result == ParentResultType::FAIL) {
29222909
if (response_returnable == true && is_stale_cache_response_returnable(s) == true) {
29232910
server_up = false;
29242911
update_current_info(&s->current, nullptr, ResolveInfo::UNDEFINED_LOOKUP, true);

tests/gold_tests/cache/proxy_serve_stale.test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@
2222

2323
# Verify that stale content is served when the parent is down.
2424
Test.ATSReplayTest(replay_file="replay/proxy_serve_stale.replay.yaml")
25+
26+
# Verify that stale content is served when the origin server is down.
27+
Test.ATSReplayTest(replay_file="replay/proxy_serve_stale_origin_down.replay.yaml")
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
#
18+
# This replay file assumes that caching is enabled and
19+
# proxy.config.http.cache.ignore_client_cc_max_age is set to 0 so that we can
20+
# test max-age in the client requests.
21+
#
22+
23+
meta:
24+
version: "1.0"
25+
26+
autest:
27+
description: 'Verify that stale content is served when the origin server is down'
28+
29+
dns:
30+
name: 'dns-serve-stale-origin-down'
31+
records:
32+
backend.example.com: ["127.0.0.1"]
33+
34+
35+
server:
36+
name: 'server-serve-stale-origin-down'
37+
38+
client:
39+
name: 'client-serve-stale-origin-down'
40+
41+
ats:
42+
name: 'ts-serve-stale-origin-down'
43+
process_config:
44+
enable_cache: true
45+
46+
records_config:
47+
proxy.config.diags.debug.enabled: 1
48+
proxy.config.diags.debug.tags: 'cache|http|dns|hostdb'
49+
proxy.config.http.cache.max_stale_age: 10
50+
proxy.config.http.connect.down.policy: 4
51+
proxy.config.http.connect_attempts_timeout: 1
52+
proxy.config.http.connect_attempts_rr_retries: 0
53+
proxy.config.http.connect_attempts_max_retries: 1
54+
proxy.config.http.connect_attempts_max_retries_down_server: 0
55+
proxy.config.http.down_server.cache_time: 5
56+
57+
remap_config:
58+
- from: "http://example.com/"
59+
to: "http://backend.example.com:{SERVER_HTTP_PORT}/"
60+
61+
plugin_config:
62+
- 'xdebug.so --enable=x-cache,x-cache-key,via'
63+
64+
sessions:
65+
- transactions:
66+
# 1. Cache object
67+
# cache-key: /path/a/
68+
# cache: miss
69+
# origin server: up
70+
- client-request:
71+
method: "GET"
72+
version: "1.1"
73+
url: /path/a/
74+
headers:
75+
fields:
76+
- [ Host, example.com ]
77+
- [ x-debug, "x-cache,x-cache-key,via" ]
78+
- [ uuid, a-1 ]
79+
80+
server-response:
81+
status: 200
82+
headers:
83+
fields:
84+
- [ Content-Length, 16]
85+
- [ Cache-Control, "public, max-age=1"]
86+
87+
proxy-response:
88+
status: 200
89+
headers:
90+
fields:
91+
- [ X-Cache, { value: miss, as: equal } ]
92+
93+
# 2. Make the origin server down
94+
# cache-key: /path/b/
95+
# cache: miss
96+
# origin server: down
97+
- client-request:
98+
method: "GET"
99+
version: "1.1"
100+
url: /path/b/
101+
headers:
102+
fields:
103+
- [ Host, example.com ]
104+
- [ x-debug, "x-cache,x-cache-key,via" ]
105+
- [ uuid, b-1 ]
106+
107+
server-response:
108+
on_connect: reset
109+
110+
proxy-response:
111+
status: 502
112+
headers:
113+
fields:
114+
- [ X-Cache, { value: miss, as: equal } ]
115+
116+
# 3. Serve stale while down_serve.cache_time
117+
# cache-key: /path/a/
118+
# cache: stale
119+
# origin server: down (cached)
120+
- client-request:
121+
delay: 2s
122+
method: "GET"
123+
version: "1.1"
124+
url: /path/a/
125+
headers:
126+
fields:
127+
- [ Host, example.com ]
128+
- [ x-debug, "x-cache,x-cache-key,via" ]
129+
- [ uuid, a-2 ]
130+
131+
proxy-request:
132+
expect: absent
133+
134+
server-response:
135+
on_connect: reset
136+
137+
proxy-response:
138+
status: 200
139+
headers:
140+
fields:
141+
- [ X-Cache, { value: hit-stale, as: equal } ]
142+
143+
# 4. Revalidate stale contents
144+
# cache-key: /path/a/
145+
# cache: stale
146+
# origin server: up
147+
- client-request:
148+
delay: 5s
149+
method: "GET"
150+
version: "1.1"
151+
url: /path/a/
152+
headers:
153+
fields:
154+
- [ Host, example.com ]
155+
- [ x-debug, "x-cache,x-cache-key,via" ]
156+
- [ uuid, a-99 ]
157+
158+
server-response:
159+
status: 304
160+
161+
proxy-response:
162+
status: 200
163+
headers:
164+
fields:
165+
- [ X-Cache, { value: hit-stale, as: equal } ]
166+

0 commit comments

Comments
 (0)