TS-974: Partial Object Caching.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/528eab64 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/528eab64 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/528eab64 Branch: refs/heads/poc-6-0-x Commit: 528eab64a26e869ce69a4bb3729c7441cd9b4906 Parents: 703ccb7 Author: Alan M. Carroll <solidwallofc...@yahoo-inc.com> Authored: Wed Mar 25 20:13:14 2015 -0500 Committer: Alan M. Carroll <solidwallofc...@yahoo-inc.com> Committed: Fri Jun 26 22:06:50 2015 -0500 ---------------------------------------------------------------------- cmd/traffic_cop/traffic_cop.cc | 29 +- cmd/traffic_crashlog/procinfo.cc | 12 +- cmd/traffic_crashlog/traffic_crashlog.cc | 6 +- cmd/traffic_crashlog/traffic_crashlog.h | 3 +- cmd/traffic_ctl/alarm.cc | 3 +- cmd/traffic_ctl/metric.cc | 6 +- cmd/traffic_ctl/traffic_ctl.h | 3 +- cmd/traffic_line/traffic_line.cc | 29 +- cmd/traffic_manager/AddConfigFilesHere.cc | 1 - cmd/traffic_manager/StatProcessor.cc | 11 - cmd/traffic_manager/StatProcessor.h | 1 - cmd/traffic_manager/StatType.cc | 36 - cmd/traffic_manager/StatType.h | 2 - cmd/traffic_manager/StatXML.cc | 1 - cmd/traffic_manager/StatXML.h | 1 - cmd/traffic_manager/WebOverview.cc | 13 +- cmd/traffic_top/stats.h | 12 +- cmd/traffic_top/traffic_top.cc | 26 +- cmd/traffic_via/traffic_via.cc | 23 +- doc/arch/cache/cache-data-structures.en.rst | 3 +- iocore/cache/Cache.cc | 76 ++- iocore/cache/CacheDir.cc | 132 ++-- iocore/cache/CacheHttp.cc | 325 ++++++++- iocore/cache/CacheRead.cc | 713 +++++++++---------- iocore/cache/CacheTest.cc | 4 +- iocore/cache/CacheVol.cc | 5 +- iocore/cache/CacheWrite.cc | 417 +++++++++--- iocore/cache/I_Cache.h | 72 ++ iocore/cache/I_CacheDefs.h | 4 +- iocore/cache/P_CacheBC.h | 30 +- iocore/cache/P_CacheDir.h | 97 ++- iocore/cache/P_CacheHttp.h | 287 +++++++- iocore/cache/P_CacheInternal.h | 105 ++- iocore/cache/P_CacheVol.h | 10 +- iocore/cluster/ClusterCache.cc | 2 +- iocore/cluster/ClusterVConnection.cc | 1 + iocore/cluster/P_Cluster.h | 3 +- iocore/cluster/P_ClusterCache.h | 22 + lib/ts/CryptoHash.h | 47 +- lib/ts/InkErrno.h | 2 + lib/ts/ParseRules.cc | 18 + lib/ts/ParseRules.h | 20 + lib/ts/TsBuffer.h | 97 ++- lib/ts/ink_code.cc | 29 + mgmt/Alarms.cc | 13 +- mgmt/Alarms.h | 1 - mgmt/BaseManager.cc | 5 - mgmt/BaseManager.h | 4 - mgmt/FileManager.cc | 40 +- mgmt/LocalManager.cc | 82 ++- mgmt/MultiFile.cc | 1 - mgmt/ProcessManager.cc | 22 +- mgmt/ProxyConfig.h | 6 +- mgmt/RecordsConfig.h | 4 +- mgmt/RecordsConfigUtils.cc | 21 +- mgmt/Rollback.cc | 45 +- mgmt/Rollback.h | 3 +- mgmt/WebMgmtUtils.cc | 10 +- mgmt/api/APITestCliRemote.cc | 64 +- mgmt/api/CfgContextImpl.cc | 19 +- mgmt/api/CfgContextManager.cc | 5 - mgmt/api/CfgContextManager.h | 2 - mgmt/api/CfgContextUtils.cc | 19 +- mgmt/api/CfgContextUtils.h | 2 - mgmt/api/CoreAPI.cc | 7 +- mgmt/api/CoreAPI.h | 4 +- mgmt/api/CoreAPIRemote.cc | 3 +- mgmt/api/CoreAPIShared.cc | 20 +- mgmt/api/EventCallback.cc | 12 +- mgmt/api/EventControlMain.cc | 27 +- mgmt/api/GenericParser.cc | 25 +- mgmt/api/GenericParser.h | 1 - mgmt/api/INKMgmtAPI.cc | 9 +- mgmt/api/NetworkMessage.cc | 9 +- mgmt/api/NetworkMessage.h | 9 +- mgmt/api/NetworkUtilsLocal.cc | 6 +- mgmt/api/NetworkUtilsRemote.cc | 15 +- mgmt/api/NetworkUtilsRemote.h | 3 +- mgmt/api/TSControlMain.cc | 24 +- mgmt/cluster/ClusterCom.cc | 166 ++--- mgmt/cluster/ClusterCom.h | 17 +- mgmt/cluster/VMap.cc | 58 +- mgmt/cluster/VMap.h | 6 +- mgmt/utils/MgmtHashTable.h | 1 - mgmt/utils/MgmtMarshall.h | 12 +- mgmt/utils/MgmtUtils.cc | 3 +- mgmt/utils/test_marshall.cc | 6 +- proxy/ControlMatcher.cc | 9 +- proxy/ControlMatcher.h | 6 +- proxy/CoreUtils.cc | 13 +- proxy/Crash.cc | 12 +- proxy/DynamicStats.h | 13 +- proxy/EventName.cc | 4 - proxy/FetchSM.cc | 12 +- proxy/ICP.cc | 2 - proxy/ICPConfig.cc | 8 +- proxy/ICPProcessor.cc | 1 - proxy/ICPProcessor.h | 1 - proxy/ICPlog.h | 1 - proxy/IPAllow.cc | 7 +- proxy/InkAPITest.cc | 307 ++++----- proxy/InkAPITestTool.cc | 20 +- proxy/InkIOCoreAPI.cc | 7 - proxy/Main.h | 1 - proxy/ParentSelection.cc | 49 +- proxy/Plugin.cc | 7 +- proxy/PluginVC.cc | 9 +- proxy/Prefetch.cc | 61 +- proxy/Prefetch.h | 1 - proxy/ProtoSM.h | 1 - proxy/ProtocolProbeSessionAccept.cc | 12 +- proxy/ProtocolProbeSessionAccept.h | 3 +- proxy/ProxyClientSession.h | 6 +- proxy/ReverseProxy.h | 3 +- proxy/Show.h | 1 - proxy/StatSystem.cc | 7 +- proxy/TestClusterHash.cc | 1 - proxy/TestPreProc.cc | 2 - proxy/TestProxy.cc | 1 - proxy/TestSimpleProxy.cc | 1 - proxy/TimeTrace.h | 1 - proxy/Transform.h | 1 - proxy/UDPAPIClientTest.cc | 2 - proxy/api/ts/InkAPIPrivateIOCore.h | 1 - proxy/api/ts/remap.h | 40 +- proxy/api/ts/ts.h | 76 ++- proxy/hdrs/HTTP.cc | 798 ++++++++++++++++++---- proxy/hdrs/HTTP.h | 826 ++++++++++++++++++++--- proxy/http/HttpCacheSM.cc | 31 + proxy/http/HttpCacheSM.h | 9 +- proxy/http/HttpDebugNames.cc | 2 + proxy/http/HttpSM.cc | 286 +++++--- proxy/http/HttpSM.h | 4 +- proxy/http/HttpTransact.cc | 209 ++++-- proxy/http/HttpTransact.h | 93 ++- proxy/http/HttpTransactHeaders.cc | 13 + proxy/http/HttpTransactHeaders.h | 1 + proxy/http/HttpTunnel.cc | 14 +- proxy/http2/HPACK.cc | 10 +- proxy/http2/HPACK.h | 9 +- proxy/http2/HTTP2.cc | 25 +- proxy/http2/HTTP2.h | 35 +- proxy/http2/Http2ClientSession.cc | 18 +- proxy/http2/Http2ClientSession.h | 4 +- proxy/http2/Http2ConnectionState.h | 13 +- proxy/http2/Http2SessionAccept.cc | 11 +- proxy/http2/Http2SessionAccept.h | 12 +- proxy/logging/Log.cc | 29 +- proxy/logging/Log.h | 4 +- proxy/logging/LogAccess.cc | 11 +- proxy/logging/LogAccessHttp.cc | 18 +- proxy/logging/LogAccessHttp.h | 1 - proxy/logging/LogAccessICP.h | 1 - proxy/logging/LogAccessTest.h | 1 - proxy/logging/LogBuffer.cc | 3 - proxy/logging/LogBuffer.h | 10 +- proxy/logging/LogCollationHostSM.cc | 3 +- proxy/logging/LogConfig.h | 5 - proxy/logging/LogField.cc | 5 - proxy/logging/LogField.h | 3 - proxy/logging/LogFieldAliasMap.h | 6 +- proxy/logging/LogFile.cc | 4 +- proxy/logging/LogFile.h | 1 - proxy/logging/LogFilter.cc | 16 +- proxy/logging/LogFilter.h | 3 - proxy/logging/LogFormat.cc | 17 +- proxy/logging/LogFormat.h | 3 +- proxy/logging/LogObject.cc | 46 +- proxy/logging/LogObject.h | 4 +- proxy/logging/LogSock.h | 1 - proxy/logging/LogStandalone.cc | 2 - proxy/logging/LogUtils.cc | 6 +- proxy/logstats.cc | 45 +- 173 files changed, 4743 insertions(+), 2188 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_cop/traffic_cop.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_cop/traffic_cop.cc b/cmd/traffic_cop/traffic_cop.cc index e3476fe..55778ff 100644 --- a/cmd/traffic_cop/traffic_cop.cc +++ b/cmd/traffic_cop/traffic_cop.cc @@ -202,7 +202,6 @@ cop_log(int priority, const char *format, ...) va_end(args); } - void chown_file_to_admin_user(const char *file) { @@ -412,7 +411,6 @@ safe_kill(const char *lockfile_name, const char *pname, bool group) cop_log_trace("Leaving safe_kill(%s, %s, %d)\n", lockfile_name, pname, group); } - // ink_hrtime milliseconds() // // Returns the result of gettimeofday converted to @@ -817,7 +815,6 @@ spawn_manager() cop_log_trace("Leaving spawn_manager()\n"); } - static int poll_read_or_write(int fd, int timeout, int inorout) { @@ -917,7 +914,8 @@ open_socket(int port, const char *ip = NULL, char const *ip_to_bind = NULL) ((sockaddr_in6 *)result_to_bind->ai_addr)->sin6_port = htons(source_port); } - // also set REUSEADDR so that previous cop connections in the TIME_WAIT state + // also set REUSEADDR so that previous cop connections in the TIME_WAIT + // state // do not interfere if (safe_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, SOCKOPT_ON, sizeof(int)) < 0) { cop_log(COP_WARNING, "(test) unable to set REUSEADDR socket option [%d '%s']\n", errno, strerror(errno)); @@ -1176,7 +1174,6 @@ read_mgmt_cli_int(const char *variable, int *value) return 0; } - static int test_rs_port() { @@ -1196,7 +1193,6 @@ test_rs_port() return 0; } - static int test_mgmt_cli_port() { @@ -1218,7 +1214,6 @@ test_mgmt_cli_port() return ret; } - static int test_http_port(int port, char *request, int timeout, char const *ip = NULL, char const *ip_to_bind = NULL) { @@ -1301,7 +1296,8 @@ heartbeat_manager() err = test_rs_port(); if (err < 0) { - // See heartbeat_server()'s comments for how we determine a server/manager failure. + // See heartbeat_server()'s comments for how we determine a server/manager + // failure. manager_failures += 1; cop_log(COP_WARNING, "manager heartbeat [variable] failed [%d]\n", manager_failures); @@ -1401,7 +1397,6 @@ server_up() } } - // | state | status | action // --------|---------|----------|--------------- // manager | up | ok | nothing @@ -1416,7 +1411,6 @@ server_up() // manager | up | ok | kill server // server | up | bad | - static void check_programs() { @@ -1653,7 +1647,8 @@ check(void *arg) // the SIGALRM signal which we use to heartbeat the cop. millisleep(sleep_time * 1000); - // We do this after the first round of checks, since the first "check" will spawn traffic_manager + // We do this after the first round of checks, since the first "check" will + // spawn traffic_manager if (!mgmt_init) { ats_scoped_str runtimedir(config_read_runtime_dir()); TSInit(runtimedir, static_cast<TSInitOptionT>(TS_MGMT_OPT_NO_EVENTS)); @@ -1673,7 +1668,6 @@ check(void *arg) return arg; } - static void check_lockfile() { @@ -1795,8 +1789,9 @@ init_config_file() if (stat(config_file, &info) < 0) { Layout::relative_to(config_file, sizeof(config_file), config_dir, "records.config"); if (stat(config_file, &info) < 0) { - cop_log(COP_FATAL, "unable to locate \"%s/records.config\" or \"%s/records.config.shadow\"\n", (const char *)config_dir, - (const char *)config_dir); + cop_log(COP_FATAL, "unable to locate \"%s/records.config\" or " + "\"%s/records.config.shadow\"\n", + (const char *)config_dir, (const char *)config_dir); exit(1); } } @@ -1810,7 +1805,8 @@ init() cop_log_trace("Entering init()\n"); - // Start up the records store and load the defaults so that we can locate our configuration. + // Start up the records store and load the defaults so that we can locate our + // configuration. RecConfigFileInit(); RecordsConfigIterate(config_register_default, NULL); @@ -1823,7 +1819,8 @@ init() runtime_dir = config_read_runtime_dir(); if (stat(runtime_dir, &info) < 0) { cop_log(COP_FATAL, "unable to locate local state directory '%s'\n", runtime_dir); - cop_log(COP_FATAL, " please try setting correct root path in either env variable TS_ROOT \n"); + cop_log(COP_FATAL, " please try setting correct root path in either env " + "variable TS_ROOT \n"); exit(1); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_crashlog/procinfo.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_crashlog/procinfo.cc b/cmd/traffic_crashlog/procinfo.cc index cb15b87..b8a9414 100644 --- a/cmd/traffic_crashlog/procinfo.cc +++ b/cmd/traffic_crashlog/procinfo.cc @@ -146,9 +146,12 @@ crashlog_write_backtrace(FILE *fp, const crashlog_target &) TSString trace = NULL; TSMgmtError mgmterr; - // NOTE: sometimes we can't get a backtrace because the ptrace attach will fail with - // EPERM. I've seen this happen when a debugger is attached, which makes sense, but it - // can also happen without a debugger. Possibly in that case, there is a race with the + // NOTE: sometimes we can't get a backtrace because the ptrace attach will + // fail with + // EPERM. I've seen this happen when a debugger is attached, which makes + // sense, but it + // can also happen without a debugger. Possibly in that case, there is a race + // with the // kernel locking the process information? if ((mgmterr = TSProxyBacktraceGet(0, &trace)) != TS_ERR_OKAY) { @@ -177,7 +180,8 @@ crashlog_write_records(FILE *fp, const crashlog_target &) goto done; } - // If the RPC call failed, the list will be empty, so we won't print anything. Otherwise, + // If the RPC call failed, the list will be empty, so we won't print anything. + // Otherwise, // print all the results, freeing them as we go. for (TSRecordEle *rec_ele = (TSRecordEle *)TSListDequeue(list); rec_ele; rec_ele = (TSRecordEle *)TSListDequeue(list)) { if (!success) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_crashlog/traffic_crashlog.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_crashlog/traffic_crashlog.cc b/cmd/traffic_crashlog/traffic_crashlog.cc index 7c5599f..1460488 100644 --- a/cmd/traffic_crashlog/traffic_crashlog.cc +++ b/cmd/traffic_crashlog/traffic_crashlog.cc @@ -101,8 +101,10 @@ main(int /* argc ATS_UNUSED */, const char **argv) kill(getpid(), SIGSTOP); } - // XXX This is a hack. traffic_manager starts traffic_server with the euid of the admin user. We are still - // privileged, but won't be able to open files in /proc or ptrace the target. This really should be fixed + // XXX This is a hack. traffic_manager starts traffic_server with the euid of + // the admin user. We are still + // privileged, but won't be able to open files in /proc or ptrace the target. + // This really should be fixed // in traffic_manager. if (getuid() == 0) { ATS_UNUSED_RETURN(seteuid(0)); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_crashlog/traffic_crashlog.h ---------------------------------------------------------------------- diff --git a/cmd/traffic_crashlog/traffic_crashlog.h b/cmd/traffic_crashlog/traffic_crashlog.h index 0b066d1..6da4128 100644 --- a/cmd/traffic_crashlog/traffic_crashlog.h +++ b/cmd/traffic_crashlog/traffic_crashlog.h @@ -27,7 +27,8 @@ #include "libts.h" #include "mgmtapi.h" -// ucontext.h is deprecated on Darwin, and we really only need it on Linux, so only +// ucontext.h is deprecated on Darwin, and we really only need it on Linux, so +// only // include it if we are planning to use it. #if defined(__linux__) #include <ucontext.h> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_ctl/alarm.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_ctl/alarm.cc b/cmd/traffic_ctl/alarm.cc index c341ffa..88754e9 100644 --- a/cmd/traffic_ctl/alarm.cc +++ b/cmd/traffic_ctl/alarm.cc @@ -128,7 +128,8 @@ subcommand_alarm(unsigned argc, const char **argv) {alarm_clear, "clear", "Clear all current alarms"}, {alarm_list, "list", "List all current alarms"}, - // Note that we separate resolve one from resolve all for the same reasons that + // Note that we separate resolve one from resolve all for the same reasons + // that // we have "metric zero" and "metric clear". {alarm_resolve, "resolve", "Resolve the listed alarms"}, /* XXX describe a specific alarm? */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_ctl/metric.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_ctl/metric.cc b/cmd/traffic_ctl/metric.cc index 36a8b6e..9c8d124 100644 --- a/cmd/traffic_ctl/metric.cc +++ b/cmd/traffic_ctl/metric.cc @@ -132,8 +132,10 @@ subcommand_metric(unsigned argc, const char **argv) {metric_match, "match", "Get metrics matching a regular expression"}, {CtrlUnimplementedCommand, "monitor", "Display the value of a metric over time"}, - // We could allow clearing all the metrics in the "clear" subcommand, but that seems error-prone. It - // would be too easy to just expect a help message and accidentally nuke all the metrics. + // We could allow clearing all the metrics in the "clear" subcommand, but + // that seems error-prone. It + // would be too easy to just expect a help message and accidentally nuke all + // the metrics. {metric_zero, "zero", "Clear one or more metric values"}, }; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_ctl/traffic_ctl.h ---------------------------------------------------------------------- diff --git a/cmd/traffic_ctl/traffic_ctl.h b/cmd/traffic_ctl/traffic_ctl.h index b77ee40..b83c60e 100644 --- a/cmd/traffic_ctl/traffic_ctl.h +++ b/cmd/traffic_ctl/traffic_ctl.h @@ -193,7 +193,8 @@ struct CtrlCommandLine { this->args.push_back(argv[i]); } - // Always NULL-terminate to keep ink_args happy. Note that we adjust arg() accordingly. + // Always NULL-terminate to keep ink_args happy. Note that we adjust arg() + // accordingly. this->args.push_back(NULL); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_line/traffic_line.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_line/traffic_line.cc b/cmd/traffic_line/traffic_line.cc index 0c10839..743e69d 100644 --- a/cmd/traffic_line/traffic_line.cc +++ b/cmd/traffic_line/traffic_line.cc @@ -90,13 +90,16 @@ handleArgInvocation() TSRecordEleDestroy(rec_ele); return TSStatsReset(*ZeroCluster ? true : false, name); } else if (QueryDeadhosts == 1) { - fprintf(stderr, "Query Deadhosts is not implemented, it requires support for congestion control.\n"); - fprintf(stderr, "For more details, examine the old code in cli/CLI.cc: QueryDeadhosts()\n"); + fprintf(stderr, "Query Deadhosts is not implemented, it requires support " + "for congestion control.\n"); + fprintf(stderr, "For more details, examine the old code in cli/CLI.cc: " + "QueryDeadhosts()\n"); return TS_ERR_FAIL; } else if (*StorageCmdOffline) { return TSStorageDeviceCmdOffline(StorageCmdOffline); } else if (ShowAlarms == 1) { - // Show all active alarms, this was moved from the old traffic_shell implementation (show:alarms). + // Show all active alarms, this was moved from the old traffic_shell + // implementation (show:alarms). TSList events = TSListCreate(); if (TS_ERR_OKAY != TSActiveEventGetMlt(events)) { @@ -119,7 +122,8 @@ handleArgInvocation() TSListDestroy(events); return TS_ERR_OKAY; } else if (*ClearAlarms != '\0') { - // Clear (some) active alarms, this was moved from the old traffic_shell implementation (config:alarm) + // Clear (some) active alarms, this was moved from the old traffic_shell + // implementation (config:alarm) TSList events = TSListCreate(); size_t len = strlen(ClearAlarms); @@ -189,7 +193,9 @@ handleArgInvocation() return err; } else if (*ReadVar != '\0') { // Handle a value read if (*SetVar != '\0' || *VarValue != '\0') { - fprintf(stderr, "%s: Invalid Argument Combination: Can not read and set values at the same time\n", program_name); + fprintf(stderr, "%s: Invalid Argument Combination: Can not read and set " + "values at the same time\n", + program_name); return TS_ERR_FAIL; } else { TSMgmtError err; @@ -222,7 +228,9 @@ handleArgInvocation() } } else if (*MatchVar != '\0') { // Handle a value read if (*SetVar != '\0' || *VarValue != '\0') { - fprintf(stderr, "%s: Invalid Argument Combination: Can not read and set values at the same time\n", program_name); + fprintf(stderr, "%s: Invalid Argument Combination: Can not read and set " + "values at the same time\n", + program_name); return TS_ERR_FAIL; } else { TSMgmtError err; @@ -234,7 +242,8 @@ handleArgInvocation() ats_free(msg); } - // If the RPC call failed, the list will be empty, so we won't print anything. Otherwise, + // If the RPC call failed, the list will be empty, so we won't print + // anything. Otherwise, // print all the results, freeing them as we go. for (TSRecordEle *rec_ele = (TSRecordEle *)TSListDequeue(list); rec_ele; rec_ele = (TSRecordEle *)TSListDequeue(list)) { switch (rec_ele->rec_type) { @@ -334,7 +343,8 @@ main(int /* argc ATS_UNUSED */, const char **argv) ShowStatus = 0; ClearAlarms[0] = '\0'; - /* Argument description table used to describe how to parse command line args, */ + /* Argument description table used to describe how to parse command line args, + */ /* see 'ink_args.h' for meanings of the various fields */ ArgumentDescription argument_descriptions[] = { {"query_deadhosts", 'q', "Query congested sites", "F", &QueryDeadhosts, NULL, NULL}, @@ -367,7 +377,8 @@ main(int /* argc ATS_UNUSED */, const char **argv) // Connect to Local Manager and do it. if (TS_ERR_OKAY != TSInit(NULL, static_cast<TSInitOptionT>(TS_MGMT_OPT_NO_EVENTS | TS_MGMT_OPT_NO_SOCK_TESTS))) { - fprintf(stderr, "error: could not connect to management port, make sure traffic_manager is running\n"); + fprintf(stderr, "error: could not connect to management port, make sure " + "traffic_manager is running\n"); exit(1); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_manager/AddConfigFilesHere.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_manager/AddConfigFilesHere.cc b/cmd/traffic_manager/AddConfigFilesHere.cc index ea9066b..76c223b 100644 --- a/cmd/traffic_manager/AddConfigFilesHere.cc +++ b/cmd/traffic_manager/AddConfigFilesHere.cc @@ -42,7 +42,6 @@ testcall(char *foo, bool /* incVersion */) Debug("lm", "Received Callback that %s has changed\n", foo); } - // // initializeRegistry() // http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_manager/StatProcessor.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_manager/StatProcessor.cc b/cmd/traffic_manager/StatProcessor.cc index 9202aca..0261689 100644 --- a/cmd/traffic_manager/StatProcessor.cc +++ b/cmd/traffic_manager/StatProcessor.cc @@ -64,7 +64,6 @@ xml_strcmp(const xmlchar *s1, const char *s2) return strcmp((const char *)s1, s2); } - static void elementStart(void * /* userData ATS_UNUSED */, const xmlchar *name, const xmlchar **atts) { @@ -138,7 +137,6 @@ elementStart(void * /* userData ATS_UNUSED */, const xmlchar *name, const xmlcha } } - static void elementEnd(void * /* userData ATS_UNUSED */, const xmlchar * /* name ATS_UNUSED */) { @@ -158,7 +156,6 @@ elementEnd(void * /* userData ATS_UNUSED */, const xmlchar * /* name ATS_UNUSED } } - static void charDataHandler(void * /* userData ATS_UNUSED */, const xmlchar *name, int /* len ATS_UNUSED */) { @@ -179,13 +176,11 @@ charDataHandler(void * /* userData ATS_UNUSED */, const xmlchar *name, int /* le } } - StatProcessor::StatProcessor(FileManager *configFiles) : m_lmgmt(NULL), m_overviewGenerator(NULL) { rereadConfig(configFiles); } - void StatProcessor::rereadConfig(FileManager *configFiles) { @@ -256,19 +251,16 @@ StatProcessor::rereadConfig(FileManager *configFiles) xmlFreeParserCtxt(parser); #endif - delete fileContent; Debug(MODULE_INIT, "\n\n---------- END OF PARSING & INITIALIZING ---------\n\n"); } - StatProcessor::~StatProcessor() { Debug(MODULE_INIT, "[StatProcessor] Destructing Statistics Processor\n"); } - void setTest() { @@ -287,7 +279,6 @@ setTest() } } - void verifyTest() { @@ -319,7 +310,6 @@ verifyTest() } } - /** * Updating the statistics NOW. **/ @@ -337,7 +327,6 @@ StatProcessor::processStat() return (result); } - /** * ExpressionEval * -------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_manager/StatProcessor.h ---------------------------------------------------------------------- diff --git a/cmd/traffic_manager/StatProcessor.h b/cmd/traffic_manager/StatProcessor.h index c6b3dd8..caa2eab 100644 --- a/cmd/traffic_manager/StatProcessor.h +++ b/cmd/traffic_manager/StatProcessor.h @@ -75,7 +75,6 @@ public: overviewPage *m_overviewGenerator; }; - /** * External expression evaluation API. * http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_manager/StatType.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_manager/StatType.cc b/cmd/traffic_manager/StatType.cc index 11b1484..d500a62 100644 --- a/cmd/traffic_manager/StatType.cc +++ b/cmd/traffic_manager/StatType.cc @@ -53,7 +53,6 @@ StatExprToken::StatExprToken() memset(&m_token_value_delta, 0, sizeof(m_token_value_delta)); } - /** * StatExprToken::copy() * --------------------- @@ -84,7 +83,6 @@ StatExprToken::copy(const StatExprToken &source) m_sum_var = source.m_sum_var; } - /** * StatExprToken::assignTokenName() * -------------------------------- @@ -135,7 +133,6 @@ StatExprToken::assignTokenName(const char *name) } } - /** * assignTokenType() * ----------------- @@ -164,7 +161,6 @@ StatExprToken::assignTokenType() return (m_token_type != RECD_NULL); } - void StatExprToken::clean() { @@ -172,7 +168,6 @@ StatExprToken::clean() delete m_token_value_delta; } - /** * FOR DEBUGGING ONLY * Print the token according to its type in a human-readable format. :) @@ -187,7 +182,6 @@ StatExprToken::print(const char *prefix) } } - /** * StatExprToken::precedence() * --------------------------- @@ -214,7 +208,6 @@ StatExprToken::precedence() } } - /** * StatExprToken::statVarSet() * --------------------------- @@ -280,7 +273,6 @@ StatExprToken::statVarSet(RecDataT type, RecData value) return varSetData(m_token_type, m_token_name, converted_value); } - /*********************************************************************** StatExprList **********************************************************************/ @@ -293,7 +285,6 @@ StatExprList::StatExprList() : m_size(0) { } - /** * StatExprList::clean() * --------------------- @@ -310,7 +301,6 @@ StatExprList::clean() ink_assert(m_size == 0); } - void StatExprList::enqueue(StatExprToken *entry) { @@ -319,7 +309,6 @@ StatExprList::enqueue(StatExprToken *entry) m_size += 1; } - void StatExprList::push(StatExprToken *entry) { @@ -328,7 +317,6 @@ StatExprList::push(StatExprToken *entry) m_size += 1; } - StatExprToken * StatExprList::dequeue() { @@ -339,7 +327,6 @@ StatExprList::dequeue() return (StatExprToken *)m_tokenList.dequeue(); } - StatExprToken * StatExprList::pop() { @@ -350,7 +337,6 @@ StatExprList::pop() return m_tokenList.pop(); } - StatExprToken * StatExprList::top() { @@ -360,7 +346,6 @@ StatExprList::top() return m_tokenList.head; } - StatExprToken * StatExprList::first() { @@ -370,7 +355,6 @@ StatExprList::first() return m_tokenList.head; } - StatExprToken * StatExprList::next(StatExprToken *current) { @@ -380,7 +364,6 @@ StatExprList::next(StatExprToken *current) return (current->link).next; } - /** * StatExprList::print() * --------------------- @@ -394,7 +377,6 @@ StatExprList::print(const char *prefix) } } - /** * StatExprToken::count() * ---------------------- @@ -406,12 +388,10 @@ StatExprList::count() return m_size; } - /*********************************************************************** StatObject **********************************************************************/ - /** * StatObject::StatObject() * ------------------------ @@ -424,7 +404,6 @@ StatObject::StatObject() { } - StatObject::StatObject(unsigned identifier) : m_id(identifier), m_debug(false), m_expr_string(NULL), m_node_dest(NULL), m_cluster_dest(NULL), m_expression(NULL), m_postfix(NULL), m_last_update(-1), m_current_time(-1), m_update_interval(-1), m_stats_max(FLT_MAX), m_stats_min(FLT_MIN), @@ -432,7 +411,6 @@ StatObject::StatObject(unsigned identifier) { } - /** * StatObject::clean() * ------------------- @@ -446,7 +424,6 @@ StatObject::clean() delete m_postfix; } - /** * StatObject::assignDst() * ----------------------- @@ -489,7 +466,6 @@ StatObject::assignDst(const char *str, bool m_node_var, bool m_sum_var) } } - /** * StatObject::assignExpr() * ------------------------ @@ -553,7 +529,6 @@ StatObject::assignExpr(char *str) infix2postfix(); } - /** * StatObject::infix2postfix() * --------------------------- @@ -628,7 +603,6 @@ StatObject::infix2postfix() m_expression = NULL; } - /** * StatObject::NodeStatEval() * -------------------------- @@ -715,7 +689,6 @@ StatObject::NodeStatEval(RecDataT *result_type, bool cluster) return tempValue; } - /** * StatObject::ClusterStatEval() * ----------------------------- @@ -743,7 +716,6 @@ StatObject::ClusterStatEval(RecDataT *result_type) } } - /** * StatObject::setTokenValue() * --------------------------- @@ -804,7 +776,6 @@ StatObject::setTokenValue(StatExprToken *token, bool cluster) } // m_token_name? } - /** * StatObject::StatBinaryEval() * ------------------------ @@ -934,7 +905,6 @@ StatObject::StatBinaryEval(StatExprToken *left, char op, StatExprToken *right, b return (result); } - /*********************************************************************** StatObjectList **********************************************************************/ @@ -943,7 +913,6 @@ StatObjectList::StatObjectList() : m_size(0) { } - void StatObjectList::clean() { @@ -957,7 +926,6 @@ StatObjectList::clean() ink_assert(m_size == 0); } - void StatObjectList::enqueue(StatObject *object) { @@ -972,21 +940,18 @@ StatObjectList::enqueue(StatObject *object) m_size += 1; } - StatObject * StatObjectList::first() { return m_statList.head; } - StatObject * StatObjectList::next(StatObject *current) { return (current->link).next; } - /** * StatObjectList::Eval() * ---------------------- @@ -1128,7 +1093,6 @@ StatObjectList::Eval() return count; } /* Eval() */ - /** * StatObjectList::print() * -------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_manager/StatType.h ---------------------------------------------------------------------- diff --git a/cmd/traffic_manager/StatType.h b/cmd/traffic_manager/StatType.h index 3ab0367..5f87134 100644 --- a/cmd/traffic_manager/StatType.h +++ b/cmd/traffic_manager/StatType.h @@ -112,7 +112,6 @@ public: bool statVarSet(RecDataT, RecData); }; - /** * StatExprList * simply a list of StatExprToken. @@ -181,7 +180,6 @@ private: void infix2postfix(); }; - /** * StatObjectList * simply a list of StatObject. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_manager/StatXML.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_manager/StatXML.cc b/cmd/traffic_manager/StatXML.cc index 1d6a7ba..57474e2 100644 --- a/cmd/traffic_manager/StatXML.cc +++ b/cmd/traffic_manager/StatXML.cc @@ -56,7 +56,6 @@ XML_extractContent(const char *name, char *content, size_t result_len) return (strlen(content)); } - // // Returns true if 'c'is an operator (in our definition), // false otherwise http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_manager/StatXML.h ---------------------------------------------------------------------- diff --git a/cmd/traffic_manager/StatXML.h b/cmd/traffic_manager/StatXML.h index 249be2f..f7428ca 100644 --- a/cmd/traffic_manager/StatXML.h +++ b/cmd/traffic_manager/StatXML.h @@ -21,7 +21,6 @@ limitations under the License. */ - #ifndef _STATXML_H_ #define _STATXML_H_ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_manager/WebOverview.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_manager/WebOverview.cc b/cmd/traffic_manager/WebOverview.cc index 252820d..6ce5a24 100644 --- a/cmd/traffic_manager/WebOverview.cc +++ b/cmd/traffic_manager/WebOverview.cc @@ -76,7 +76,6 @@ overviewRecord::overviewRecord(unsigned long inet_addr, bool local, ClusterPeerI RecGetRecordOrderAndId(node_rec_data.recs[0].name, &node_rec_first_ix, NULL); } - // Query for the name of the node. If it is not there, some // their cluster ip address name_l = this->readString("proxy.node.hostname_FQ", &name_found); @@ -278,7 +277,7 @@ overviewPage::overviewPage() : sortRecords(10, false) nodeRecords = ink_hash_table_create(InkHashTableKeyType_Word); numHosts = 0; ourAddr = 0; // We will update this when we add the record for - // this machine + // this machine } overviewPage::~overviewPage() @@ -331,7 +330,6 @@ overviewPage::checkForUpdates() ink_mutex_release(&accessLock); } - // overrviewPage::sortHosts() // // resorts sortRecords, but always leaves the local node @@ -428,7 +426,8 @@ overviewPage::findNodeByName(const char *nodeName) } } -// MgmtString overviewPage::readString(const char* nodeName, char* *name, bool *found = NULL) +// MgmtString overviewPage::readString(const char* nodeName, char* *name, bool +// *found = NULL) // // Looks up a node record for a specific by nodeName // CALLEE deallocates the string with free() @@ -457,7 +456,8 @@ overviewPage::readString(const char *nodeName, const char *name, bool *found) return r; } -// MgmtInt overviewPage::readInteger(const char* nodeName, char* *name, bool *found = NULL) +// MgmtInt overviewPage::readInteger(const char* nodeName, char* *name, bool +// *found = NULL) // // Looks up a node record for a specific by nodeName // @@ -485,7 +485,8 @@ overviewPage::readInteger(const char *nodeName, const char *name, bool *found) return r; } -// MgmtFloat overviewPage::readFloat(const char* nodeName, char* *name, bool *found = NULL) +// MgmtFloat overviewPage::readFloat(const char* nodeName, char* *name, bool +// *found = NULL) // // Looks up a node record for a specific by nodeName // http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_top/stats.h ---------------------------------------------------------------------- diff --git a/cmd/traffic_top/stats.h b/cmd/traffic_top/stats.h index 4b48bde..2982a8b 100644 --- a/cmd/traffic_top/stats.h +++ b/cmd/traffic_top/stats.h @@ -55,7 +55,6 @@ const char seperator[] = "\": \""; const char end[] = "\",\n"; }; - //---------------------------------------------------------------------------- class Stats { @@ -116,7 +115,6 @@ public: lookup_table.insert(make_pair("server_req_conn", LookupItem("Req/Conn", "server_req", "server_conn", 3))); lookup_table.insert(make_pair("server_curr_conn", LookupItem("Curr Conn", "proxy.process.http.current_server_connections", 1))); - lookup_table.insert( make_pair("client_head", LookupItem("Head Bytes", "proxy.process.http.user_agent_response_header_total_size", 2))); lookup_table.insert( @@ -132,7 +130,6 @@ public: lookup_table.insert(make_pair("ka_total", LookupItem("KA Total", "proxy.process.net.dynamic_keep_alive_timeout_in_total", 2))); lookup_table.insert(make_pair("ka_count", LookupItem("KA Count", "proxy.process.net.dynamic_keep_alive_timeout_in_count", 2))); - lookup_table.insert(make_pair("client_abort", LookupItem("Clnt Abort", "proxy.process.http.err_client_abort_count_stat", 2))); lookup_table.insert(make_pair("conn_fail", LookupItem("Conn Fail", "proxy.process.http.err_connect_fail_count_stat", 2))); lookup_table.insert(make_pair("abort", LookupItem("Abort", "proxy.process.http.transaction_counts.errors.aborts", 2))); @@ -222,7 +219,6 @@ public: lookup_table.insert(make_pair("s_1m", LookupItem("1 MB", "proxy.process.http.response_document_size_1M", 5))); lookup_table.insert(make_pair("s_>1m", LookupItem("> 1 MB", "proxy.process.http.response_document_size_inf", 5))); - // sum together lookup_table.insert(make_pair("ram_hit_miss", LookupItem("Ram Hit+Miss", "ram_hit", "ram_miss", 6))); lookup_table.insert(make_pair("client_net", LookupItem("Net (bits)", "client_head", "client_body", 7))); @@ -233,7 +229,6 @@ public: lookup_table.insert(make_pair("server_size", LookupItem("Total Size", "server_head", "server_body", 6))); lookup_table.insert(make_pair("server_avg_size", LookupItem("Avg Size", "server_size", "server_req", 3))); - lookup_table.insert(make_pair("total_time", LookupItem("Total Time", "proxy.process.http.total_transactions_time", 2))); // ratio @@ -268,8 +263,10 @@ public: (*_stats)[key] = strValue; } else { if (TSRecordGetInt(item.name, &value) != TS_ERR_OKAY) { - fprintf(stderr, "Error getting stat: %s when calling TSRecordGetInt() failed: file \"%s\", line %d\n\n", item.name, - __FILE__, __LINE__); + fprintf(stderr, "Error getting stat: %s when calling " + "TSRecordGetInt() failed: file \"%s\", line " + "%d\n\n", + item.name, __FILE__, __LINE__); abort(); } string key = item.name; @@ -344,7 +341,6 @@ public: getStat(key, value, strtmp, typetmp, overrideType); } - void getStat(const string &key, string &value) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_top/traffic_top.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_top/traffic_top.cc b/cmd/traffic_top/traffic_top.cc index df447c2..85bbd3b 100644 --- a/cmd/traffic_top/traffic_top.cc +++ b/cmd/traffic_top/traffic_top.cc @@ -154,7 +154,8 @@ response_code_page(Stats &stats) { attron(COLOR_PAIR(colorPair::border)); attron(A_BOLD); - mvprintw(0, 0, " RESPONSE CODES "); + mvprintw(0, 0, " RESPONSE CODES " + " "); attroff(COLOR_PAIR(colorPair::border)); attroff(A_BOLD); @@ -229,22 +230,24 @@ help(const string &host, const string &version) attron(A_BOLD); mvprintw(0, 0, "Overview:"); attroff(A_BOLD); - mvprintw( - 1, 0, - "traffic_top is a top like program for Apache Traffic Server (ATS). " - "There is a lot of statistical information gathered by ATS. " - "This program tries to show some of the more important stats and gives a good overview of what the proxy server is doing. " - "Hopefully this can be used as a tool for diagnosing the proxy server if there are problems."); + mvprintw(1, 0, "traffic_top is a top like program for Apache Traffic Server (ATS). " + "There is a lot of statistical information gathered by ATS. " + "This program tries to show some of the more important stats and gives " + "a good overview of what the proxy server is doing. " + "Hopefully this can be used as a tool for diagnosing the proxy server " + "if there are problems."); attron(A_BOLD); mvprintw(7, 0, "Definitions:"); attroff(A_BOLD); mvprintw(8, 0, "Fresh => Requests that were servered by fresh entries in cache"); - mvprintw(9, 0, "Revalidate => Requests that contacted the origin to verify if still valid"); + mvprintw(9, 0, "Revalidate => Requests that contacted the origin to verify " + "if still valid"); mvprintw(10, 0, "Cold => Requests that were not in cache at all"); mvprintw(11, 0, "Changed => Requests that required entries in cache to be updated"); mvprintw(12, 0, "Changed => Requests that can't be cached for some reason"); - mvprintw(12, 0, "No Cache => Requests that the client sent Cache-Control: no-cache header"); + mvprintw(12, 0, "No Cache => Requests that the client sent " + "Cache-Control: no-cache header"); attron(COLOR_PAIR(colorPair::border)); attron(A_BOLD); @@ -400,7 +403,8 @@ main(int argc, char **argv) string url = ""; if (optind >= argc) { if (TS_ERR_OKAY != TSInit(NULL, static_cast<TSInitOptionT>(TS_MGMT_OPT_NO_EVENTS | TS_MGMT_OPT_NO_SOCK_TESTS))) { - fprintf(stderr, "Error: missing URL on command line or error connecting to the local manager\n"); + fprintf(stderr, "Error: missing URL on command line or error connecting " + "to the local manager\n"); usage(); } } else { @@ -424,7 +428,6 @@ main(int argc, char **argv) init_pair(colorPair::border, COLOR_WHITE, COLOR_BLUE); // mvchgat(0, 0, -1, A_BLINK, 1, NULL); - enum Page { MAIN_PAGE, RESPONSE_PAGE, @@ -447,7 +450,6 @@ main(int argc, char **argv) attroff(COLOR_PAIR(colorPair::border)); attroff(A_BOLD); - if (page == MAIN_PAGE) { main_stats_page(stats); } else if (page == RESPONSE_PAGE) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/cmd/traffic_via/traffic_via.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_via/traffic_via.cc b/cmd/traffic_via/traffic_via.cc index 7426d1b..b377d5c 100644 --- a/cmd/traffic_via/traffic_via.cc +++ b/cmd/traffic_via/traffic_via.cc @@ -84,12 +84,16 @@ detailViaLookup(char flag) // Cache Lookup Result viaTable->next = new VIA("Cache Lookup Result"); viaTable->next->viaData[(unsigned char)'C'] = "cache hit but config forces revalidate"; - viaTable->next->viaData[(unsigned char)'I'] = "conditional miss (client sent conditional, fresh in cache, returned 412)"; + viaTable->next->viaData[(unsigned char)'I'] = "conditional miss (client " + "sent conditional, fresh in " + "cache, returned 412)"; viaTable->next->viaData[(unsigned char)' '] = "cache miss or no cache lookup"; viaTable->next->viaData[(unsigned char)'U'] = "cache hit, but client forces revalidate (e.g. Pragma: no-cache)"; viaTable->next->viaData[(unsigned char)'D'] = "cache hit, but method forces revalidated (e.g. ftp, not anonymous)"; viaTable->next->viaData[(unsigned char)'M'] = "cache miss (url not in cache)"; - viaTable->next->viaData[(unsigned char)'N'] = "conditional hit (client sent conditional, doc fresh in cache, returned 304)"; + viaTable->next->viaData[(unsigned char)'N'] = "conditional hit (client " + "sent conditional, doc fresh " + "in cache, returned 304)"; viaTable->next->viaData[(unsigned char)'H'] = "cache hit"; viaTable->next->viaData[(unsigned char)'S'] = "cache hit, but expired"; viaTable->next->viaData[(unsigned char)'K'] = "cookie miss"; @@ -254,8 +258,11 @@ decodeViaHeader(const char *str) // Invalid header size, come out. printf("\nInvalid VIA header. VIA header length should be 6 or 24 characters\n"); printf("Valid via header format is " - "[u<client-stuff>c<cache-lookup-stuff>s<server-stuff>f<cache-fill-stuff>p<proxy-stuff>]e<error-codes>:t<tunneling-info>c<" - "cache type><cache-lookup-result>i<icp-conn-info>p<parent-proxy-conn-info>s<server-conn-info>]"); + "[u<client-stuff>c<cache-lookup-stuff>s<server-stuff>f<cache-fill-" + "stuff>p<proxy-stuff>]e<error-codes>:t<tunneling-info>c<" + "cache " + "type><cache-lookup-result>i<icp-conn-info>p<parent-proxy-conn-info>s<" + "server-conn-info>]"); return TS_ERR_FAIL; } @@ -270,8 +277,8 @@ filterViaHeader() int errOffset; int pcreExecCode; int i; - const char *viaPattern = - "\\[([ucsfpe]+[^\\]]+)\\]"; // Regex to match via header with in [] which can start with character class ucsfpe + const char *viaPattern = "\\[([ucsfpe]+[^\\]]+)\\]"; // Regex to match via header with in [] which + // can start with character class ucsfpe char *viaHeaderString; char viaHeader[1024]; @@ -301,7 +308,9 @@ filterViaHeader() // Match successful, but too many substrings if (pcreExecCode == 0) { pcreExecCode = SUBSTRING_VECTOR_COUNT / 3; - printf("Too many substrings were found. %d substrings couldn't fit into subStringVector\n", pcreExecCode - 1); + printf("Too many substrings were found. %d substrings couldn't fit into " + "subStringVector\n", + pcreExecCode - 1); } // Loop based on number of matches found http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/doc/arch/cache/cache-data-structures.en.rst ---------------------------------------------------------------------- diff --git a/doc/arch/cache/cache-data-structures.en.rst b/doc/arch/cache/cache-data-structures.en.rst index 1158051..b172999 100644 --- a/doc/arch/cache/cache-data-structures.en.rst +++ b/doc/arch/cache/cache-data-structures.en.rst @@ -24,7 +24,8 @@ Cache Data Structures .. cpp:class:: OpenDir - An open directory entry. It contains all the information of a + This represents an open directory entry. An entry is open when there is an active write on the object. Read operations do not of themselves require an `OpenDir` but if there is already one for the object it will be used by the read operation to coordinate with the write operations. + :cpp:class:`Dir` plus additional information from the first :cpp:class:`Doc`. .. cpp:class:: CacheVC http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/iocore/cache/Cache.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc index 330aedd..cb7468d 100644 --- a/iocore/cache/Cache.cc +++ b/iocore/cache/Cache.cc @@ -312,7 +312,7 @@ CacheVC::CacheVC() : alternate_index(CACHE_ALT_INDEX_DEFAULT) } #ifdef HTTP_CACHE -HTTPInfo::FragOffset * +HTTPInfo::FragmentDescriptorTable * CacheVC::get_frag_table() { ink_assert(alternate.valid()); @@ -482,10 +482,29 @@ CacheVC::set_http_info(CacheHTTPInfo *ainfo) } else f.allow_empty_doc = 0; alternate.copy_shallow(ainfo); + // This is not a good place to do this but I can't figure out a better one. We must do it + // no earlier than this, because there's no actual alternate to store the value in before this + // and I don't know of any later point that's guaranteed to be called before this is needed. + alternate.m_alt->m_fixed_fragment_size = cache_config_target_fragment_size - sizeofDoc; ainfo->clear(); } #endif +int64_t +CacheVC::set_inbound_range(int64_t min, int64_t max) +{ + resp_range.clear(); + resp_range.getRangeSpec().add(min, max); + return 1 + (max - min); +} + +void +CacheVC::set_full_content_length(int64_t cl) +{ + alternate.object_size_set(cl); + resp_range.apply(cl); +} + bool CacheVC::set_pin_in_cache(time_t time_pin) { @@ -501,6 +520,25 @@ CacheVC::set_pin_in_cache(time_t time_pin) return true; } +void +CacheVC::set_content_range(HTTPRangeSpec const &r) +{ + resp_range.getRangeSpec() = r; + resp_range.start(); +} + +bool +CacheVC::get_uncached(HTTPRangeSpec const &req, HTTPRangeSpec &result, int64_t initial) +{ + HTTPRangeSpec::Range r = + od ? write_vector->get_uncached_hull(earliest_key, req, initial) : alternate.get_uncached_hull(req, initial); + if (r.isValid()) { + result.add(r); + return true; + } + return false; +} + bool CacheVC::set_disk_io_priority(int priority) { @@ -559,6 +597,7 @@ Vol::close_read(CacheVC *cont) EThread *t = cont->mutex->thread_holding; ink_assert(t == this_ethread()); ink_assert(t == mutex->thread_holding); + open_dir.close_entry(cont); if (dir_is_empty(&cont->earliest_dir)) return 1; int i = dir_evac_bucket(&cont->earliest_dir); @@ -1112,6 +1151,12 @@ CacheProcessor::open_read(Continuation *cont, const CacheKey *key, bool cluster_ } inkcoreapi Action * +CacheProcessor::open_read(Continuation *cont, CacheVConnection* writer, HTTPHdr* client_request_hdr) +{ + return caches[CACHE_FRAG_TYPE_HTTP]->open_read(cont, writer, client_request_hdr); +} + +inkcoreapi Action * CacheProcessor::open_write(Continuation *cont, CacheKey *key, bool cluster_cache_local ATS_UNUSED, CacheFragType frag_type, int expected_size ATS_UNUSED, int options, time_t pin_in_cache, char *hostname, int host_len) { @@ -2164,6 +2209,19 @@ CacheVC::is_pread_capable() return !f.read_from_writer_called; } +#if 0 +void +CacheVC::get_missing_ranges(HTTPRangeSpec& missing) +{ + missing.reset(); + if (0 == alternate.); + // For now we'll just compute the convex hull of the missing data. + for ( RangeBox::const_iterator spot = req.begin(), limit = req.end() ; spot != limit ; ++spot ) { + + } +} +#endif + #define STORE_COLLISION 1 #ifdef HTTP_CACHE @@ -2189,7 +2247,7 @@ unmarshal_helper(Doc *doc, Ptr<IOBufferData> &buf, int &okay) @internal I looked at doing this in place (rather than a copy & modify) but - The in place logic would be even worse than this mess - It wouldn't save you that much, since you end up doing inserts early in the buffer. - Without extreme care in the logic it could end up doing more copying thatn + Without extreme care in the logic it could end up doing more copying than the simpler copy & modify. @internal This logic presumes the existence of some slack at the end of the buffer, which @@ -2208,6 +2266,7 @@ upgrade_doc_version(Ptr<IOBufferData> &buf) if (0 == doc->hlen) { Debug("cache_bc", "Doc %p without header, no upgrade needed.", doc); } else if (CACHE_FRAG_TYPE_HTTP_V23 == doc->doc_type) { + typedef cache_bc::HTTPCacheFragmentTable::FragOffset FragOffset; cache_bc::HTTPCacheAlt_v21 *alt = reinterpret_cast<cache_bc::HTTPCacheAlt_v21 *>(doc->hdr()); if (alt && alt->is_unmarshalled_format()) { Ptr<IOBufferData> d_buf(ioDataAllocator.alloc()); @@ -2215,9 +2274,8 @@ upgrade_doc_version(Ptr<IOBufferData> &buf) char *src; char *dst; char *hdr_limit = doc->data(); - HTTPInfo::FragOffset *frags = - reinterpret_cast<HTTPInfo::FragOffset *>(static_cast<char *>(buf->data()) + cache_bc::sizeofDoc_v23); - int frag_count = doc->_flen / sizeof(HTTPInfo::FragOffset); + FragOffset *frags = reinterpret_cast<FragOffset *>(static_cast<char *>(buf->data()) + cache_bc::sizeofDoc_v23); + int frag_count = doc->_flen / sizeof(FragOffset); size_t n = 0; size_t content_size = doc->data_len(); @@ -2450,6 +2508,11 @@ CacheVC::handleRead(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) io.action = this; io.thread = mutex->thread_holding->tt == DEDICATED ? AIO_CALLBACK_THREAD_ANY : mutex->thread_holding; SET_HANDLER(&CacheVC::handleReadDone); + { + char xt[33]; + Debug("amc", "cache read : key = %s %" PRId64 " bytes at stripe offset =% " PRId64, key.toHexStr(xt), io.aiocb.aio_nbytes, + io.aiocb.aio_offset); + } ink_assert(ink_aio_read(&io) >= 0); CACHE_DEBUG_INCREMENT_DYN_STAT(cache_pread_count_stat); return EVENT_CONT; @@ -2514,7 +2577,7 @@ CacheVC::removeEvent(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) goto Lfree; } if (!f.remove_aborted_writers) { - if (vol->open_write(this, true, 1)) { + if (vol->open_write(this)) { // writer exists ink_release_assert(od = vol->open_read(&key)); od->dont_update_directory = 1; @@ -3256,7 +3319,6 @@ CacheProcessor::open_read(Continuation *cont, const HttpCacheKey *key, bool clus return caches[type]->open_read(cont, &key->hash, request, params, type, key->hostname, key->hostlen); } - //---------------------------------------------------------------------------- Action * CacheProcessor::open_write(Continuation *cont, int expected_size, const HttpCacheKey *key, bool cluster_cache_local, http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/iocore/cache/CacheDir.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/CacheDir.cc b/iocore/cache/CacheDir.cc index 000bc46..6fe0ddb 100644 --- a/iocore/cache/CacheDir.cc +++ b/iocore/cache/CacheDir.cc @@ -63,52 +63,44 @@ OpenDir::OpenDir() SET_HANDLER(&OpenDir::signal_readers); } -/* - If allow_if_writers is false, open_write fails if there are other writers. - max_writers sets the maximum number of concurrent writers that are - allowed. Only The first writer can set the max_writers. It is ignored - for later writers. - Returns 1 on success and 0 on failure. - */ -int -OpenDir::open_write(CacheVC *cont, int allow_if_writers, int max_writers) +OpenDirEntry * +OpenDir::open_entry(Vol *vol, CryptoHash const &key, bool force_p) { - ink_assert(cont->vol->mutex->thread_holding == this_ethread()); - unsigned int h = cont->first_key.slice32(0); + ink_assert(vol->mutex->thread_holding == this_ethread()); + unsigned int h = key.slice32(0); int b = h % OPEN_DIR_BUCKETS; for (OpenDirEntry *d = bucket[b].head; d; d = d->link.next) { - if (!(d->writers.head->first_key == cont->first_key)) + if (!(d->first_key == key)) continue; - if (allow_if_writers && d->num_writers < d->max_writers) { - d->writers.push(cont); - d->num_writers++; - cont->od = d; - cont->write_vector = &d->vector; - return 1; - } - return 0; + ++(d->num_active); + // cont->od = d; + // cont->write_vector = &d->vector; + return d; } - OpenDirEntry *od = THREAD_ALLOC(openDirEntryAllocator, cont->mutex->thread_holding); - od->readers.head = NULL; - od->writers.push(cont); - od->num_writers = 1; - od->max_writers = max_writers; + + if (!force_p) + return NULL; + + OpenDirEntry *od = THREAD_ALLOC(openDirEntryAllocator, vol->mutex->thread_holding); + od->mutex = new_ProxyMutex(); + od->first_key = key; + od->num_active = 1; od->vector.data.data = &od->vector.data.fast_data[0]; od->dont_update_directory = 0; od->move_resident_alt = 0; od->reading_vec = 0; od->writing_vec = 0; dir_clear(&od->first_dir); - cont->od = od; - cont->write_vector = &od->vector; + // cont->od = od; + // cont->write_vector = &od->vector; bucket[b].push(od); - return 1; + return od; } int OpenDir::signal_readers(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) { - Queue<CacheVC, Link_CacheVC_opendir_link> newly_delayed_readers; + CacheVCQ newly_delayed_readers; EThread *t = mutex->thread_holding; CacheVC *c = NULL; while ((c = delayed_readers.dequeue())) { @@ -130,32 +122,29 @@ OpenDir::signal_readers(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) return 0; } -int -OpenDir::close_write(CacheVC *cont) +void +OpenDir::close_entry(CacheVC *vc) { - ink_assert(cont->vol->mutex->thread_holding == this_ethread()); - cont->od->writers.remove(cont); - cont->od->num_writers--; - if (!cont->od->writers.head) { - unsigned int h = cont->first_key.slice32(0); + ink_assert(vc->vol->mutex->thread_holding == this_ethread()); + if (vc->od && --(vc->od->num_active) < 1) { + unsigned int h = vc->od->first_key.slice32(0); int b = h % OPEN_DIR_BUCKETS; - bucket[b].remove(cont->od); - delayed_readers.append(cont->od->readers); - signal_readers(0, 0); - cont->od->vector.clear(); - THREAD_FREE(cont->od, openDirEntryAllocator, cont->mutex->thread_holding); + bucket[b].remove(vc->od); + vc->od->vector.clear(); + vc->od->mutex = 0; + THREAD_FREE(vc->od, openDirEntryAllocator, vc->vol->mutex->thread_holding); } - cont->od = NULL; - return 0; + vc->od = NULL; } +#if 0 OpenDirEntry * OpenDir::open_read(const CryptoHash *key) { unsigned int h = key->slice32(0); int b = h % OPEN_DIR_BUCKETS; for (OpenDirEntry *d = bucket[b].head; d; d = d->link.next) - if (d->writers.head->first_key == *key) + if (d->first_key == *key) return d; return NULL; } @@ -170,6 +159,61 @@ OpenDirEntry::wait(CacheVC *cont, int msec) readers.push(cont); return EVENT_CONT; } +#endif + +int +OpenDirEntry::index_of(CacheKey const &alt_key) +{ + return vector.index_of(alt_key); +} + +bool +OpenDirEntry::has_writer(CacheKey const &alt_key) +{ + return vector.has_writer(alt_key); +} + +OpenDirEntry & +OpenDirEntry::write_active(CacheKey const &alt_key, CacheVC *vc, int64_t offset) +{ + Debug("amc", "VC %p write active @ %" PRId64, vc, offset); + vector.write_active(alt_key, vc, offset); + return *this; +} + +OpenDirEntry & +OpenDirEntry::write_complete(CacheKey const &alt_key, CacheVC *vc, bool success) +{ + Debug("amc", "[OpenDir::write_complete] VC %p write %s", vc, (success ? "succeeded" : "failed")); + vector.write_complete(alt_key, vc, success); + return *this; +} + +bool +OpenDirEntry::is_write_active(CacheKey const &alt_key, int64_t offset) +{ + return vector.is_write_active(alt_key, offset); +} + +CacheKey const & +OpenDirEntry::key_for(CacheKey const &alt_key, int64_t offset) +{ + return vector.key_for(alt_key, offset); +} + +bool +OpenDirEntry::wait_for(CacheKey const &alt_key, CacheVC *vc, int64_t offset) +{ + Debug("amc", "vc %p waiting for %" PRId64, vc, offset); + return vector.wait_for(alt_key, vc, offset); +} + +OpenDirEntry & +OpenDirEntry::close_writer(CacheKey const &alt_key, CacheVC *vc) +{ + vector.close_writer(alt_key, vc); + return *this; +} // // Cache Directory http://git-wip-us.apache.org/repos/asf/trafficserver/blob/528eab64/iocore/cache/CacheHttp.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/CacheHttp.cc b/iocore/cache/CacheHttp.cc index 3d7dfba..0ba989d 100644 --- a/iocore/cache/CacheHttp.cc +++ b/iocore/cache/CacheHttp.cc @@ -29,10 +29,10 @@ /*------------------------------------------------------------------------- -------------------------------------------------------------------------*/ -static vec_info default_vec_info; +// Guaranteed to be all zero? +static CacheHTTPInfoVector::Item default_vec_info; #ifdef HTTP_CACHE -static CacheHTTPInfo default_http_info; CacheHTTPInfoVector::CacheHTTPInfoVector() : magic(NULL), data(&default_vec_info, 4), xcount(0) { @@ -46,7 +46,7 @@ CacheHTTPInfoVector::~CacheHTTPInfoVector() int i; for (i = 0; i < xcount; i++) { - data[i].alternate.destroy(); + data[i]._alternate.destroy(); } vector_buf.clear(); magic = NULL; @@ -61,7 +61,7 @@ CacheHTTPInfoVector::insert(CacheHTTPInfo *info, int index) if (index == CACHE_ALT_INDEX_DEFAULT) index = xcount++; - data(index).alternate.copy_shallow(info); + data(index)._alternate.copy_shallow(info); return index; } @@ -77,8 +77,8 @@ CacheHTTPInfoVector::detach(int idx, CacheHTTPInfo *r) ink_assert(idx >= 0); ink_assert(idx < xcount); - r->copy_shallow(&data[idx].alternate); - data[idx].alternate.destroy(); + r->copy_shallow(&data[idx]._alternate); + data[idx]._alternate.destroy(); for (i = idx; i < (xcount - 1); i++) { data[i] = data[i + i]; @@ -94,7 +94,7 @@ void CacheHTTPInfoVector::remove(int idx, bool destroy) { if (destroy) - data[idx].alternate.destroy(); + data[idx]._alternate.destroy(); for (; idx < (xcount - 1); idx++) data[idx] = data[idx + 1]; @@ -112,7 +112,7 @@ CacheHTTPInfoVector::clear(bool destroy) if (destroy) { for (i = 0; i < xcount; i++) { - data[i].alternate.destroy(); + data[i]._alternate.destroy(); } } xcount = 0; @@ -134,14 +134,14 @@ CacheHTTPInfoVector::print(char *buffer, size_t buf_size, bool temps) purl = 1; for (i = 0; i < xcount; i++) { - if (data[i].alternate.valid()) { + if (data[i]._alternate.valid()) { if (purl) { Arena arena; char *url; purl = 0; URL u; - data[i].alternate.request_url_get(&u); + data[i]._alternate.request_url_get(&u); url = u.string_get(&arena); if (url) { snprintf(p, buf_size, "[%s] ", url); @@ -151,8 +151,8 @@ CacheHTTPInfoVector::print(char *buffer, size_t buf_size, bool temps) } } - if (temps || !(data[i].alternate.object_key_get() == zero_key)) { - snprintf(p, buf_size, "[%d %s]", data[i].alternate.id_get(), CacheKey(data[i].alternate.object_key_get()).toHexStr(buf)); + if (temps || !(data[i]._alternate.object_key_get() == zero_key)) { + snprintf(p, buf_size, "[%d %s]", data[i]._alternate.id_get(), CacheKey(data[i]._alternate.object_key_get()).toHexStr(buf)); tmp = strlen(p); p += tmp; buf_size -= tmp; @@ -170,7 +170,7 @@ CacheHTTPInfoVector::marshal_length() int length = 0; for (int i = 0; i < xcount; i++) { - length += data[i].alternate.marshal_length(); + length += data[i]._alternate.marshal_length(); } return length; @@ -187,7 +187,7 @@ CacheHTTPInfoVector::marshal(char *buf, int length) ink_assert(!(((intptr_t)buf) & 3)); // buf must be aligned for (int i = 0; i < xcount; i++) { - int tmp = data[i].alternate.marshal(buf, length); + int tmp = data[i]._alternate.marshal(buf, length); length -= tmp; buf += tmp; count++; @@ -199,8 +199,10 @@ CacheHTTPInfoVector::marshal(char *buf, int length) return buf - start; } -int -CacheHTTPInfoVector::unmarshal(const char *buf, int length, RefCountObj *block_ptr) +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ +uint32_t +CacheHTTPInfoVector::get_handles(const char *buf, int length, RefCountObj *block_ptr) { ink_assert(!(((intptr_t)buf) & 3)); // buf must be aligned @@ -208,50 +210,299 @@ CacheHTTPInfoVector::unmarshal(const char *buf, int length, RefCountObj *block_p CacheHTTPInfo info; xcount = 0; + vector_buf = block_ptr; + while (length - (buf - start) > (int)sizeof(HTTPCacheAlt)) { - int tmp = HTTPInfo::unmarshal((char *)buf, length - (buf - start), block_ptr); + int tmp = info.get_handle((char *)buf, length - (buf - start)); if (tmp < 0) { - return -1; + ink_assert(!"CacheHTTPInfoVector::unmarshal get_handle() failed"); + return (uint32_t)-1; } - info.m_alt = (HTTPCacheAlt *)buf; buf += tmp; - data(xcount).alternate = info; + data(xcount)._alternate = info; xcount++; } return ((caddr_t)buf - (caddr_t)start); } +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ + +int +CacheHTTPInfoVector::index_of(CacheKey const &alt_key) +{ + int zret; + for (zret = 0; zret < xcount && alt_key != data[zret]._alternate.object_key_get(); ++zret) + ; + return zret < xcount ? zret : -1; +} /*------------------------------------------------------------------------- -------------------------------------------------------------------------*/ -uint32_t -CacheHTTPInfoVector::get_handles(const char *buf, int length, RefCountObj *block_ptr) + +CacheKey const & +CacheHTTPInfoVector::key_for(CacheKey const &alt_key, int64_t offset) { - ink_assert(!(((intptr_t)buf) & 3)); // buf must be aligned + int idx = this->index_of(alt_key); + Item &item = data[idx]; + return item._alternate.get_frag_key_of(offset); +} - const char *start = buf; - CacheHTTPInfo info; - xcount = 0; +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ - vector_buf = block_ptr; +CacheHTTPInfoVector & +CacheHTTPInfoVector::write_active(CacheKey const &alt_key, CacheVC *vc, int64_t offset) +{ + int idx = this->index_of(alt_key); + Item &item = data[idx]; - while (length - (buf - start) > (int)sizeof(HTTPCacheAlt)) { - int tmp = info.get_handle((char *)buf, length - (buf - start)); - if (tmp < 0) { - ink_assert(!"CacheHTTPInfoVector::unmarshal get_handle() failed"); - return (uint32_t)-1; + Debug("amc", "[CacheHTTPInfoVector::write_active] VC %p write %" PRId64, vc, offset); + + vc->fragment = item._alternate.get_frag_index_of(offset); + item._active.push(vc); + return *this; +} + +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ + +CacheHTTPInfoVector & +CacheHTTPInfoVector::write_complete(CacheKey const &alt_key, CacheVC *vc, bool success) +{ + int idx = this->index_of(alt_key); + Item &item = data[idx]; + CacheVC *reader; + + Debug("amc", "[CacheHTTPInfoVector::write_complete] VC %p write %s", vc, (success ? "succeeded" : "failed")); + + item._active.remove(vc); + if (success) + item._alternate.mark_frag_write(vc->fragment); + + // Kick all the waiters, success or fail. + while (NULL != (reader = item._waiting.pop())) { + Debug("amc", "[write_complete] wake up %p", reader); + reader->wake_up_thread->schedule_imm(reader)->cookie = reinterpret_cast<void *>(0x56); + } + + return *this; +} + +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ + +bool +CacheHTTPInfoVector::has_writer(CacheKey const &alt_key) +{ + int alt_idx = this->index_of(alt_key); + return alt_idx >= 0 && data[alt_idx]._writers.head != NULL; +} + +bool +CacheHTTPInfoVector::is_write_active(CacheKey const &alt_key, int64_t offset) +{ + int alt_idx = this->index_of(alt_key); + Item &item = data[alt_idx]; + int frag_idx = item._alternate.get_frag_index_of(offset); + for (CacheVC *vc = item._active.head; vc; vc = item._active.next(vc)) { + if (vc->fragment == frag_idx) + return true; + } + return false; +} + +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ + +bool +CacheHTTPInfoVector::wait_for(CacheKey const &alt_key, CacheVC *vc, int64_t offset) +{ + bool zret = true; + int alt_idx = this->index_of(alt_key); + Item &item = data[alt_idx]; + int frag_idx = item._alternate.get_frag_index_of(offset); + vc->fragment = frag_idx; // really? Shouldn't this already be set? + if (item.has_writers()) { + if (!item._waiting.in(vc)) + item._waiting.push(vc); + } else { + zret = false; + } + return zret; +} + +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ + +CacheHTTPInfoVector & +CacheHTTPInfoVector::close_writer(CacheKey const &alt_key, CacheVC *vc) +{ + CacheVC *reader; + int alt_idx = this->index_of(alt_key); + Item &item = data[alt_idx]; + item._writers.remove(vc); + while (NULL != (reader = item._waiting.pop())) { + Debug("amc", "[close_writer] wake up %p", reader); + reader->wake_up_thread->schedule_imm(reader)->cookie = reinterpret_cast<void *>(0x56); + } + return *this; +} + +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ + +HTTPRangeSpec::Range +CacheHTTPInfoVector::get_uncached_hull(CacheKey const &alt_key, HTTPRangeSpec const &req, int64_t initial) +{ + int alt_idx = this->index_of(alt_key); + Item &item = data[alt_idx]; + Queue<CacheVC, Link_CacheVC_OpenDir_Link> writers; + CacheVC *vc; + CacheVC *cycle_vc = NULL; + // Yeah, this need to be tunable. + uint64_t DELTA = item._alternate.get_frag_fixed_size() * 16; + HTTPRangeSpec::Range r(item._alternate.get_uncached_hull(req, initial)); + + if (r.isValid()) { + /* Now clip against the writers. + We move all the writers to a local list and move them back as we are done using them to clip. + This is so we don't skip a potentially valid writer because they are not in start order. + */ + writers.append(item._writers); + item._writers.clear(); + while (r._min < r._max && NULL != (vc = writers.pop())) { + uint64_t base = static_cast<int64_t>(writers.head->resp_range.getOffset()); + uint64_t delta = static_cast<int64_t>(writers.head->resp_range.getRemnantSize()); + + if (base + delta < r._min || base > r._max) { + item._writers.push(vc); // of no use to us, just put it back. + } else if (base < r._min + DELTA) { + r._min = base + delta; // we can wait, so depend on this writer and clip. + item._writers.push(vc); // we're done with it, put it back. + cycle_vc = NULL; // we did something so clear cycle indicator + } else if (vc == cycle_vc) { // we're looping. + item._writers.push(vc); // put this one back. + while (NULL != (vc = writers.pop())) + item._writers.push(vc); // and the rest. + } else { + writers.enqueue(vc); // put it back to later checking. + if (NULL == cycle_vc) + cycle_vc = vc; // but keep an eye out for it coming around again. + } } - buf += tmp; + } + return r; +} - data(xcount).alternate = info; - xcount++; +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ + +void +CacheRange::clear() +{ + _offset = 0; + _idx = -1; + _pending_range_shift_p = false; + _ct_field = NULL; // need to do real cleanup at some point. + _r.clear(); +} + +bool +CacheRange::init(HTTPHdr *req) +{ + bool zret = true; + MIMEField *rf = req->field_find(MIME_FIELD_RANGE, MIME_LEN_RANGE); + if (rf) { + int len; + char const *val = rf->value_get(&len); + zret = _r.parseRangeFieldValue(val, len); } + return zret; +} - return ((caddr_t)buf - (caddr_t)start); +bool +CacheRange::start() +{ + bool zret = true; + + if (_r.hasRanges()) { + _offset = _r[_idx = 0]._min; + _pending_range_shift_p = _r.isMulti(); + } else if (_r.isEmpty()) { + _offset = 0; + } else { + zret = false; + } + return zret; +} + +bool +CacheRange::apply(uint64_t len) +{ + bool zret = _r.apply(len); + if (zret) { + _len = len; + if (_r.hasRanges()) { + _offset = _r[_idx = 0]._min; + if (_r.isMulti()) + _pending_range_shift_p = true; + } + } + return zret; +} + +uint64_t +CacheRange::consume(uint64_t size) +{ + switch (_r._state) { + case HTTPRangeSpec::EMPTY: + _offset += size; + break; + case HTTPRangeSpec::SINGLE: + _offset += std::min(size, (_r._single._max - _offset) + 1); + break; + case HTTPRangeSpec::MULTI: + ink_assert(_idx < static_cast<int>(_r.count())); + // Must not consume more than 1 range or the boundary strings won't get sent. + ink_assert(!_pending_range_shift_p); + ink_assert(size <= (_r[_idx]._max - _offset) + 1); + _offset += size; + if (_offset > _r[_idx]._max && ++_idx < static_cast<int>(_r.count())) { + _offset = _r[_idx]._min; + _pending_range_shift_p = true; + } + break; + default: + break; + } + + return _offset; +} + +CacheRange & +CacheRange::generateBoundaryStr(CacheKey const &key) +{ + uint64_t rnd = this_ethread()->generator.random(); + snprintf(_boundary, sizeof(_boundary), "%016" PRIx64 "%016" PRIx64 "..%016" PRIx64, key.slice64(0), key.slice64(1), rnd); + // GAH! snprintf null terminates so we can't actually print the last nybble that way and all of + // the internal hex converters do the same thing. This is crazy code I need to fix at some point. + // It is critical to print every nybble or the content lengths won't add up. + _boundary[HTTP_RANGE_BOUNDARY_LEN - 1] = "0123456789abcdef"[rnd & 0xf]; + return *this; +} + +uint64_t +CacheRange::calcContentLength() const +{ + return _r.calcContentLength(_len, _ct_field ? _ct_field->m_len_value : 0); } +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ + #else // HTTP_CACHE CacheHTTPInfoVector::CacheHTTPInfoVector() : data(&default_vec_info, 4), xcount(0) @@ -348,5 +599,7 @@ CacheHTTPInfoVector::get_handles(const char * /* buf ATS_UNUSED */, int /* lengt ink_assert(0); return 0; } +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ #endif // HTTP_CACHE