Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions doc/admin-guide/plugins/prefetch.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,29 @@ specified with an integer followed by a colon, e.g. ``{8:$2+2}``,
causing the resulting number to be padded with leading zeroes if it
has fewer digits than the width.

CMCD (Common Media Client Data) CMCD-Request header with nor field
------------------------------------------------------------------

If the ``--cmcd-nor`` option is specified the Cmcd-Request header with nor field is handled.

With setup ::

map http://example.com http://origin.com \
@plugin=cachekey.so @pparam=--remove-all-params=true \
@plugin=prefetch.so \
@pparam=--cmcd-nor=true

If the incoming request is ::

http://example-seed.com/path/someitem.m4a

with header ::

Cmcd-Request: nor="otheritem.m4a"

The following URL will be requested to be prefetched ::

http://example-seed.com/path/otheritem.m4a

Overhead from **next object** prefetch
--------------------------------------
Expand Down Expand Up @@ -238,6 +261,7 @@ Plugin parameters
- ``true`` - configures the plugin run on the **front-tier**,
- ``false`` - to be run on the **back-tier**.
* ``--api-header`` - the header used by the plugin internally, also used to mark a prefetch request to the next tier in dual-tier usage.
* ``--cmcd-nor`` - prefetch for a Cmcd-Request header with nor field.
* ``--fetch-policy`` - fetch policy
- ``simple`` - this policy just makes sure there are no same concurrent prefetches triggered (default and always used in combination with any other policy)
- ``lru:n`` - this policy uses LRU to identify "hot" objects and triggers prefetch if the object is not found. `n` is the size of the LRU
Expand Down
1 change: 1 addition & 0 deletions plugins/prefetch/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <vector>

typedef std::string String;
typedef std::string_view StringView;
typedef std::set<std::string> StringSet;
typedef std::list<std::string> StringList;
typedef std::vector<std::string> StringVector;
Expand Down
12 changes: 9 additions & 3 deletions plugins/prefetch/configs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ PrefetchConfig::init(int argc, char *argv[])
static const struct option longopt[] = {
{const_cast<char *>("front"), optional_argument, nullptr, 'f'},
{const_cast<char *>("api-header"), optional_argument, nullptr, 'h'},
{const_cast<char *>("cmcd-nor"), optional_argument, nullptr, 'd'},
{const_cast<char *>("next-header"), optional_argument, nullptr, 'n'},
{const_cast<char *>("fetch-policy"), optional_argument, nullptr, 'p'},
{const_cast<char *>("fetch-count"), optional_argument, nullptr, 'c'},
Expand All @@ -68,15 +69,15 @@ PrefetchConfig::init(int argc, char *argv[])
{const_cast<char *>("metrics-prefix"), optional_argument, nullptr, 'm'},
{const_cast<char *>("exact-match"), optional_argument, nullptr, 'y'},
{const_cast<char *>("log-name"), optional_argument, nullptr, 'l'},
{nullptr, 0, nullptr, 0 }
{nullptr, 0, nullptr, 0 },
};

bool status = true;
optind = 0;

/* argv contains the "to" and "from" URLs. Skip the first so that the second one poses as the program name. */
argc--;
argv++;
--argc;
++argv;

