Permalink
Browse files

TS-1270 add force local cache control in clustering mode

  • Loading branch information...
Chen Bin authored and mingzym committed Sep 10, 2012
1 parent 00953ff commit 5a48e53cf2a5e292ad78388625bb0d7cded43bc9
View
@@ -1,6 +1,8 @@
-*- coding: utf-8 -*-
Changes with Apache Traffic Server 3.3.0
+ *) [TS-1270] add force local cache control in clustering mode
+
*) [TS-1386] thread hang in cluster type=1, which will trigger the
throttling
@@ -423,6 +423,7 @@ The Apache Traffic Server Administration Manual will explain what these strings
proxy.config.http.cache.ignore_accept_mismatch
proxy.config.http.cache.ignore_authentication
proxy.config.http.cache.ignore_client_cc_max_age
+ proxy.config.http.cache.cluster_cache_local
proxy.config.http.cache.ignore_client_no_cache
proxy.config.http.cache.ignore_server_no_cache
proxy.config.http.cache.ims_on_client_no_cache
View
@@ -2794,11 +2794,11 @@ ink_cache_init(ModuleVersion v)
#ifdef NON_MODULAR
//----------------------------------------------------------------------------
Action *
-CacheProcessor::open_read(Continuation *cont, URL *url, CacheHTTPHdr *request,
+CacheProcessor::open_read(Continuation *cont, URL *url, bool cluster_cache_local, CacheHTTPHdr *request,
CacheLookupHttpConfig *params, time_t pin_in_cache, CacheFragType type)
{
#ifdef CLUSTER_CACHE
- if (cache_clustering_enabled > 0) {
+ if (cache_clustering_enabled > 0 && !cluster_cache_local) {
return open_read_internal(CACHE_OPEN_READ_LONG, cont, (MIOBuffer *) 0,
url, request, params, (CacheKey *) 0, pin_in_cache, type, (char *) 0, 0);
}
@@ -2809,11 +2809,11 @@ CacheProcessor::open_read(Continuation *cont, URL *url, CacheHTTPHdr *request,
//----------------------------------------------------------------------------
Action *
-CacheProcessor::open_write(Continuation *cont, int expected_size, URL *url,
+CacheProcessor::open_write(Continuation *cont, int expected_size, URL *url, bool cluster_cache_local,
CacheHTTPHdr *request, CacheHTTPInfo *old_info, time_t pin_in_cache, CacheFragType type)
{
#ifdef CLUSTER_CACHE
- if (cache_clustering_enabled > 0) {
+ if (cache_clustering_enabled > 0 && !cluster_cache_local) {
INK_MD5 url_md5;
Cache::generate_key(&url_md5, url, request);
ClusterMachine *m = cluster_machine_at_depth(cache_hash(url_md5));
@@ -2836,7 +2836,7 @@ CacheProcessor::open_write(Continuation *cont, int expected_size, URL *url,
// Note: this should not be called from from the cluster processor, or bad
// recursion could occur. This is merely a convenience wrapper.
Action *
-CacheProcessor::remove(Continuation *cont, URL *url, CacheFragType frag_type)
+CacheProcessor::remove(Continuation *cont, URL *url, bool cluster_cache_local, CacheFragType frag_type)
{
INK_MD5 md5;
int len = 0;
@@ -2847,9 +2847,9 @@ CacheProcessor::remove(Continuation *cont, URL *url, CacheFragType frag_type)
Debug("cache_remove", "[CacheProcessor::remove] Issuing cache delete for %s", url->string_get_ref());
#ifdef CLUSTER_CACHE
- if (cache_clustering_enabled > 0) {
+ if (cache_clustering_enabled > 0 && !cluster_cache_local) {
// Remove from cluster
- return remove(cont, &md5, frag_type, true, false, const_cast<char *>(hostname), len);
+ return remove(cont, &md5, cluster_cache_local, frag_type, true, false, const_cast<char *>(hostname), len);
}
#endif
@@ -27,6 +27,7 @@
#include "api/ts/ts.h"
#include "Show.h"
#include "I_Tasks.h"
+#include "CacheControl.h"
struct ShowCache: public ShowCont {
enum scan_type {
@@ -420,7 +421,7 @@ ShowCache::lookup_url(int event, Event *e) {
url.MD5_get(&md5);
const char *hostname = url.host_get(&len);
SET_HANDLER(&ShowCache::handleCacheEvent);
- Action *lookup_result = cacheProcessor.open_read(this, &md5, CACHE_FRAG_TYPE_HTTP, (char *) hostname, len);
+ Action *lookup_result = cacheProcessor.open_read(this, &md5, getClusterCacheLocal(&url, (char *)hostname), CACHE_FRAG_TYPE_HTTP, (char *) hostname, len);
if (!lookup_result)
lookup_result = ACTION_IO_ERROR;
if (lookup_result == ACTION_RESULT_DONE)
@@ -458,7 +459,9 @@ ShowCache::delete_url(int event, Event *e)
// increment the index so that the next time
// delete_url is called you delete the next url
urlstrs_index++;
- cacheProcessor.remove(this, &url, CACHE_FRAG_TYPE_HTTP);
+ int len;
+ const char *hostname = url.host_get(&len);
+ cacheProcessor.remove(this, &url, getClusterCacheLocal(&url, (char *)hostname), CACHE_FRAG_TYPE_HTTP);
return EVENT_DONE;
}
View
@@ -286,41 +286,41 @@ EXCLUSIVE_REGRESSION_TEST(cache)(RegressionTest *t, int atype, int *pstatus) {
EThread *thread = this_ethread();
CACHE_SM(t, write_test, { cacheProcessor.open_write(
- this, &key, CACHE_FRAG_TYPE_NONE, 100,
+ this, &key, false, CACHE_FRAG_TYPE_NONE, 100,
CACHE_WRITE_OPT_SYNC); } );
write_test.expect_initial_event = CACHE_EVENT_OPEN_WRITE;
write_test.expect_event = VC_EVENT_WRITE_COMPLETE;
write_test.nbytes = 100;
rand_CacheKey(&write_test.key, thread->mutex);
- CACHE_SM(t, lookup_test, { cacheProcessor.lookup(this, &key); } );
+ CACHE_SM(t, lookup_test, { cacheProcessor.lookup(this, &key, false); } );
lookup_test.expect_event = CACHE_EVENT_LOOKUP;
lookup_test.key = write_test.key;
- CACHE_SM(t, read_test, { cacheProcessor.open_read(this, &key); } );
+ CACHE_SM(t, read_test, { cacheProcessor.open_read(this, &key, false); } );
read_test.expect_initial_event = CACHE_EVENT_OPEN_READ;
read_test.expect_event = VC_EVENT_READ_COMPLETE;
read_test.nbytes = 100;
read_test.key = write_test.key;
- CACHE_SM(t, remove_test, { cacheProcessor.remove(this, &key); } );
+ CACHE_SM(t, remove_test, { cacheProcessor.remove(this, &key, false); } );
remove_test.expect_event = CACHE_EVENT_REMOVE;
remove_test.key = write_test.key;
- CACHE_SM(t, lookup_fail_test, { cacheProcessor.lookup(this, &key); } );
+ CACHE_SM(t, lookup_fail_test, { cacheProcessor.lookup(this, &key, false); } );
lookup_fail_test.expect_event = CACHE_EVENT_LOOKUP_FAILED;
lookup_fail_test.key = write_test.key;
- CACHE_SM(t, read_fail_test, { cacheProcessor.open_read(this, &key); } );
+ CACHE_SM(t, read_fail_test, { cacheProcessor.open_read(this, &key, false); } );
read_fail_test.expect_event = CACHE_EVENT_OPEN_READ_FAILED;
read_fail_test.key = write_test.key;
- CACHE_SM(t, remove_fail_test, { cacheProcessor.remove(this, &key); } );
+ CACHE_SM(t, remove_fail_test, { cacheProcessor.remove(this, &key, false); } );
remove_fail_test.expect_event = CACHE_EVENT_REMOVE_FAILED;
rand_CacheKey(&remove_fail_test.key, thread->mutex);
CACHE_SM(t, replace_write_test, {
- cacheProcessor.open_write(this, &key, CACHE_FRAG_TYPE_NONE, 100,
+ cacheProcessor.open_write(this, &key, false, CACHE_FRAG_TYPE_NONE, 100,
CACHE_WRITE_OPT_SYNC);
}
int open_write_callout() {
@@ -335,7 +335,7 @@ EXCLUSIVE_REGRESSION_TEST(cache)(RegressionTest *t, int atype, int *pstatus) {
rand_CacheKey(&replace_write_test.key, thread->mutex);
CACHE_SM(t, replace_test, {
- cacheProcessor.open_write(this, &key, CACHE_FRAG_TYPE_NONE, 100,
+ cacheProcessor.open_write(this, &key, false, CACHE_FRAG_TYPE_NONE, 100,
CACHE_WRITE_OPT_OVERWRITE_SYNC);
}
int open_write_callout() {
@@ -357,7 +357,7 @@ EXCLUSIVE_REGRESSION_TEST(cache)(RegressionTest *t, int atype, int *pstatus) {
replace_test.content_salt = 1;
CACHE_SM(t, replace_read_test, {
- cacheProcessor.open_read(this, &key);
+ cacheProcessor.open_read(this, &key, false);
}
int open_read_callout() {
CacheTestHeader *h = 0;
@@ -376,15 +376,15 @@ EXCLUSIVE_REGRESSION_TEST(cache)(RegressionTest *t, int atype, int *pstatus) {
replace_read_test.content_salt = 1;
CACHE_SM(t, large_write_test, { cacheProcessor.open_write(
- this, &key, CACHE_FRAG_TYPE_NONE, 100,
+ this, &key, false, CACHE_FRAG_TYPE_NONE, 100,
CACHE_WRITE_OPT_SYNC); } );
large_write_test.expect_initial_event = CACHE_EVENT_OPEN_WRITE;
large_write_test.expect_event = VC_EVENT_WRITE_COMPLETE;
large_write_test.nbytes = 10000000;
rand_CacheKey(&large_write_test.key, thread->mutex);
CACHE_SM(t, pread_test, {
- cacheProcessor.open_read(this, &key);
+ cacheProcessor.open_read(this, &key, false);
}
int open_read_callout() {
cvio = cache_vc->do_io_pread(this, nbytes, buffer, 7000000);
View
@@ -307,7 +307,7 @@ CacheVC::scanObject(int event, Event * e)
ink_debug_assert(hostinfo_copied);
SET_HANDLER(&CacheVC::scanRemoveDone);
// force remove even if there is a writer
- cacheProcessor.remove(this, &doc->first_key, CACHE_FRAG_TYPE_HTTP, true, false, (char *) hname, hlen);
+ cacheProcessor.remove(this, &doc->first_key, true, CACHE_FRAG_TYPE_HTTP, true, false, (char *) hname, hlen);
return EVENT_CONT;
} else {
offset = (char *) doc - buf->data();
View
@@ -76,16 +76,17 @@ struct CacheProcessor:public Processor
int dir_check(bool fix);
int db_check(bool fix);
- inkcoreapi Action *lookup(Continuation *cont, CacheKey *key,
+ inkcoreapi Action *lookup(Continuation *cont, CacheKey *key, bool cluster_cache_local,
bool local_only = false,
CacheFragType frag_type = CACHE_FRAG_TYPE_NONE, char *hostname = 0, int host_len = 0);
- inkcoreapi Action *open_read(Continuation *cont, CacheKey *key,
+ inkcoreapi Action *open_read(Continuation *cont, CacheKey *key, bool cluster_cache_local,
CacheFragType frag_type = CACHE_FRAG_TYPE_NONE, char *hostname = 0, int host_len = 0);
Action *open_read_buffer(Continuation *cont, MIOBuffer *buf, CacheKey *key,
CacheFragType frag_type = CACHE_FRAG_TYPE_NONE, char *hostname = 0, int host_len = 0);
inkcoreapi Action *open_write(Continuation *cont,
CacheKey *key,
+ bool cluster_cache_local,
CacheFragType frag_type = CACHE_FRAG_TYPE_NONE,
int expected_size = CACHE_EXPECTED_SIZE,
int options = 0,
@@ -98,36 +99,38 @@ struct CacheProcessor:public Processor
time_t pin_in_cache = (time_t) 0,
char *hostname = 0, int host_len = 0);
inkcoreapi Action *remove(Continuation *cont, CacheKey *key,
+ bool cluster_cache_local,
CacheFragType frag_type = CACHE_FRAG_TYPE_NONE,
bool rm_user_agents = true, bool rm_link = false,
char *hostname = 0, int host_len = 0);
Action *scan(Continuation *cont, char *hostname = 0, int host_len = 0, int KB_per_second = SCAN_KB_PER_SECOND);
#ifdef HTTP_CACHE
- Action *lookup(Continuation *cont, URL *url, bool local_only = false,
+ Action *lookup(Continuation *cont, URL *url, bool cluster_cache_local, bool local_only = false,
CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
inkcoreapi Action *open_read(Continuation *cont, URL *url,
+ bool cluster_cache_local,
CacheHTTPHdr *request,
CacheLookupHttpConfig *params,
time_t pin_in_cache = (time_t) 0, CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
Action *open_read_buffer(Continuation *cont, MIOBuffer *buf, URL *url,
CacheHTTPHdr *request,
CacheLookupHttpConfig *params, CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
- Action *open_write(Continuation *cont, int expected_size, URL *url,
+ Action *open_write(Continuation *cont, int expected_size, URL *url, bool cluster_cache_local,
CacheHTTPHdr *request, CacheHTTPInfo *old_info,
time_t pin_in_cache = (time_t) 0, CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
Action *open_write_buffer(Continuation *cont, MIOBuffer *buf, URL *url,
CacheHTTPHdr *request, CacheHTTPHdr *response,
CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
- Action *remove(Continuation *cont, URL *url, CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
+ Action *remove(Continuation *cont, URL *url, bool cluster_cache_local, CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
Action *open_read_internal(int, Continuation *, MIOBuffer *, CacheURL *,
CacheHTTPHdr *, CacheLookupHttpConfig *,
CacheKey *, time_t, CacheFragType type, char *hostname, int host_len);
#endif
- Action *link(Continuation *cont, CacheKey *from, CacheKey *to,
+ Action *link(Continuation *cont, CacheKey *from, CacheKey *to, bool cluster_cache_local,
CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP, char *hostname = 0, int host_len = 0);
- Action *deref(Continuation *cont, CacheKey *key,
+ Action *deref(Continuation *cont, CacheKey *key, bool cluster_cache_local,
CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP, char *hostname = 0, int host_len = 0);
static int IsCacheEnabled();
@@ -1100,13 +1100,13 @@ cache_hash(INK_MD5 & md5)
#endif
TS_INLINE Action *
-CacheProcessor::lookup(Continuation *cont, CacheKey *key, bool local_only,
+CacheProcessor::lookup(Continuation *cont, CacheKey *key, bool cluster_cache_local, bool local_only,
CacheFragType frag_type, char *hostname, int host_len)
{
(void) local_only;
#ifdef CLUSTER_CACHE
// Try to send remote, if not possible, handle locally
- if ((cache_clustering_enabled > 0) && !local_only) {
+ if ((cache_clustering_enabled > 0) && !cluster_cache_local && !local_only) {
Action *a = Cluster_lookup(cont, key, frag_type, hostname, host_len);
if (a) {
return a;
@@ -1117,10 +1117,10 @@ CacheProcessor::lookup(Continuation *cont, CacheKey *key, bool local_only,
}
TS_INLINE inkcoreapi Action *
-CacheProcessor::open_read(Continuation *cont, CacheKey *key, CacheFragType frag_type, char *hostname, int host_len)
+CacheProcessor::open_read(Continuation *cont, CacheKey *key, bool cluster_cache_local, CacheFragType frag_type, char *hostname, int host_len)
{
#ifdef CLUSTER_CACHE
- if (cache_clustering_enabled > 0) {
+ if (cache_clustering_enabled > 0 && !cluster_cache_local) {
return open_read_internal(CACHE_OPEN_READ, cont, (MIOBuffer *) 0,
(CacheURL *) 0, (CacheHTTPHdr *) 0,
(CacheLookupHttpConfig *) 0, key, 0, frag_type, hostname, host_len);
@@ -1146,13 +1146,13 @@ CacheProcessor::open_read_buffer(Continuation *cont, MIOBuffer *buf, CacheKey *k
TS_INLINE inkcoreapi Action *
-CacheProcessor::open_write(Continuation *cont, CacheKey *key, CacheFragType frag_type,
+CacheProcessor::open_write(Continuation *cont, CacheKey *key, bool cluster_cache_local, CacheFragType frag_type,
int expected_size, int options, time_t pin_in_cache,
char *hostname, int host_len)
{
(void) expected_size;
#ifdef CLUSTER_CACHE
- if (cache_clustering_enabled > 0) {
+ if (cache_clustering_enabled > 0 && !cluster_cache_local) {
ClusterMachine *m = cluster_machine_at_depth(cache_hash(*key));
if (m)
return Cluster_write(cont, expected_size, (MIOBuffer *) 0, m,
@@ -1182,12 +1182,12 @@ CacheProcessor::open_write_buffer(Continuation *cont, MIOBuffer *buf, CacheKey *
}
TS_INLINE Action *
-CacheProcessor::remove(Continuation *cont, CacheKey *key, CacheFragType frag_type,
+CacheProcessor::remove(Continuation *cont, CacheKey *key, bool cluster_cache_local, CacheFragType frag_type,
bool rm_user_agents, bool rm_link, char *hostname, int host_len)
{
Debug("cache_remove", "[CacheProcessor::remove] Issuing cache delete for %u", cache_hash(*key));
#ifdef CLUSTER_CACHE
- if (cache_clustering_enabled > 0) {
+ if (cache_clustering_enabled > 0 && !cluster_cache_local) {
ClusterMachine *m = cluster_machine_at_depth(cache_hash(*key));
if (m) {
@@ -1206,15 +1206,15 @@ scan(Continuation *cont, char *hostname = 0, int host_len = 0, int KB_per_second
#ifdef HTTP_CACHE
TS_INLINE Action *
-CacheProcessor::lookup(Continuation *cont, URL *url, bool local_only, CacheFragType frag_type)
+CacheProcessor::lookup(Continuation *cont, URL *url, bool cluster_cache_local, bool local_only, CacheFragType frag_type)
{
(void) local_only;
INK_MD5 md5;
url->MD5_get(&md5);
int host_len = 0;
const char *hostname = url->host_get(&host_len);
- return lookup(cont, &md5, local_only, frag_type, (char *) hostname, host_len);
+ return lookup(cont, &md5, cluster_cache_local, local_only, frag_type, (char *) hostname, host_len);
}
TS_INLINE Action *
@@ -1282,10 +1282,10 @@ CacheProcessor::open_read_internal(int opcode,
#ifdef CLUSTER_CACHE
TS_INLINE Action *
-CacheProcessor::link(Continuation *cont, CacheKey *from, CacheKey *to,
+CacheProcessor::link(Continuation *cont, CacheKey *from, CacheKey *to, bool cluster_cache_local,
CacheFragType type, char *hostname, int host_len)
{
- if (cache_clustering_enabled > 0) {
+ if (cache_clustering_enabled > 0 && !cluster_cache_local) {
// Use INK_MD5 in "from" to determine target machine
ClusterMachine *m = cluster_machine_at_depth(cache_hash(*from));
if (m) {
@@ -1296,9 +1296,9 @@ CacheProcessor::link(Continuation *cont, CacheKey *from, CacheKey *to,
}
TS_INLINE Action *
-CacheProcessor::deref(Continuation *cont, CacheKey *key, CacheFragType type, char *hostname, int host_len)
+CacheProcessor::deref(Continuation *cont, CacheKey *key, bool cluster_cache_local, CacheFragType type, char *hostname, int host_len)
{
- if (cache_clustering_enabled > 0) {
+ if (cache_clustering_enabled > 0 && !cluster_cache_local) {
ClusterMachine *m = cluster_machine_at_depth(cache_hash(*key));
if (m) {
return Cluster_deref(m, cont, key, type, hostname, host_len);
View
@@ -639,6 +639,8 @@ RecordElement RecordsConfig[] = {
// #################
{RECT_CONFIG, "proxy.config.http.cache.http", RECD_INT, "1", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL}
,
+ {RECT_CONFIG, "proxy.config.http.cache.cluster_cache_local", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL}
+ ,
{RECT_CONFIG, "proxy.config.http.cache.ignore_client_no_cache", RECD_INT, "1", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL}
,
{RECT_CONFIG, "proxy.config.http.cache.ignore_client_cc_max_age", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL}
@@ -152,6 +152,9 @@ CacheObj::formatEleToRule()
case TS_CACHE_IGNORE_NO_CACHE:
ink_strlcat(buf, "action=ignore-no-cache ", sizeof(buf));
break;
+ case TS_CACHE_CLUSTER_CACHE_LOCAL:
+ ink_strlcat(buf, "action=cluster-cache-local ", sizeof(buf));
+ break;
case TS_CACHE_IGNORE_CLIENT_NO_CACHE:
ink_strlcat(buf, "action=ignore-client-no-cache ", sizeof(buf));
break;
@@ -213,6 +216,7 @@ bool CacheObj::isValid()
switch (m_ele->cfg_ele.type) {
case TS_CACHE_NEVER:
case TS_CACHE_IGNORE_NO_CACHE:
+ case TS_CACHE_CLUSTER_CACHE_LOCAL:
case TS_CACHE_IGNORE_CLIENT_NO_CACHE:
case TS_CACHE_IGNORE_SERVER_NO_CACHE:
case TS_CACHE_AUTH_CONTENT:
Oops, something went wrong.

0 comments on commit 5a48e53

Please sign in to comment.