MCPcopy Create free account
hub / github.com/apache/trafficserver / getHashKey

Method getHashKey

src/proxy/http/remap/NextHopConsistentHash.cc:168–271  ·  view source on GitHub ↗

returns a hash key calculated from the request and 'hash_key' configuration parameter.

Source from the content-addressed store, hash-verified

166// returns a hash key calculated from the request and 'hash_key' configuration
167// parameter.
168uint64_t
169NextHopConsistentHash::getHashKey(uint64_t sm_id, const HttpRequestData &hrdata, ATSHash64 *h)
170{
171 URL *url = nullptr;
172 int len = 0;
173 const char *url_string_ref = nullptr;
174
175 switch (hash_url) {
176 case NH_HASH_URL_REQUEST:
177 break;
178 case NH_HASH_URL_CACHE:
179 if (hrdata.cache_info_lookup_url) {
180 url = *(hrdata.cache_info_lookup_url);
181 }
182 break;
183 case NH_HASH_URL_PARENT:
184 if (hrdata.cache_info_parent_selection_url) {
185 url = *(hrdata.cache_info_parent_selection_url);
186 }
187 break;
188 }
189
190 // Make sure we default to the request URL if nothing else worked
191 if (!url) {
192 url = hrdata.hdr->url_get();
193 }
194
195 // calculate a hash using the selected config.
196 switch (hash_key) {
197 case NH_URL_HASH_KEY:
198 url_string_ref = url->string_get_ref(&len, URLNormalize::LC_SCHEME_HOST);
199 if (url_string_ref && len > 0) {
200 h->update(url_string_ref, len);
201 NH_Dbg(NH_DBG_CTL, "[%" PRIu64 "] url hash string: %s", sm_id, url_string_ref);
202 }
203 break;
204 // hostname hash
205 case NH_HOSTNAME_HASH_KEY:
206 url_string_ref = url->host_get(&len);
207 if (url_string_ref && len > 0) {
208 h->update(url_string_ref, len);
209 }
210 break;
211 // path + query string
212 case NH_PATH_QUERY_HASH_KEY:
213 url_string_ref = url->path_get(&len);
214 h->update("/", 1);
215 if (url_string_ref && len > 0) {
216 h->update(url_string_ref, len);
217 }
218 url_string_ref = url->query_get(&len);
219 if (url_string_ref && len > 0) {
220 h->update("?", 1);
221 h->update(url_string_ref, len);
222 }
223 break;
224 // path + fragment hash
225 case NH_PATH_FRAGMENT_HASH_KEY:

Callers

nothing calls this directly

Calls 9

url_getMethod · 0.80
string_get_refMethod · 0.80
updateMethod · 0.45
host_getMethod · 0.45
path_getMethod · 0.45
query_getMethod · 0.45
fragment_getMethod · 0.45
finalMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected