You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2016/05/02 18:08:18 UTC
[trafficserver] 02/04: TS-4380: Make TSCacheClearT a bitmask.
This is an automated email from the ASF dual-hosted git repository.
jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git
commit 6b263f9780b77c7cce17039631f36c5a7092360e
Author: James Peach <jp...@apache.org>
AuthorDate: Sun Apr 24 14:12:22 2016 -0700
TS-4380: Make TSCacheClearT a bitmask.
Make TSCacheClearT a bitmask so that on server restart we will be
able to clear the cache, hostdb or both.
---
cmd/traffic_line/traffic_line.cc | 4 ++--
mgmt/api/APITestCliRemote.cc | 10 +++++-----
mgmt/api/CoreAPI.cc | 43 +++++++++++++++++++---------------------
mgmt/api/INKMgmtAPI.cc | 12 ++++++++---
mgmt/api/include/mgmtapi.h | 15 +++++++-------
5 files changed, 44 insertions(+), 40 deletions(-)
diff --git a/cmd/traffic_line/traffic_line.cc b/cmd/traffic_line/traffic_line.cc
index a0194ad..cfa28e7 100644
--- a/cmd/traffic_line/traffic_line.cc
+++ b/cmd/traffic_line/traffic_line.cc
@@ -66,13 +66,13 @@ handleArgInvocation()
} else if (ShutdownMgmtLocal == 1) {
return TSRestart(restart);
} else if (Shutdown == 1) {
- return TSProxyStateSet(TS_PROXY_OFF, TS_CACHE_CLEAR_OFF);
+ return TSProxyStateSet(TS_PROXY_OFF, TS_CACHE_CLEAR_NONE);
} else if (BounceCluster == 1) {
return TSBounce(restart | TS_RESTART_OPT_CLUSTER);
} else if (BounceLocal == 1) {
return TSBounce(restart);
} else if (Startup == 1) {
- return TSProxyStateSet(TS_PROXY_ON, TS_CACHE_CLEAR_OFF);
+ return TSProxyStateSet(TS_PROXY_ON, TS_CACHE_CLEAR_NONE);
} else if (ClearCluster == 1) {
return TSStatsReset(true, NULL);
} else if (ClearNode == 1) {
diff --git a/mgmt/api/APITestCliRemote.cc b/mgmt/api/APITestCliRemote.cc
index a6a38e7..39cd000 100644
--- a/mgmt/api/APITestCliRemote.cc
+++ b/mgmt/api/APITestCliRemote.cc
@@ -859,18 +859,18 @@ void
start_TS(char *tsArgs)
{
TSMgmtError ret;
- TSCacheClearT clear = TS_CACHE_CLEAR_OFF;
+ TSCacheClearT clear = TS_CACHE_CLEAR_NONE;
char *args;
strtok(tsArgs, ":");
args = strtok(NULL, ":");
if (args) {
if (strcmp(args, "all\n") == 0)
- clear = TS_CACHE_CLEAR_ON;
+ clear = TS_CACHE_CLEAR_CACHE;
else if (strcmp(args, "hostdb\n") == 0)
clear = TS_CACHE_CLEAR_HOSTDB;
} else {
- clear = TS_CACHE_CLEAR_OFF;
+ clear = TS_CACHE_CLEAR_NONE;
}
printf("STARTING PROXY with cache: %d\n", clear);
@@ -886,7 +886,7 @@ stop_TS()
TSMgmtError ret;
printf("STOPPING PROXY\n");
- if ((ret = TSProxyStateSet(TS_PROXY_OFF, TS_CACHE_CLEAR_OFF)) != TS_ERR_OKAY)
+ if ((ret = TSProxyStateSet(TS_PROXY_OFF, TS_CACHE_CLEAR_NONE)) != TS_ERR_OKAY)
printf("[TSProxyStateSet] turn off FAILED\n");
print_err("stop_TS", ret);
}
@@ -2267,7 +2267,7 @@ sync_test()
printf("[TSRecordSet] proxy.config.http.cache.fuzz.probability=-0.3333\n");
TSMgmtError ret;
- if ((ret = TSProxyStateSet(TS_PROXY_OFF, TS_CACHE_CLEAR_OFF)) != TS_ERR_OKAY)
+ if ((ret = TSProxyStateSet(TS_PROXY_OFF, TS_CACHE_CLEAR_NONE)) != TS_ERR_OKAY)
printf("[TSProxyStateSet] turn off FAILED\n");
print_err("stop_TS", ret);
}
diff --git a/mgmt/api/CoreAPI.cc b/mgmt/api/CoreAPI.cc
index 1fe0707..605e42c 100644
--- a/mgmt/api/CoreAPI.cc
+++ b/mgmt/api/CoreAPI.cc
@@ -203,9 +203,8 @@ ProxyStateSet(TSProxyStateT state, TSCacheClearT clear)
int i = 0;
char tsArgs[MAX_BUF_SIZE];
char *proxy_options;
- bool found;
- memset(tsArgs, 0, MAX_BUF_SIZE);
+ ink_zero(tsArgs);
switch (state) {
case TS_PROXY_OFF:
@@ -213,28 +212,22 @@ ProxyStateSet(TSProxyStateT state, TSCacheClearT clear)
goto Lerror; // unsuccessful shutdown
break;
case TS_PROXY_ON:
- if (lmgmt->processRunning()) // already on
+ if (lmgmt->processRunning()) { // already on
break;
+ }
- // taken from mgmt/Main.cc when check the -tsArgs option
- // Update cmd line overrides/environmental overrides/etc
- switch (clear) {
- case TS_CACHE_CLEAR_ON: // traffic_server -K
- snprintf(tsArgs, sizeof(tsArgs), "-K -M");
- break;
- case TS_CACHE_CLEAR_HOSTDB: // traffic_server -k
- snprintf(tsArgs, sizeof(tsArgs), "-k -M");
- break;
- case TS_CACHE_CLEAR_OFF:
- // use default tsargs in records.config
- int rec_err = RecGetRecordString_Xmalloc("proxy.config.proxy_binary_opts", &proxy_options);
- found = (rec_err == REC_ERR_OKAY);
- if (!found)
- goto Lerror;
-
- snprintf(tsArgs, MAX_BUF_SIZE, "%s", proxy_options);
+ // Start with the default options from records.config.
+ if (RecGetRecordString_Xmalloc("proxy.config.proxy_binary_opts", &proxy_options) == REC_ERR_OKAY) {
+ snprintf(tsArgs, sizeof(tsArgs), "%s", proxy_options);
ats_free(proxy_options);
- break;
+ }
+
+ if (clear & TS_CACHE_CLEAR_CACHE) {
+ ink_strlcat(tsArgs, " -K", sizeof(tsArgs));
+ }
+
+ if (clear & TS_CACHE_CLEAR_HOSTDB) {
+ ink_strlcat(tsArgs, " -k", sizeof(tsArgs));
}
if (strlen(tsArgs) > 0) { /* Passed command line args for proxy */
@@ -245,11 +238,15 @@ ProxyStateSet(TSProxyStateT state, TSCacheClearT clear)
lmgmt->run_proxy = true;
lmgmt->listenForProxy();
+
do {
mgmt_sleep_sec(1);
} while (i++ < 20 && (lmgmt->proxy_running == 0));
- if (!lmgmt->processRunning())
+
+ if (!lmgmt->processRunning()) {
goto Lerror;
+ }
+
break;
default:
goto Lerror;
@@ -258,7 +255,7 @@ ProxyStateSet(TSProxyStateT state, TSCacheClearT clear)
return TS_ERR_OKAY;
Lerror:
- return TS_ERR_FAIL; /* failed to set proxy state */
+ return TS_ERR_FAIL; /* failed to set proxy state */
}
#if TS_USE_REMOTE_UNWINDING
diff --git a/mgmt/api/INKMgmtAPI.cc b/mgmt/api/INKMgmtAPI.cc
index f989b71..596b85e 100644
--- a/mgmt/api/INKMgmtAPI.cc
+++ b/mgmt/api/INKMgmtAPI.cc
@@ -1686,13 +1686,19 @@ TSProxyStateGet()
/* TSProxyStateSet: set the proxy state (on/off)
* Input: proxy_state - set to on/off
* clear - start TS with cache clearing option,
- * when stopping TS should always be TS_CACHE_CLEAR_OFF
+ * when stopping TS should always be TS_CACHE_CLEAR_NONE
* Output: TSMgmtError
*/
tsapi TSMgmtError
-TSProxyStateSet(TSProxyStateT proxy_state, TSCacheClearT clear)
+TSProxyStateSet(TSProxyStateT proxy_state, unsigned clear)
{
- return ProxyStateSet(proxy_state, clear);
+ unsigned mask = TS_CACHE_CLEAR_NONE | TS_CACHE_CLEAR_CACHE | TS_CACHE_CLEAR_HOSTDB;
+
+ if (clear & ~mask) {
+ return TS_ERR_PARAMS;
+ }
+
+ return ProxyStateSet(proxy_state, static_cast<TSCacheClearT>(clear));
}
tsapi TSMgmtError
diff --git a/mgmt/api/include/mgmtapi.h b/mgmt/api/include/mgmtapi.h
index fbadc9c..64e4945 100644
--- a/mgmt/api/include/mgmtapi.h
+++ b/mgmt/api/include/mgmtapi.h
@@ -144,9 +144,9 @@ typedef enum {
/* used when starting Traffic Server process */
typedef enum {
- TS_CACHE_CLEAR_ON, /* run TS in "clear entire cache" mode */
- TS_CACHE_CLEAR_HOSTDB, /* run TS in "only clear the host db cache" mode */
- TS_CACHE_CLEAR_OFF /* starts TS in regualr mode w/o any options */
+ TS_CACHE_CLEAR_NONE = 0, /* starts TS in regular mode w/o any options */
+ TS_CACHE_CLEAR_CACHE = (1 << 0), /* run TS in "clear cache" mode */
+ TS_CACHE_CLEAR_HOSTDB = (1 << 1), /* run TS in "clear the host db cache" mode */
} TSCacheClearT;
/*--- diagnostic output operations ----------------------------------------*/
@@ -900,12 +900,13 @@ tsapi TSProxyStateT TSProxyStateGet();
/* TSProxyStateSet: set the proxy state (on/off)
* Input: proxy_state - set to on/off
- * clear - specifies if want to start TS with clear_cache or
- * clear_cache_hostdb option, or just run TS with no options;
- * only applies when turning proxy on
+ * clear - a TSCacheClearT bitmask,
+ * specifies if want to start TS with clear_cache or
+ * clear_cache_hostdb option, or just run TS with no options;
+ * only applies when turning proxy on
* Output: TSMgmtError
*/
-tsapi TSMgmtError TSProxyStateSet(TSProxyStateT proxy_state, TSCacheClearT clear);
+tsapi TSMgmtError TSProxyStateSet(TSProxyStateT proxy_state, unsigned clear);
/* TSProxyBacktraceGet: get a backtrace of the proxy
* Input: unsigned options - stack trace options
--
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.