This is an automated email from the ASF dual-hosted git repository.
masaori pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 9d34ca4f07 Take string view arguments in cache processor (#12147)
9d34ca4f07 is described below
commit 9d34ca4f07e938ab51b760603189b47d7a1c6ed5
Author: Hiroaki Nakamura <[email protected]>
AuthorDate: Tue Apr 22 07:53:03 2025 +0900
Take string view arguments in cache processor (#12147)
* Take string_view in CacheProcessor::remove and dependencies
* Take string_view in CacheProcessor::open_write and dependencies
* Take string_view in CacheProcessor::open_read and dependencies
* Take string_view in CacheProcessor::lookup and dependencies
* Take string_view in CacheProcessor::scan and dependencies
* Remove CacheProcessor::link declaration without definition
* Remove CacheProcessor::deref declaration without definition
* Take string_view in CacheProcessor::find_by_path
---
include/iocore/cache/Cache.h | 19 ++++++--------
src/api/InkAPI.cc | 14 +++++++----
src/iocore/cache/Cache.cc | 43 ++++++++++++++++----------------
src/iocore/cache/CacheHosting.cc | 19 +++++++-------
src/iocore/cache/CacheProcessor.cc | 41 +++++++++++++++---------------
src/iocore/cache/CacheTest.cc | 4 ++-
src/iocore/cache/CacheVC.cc | 7 +++---
src/iocore/cache/CacheVC.h | 3 +--
src/iocore/cache/P_CacheHosting.h | 4 +--
src/iocore/cache/P_CacheInternal.h | 19 +++++++-------
src/mgmt/rpc/handlers/storage/Storage.cc | 4 +--
11 files changed, 88 insertions(+), 89 deletions(-)
diff --git a/include/iocore/cache/Cache.h b/include/iocore/cache/Cache.h
index 4de07a36a8..29ef9ddb0b 100644
--- a/include/iocore/cache/Cache.h
+++ b/include/iocore/cache/Cache.h
@@ -72,26 +72,21 @@ struct CacheProcessor : public Processor {
int dir_check(bool fix);
Action *lookup(Continuation *cont, const CacheKey *key, CacheFragType
frag_type = CACHE_FRAG_TYPE_NONE,
- const char *hostname = nullptr, int host_len = 0);
+ std::string_view hostname = std::string_view{});
Action *open_read(Continuation *cont, const CacheKey *key, CacheFragType
frag_type = CACHE_FRAG_TYPE_NONE,
- const char *hostname = nullptr, int host_len = 0);
+ std::string_view hostname = std::string_view{});
Action *open_write(Continuation *cont, CacheKey *key, CacheFragType
frag_type = CACHE_FRAG_TYPE_NONE,
- int expected_size = CACHE_EXPECTED_SIZE, int options = 0,
time_t pin_in_cache = 0, char *hostname = nullptr,
- int host_len = 0);
+ int expected_size = CACHE_EXPECTED_SIZE, int options = 0,
time_t pin_in_cache = 0,
+ std::string_view hostname = std::string_view{});
Action *remove(Continuation *cont, const CacheKey *key, CacheFragType
frag_type = CACHE_FRAG_TYPE_NONE,
- const char *hostname = nullptr, int host_len = 0);
- Action *scan(Continuation *cont, char *hostname = nullptr, int host_len = 0,
int KB_per_second = SCAN_KB_PER_SECOND);
+ std::string_view hostname = std::string_view{});
+ Action *scan(Continuation *cont, std::string_view hostname =
std::string_view{}, int KB_per_second = SCAN_KB_PER_SECOND);
Action *lookup(Continuation *cont, const HttpCacheKey *key, CacheFragType
frag_type = CACHE_FRAG_TYPE_HTTP);
Action *open_read(Continuation *cont, const HttpCacheKey *key, CacheHTTPHdr
*request, const HttpConfigAccessor *params,
CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
Action *open_write(Continuation *cont, const HttpCacheKey *key,
CacheHTTPInfo *old_info, time_t pin_in_cache = 0,
CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
Action *remove(Continuation *cont, const HttpCacheKey *key, CacheFragType
frag_type = CACHE_FRAG_TYPE_HTTP);
- Action *link(Continuation *cont, CacheKey *from, CacheKey *to, CacheFragType
frag_type = CACHE_FRAG_TYPE_HTTP,
- char *hostname = nullptr, int host_len = 0);
-
- Action *deref(Continuation *cont, CacheKey *key, CacheFragType frag_type =
CACHE_FRAG_TYPE_HTTP, char *hostname = nullptr,
- int host_len = 0);
/** Mark physical disk/device/file as offline.
All stripes for this device are disabled.
@@ -106,7 +101,7 @@ struct CacheProcessor : public Processor {
If @a len is 0 then @a path is presumed null terminated.
@return @c nullptr if the path does not match any defined storage.
*/
- CacheDisk *find_by_path(const char *path, int len = 0);
+ CacheDisk *find_by_path(std::string_view path = std::string_view{});
/** Check if there are any online storage devices.
If this returns @c false then the cache should be disabled as there is
no storage available.
diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc
index ff1ff2b57d..9afa069b29 100644
--- a/src/api/InkAPI.cc
+++ b/src/api/InkAPI.cc
@@ -6182,7 +6182,8 @@ TSCacheRead(TSCont contp, TSCacheKey key)
CacheInfo *info = reinterpret_cast<CacheInfo *>(key);
Continuation *i = reinterpret_cast<INKContInternal *>(contp);
- return reinterpret_cast<TSAction>(cacheProcessor.open_read(i,
&info->cache_key, info->frag_type, info->hostname, info->len));
+ return reinterpret_cast<TSAction>(cacheProcessor.open_read(
+ i, &info->cache_key, info->frag_type, std::string_view{info->hostname,
static_cast<std::string_view::size_type>(info->len)}));
}
TSAction
@@ -6197,7 +6198,8 @@ TSCacheWrite(TSCont contp, TSCacheKey key)
Continuation *i = reinterpret_cast<INKContInternal *>(contp);
return reinterpret_cast<TSAction>(
- cacheProcessor.open_write(i, &info->cache_key, info->frag_type, 0, false,
info->pin_in_cache, info->hostname, info->len));
+ cacheProcessor.open_write(i, &info->cache_key, info->frag_type, 0, false,
info->pin_in_cache,
+ std::string_view{info->hostname,
static_cast<std::string_view::size_type>(info->len)}));
}
TSAction
@@ -6211,7 +6213,8 @@ TSCacheRemove(TSCont contp, TSCacheKey key)
CacheInfo *info = reinterpret_cast<CacheInfo *>(key);
INKContInternal *i = reinterpret_cast<INKContInternal *>(contp);
- return reinterpret_cast<TSAction>(cacheProcessor.remove(i, &info->cache_key,
info->frag_type, info->hostname, info->len));
+ return reinterpret_cast<TSAction>(cacheProcessor.remove(
+ i, &info->cache_key, info->frag_type, std::string_view{info->hostname,
static_cast<std::string_view::size_type>(info->len)}));
}
TSAction
@@ -6226,9 +6229,10 @@ TSCacheScan(TSCont contp, TSCacheKey key, int
KB_per_second)
if (key) {
CacheInfo *info = reinterpret_cast<CacheInfo *>(key);
- return reinterpret_cast<TSAction>(cacheProcessor.scan(i, info->hostname,
info->len, KB_per_second));
+ return reinterpret_cast<TSAction>(
+ cacheProcessor.scan(i, std::string_view{info->hostname,
static_cast<std::string_view::size_type>(info->len)}, KB_per_second));
}
- return reinterpret_cast<TSAction>(cacheProcessor.scan(i, nullptr, 0,
KB_per_second));
+ return reinterpret_cast<TSAction>(cacheProcessor.scan(i, std::string_view{},
KB_per_second));
}
/************************ REC Stats API **************************/
diff --git a/src/iocore/cache/Cache.cc b/src/iocore/cache/Cache.cc
index 11e12ce479..9c7daaefe5 100644
--- a/src/iocore/cache/Cache.cc
+++ b/src/iocore/cache/Cache.cc
@@ -301,14 +301,14 @@ Cache::close()
}
Action *
-Cache::lookup(Continuation *cont, const CacheKey *key, CacheFragType type,
const char *hostname, int host_len) const
+Cache::lookup(Continuation *cont, const CacheKey *key, CacheFragType type,
std::string_view hostname) const
{
if (!CacheProcessor::IsCacheReady(type)) {
cont->handleEvent(CACHE_EVENT_LOOKUP_FAILED, nullptr);
return ACTION_RESULT_DONE;
}
- StripeSM *stripe = key_to_stripe(key, hostname, host_len);
+ StripeSM *stripe = key_to_stripe(key, hostname);
CacheVC *c = new_CacheVC(cont);
SET_CONTINUATION_HANDLER(c, &CacheVC::openReadStartHead);
c->vio.op = VIO::READ;
@@ -329,7 +329,7 @@ Cache::lookup(Continuation *cont, const CacheKey *key,
CacheFragType type, const
}
Action *
-Cache::open_read(Continuation *cont, const CacheKey *key, CacheFragType type,
const char *hostname, int host_len) const
+Cache::open_read(Continuation *cont, const CacheKey *key, CacheFragType type,
std::string_view hostname) const
{
if (!CacheProcessor::IsCacheReady(type)) {
cont->handleEvent(CACHE_EVENT_OPEN_READ_FAILED, reinterpret_cast<void
*>(-ECACHE_NOT_READY));
@@ -337,7 +337,7 @@ Cache::open_read(Continuation *cont, const CacheKey *key,
CacheFragType type, co
}
ink_assert(caches[type] == this);
- StripeSM *stripe = key_to_stripe(key, hostname, host_len);
+ StripeSM *stripe = key_to_stripe(key, hostname);
Dir result, *last_collision = nullptr;
ProxyMutex *mutex = cont->mutex.get();
OpenDirEntry *od = nullptr;
@@ -398,7 +398,7 @@ Lcallreturn:
// main entry point for writing of non-http documents
Action *
Cache::open_write(Continuation *cont, const CacheKey *key, CacheFragType
frag_type, int options, time_t apin_in_cache,
- const char *hostname, int host_len) const
+ std::string_view hostname) const
{
if (!CacheProcessor::IsCacheReady(frag_type)) {
cont->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, reinterpret_cast<void
*>(-ECACHE_NOT_READY));
@@ -412,7 +412,7 @@ Cache::open_write(Continuation *cont, const CacheKey *key,
CacheFragType frag_ty
SCOPED_MUTEX_LOCK(lock, c->mutex, this_ethread());
c->vio.op = VIO::WRITE;
c->op_type = static_cast<int>(CacheOpType::Write);
- c->stripe = key_to_stripe(key, hostname, host_len);
+ c->stripe = key_to_stripe(key, hostname);
StripeSM *stripe = c->stripe;
ts::Metrics::Gauge::increment(cache_rsb.status[c->op_type].active);
ts::Metrics::Gauge::increment(stripe->cache_vol->vol_rsb.status[c->op_type].active);
@@ -464,7 +464,7 @@ Cache::open_write(Continuation *cont, const CacheKey *key,
CacheFragType frag_ty
}
Action *
-Cache::remove(Continuation *cont, const CacheKey *key, CacheFragType type,
const char *hostname, int host_len) const
+Cache::remove(Continuation *cont, const CacheKey *key, CacheFragType type,
std::string_view hostname) const
{
if (!CacheProcessor::IsCacheReady(type)) {
if (cont) {
@@ -480,7 +480,7 @@ Cache::remove(Continuation *cont, const CacheKey *key,
CacheFragType type, const
CACHE_TRY_LOCK(lock, cont->mutex, this_ethread());
ink_assert(lock.is_locked());
- StripeSM *stripe = key_to_stripe(key, hostname, host_len);
+ StripeSM *stripe = key_to_stripe(key, hostname);
// coverity[var_decl]
Dir result;
dir_clear(&result); // initialized here, set result empty so we can
recognize missed lock
@@ -507,7 +507,7 @@ Cache::remove(Continuation *cont, const CacheKey *key,
CacheFragType type, const
}
Action *
-Cache::scan(Continuation *cont, const char *hostname, int host_len, int
KB_per_second) const
+Cache::scan(Continuation *cont, std::string_view hostname, int KB_per_second)
const
{
Dbg(dbg_ctl_cache_scan_truss, "inside scan");
if (!CacheProcessor::IsCacheReady(CACHE_FRAG_TYPE_HTTP)) {
@@ -518,8 +518,7 @@ Cache::scan(Continuation *cont, const char *hostname, int
host_len, int KB_per_s
CacheVC *c = new_CacheVC(cont);
c->stripe = nullptr;
/* do we need to make a copy */
- c->hostname = const_cast<char *>(hostname);
- c->host_len = host_len;
+ c->hostname = hostname;
c->op_type = static_cast<int>(CacheOpType::Scan);
c->buf =
new_IOBufferData(BUFFER_SIZE_FOR_XMALLOC(SCAN_BUF_SIZE), MEMALIGNED);
c->scan_msec_delay = (SCAN_BUF_SIZE / KB_per_second);
@@ -532,7 +531,7 @@ Cache::scan(Continuation *cont, const char *hostname, int
host_len, int KB_per_s
Action *
Cache::open_read(Continuation *cont, const CacheKey *key, CacheHTTPHdr
*request, const HttpConfigAccessor *params,
- CacheFragType type, const char *hostname, int host_len) const
+ CacheFragType type, std::string_view hostname) const
{
if (!CacheProcessor::IsCacheReady(type)) {
cont->handleEvent(CACHE_EVENT_OPEN_READ_FAILED, reinterpret_cast<void
*>(-ECACHE_NOT_READY));
@@ -540,7 +539,7 @@ Cache::open_read(Continuation *cont, const CacheKey *key,
CacheHTTPHdr *request,
}
ink_assert(caches[type] == this);
- StripeSM *stripe = key_to_stripe(key, hostname, host_len);
+ StripeSM *stripe = key_to_stripe(key, hostname);
Dir result, *last_collision = nullptr;
ProxyMutex *mutex = cont->mutex.get();
OpenDirEntry *od = nullptr;
@@ -607,7 +606,7 @@ Lcallreturn:
// main entry point for writing of http documents
Action *
Cache::open_write(Continuation *cont, const CacheKey *key, CacheHTTPInfo
*info, time_t apin_in_cache, CacheFragType type,
- const char *hostname, int host_len) const
+ std::string_view hostname) const
{
if (!CacheProcessor::IsCacheReady(type)) {
cont->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, reinterpret_cast<void
*>(-ECACHE_NOT_READY));
@@ -632,7 +631,7 @@ Cache::open_write(Continuation *cont, const CacheKey *key,
CacheHTTPInfo *info,
} while (DIR_MASK_TAG(c->key.slice32(2)) ==
DIR_MASK_TAG(c->first_key.slice32(2)));
c->earliest_key = c->key;
c->frag_type = CACHE_FRAG_TYPE_HTTP;
- c->stripe = key_to_stripe(key, hostname, host_len);
+ c->stripe = key_to_stripe(key, hostname);
StripeSM *stripe = c->stripe;
c->info = info;
if (c->info && reinterpret_cast<uintptr_t>(info) !=
CACHE_ALLOW_MULTIPLE_WRITES) {
@@ -748,7 +747,7 @@ CacheVConnection::CacheVConnection() : VConnection(nullptr)
{}
// if generic_host_rec.stripes == nullptr, what do we do???
StripeSM *
-Cache::key_to_stripe(const CacheKey *key, const char *hostname, int host_len)
const
+Cache::key_to_stripe(const CacheKey *key, std::string_view hostname) const
{
ReplaceablePtr<CacheHostTable>::ScopedReader hosttable(&this->hosttable);
@@ -756,16 +755,16 @@ Cache::key_to_stripe(const CacheKey *key, const char
*hostname, int host_len) co
unsigned short *hash_table = hosttable->gen_host_rec.vol_hash_table;
const CacheHostRecord *host_rec = &hosttable->gen_host_rec;
- if (hosttable->m_numEntries > 0 && host_len) {
+ if (hosttable->m_numEntries > 0 && !hostname.empty()) {
CacheHostResult res;
- hosttable->Match(hostname, host_len, &res);
+ hosttable->Match(hostname, &res);
if (res.record) {
unsigned short *host_hash_table = res.record->vol_hash_table;
if (host_hash_table) {
if (dbg_ctl_cache_hosting.on()) {
char format_str[50];
- snprintf(format_str, sizeof(format_str), "Volume: %%xd for host:
%%.%ds", host_len);
- Dbg(dbg_ctl_cache_hosting, format_str, res.record, hostname);
+ snprintf(format_str, sizeof(format_str), "Volume: %%xd for host:
%%.%ds", static_cast<int>(hostname.length()));
+ Dbg(dbg_ctl_cache_hosting, format_str, res.record, hostname.data());
}
return res.record->stripes[host_hash_table[h]];
}
@@ -774,8 +773,8 @@ Cache::key_to_stripe(const CacheKey *key, const char
*hostname, int host_len) co
if (hash_table) {
if (dbg_ctl_cache_hosting.on()) {
char format_str[50];
- snprintf(format_str, sizeof(format_str), "Generic volume: %%xd for host:
%%.%ds", host_len);
- Dbg(dbg_ctl_cache_hosting, format_str, host_rec, hostname);
+ snprintf(format_str, sizeof(format_str), "Generic volume: %%xd for host:
%%.%ds", static_cast<int>(hostname.length()));
+ Dbg(dbg_ctl_cache_hosting, format_str, host_rec, hostname.data());
}
return host_rec->stripes[hash_table[h]];
} else {
diff --git a/src/iocore/cache/CacheHosting.cc b/src/iocore/cache/CacheHosting.cc
index ab8e3b23aa..f90d19f0ab 100644
--- a/src/iocore/cache/CacheHosting.cc
+++ b/src/iocore/cache/CacheHosting.cc
@@ -99,13 +99,13 @@ CacheHostMatcher::AllocateSpace(int num_entries)
num_el = 0;
}
-// void CacheHostMatcher::Match(RequestData* rdata, Result* result)
+// void CacheHostMatcher::Match(std::string_view rdata, Result* result)
//
// Searches our tree and updates argresult for each element matching
// arg hostname
//
void
-CacheHostMatcher::Match(const char *rdata, int rlen, CacheHostResult *result)
const
+CacheHostMatcher::Match(std::string_view rdata, CacheHostResult *result) const
{
void *opaque_ptr;
CacheHostRecord *data_ptr;
@@ -117,14 +117,13 @@ CacheHostMatcher::Match(const char *rdata, int rlen,
CacheHostResult *result) co
return;
}
- if (rlen == 0) {
+ if (rdata.empty()) {
return;
}
- std::string_view data{rdata, static_cast<size_t>(rlen)};
- HostLookupState s;
+ HostLookupState s;
- r = host_lookup->MatchFirst(data, &s, &opaque_ptr);
+ r = host_lookup->MatchFirst(rdata, &s, &opaque_ptr);
while (r == true) {
ink_assert(opaque_ptr != nullptr);
@@ -223,15 +222,15 @@ CacheHostTable::Print() const
}
}
-// void ControlMatcher<Data, Result>::Match(RequestData* rdata
-// Result* result)
+// void ControlMatcher<Result>::Match(std::string_view rdata
+// Result* result)
//
// Queries each table for the Result*
//
void
-CacheHostTable::Match(const char *rdata, int rlen, CacheHostResult *result)
const
+CacheHostTable::Match(std::string_view rdata, CacheHostResult *result) const
{
- hostMatch->Match(rdata, rlen, result);
+ hostMatch->Match(rdata, result);
}
int
diff --git a/src/iocore/cache/CacheProcessor.cc
b/src/iocore/cache/CacheProcessor.cc
index 7193c3b1bd..d56aab2bc6 100644
--- a/src/iocore/cache/CacheProcessor.cc
+++ b/src/iocore/cache/CacheProcessor.cc
@@ -368,55 +368,58 @@ CacheProcessor::dir_check(bool /* afix ATS_UNUSED */)
}
Action *
-CacheProcessor::lookup(Continuation *cont, const CacheKey *key, CacheFragType
frag_type, const char *hostname, int host_len)
+CacheProcessor::lookup(Continuation *cont, const CacheKey *key, CacheFragType
frag_type, std::string_view hostname)
{
- return caches[frag_type]->lookup(cont, key, frag_type, hostname, host_len);
+ return caches[frag_type]->lookup(cont, key, frag_type, hostname);
}
Action *
-CacheProcessor::open_read(Continuation *cont, const CacheKey *key,
CacheFragType frag_type, const char *hostname, int hostlen)
+CacheProcessor::open_read(Continuation *cont, const CacheKey *key,
CacheFragType frag_type, std::string_view hostname)
{
- return caches[frag_type]->open_read(cont, key, frag_type, hostname, hostlen);
+ return caches[frag_type]->open_read(cont, key, frag_type, hostname);
}
Action *
CacheProcessor::open_write(Continuation *cont, CacheKey *key, CacheFragType
frag_type, int expected_size ATS_UNUSED, int options,
- time_t pin_in_cache, char *hostname, int host_len)
+ time_t pin_in_cache, std::string_view hostname)
{
- return caches[frag_type]->open_write(cont, key, frag_type, options,
pin_in_cache, hostname, host_len);
+ return caches[frag_type]->open_write(cont, key, frag_type, options,
pin_in_cache, hostname);
}
Action *
-CacheProcessor::remove(Continuation *cont, const CacheKey *key, CacheFragType
frag_type, const char *hostname, int host_len)
+CacheProcessor::remove(Continuation *cont, const CacheKey *key, CacheFragType
frag_type, std::string_view hostname)
{
Dbg(dbg_ctl_cache_remove, "[CacheProcessor::remove] Issuing cache delete for
%u", cache_hash(*key));
- return caches[frag_type]->remove(cont, key, frag_type, hostname, host_len);
+ return caches[frag_type]->remove(cont, key, frag_type, hostname);
}
Action *
-CacheProcessor::scan(Continuation *cont, char *hostname, int host_len, int
KB_per_second)
+CacheProcessor::scan(Continuation *cont, std::string_view hostname, int
KB_per_second)
{
- return caches[CACHE_FRAG_TYPE_HTTP]->scan(cont, hostname, host_len,
KB_per_second);
+ return caches[CACHE_FRAG_TYPE_HTTP]->scan(cont, hostname, KB_per_second);
}
Action *
CacheProcessor::lookup(Continuation *cont, const HttpCacheKey *key,
CacheFragType frag_type)
{
- return lookup(cont, &key->hash, frag_type, key->hostname, key->hostlen);
+ return lookup(cont, &key->hash, frag_type,
+ std::string_view{key->hostname,
static_cast<std::string_view::size_type>(key->hostlen)});
}
Action *
CacheProcessor::open_read(Continuation *cont, const HttpCacheKey *key,
CacheHTTPHdr *request, const HttpConfigAccessor *params,
CacheFragType type)
{
- return caches[type]->open_read(cont, &key->hash, request, params, type,
key->hostname, key->hostlen);
+ return caches[type]->open_read(cont, &key->hash, request, params, type,
+ std::string_view{key->hostname,
static_cast<std::string_view::size_type>(key->hostlen)});
}
Action *
CacheProcessor::open_write(Continuation *cont, const HttpCacheKey *key,
CacheHTTPInfo *old_info, time_t pin_in_cache,
CacheFragType type)
{
- return caches[type]->open_write(cont, &key->hash, old_info, pin_in_cache,
type, key->hostname, key->hostlen);
+ return caches[type]->open_write(cont, &key->hash, old_info, pin_in_cache,
type,
+ std::string_view{key->hostname,
static_cast<std::string_view::size_type>(key->hostlen)});
}
//----------------------------------------------------------------------------
@@ -425,7 +428,8 @@ CacheProcessor::open_write(Continuation *cont, const
HttpCacheKey *key, CacheHTT
Action *
CacheProcessor::remove(Continuation *cont, const HttpCacheKey *key,
CacheFragType frag_type)
{
- return caches[frag_type]->remove(cont, &key->hash, frag_type, key->hostname,
key->hostlen);
+ return caches[frag_type]->remove(cont, &key->hash, frag_type,
+ std::string_view{key->hostname,
static_cast<std::string_view::size_type>(key->hostlen)});
}
/** Set the state of a disk programmatically.
@@ -665,16 +669,11 @@ persist_bad_disks()
}
CacheDisk *
-CacheProcessor::find_by_path(const char *path, int len)
+CacheProcessor::find_by_path(std::string_view path)
{
if (CACHE_INITIALIZED == initialized) {
- // If no length is passed in, assume it's null terminated.
- if (0 >= len && 0 != *path) {
- len = strlen(path);
- }
-
for (int i = 0; i < gndisks; ++i) {
- if (0 == strncmp(path, gdisks[i]->path, len)) {
+ if (0 == strncmp(path.data(), gdisks[i]->path, path.length())) {
return gdisks[i];
}
}
diff --git a/src/iocore/cache/CacheTest.cc b/src/iocore/cache/CacheTest.cc
index 0cbf0df6cb..f9830f2d84 100644
--- a/src/iocore/cache/CacheTest.cc
+++ b/src/iocore/cache/CacheTest.cc
@@ -32,6 +32,8 @@
#include <cmath>
#include <cstdlib>
+using namespace std::literals;
+
CacheTestSM::CacheTestSM(RegressionTest *t, const char *name) :
RegressionSM(t), cache_test_name(name)
{
SET_HANDLER(&CacheTestSM::event_handler);
@@ -555,7 +557,7 @@ test_RamCache(RegressionTest *t, RamCache *cache, const
char *name, int64_t cach
{
bool pass = true;
CacheKey key;
- StripeSM *stripe = theCache->key_to_stripe(&key,
"example.com", sizeof("example.com") - 1);
+ StripeSM *stripe = theCache->key_to_stripe(&key,
"example.com"sv);
std::vector<Ptr<IOBufferData>> data;
cache->init(cache_size, stripe);
diff --git a/src/iocore/cache/CacheVC.cc b/src/iocore/cache/CacheVC.cc
index e81d5c345c..552402ada0 100644
--- a/src/iocore/cache/CacheVC.cc
+++ b/src/iocore/cache/CacheVC.cc
@@ -631,9 +631,9 @@ CacheVC::scanStripe(int /* event ATS_UNUSED */, Event * /*
e ATS_UNUSED */)
ReplaceablePtr<CacheHostTable>::ScopedReader hosttable(&theCache->hosttable);
const CacheHostRecord *rec = &hosttable->gen_host_rec;
- if (host_len) {
+ if (!hostname.empty()) {
CacheHostResult res;
- hosttable->Match(hostname, host_len, &res);
+ hosttable->Match(hostname, &res);
if (res.record) {
rec = res.record;
}
@@ -824,7 +824,8 @@ CacheVC::scanObject(int /* event ATS_UNUSED */, Event * /*
e ATS_UNUSED */)
ink_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,
hname, hlen);
+ cacheProcessor.remove(this, &doc->first_key, CACHE_FRAG_TYPE_HTTP,
+ std::string_view{hname,
static_cast<std::string_view::size_type>(hlen)});
return EVENT_CONT;
} else {
offset = reinterpret_cast<char *>(doc) - buf->data();
diff --git a/src/iocore/cache/CacheVC.h b/src/iocore/cache/CacheVC.h
index 9c362fc2d0..28ef804c6c 100644
--- a/src/iocore/cache/CacheVC.h
+++ b/src/iocore/cache/CacheVC.h
@@ -281,8 +281,7 @@ struct CacheVC : public CacheVConnection {
int fragment;
int scan_msec_delay;
CacheVC *write_vc;
- char *hostname;
- int host_len;
+ std::string_view hostname;
int header_to_write_len;
void *header_to_write;
short writer_lock_retry;
diff --git a/src/iocore/cache/P_CacheHosting.h
b/src/iocore/cache/P_CacheHosting.h
index 59ef9d1268..cb53ad86e0 100644
--- a/src/iocore/cache/P_CacheHosting.h
+++ b/src/iocore/cache/P_CacheHosting.h
@@ -79,7 +79,7 @@ public:
void AllocateSpace(int num_entries);
void NewEntry(matcher_line *line_info);
- void Match(const char *rdata, int rlen, CacheHostResult *result) const;
+ void Match(std::string_view rdata, CacheHostResult *result) const;
void Print() const;
int
@@ -226,7 +226,7 @@ public:
int BuildTable(const char *config_file_path);
int BuildTableFromString(const char *config_file_path, char *str);
- void Match(const char *rdata, int rlen, CacheHostResult *result) const;
+ void Match(std::string_view rdata, CacheHostResult *result) const;
void Print() const;
int
diff --git a/src/iocore/cache/P_CacheInternal.h
b/src/iocore/cache/P_CacheInternal.h
index bf324266de..35100648e6 100644
--- a/src/iocore/cache/P_CacheInternal.h
+++ b/src/iocore/cache/P_CacheInternal.h
@@ -455,18 +455,19 @@ struct Cache {
int open(bool reconfigure, bool fix);
int close();
- Action *lookup(Continuation *cont, const CacheKey *key, CacheFragType type,
const char *hostname, int host_len) const;
- Action *open_read(Continuation *cont, const CacheKey *key, CacheFragType
type, const char *hostname, int len) const;
+ Action *lookup(Continuation *cont, const CacheKey *key, CacheFragType type,
std::string_view hostname) const;
+ Action *open_read(Continuation *cont, const CacheKey *key, CacheFragType
type,
+ std::string_view hostname = std::string_view{}) const;
Action *open_write(Continuation *cont, const CacheKey *key, CacheFragType
frag_type, int options = 0, time_t pin_in_cache = 0,
- const char *hostname = nullptr, int host_len = 0) const;
- Action *remove(Continuation *cont, const CacheKey *key, CacheFragType type =
CACHE_FRAG_TYPE_HTTP, const char *hostname = nullptr,
- int host_len = 0) const;
- Action *scan(Continuation *cont, const char *hostname = nullptr, int
host_len = 0, int KB_per_second = 2500) const;
+ std::string_view hostname = std::string_view{}) const;
+ Action *remove(Continuation *cont, const CacheKey *key, CacheFragType type =
CACHE_FRAG_TYPE_HTTP,
+ std::string_view hostname = std::string_view{}) const;
+ Action *scan(Continuation *cont, std::string_view hostname =
std::string_view{}, int KB_per_second = 2500) const;
Action *open_read(Continuation *cont, const CacheKey *key, CacheHTTPHdr
*request, const HttpConfigAccessor *params,
- CacheFragType type, const char *hostname, int
host_len) const;
+ CacheFragType type, std::string_view hostname =
std::string_view{}) const;
Action *open_write(Continuation *cont, const CacheKey *key,
CacheHTTPInfo *old_info, time_t pin_in_cache = 0,
- CacheFragType type = CACHE_FRAG_TYPE_HTTP, const char
*hostname = nullptr, int host_len = 0) const;
+ CacheFragType type = CACHE_FRAG_TYPE_HTTP,
std::string_view hostname = std::string_view{}) const;
static void generate_key(CryptoHash *hash, CacheURL *url);
static void generate_key(HttpCacheKey *hash, CacheURL *url, bool
ignore_query = false, cache_generation_t generation = -1);
@@ -474,7 +475,7 @@ struct Cache {
int open_done();
- StripeSM *key_to_stripe(const CacheKey *key, const char *hostname, int
host_len) const;
+ StripeSM *key_to_stripe(const CacheKey *key, std::string_view hostname)
const;
Cache() {}
};
diff --git a/src/mgmt/rpc/handlers/storage/Storage.cc
b/src/mgmt/rpc/handlers/storage/Storage.cc
index 22e45c97db..fabf2766c0 100644
--- a/src/mgmt/rpc/handlers/storage/Storage.cc
+++ b/src/mgmt/rpc/handlers/storage/Storage.cc
@@ -70,7 +70,7 @@ set_storage_offline(std::string_view const & /* id ATS_UNUSED
*/, YAML::Node con
for (auto &&it : params) {
std::string device = it.as<std::string>();
- CacheDisk *d = cacheProcessor.find_by_path(device.c_str(),
(device.size()));
+ CacheDisk *d = cacheProcessor.find_by_path(device);
if (d) {
Dbg(dbg_ctl_rpc_server, "Marking %s offline", device.c_str());
@@ -96,7 +96,7 @@ get_storage_status(std::string_view const & /* id ATS_UNUSED
*/, YAML::Node cons
for (auto &&it : params) {
std::string device = it.as<std::string>();
- CacheDisk *d = cacheProcessor.find_by_path(device.c_str(),
static_cast<int>(device.size()));
+ CacheDisk *d = cacheProcessor.find_by_path(device);
if (d) {
resp.result().push_back(*d);