for (;;) {
int opt;
Expand All @@ -97,6 +98,10 @@ PrefetchConfig::init(int argc, char *argv[])
setApiHeader(optarg);
break;

case 'd': /* --cmcd-nor */
_cmcd_nor = ::isTrue(optarg);
break;

case 'n': /* --next-header */
setNextHeader(optarg);
break;
Expand Down Expand Up @@ -167,6 +172,7 @@ PrefetchConfig::finalize()
PrefetchDebug("front-end: %s", (_front ? "true" : "false"));
PrefetchDebug("exact match: %s", (_exactMatch ? "true" : "false"));
PrefetchDebug("query key: %s", _queryKey.c_str());
PrefetchDebug("cncd-nor: %s", (_front ? "true" : "false"));
PrefetchDebug("API header name: %s", _apiHeader.c_str());
PrefetchDebug("next object header name: %s", _nextHeader.c_str());
PrefetchDebug("fetch policy parameters: %s", _fetchPolicy.c_str());
Expand Down
11 changes: 9 additions & 2 deletions plugins/prefetch/configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class PrefetchConfig
{
public:
PrefetchConfig()
: _apiHeader("X-AppleCDN-Prefetch"),
_nextHeader("X-AppleCDN-Prefetch-Next"),
: _apiHeader("X-CDN-Prefetch"),
_nextHeader("X-CDN-Prefetch-Next"),
_replaceHost(),
_namespace("default"),
_metricsPrefix("prefetch.stats")
Expand Down Expand Up @@ -111,6 +111,12 @@ class PrefetchConfig
return _exactMatch;
}

bool
isCmcdNor() const
{
return _cmcd_nor;
}

void
setFetchCount(const char *optarg)
{
Expand Down Expand Up @@ -208,5 +214,6 @@ class PrefetchConfig
unsigned _fetchMax = 0;
bool _front = false;
bool _exactMatch = false;
bool _cmcd_nor = false;
MultiPattern _nextPaths;
};
16 changes: 13 additions & 3 deletions plugins/prefetch/fetch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,12 @@ BgFetch::~BgFetch()

bool
BgFetch::schedule(BgFetchState *state, const PrefetchConfig &config, bool askPermission, TSMBuffer requestBuffer,
TSMLoc requestHeaderLoc, TSHttpTxn txnp, const char *path, size_t pathLen, const String &cachekey)
TSMLoc requestHeaderLoc, TSHttpTxn txnp, const char *path, size_t pathLen, const String &cachekey,
bool removeQuery)
{
bool ret = false;
BgFetch *fetch = new BgFetch(state, config, askPermission);
if (fetch->init(requestBuffer, requestHeaderLoc, txnp, path, pathLen, cachekey)) {
if (fetch->init(requestBuffer, requestHeaderLoc, txnp, path, pathLen, cachekey, removeQuery)) {
fetch->schedule();
ret = true;
} else {
Expand Down Expand Up @@ -451,7 +452,7 @@ BgFetch::addBytes(int64_t b)
*/
bool
BgFetch::init(TSMBuffer reqBuffer, TSMLoc reqHdrLoc, TSHttpTxn txnp, const char *fetchPath, size_t fetchPathLen,
const String &cachekey)
const String &cachekey, bool removeQuery)
{
TSAssert(TS_NULL_MLOC == _headerLoc);
TSAssert(TS_NULL_MLOC == _urlLoc);
Expand Down Expand Up @@ -506,6 +507,15 @@ BgFetch::init(TSMBuffer reqBuffer, TSMLoc reqHdrLoc, TSHttpTxn txnp, const char
return false;
}

/* Remove the query string */
if (removeQuery) {
if (TS_SUCCESS == TSUrlHttpQuerySet(_mbuf, _urlLoc, "", 0)) {
PrefetchDebug("original query string removed");
} else {
PrefetchError("failed to remove original query string");
}
}

/* Now set or remove the prefetch API header */
const String &header = _config.getApiHeader();
if (_config.isFront()) {
Expand Down
5 changes: 3 additions & 2 deletions plugins/prefetch/fetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,14 @@ class BgFetch
{
public:
static bool schedule(BgFetchState *state, const PrefetchConfig &config, bool askPermission, TSMBuffer requestBuffer,
TSMLoc requestHeaderLoc, TSHttpTxn txnp, const char *path, size_t pathLen, const String &cachekey);
TSMLoc requestHeaderLoc, TSHttpTxn txnp, const char *path, size_t pathLen, const String &cachekey,
bool removeQuery = false);

private:
BgFetch(BgFetchState *state, const PrefetchConfig &config, bool lock);
~BgFetch();
bool init(TSMBuffer requestBuffer, TSMLoc requestHeaderLoc, TSHttpTxn txnp, const char *fetchPath, size_t fetchPathLen,
const String &cacheKey);
const String &cacheKey, bool removeQuery = false);
void schedule();
static int handler(TSCont contp, TSEvent event, void * /* edata ATS_UNUSED */);
bool saveIp(TSHttpTxn txnp);
Expand Down
Loading