This is an automated email from the ASF dual-hosted git repository.
jvanderzee 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 9ff94763d1 Make directory operations methods on `Directory` (#11945)
9ff94763d1 is described below
commit 9ff94763d14449a9f7b96c0c9369dddcae089240
Author: JosiahWI <[email protected]>
AuthorDate: Mon Jun 16 10:58:44 2025 -0500
Make directory operations methods on `Directory` (#11945)
* Move `dir_probe` to `Directory::dir_probe`
* Move `dir_insert` to `Directory::insert`
* Move `dir_overwrite` to `Directory::overwrite`
* Move `dir_delete` to `Directory::remove`
* Move `dir_free_entry` to `Directory::free_entry`
* Move `check_dir` to `Directory::check`
* Move `dir_clean_vol` to `Directory::cleanup`
* Move `dir_clear_range` to `Directory::clear_range`
* Move `dir_entries_used` to Directory struct
* Move `dir_bucket_length` to Directory struct
* Move `dir_freelist_length` to Directory struct
* Move `dir_clean_segment` to Directory struct
* Use `Directory` instead of `Stripe` where possible
Some static functions can now take `Directory` parameters instead of
`Stripe`.
* Remove unused `Stripe` parameters
---
src/iocore/cache/Cache.cc | 6 +-
src/iocore/cache/CacheDir.cc | 168 ++++++++++-----------
src/iocore/cache/CacheEvacuateDocVC.cc | 8 +-
src/iocore/cache/CacheProcessor.cc | 4 +-
src/iocore/cache/CacheRead.cc | 35 ++---
src/iocore/cache/CacheVC.cc | 18 +--
src/iocore/cache/CacheWrite.cc | 18 +--
src/iocore/cache/P_CacheDir.h | 42 +++---
src/iocore/cache/Stripe.cc | 4 +-
src/iocore/cache/StripeSM.cc | 12 +-
.../unit_tests/test_Alternate_L_to_S_remove_L.cc | 4 +-
.../unit_tests/test_Alternate_L_to_S_remove_S.cc | 4 +-
.../unit_tests/test_Alternate_S_to_L_remove_L.cc | 4 +-
.../unit_tests/test_Alternate_S_to_L_remove_S.cc | 4 +-
src/iocore/cache/unit_tests/test_CacheDir.cc | 60 ++++----
15 files changed, 196 insertions(+), 195 deletions(-)
diff --git a/src/iocore/cache/Cache.cc b/src/iocore/cache/Cache.cc
index 0e39ee8146..b713f94465 100644
--- a/src/iocore/cache/Cache.cc
+++ b/src/iocore/cache/Cache.cc
@@ -342,7 +342,7 @@ Cache::open_read(Continuation *cont, const CacheKey *key,
CacheFragType type, st
CacheVC *c = nullptr;
{
CACHE_TRY_LOCK(lock, stripe->mutex, mutex->thread_holding);
- if (!lock.is_locked() || (od = stripe->open_read(key)) || dir_probe(key,
stripe, &result, &last_collision)) {
+ if (!lock.is_locked() || (od = stripe->open_read(key)) ||
stripe->directory.probe(key, stripe, &result, &last_collision)) {
c = new_CacheVC(cont);
SET_CONTINUATION_HANDLER(c, &CacheVC::openReadStartHead);
c->vio.op = VIO::READ;
@@ -545,7 +545,7 @@ Cache::open_read(Continuation *cont, const CacheKey *key,
CacheHTTPHdr *request,
{
CACHE_TRY_LOCK(lock, stripe->mutex, mutex->thread_holding);
- if (!lock.is_locked() || (od = stripe->open_read(key)) || dir_probe(key,
stripe, &result, &last_collision)) {
+ if (!lock.is_locked() || (od = stripe->open_read(key)) ||
stripe->directory.probe(key, stripe, &result, &last_collision)) {
c = new_CacheVC(cont);
c->first_key = c->key = c->earliest_key = *key;
c->stripe = stripe;
@@ -688,7 +688,7 @@ Cache::open_write(Continuation *cont, const CacheKey *key,
CacheHTTPInfo *info,
if (c->od->has_multiple_writers()) {
goto Lmiss;
}
- if (!dir_probe(key, c->stripe, &c->dir, &c->last_collision)) {
+ if (!c->stripe->directory.probe(key, c->stripe, &c->dir,
&c->last_collision)) {
if (c->f.update) {
// fail update because vector has been GC'd
// This situation can also arise in openWriteStartDone
diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc
index efacf89ba7..76b32a298e 100644
--- a/src/iocore/cache/CacheDir.cc
+++ b/src/iocore/cache/CacheDir.cc
@@ -206,16 +206,16 @@ dir_bucket_loop_check(Dir *start_dir, Dir *seg)
// adds all the directory entries
// in a segment to the segment freelist
void
-dir_init_segment(int s, Stripe *stripe)
+dir_init_segment(int s, Directory *directory)
{
- stripe->directory.header->freelist[s] = 0;
- Dir *seg = stripe->directory.get_segment(s);
+ directory->header->freelist[s] = 0;
+ Dir *seg = directory->get_segment(s);
int l, b;
- memset(static_cast<void *>(seg), 0, SIZEOF_DIR * DIR_DEPTH *
stripe->directory.buckets);
+ memset(static_cast<void *>(seg), 0, SIZEOF_DIR * DIR_DEPTH *
directory->buckets);
for (l = 1; l < DIR_DEPTH; l++) {
- for (b = 0; b < stripe->directory.buckets; b++) {
+ for (b = 0; b < directory->buckets; b++) {
Dir *bucket = dir_bucket(b, seg);
- dir_free_entry(dir_bucket_row(bucket, l), s, stripe);
+ directory->free_entry(dir_bucket_row(bucket, l), s);
}
}
}
@@ -223,24 +223,24 @@ dir_init_segment(int s, Stripe *stripe)
// break the infinite loop in directory entries
// Note : abuse of the token bit in dir entries
int
-dir_bucket_loop_fix(Dir *start_dir, int s, Stripe *stripe)
+dir_bucket_loop_fix(Dir *start_dir, int s, Directory *directory)
{
- if (!dir_bucket_loop_check(start_dir, stripe->directory.get_segment(s))) {
+ if (!dir_bucket_loop_check(start_dir, directory->get_segment(s))) {
Warning("Dir loop exists, clearing segment %d", s);
- dir_init_segment(s, stripe);
+ dir_init_segment(s, directory);
return 1;
}
return 0;
}
int
-dir_freelist_length(Stripe *stripe, int s)
+Directory::freelist_length(int s)
{
int free = 0;
- Dir *seg = stripe->directory.get_segment(s);
- Dir *e = dir_from_offset(stripe->directory.header->freelist[s], seg);
- if (dir_bucket_loop_fix(e, s, stripe)) {
- return (DIR_DEPTH - 1) * stripe->directory.buckets;
+ Dir *seg = this->get_segment(s);
+ Dir *e = dir_from_offset(this->header->freelist[s], seg);
+ if (dir_bucket_loop_fix(e, s, this)) {
+ return (DIR_DEPTH - 1) * this->buckets;
}
while (e) {
free++;
@@ -250,13 +250,13 @@ dir_freelist_length(Stripe *stripe, int s)
}
int
-dir_bucket_length(Dir *b, int s, Stripe *stripe)
+Directory::bucket_length(Dir *b, int s)
{
Dir *e = b;
int i = 0;
- Dir *seg = stripe->directory.get_segment(s);
+ Dir *seg = this->get_segment(s);
#ifdef LOOP_CHECK_MODE
- if (dir_bucket_loop_fix(b, s, vol))
+ if (dir_bucket_loop_fix(b, s, this))
return 1;
#endif
while (e) {
@@ -270,15 +270,15 @@ dir_bucket_length(Dir *b, int s, Stripe *stripe)
}
int
-check_dir(Stripe *stripe)
+Directory::check()
{
int i, s;
Dbg(dbg_ctl_cache_check_dir, "inside check dir");
- for (s = 0; s < stripe->directory.segments; s++) {
- Dir *seg = stripe->directory.get_segment(s);
- for (i = 0; i < stripe->directory.buckets; i++) {
+ for (s = 0; s < this->segments; s++) {
+ Dir *seg = this->get_segment(s);
+ for (i = 0; i < this->buckets; i++) {
Dir *b = dir_bucket(i, seg);
- if (!(dir_bucket_length(b, s, stripe) >= 0)) {
+ if (!(this->bucket_length(b, s) >= 0)) {
return 0;
}
if (!(!dir_next(b) || dir_offset(b))) {
@@ -293,14 +293,14 @@ check_dir(Stripe *stripe)
}
inline void
-unlink_from_freelist(Dir *e, int s, Stripe *stripe)
+unlink_from_freelist(Dir *e, int s, Directory *directory)
{
- Dir *seg = stripe->directory.get_segment(s);
+ Dir *seg = directory->get_segment(s);
Dir *p = dir_from_offset(dir_prev(e), seg);
if (p) {
dir_set_next(p, dir_next(e));
} else {
- stripe->directory.header->freelist[s] = dir_next(e);
+ directory->header->freelist[s] = dir_next(e);
}
Dir *n = dir_from_offset(dir_next(e), seg);
if (n) {
@@ -309,13 +309,13 @@ unlink_from_freelist(Dir *e, int s, Stripe *stripe)
}
inline Dir *
-dir_delete_entry(Dir *e, Dir *p, int s, Stripe *stripe)
+dir_delete_entry(Dir *e, Dir *p, int s, Directory *directory)
{
- Dir *seg = stripe->directory.get_segment(s);
- int no = dir_next(e);
- stripe->directory.header->dirty = 1;
+ Dir *seg = directory->get_segment(s);
+ int no = dir_next(e);
+ directory->header->dirty = 1;
if (p) {
- unsigned int fo = stripe->directory.header->freelist[s];
+ unsigned int fo = directory->header->freelist[s];
unsigned int eo = dir_to_offset(e, seg);
dir_clear(e);
dir_set_next(p, no);
@@ -323,12 +323,12 @@ dir_delete_entry(Dir *e, Dir *p, int s, Stripe *stripe)
if (fo) {
dir_set_prev(dir_from_offset(fo, seg), eo);
}
- stripe->directory.header->freelist[s] = eo;
+ directory->header->freelist[s] = eo;
} else {
Dir *n = next_dir(e, seg);
if (n) {
dir_assign(e, n);
- dir_delete_entry(n, e, s, stripe);
+ dir_delete_entry(n, e, s, directory);
return e;
} else {
dir_clear(e);
@@ -350,20 +350,20 @@ dir_clean_bucket(Dir *b, int s, Stripe *stripe)
#ifdef LOOP_CHECK_MODE
loop_count++;
if (loop_count > DIR_LOOP_THRESHOLD) {
- if (dir_bucket_loop_fix(b, s, vol))
+ if (dir_bucket_loop_fix(b, s, vol->directory))
return;
}
#endif
if (!stripe->dir_valid(e) || !dir_offset(e)) {
if (dbg_ctl_dir_clean.on()) {
Dbg(dbg_ctl_dir_clean, "cleaning Stripe:%s: %p tag %X boffset %"
PRId64 " b %p p %p bucket len %d", stripe->hash_text.get(),
- e, dir_tag(e), dir_offset(e), b, p, dir_bucket_length(b, s,
stripe));
+ e, dir_tag(e), dir_offset(e), b, p,
stripe->directory.bucket_length(b, s));
}
if (dir_offset(e)) {
ts::Metrics::Gauge::decrement(cache_rsb.direntries_used);
ts::Metrics::Gauge::decrement(stripe->cache_vol->vol_rsb.direntries_used);
}
- e = dir_delete_entry(e, p, s, stripe);
+ e = dir_delete_entry(e, p, s, &stripe->directory);
continue;
}
p = e;
@@ -372,28 +372,28 @@ dir_clean_bucket(Dir *b, int s, Stripe *stripe)
}
void
-dir_clean_segment(int s, Stripe *stripe)
+Directory::clean_segment(int s, Stripe *stripe)
{
- Dir *seg = stripe->directory.get_segment(s);
- for (int64_t i = 0; i < stripe->directory.buckets; i++) {
+ Dir *seg = this->get_segment(s);
+ for (int64_t i = 0; i < this->buckets; i++) {
dir_clean_bucket(dir_bucket(i, seg), s, stripe);
ink_assert(!dir_next(dir_bucket(i, seg)) || dir_offset(dir_bucket(i,
seg)));
}
}
void
-dir_clean_vol(Stripe *stripe)
+Directory::cleanup(Stripe *stripe)
{
- for (int64_t i = 0; i < stripe->directory.segments; i++) {
- dir_clean_segment(i, stripe);
+ for (int64_t i = 0; i < this->segments; i++) {
+ this->clean_segment(i, stripe);
}
CHECK_DIR(d);
}
void
-dir_clear_range(off_t start, off_t end, Stripe *stripe)
+Directory::clear_range(off_t start, off_t end, Stripe *stripe)
{
- for (off_t i = 0; i < stripe->directory.entries(); i++) {
+ for (off_t i = 0; i < this->entries(); i++) {
Dir *e = dir_index(stripe, i);
if (dir_offset(e) >= static_cast<int64_t>(start) && dir_offset(e) <
static_cast<int64_t>(end)) {
ts::Metrics::Gauge::decrement(cache_rsb.direntries_used);
@@ -401,7 +401,7 @@ dir_clear_range(off_t start, off_t end, Stripe *stripe)
dir_set_offset(e, 0); // delete
}
}
- dir_clean_vol(stripe);
+ this->cleanup(stripe);
}
void
@@ -420,7 +420,7 @@ check_bucket_not_contains(Dir *b, Dir *e, Dir *seg)
void
freelist_clean(int s, StripeSM *stripe)
{
- dir_clean_segment(s, stripe);
+ stripe->directory.clean_segment(s, stripe);
if (stripe->directory.header->freelist[s]) {
return;
}
@@ -438,7 +438,7 @@ freelist_clean(int s, StripeSM *stripe)
}
}
}
- dir_clean_segment(s, stripe);
+ stripe->directory.clean_segment(s, stripe);
}
inline Dir *
@@ -453,7 +453,7 @@ freelist_pop(int s, StripeSM *stripe)
stripe->directory.header->freelist[s] = dir_next(e);
// if the freelist if bad, punt.
if (dir_offset(e)) {
- dir_init_segment(s, stripe);
+ dir_init_segment(s, &stripe->directory);
return nullptr;
}
Dir *h = dir_from_offset(stripe->directory.header->freelist[s], seg);
@@ -464,29 +464,29 @@ freelist_pop(int s, StripeSM *stripe)
}
void
-dir_free_entry(Dir *e, int s, Stripe *stripe)
+Directory::free_entry(Dir *e, int s)
{
- Dir *seg = stripe->directory.get_segment(s);
- unsigned int fo = stripe->directory.header->freelist[s];
+ Dir *seg = this->get_segment(s);
+ unsigned int fo = this->header->freelist[s];
unsigned int eo = dir_to_offset(e, seg);
dir_set_next(e, fo);
if (fo) {
dir_set_prev(dir_from_offset(fo, seg), eo);
}
- stripe->directory.header->freelist[s] = eo;
+ this->header->freelist[s] = eo;
}
int
-dir_probe(const CacheKey *key, StripeSM *stripe, Dir *result, Dir
**last_collision)
+Directory::probe(const CacheKey *key, StripeSM *stripe, Dir *result, Dir
**last_collision)
{
ink_assert(stripe->mutex->thread_holding == this_ethread());
- int s = key->slice32(0) % stripe->directory.segments;
- int b = key->slice32(1) % stripe->directory.buckets;
- Dir *seg = stripe->directory.get_segment(s);
+ int s = key->slice32(0) % this->segments;
+ int b = key->slice32(1) % this->buckets;
+ Dir *seg = this->get_segment(s);
Dir *e = nullptr, *p = nullptr, *collision = *last_collision;
CHECK_DIR(d);
#ifdef LOOP_CHECK_MODE
- if (dir_bucket_loop_fix(dir_bucket(b, seg), s, vol))
+ if (dir_bucket_loop_fix(dir_bucket(b, seg), s, this))
return 0;
#endif
Lagain:
@@ -522,7 +522,7 @@ Lagain:
} else { // delete the invalid entry
ts::Metrics::Gauge::decrement(cache_rsb.direntries_used);
ts::Metrics::Gauge::decrement(stripe->cache_vol->vol_rsb.direntries_used);
- e = dir_delete_entry(e, p, s, stripe);
+ e = dir_delete_entry(e, p, s, this);
continue;
}
} else {
@@ -546,13 +546,13 @@ Lagain:
}
int
-dir_insert(const CacheKey *key, StripeSM *stripe, Dir *to_part)
+Directory::insert(const CacheKey *key, StripeSM *stripe, Dir *to_part)
{
ink_assert(stripe->mutex->thread_holding == this_ethread());
- int s = key->slice32(0) % stripe->directory.segments, l;
- int bi = key->slice32(1) % stripe->directory.buckets;
+ int s = key->slice32(0) % this->segments, l;
+ int bi = key->slice32(1) % this->buckets;
ink_assert(dir_approx_size(to_part) <= MAX_FRAG_SIZE + sizeof(Doc));
- Dir *seg = stripe->directory.get_segment(s);
+ Dir *seg = this->get_segment(s);
Dir *e = nullptr;
Dir *b = dir_bucket(bi, seg);
#if defined(DEBUG) && defined(DO_CHECK_DIR_FAST)
@@ -574,7 +574,7 @@ Lagain:
for (l = 1; l < DIR_DEPTH; l++) {
e = dir_bucket_row(b, l);
if (dir_is_empty(e)) {
- unlink_from_freelist(e, s, stripe);
+ unlink_from_freelist(e, s, this);
goto Llink;
}
}
@@ -595,7 +595,7 @@ Llink:
do {
prev = last;
last = next_dir(last, seg);
- } while (last && (++l <= stripe->directory.buckets * DIR_DEPTH));
+ } while (last && (++l <= this->buckets * DIR_DEPTH));
dir_set_next(e, 0);
dir_set_next(prev, dir_to_offset(e, seg));
@@ -614,12 +614,12 @@ Lfill:
}
int
-dir_overwrite(const CacheKey *key, StripeSM *stripe, Dir *dir, Dir *overwrite,
bool must_overwrite)
+Directory::overwrite(const CacheKey *key, StripeSM *stripe, Dir *dir, Dir
*overwrite, bool must_overwrite)
{
ink_assert(stripe->mutex->thread_holding == this_ethread());
- int s = key->slice32(0) % stripe->directory.segments, l;
- int bi = key->slice32(1) % stripe->directory.buckets;
- Dir *seg = stripe->directory.get_segment(s);
+ int s = key->slice32(0) % this->segments, l;
+ int bi = key->slice32(1) % this->buckets;
+ Dir *seg = this->get_segment(s);
Dir *e = nullptr;
Dir *b = dir_bucket(bi, seg);
unsigned int t = DIR_MASK_TAG(key->slice32(2));
@@ -640,7 +640,7 @@ Lagain:
#ifdef LOOP_CHECK_MODE
loop_count++;
if (loop_count > DIR_LOOP_THRESHOLD && loop_possible) {
- if (dir_bucket_loop_fix(b, s, vol)) {
+ if (dir_bucket_loop_fix(b, s, this)) {
loop_possible = false;
goto Lagain;
}
@@ -666,7 +666,7 @@ Lagain:
for (l = 1; l < DIR_DEPTH; l++) {
e = dir_bucket_row(b, l);
if (dir_is_empty(e)) {
- unlink_from_freelist(e, s, stripe);
+ unlink_from_freelist(e, s, this);
goto Llink;
}
}
@@ -686,7 +686,7 @@ Llink:
do {
prev = last;
last = next_dir(last, seg);
- } while (last && (++l <= stripe->directory.buckets * DIR_DEPTH));
+ } while (last && (++l <= this->buckets * DIR_DEPTH));
dir_set_next(e, 0);
dir_set_next(prev, dir_to_offset(e, seg));
@@ -697,17 +697,17 @@ Lfill:
DDbg(dbg_ctl_dir_overwrite, "overwrite %p %X into vol %d bucket %d at %p tag
%X %X boffset %" PRId64 "", e, key->slice32(0),
stripe->fd, bi, e, t, dir_tag(e), dir_offset(e));
CHECK_DIR(d);
- stripe->directory.header->dirty = 1;
+ this->header->dirty = 1;
return res;
}
int
-dir_delete(const CacheKey *key, StripeSM *stripe, Dir *del)
+Directory::remove(const CacheKey *key, StripeSM *stripe, Dir *del)
{
ink_assert(stripe->mutex->thread_holding == this_ethread());
- int s = key->slice32(0) % stripe->directory.segments;
- int b = key->slice32(1) % stripe->directory.buckets;
- Dir *seg = stripe->directory.get_segment(s);
+ int s = key->slice32(0) % this->segments;
+ int b = key->slice32(1) % this->buckets;
+ Dir *seg = this->get_segment(s);
Dir *e = nullptr, *p = nullptr;
#ifdef LOOP_CHECK_MODE
int loop_count = 0;
@@ -720,14 +720,14 @@ dir_delete(const CacheKey *key, StripeSM *stripe, Dir
*del)
#ifdef LOOP_CHECK_MODE
loop_count++;
if (loop_count > DIR_LOOP_THRESHOLD) {
- if (dir_bucket_loop_fix(dir_bucket(b, seg), s, vol))
+ if (dir_bucket_loop_fix(dir_bucket(b, seg), s, this))
return 0;
}
#endif
if (dir_compare_tag(e, key) && dir_offset(e) == dir_offset(del)) {
ts::Metrics::Gauge::decrement(cache_rsb.direntries_used);
ts::Metrics::Gauge::decrement(stripe->cache_vol->vol_rsb.direntries_used);
- dir_delete_entry(e, p, s, stripe);
+ dir_delete_entry(e, p, s, this);
CHECK_DIR(d);
return 1;
}
@@ -791,7 +791,7 @@ dir_lookaside_fixup(const CacheKey *key, StripeSM *stripe)
EvacuationBlock *b = stripe->lookaside[i].head;
while (b) {
if (b->evac_frags.key == *key) {
- int res = dir_overwrite(key, stripe, &b->new_dir, &b->dir, false);
+ int res = stripe->directory.overwrite(key, stripe, &b->new_dir, &b->dir,
false);
DDbg(dbg_ctl_dir_lookaside, "fixup %X %X offset %" PRId64 " phase %d
%d", key->slice32(0), key->slice32(1),
dir_offset(&b->new_dir), dir_phase(&b->new_dir), res);
int64_t o = dir_offset(&b->dir), n = dir_offset(&b->new_dir);
@@ -872,16 +872,16 @@ CacheSync::aio_write(int fd, char *b, int n, off_t o)
}
uint64_t
-dir_entries_used(Stripe *stripe)
+Directory::entries_used()
{
uint64_t full = 0;
uint64_t sfull = 0;
- for (int s = 0; s < stripe->directory.segments; full += sfull, s++) {
- Dir *seg = stripe->directory.get_segment(s);
+ for (int s = 0; s < this->segments; full += sfull, s++) {
+ Dir *seg = this->get_segment(s);
sfull = 0;
- for (int b = 0; b < stripe->directory.buckets; b++) {
+ for (int b = 0; b < this->buckets; b++) {
Dir *e = dir_bucket(b, seg);
- if (dir_bucket_loop_fix(e, s, stripe)) {
+ if (dir_bucket_loop_fix(e, s, this)) {
sfull = 0;
break;
}
@@ -985,7 +985,7 @@ Lrestart:
/* Don't sync the directory to disk if its not dirty. Syncing the
clean directory to disk is also the cause of INKqa07151. Increasing
the serial number causes the cache to recover more data than
necessary.
- The dirty bit it set in dir_insert, dir_overwrite and dir_delete_entry
+ The dirty bit it set in dir_insert, overwrite and dir_delete_entry
*/
if (!stripe->directory.header->dirty) {
Dbg(dbg_ctl_cache_dir_sync, "Dir %s not dirty",
stripe->hash_text.get());
diff --git a/src/iocore/cache/CacheEvacuateDocVC.cc
b/src/iocore/cache/CacheEvacuateDocVC.cc
index a525c76675..3e18610e08 100644
--- a/src/iocore/cache/CacheEvacuateDocVC.cc
+++ b/src/iocore/cache/CacheEvacuateDocVC.cc
@@ -88,7 +88,7 @@ CacheEvacuateDocVC::evacuateDocDone(int /* event ATS_UNUSED
*/, Event * /* e ATS
}
}
}
- dir_overwrite(&doc->key, this->stripe, &this->dir, &this->overwrite_dir);
+ this->stripe->directory.overwrite(&doc->key, this->stripe, &this->dir,
&this->overwrite_dir);
}
// if the tag in the overwrite_dir matches the first_key in the
// document, then it has to be the vector. We guarantee that
@@ -108,7 +108,7 @@ CacheEvacuateDocVC::evacuateDocDone(int /* event ATS_UNUSED
*/, Event * /* e ATS
dir_offset(&cod->first_dir), dir_offset(&this->dir));
cod->first_dir = this->dir;
}
- if (dir_overwrite(&doc->first_key, this->stripe, &this->dir,
&this->overwrite_dir)) {
+ if (this->stripe->directory.overwrite(&doc->first_key, this->stripe,
&this->dir, &this->overwrite_dir)) {
int64_t o = dir_offset(&this->overwrite_dir), n =
dir_offset(&this->dir);
this->stripe->ram_cache->fixup(&doc->first_key,
static_cast<uint64_t>(o), static_cast<uint64_t>(n));
}
@@ -119,7 +119,7 @@ CacheEvacuateDocVC::evacuateDocDone(int /* event ATS_UNUSED
*/, Event * /* e ATS
this->total_len += doc->data_len();
this->first_key = doc->first_key;
this->earliest_dir = this->dir;
- if (dir_probe(&this->first_key, this->stripe, &this->dir,
&last_collision) > 0) {
+ if (this->stripe->directory.probe(&this->first_key, this->stripe,
&this->dir, &last_collision) > 0) {
dir_lookaside_insert(b, this->stripe, &this->earliest_dir);
// read the vector
SET_HANDLER(&CacheEvacuateDocVC::evacuateReadHead);
@@ -188,7 +188,7 @@ CacheEvacuateDocVC::evacuateReadHead(int /* event
ATS_UNUSED */, Event * /* e AT
}
return EVENT_CONT;
Lcollision:
- if (dir_probe(&this->first_key, this->stripe, &this->dir, &last_collision)) {
+ if (this->stripe->directory.probe(&this->first_key, this->stripe,
&this->dir, &last_collision)) {
int ret = do_read_call(&this->first_key);
if (ret == EVENT_RETURN) {
return handleEvent(AIO_EVENT_DONE, nullptr);
diff --git a/src/iocore/cache/CacheProcessor.cc
b/src/iocore/cache/CacheProcessor.cc
index e042993f1e..2a8c9bb7a5 100644
--- a/src/iocore/cache/CacheProcessor.cc
+++ b/src/iocore/cache/CacheProcessor.cc
@@ -461,7 +461,7 @@ CacheProcessor::mark_storage_offline(CacheDisk *d, ///<
Target disk
for (p = 0; p < gnstripes; p++) {
if (d->fd == gstripes[p]->fd) {
total_dir_delete += gstripes[p]->directory.entries();
- used_dir_delete += dir_entries_used(gstripes[p]);
+ used_dir_delete += gstripes[p]->directory.entries_used();
total_bytes_delete += gstripes[p]->len - gstripes[p]->dirlen();
}
}
@@ -1505,7 +1505,7 @@ CacheProcessor::cacheInitialized()
total_direntries += vol_total_direntries;
ts::Metrics::Gauge::increment(stripe->cache_vol->vol_rsb.direntries_total,
vol_total_direntries);
- uint64_t vol_used_direntries = dir_entries_used(stripe);
+ uint64_t vol_used_direntries = stripe->directory.entries_used();
ts::Metrics::Gauge::increment(stripe->cache_vol->vol_rsb.direntries_used,
vol_used_direntries);
used_direntries += vol_used_direntries;
}
diff --git a/src/iocore/cache/CacheRead.cc b/src/iocore/cache/CacheRead.cc
index b4daaf4fc1..7565d9f761 100644
--- a/src/iocore/cache/CacheRead.cc
+++ b/src/iocore/cache/CacheRead.cc
@@ -476,7 +476,7 @@ CacheVC::openReadReadDone(int event, Event *e)
if (last_collision && dir_offset(&dir) != dir_offset(last_collision)) {
last_collision = nullptr; // object has been/is being overwritten
}
- if (dir_probe(&key, stripe, &dir, &last_collision)) {
+ if (stripe->directory.probe(&key, stripe, &dir, &last_collision)) {
int ret = do_read_call(&key);
if (ret == EVENT_RETURN) {
goto Lcallreturn;
@@ -485,7 +485,7 @@ CacheVC::openReadReadDone(int event, Event *e)
} else if (write_vc) {
if (writer_done()) {
last_collision = nullptr;
- while (dir_probe(&earliest_key, stripe, &dir, &last_collision)) {
+ while (stripe->directory.probe(&earliest_key, stripe, &dir,
&last_collision)) {
if (dir_offset(&dir) == dir_offset(&earliest_dir)) {
DDbg(dbg_ctl_cache_read_agg, "%p: key: %X ReadRead complete: %"
PRId64, this, first_key.slice32(1), vio.ndone);
doc_len = vio.ndone;
@@ -515,7 +515,7 @@ CacheVC::openReadReadDone(int event, Event *e)
} else {
Warning("Document %s truncated .. clearing",
earliest_key.toHexStr(tmpstring));
}
- dir_delete(&earliest_key, stripe, &earliest_dir);
+ stripe->directory.remove(&earliest_key, stripe, &earliest_dir);
}
}
return calluser(VC_EVENT_ERROR);
@@ -651,7 +651,7 @@ CacheVC::openReadMain(int /* event ATS_UNUSED */, Event *
/* e ATS_UNUSED */)
VC_SCHED_LOCK_RETRY();
}
- dir_delete(&earliest_key, stripe, &earliest_dir);
+ stripe->directory.remove(&earliest_key, stripe, &earliest_dir);
goto Lerror;
}
}
@@ -702,7 +702,7 @@ Lread: {
SET_HANDLER(&CacheVC::openReadMain);
VC_SCHED_LOCK_RETRY();
}
- if (dir_probe(&key, stripe, &dir, &last_collision)) {
+ if (stripe->directory.probe(&key, stripe, &dir, &last_collision)) {
SET_HANDLER(&CacheVC::openReadReadDone);
int ret = do_read_call(&key);
if (ret == EVENT_RETURN) {
@@ -712,7 +712,7 @@ Lread: {
} else if (write_vc) {
if (writer_done()) {
last_collision = nullptr;
- while (dir_probe(&earliest_key, stripe, &dir, &last_collision)) {
+ while (stripe->directory.probe(&earliest_key, stripe, &dir,
&last_collision)) {
if (dir_offset(&dir) == dir_offset(&earliest_dir)) {
DDbg(dbg_ctl_cache_read_agg, "%p: key: %X ReadMain complete: %"
PRId64, this, first_key.slice32(1), vio.ndone);
doc_len = vio.ndone;
@@ -732,7 +732,7 @@ Lread: {
Warning("Document %X truncated at %" PRId64 " of %" PRIu64 ", missing
fragment %X", first_key.slice32(1), vio.ndone, doc_len,
key.slice32(1));
// remove the directory entry
- dir_delete(&earliest_key, stripe, &earliest_dir);
+ stripe->directory.remove(&earliest_key, stripe, &earliest_dir);
}
Lerror:
return calluser(VC_EVENT_ERROR);
@@ -788,7 +788,7 @@ CacheVC::openReadStartEarliest(int /* event ATS_UNUSED */,
Event * /* e ATS_UNUS
Warning("Earliest: Doc magic does not match for %s",
key.toHexStr(tmpstring));
}
// remove the dir entry
- dir_delete(&key, stripe, &dir);
+ stripe->directory.remove(&key, stripe, &dir);
// try going through the directory entries again
// in case the dir entry we deleted doesnt correspond
// to the key we are looking for. This is possible
@@ -812,7 +812,8 @@ CacheVC::openReadStartEarliest(int /* event ATS_UNUSED */,
Event * /* e ATS_UNUS
}
goto Lsuccess;
Lread:
- if (dir_probe(&key, stripe, &earliest_dir, &last_collision) ||
dir_lookaside_probe(&key, stripe, &earliest_dir, nullptr)) {
+ if (stripe->directory.probe(&key, stripe, &earliest_dir, &last_collision)
||
+ dir_lookaside_probe(&key, stripe, &earliest_dir, nullptr)) {
dir = earliest_dir;
if ((ret = do_read_call(&key)) == EVENT_RETURN) {
goto Lcallreturn;
@@ -833,7 +834,7 @@ CacheVC::openReadStartEarliest(int /* event ATS_UNUSED */,
Event * /* e ATS_UNUS
// sometimes the delete fails when there is a race and another read
// finds that the directory entry has been overwritten
// (cannot assert on the return value)
- dir_delete(&first_key, stripe, &first_dir);
+ stripe->directory.remove(&first_key, stripe, &first_dir);
} else {
buf = nullptr;
last_collision = nullptr;
@@ -922,9 +923,9 @@ CacheVC::openReadVecWrite(int /* event ATS_UNUSED */, Event
* /* e ATS_UNUSED */
alternate_index = CACHE_ALT_INDEX_DEFAULT;
f.use_first_key = 0;
vio.op = VIO::READ;
- dir_overwrite(&first_key, stripe, &dir, &od->first_dir);
+ stripe->directory.overwrite(&first_key, stripe, &dir, &od->first_dir);
if (od->move_resident_alt) {
- dir_insert(&od->single_doc_key, stripe, &od->single_doc_dir);
+ stripe->directory.insert(&od->single_doc_key, stripe,
&od->single_doc_dir);
}
int alt_ndx = HttpTransactCache::SelectFromAlternates(write_vector,
&request, params);
stripe->close_write(this);
@@ -995,7 +996,7 @@ CacheVC::openReadStartHead(int event, Event *e)
Warning("Head: Doc magic does not match for %s",
key.toHexStr(tmpstring));
}
// remove the dir entry
- dir_delete(&key, stripe, &dir);
+ stripe->directory.remove(&key, stripe, &dir);
// try going through the directory entries again
// in case the dir entry we deleted doesnt correspond
// to the key we are looking for. This is possible
@@ -1039,7 +1040,7 @@ CacheVC::openReadStartHead(int event, Event *e)
CacheAltMagic::MARSHALED == alt->m_magic ? "serial" :
CacheAltMagic::DEAD == alt->m_magic ? "dead" :
"bogus"));
- dir_delete(&key, stripe, &dir);
+ stripe->directory.remove(&key, stripe, &dir);
}
err = ECACHE_BAD_META_DATA;
goto Ldone;
@@ -1057,7 +1058,7 @@ CacheVC::openReadStartHead(int event, Event *e)
if (!alternate_tmp->valid()) {
if (buf) {
Note("OpenReadHead failed for cachekey %X : alternate
inconsistency", key.slice32(0));
- dir_delete(&key, stripe, &dir);
+ stripe->directory.remove(&key, stripe, &dir);
}
goto Ldone;
}
@@ -1137,7 +1138,7 @@ CacheVC::openReadStartHead(int event, Event *e)
SET_HANDLER(&CacheVC::openReadFromWriter);
return handleEvent(EVENT_IMMEDIATE, nullptr);
}
- if (dir_probe(&key, stripe, &dir, &last_collision)) {
+ if (stripe->directory.probe(&key, stripe, &dir, &last_collision)) {
first_dir = dir;
int ret = do_read_call(&key);
if (ret == EVENT_RETURN) {
@@ -1187,6 +1188,6 @@ CacheVC::openReadDirDelete(int /* event ATS_UNUSED */,
Event * /* e ATS_UNUSED *
VC_SCHED_LOCK_RETRY();
}
- dir_delete(&earliest_key, stripe, &earliest_dir);
+ stripe->directory.remove(&earliest_key, stripe, &earliest_dir);
return calluser(VC_EVENT_ERROR);
}
diff --git a/src/iocore/cache/CacheVC.cc b/src/iocore/cache/CacheVC.cc
index dc41fc4195..951678f2a4 100644
--- a/src/iocore/cache/CacheVC.cc
+++ b/src/iocore/cache/CacheVC.cc
@@ -111,7 +111,7 @@ next_in_map(Stripe *stripe, char *vol_map, off_t offset)
}
// Function in CacheDir.cc that we need for make_vol_map().
-int dir_bucket_loop_fix(Dir *start_dir, int s, Stripe *stripe);
+int dir_bucket_loop_fix(Dir *start_dir, int s, Directory *directory);
// TODO: If we used a bit vector, we could make a smaller map structure.
// TODO: If we saved a high water mark we could have a smaller buf, and avoid
searching it
@@ -136,7 +136,7 @@ make_vol_map(Stripe *stripe)
Dir *seg = stripe->directory.get_segment(s);
for (int b = 0; b < stripe->directory.buckets; b++) {
Dir *e = dir_bucket(b, seg);
- if (dir_bucket_loop_fix(e, s, stripe)) {
+ if (dir_bucket_loop_fix(e, s, &stripe->directory)) {
break;
}
while (e) {
@@ -585,7 +585,7 @@ CacheVC::removeEvent(int /* event ATS_UNUSED */, Event * /*
e ATS_UNUSED */)
/* should be first_key not key..right?? */
if (doc->first_key == key) {
ink_assert(doc->magic == DOC_MAGIC);
- if (dir_delete(&key, stripe, &dir) > 0) {
+ if (stripe->directory.remove(&key, stripe, &dir) > 0) {
if (od) {
stripe->close_write(this);
}
@@ -597,7 +597,7 @@ CacheVC::removeEvent(int /* event ATS_UNUSED */, Event * /*
e ATS_UNUSED */)
}
Lcollision:
// check for collision
- if (dir_probe(&key, stripe, &dir, &last_collision) > 0) {
+ if (stripe->directory.probe(&key, stripe, &dir, &last_collision) > 0) {
int ret = do_read_call(&key);
if (ret == EVENT_RETURN) {
goto Lread;
@@ -739,7 +739,7 @@ CacheVC::scanObject(int /* event ATS_UNUSED */, Event * /*
e ATS_UNUSED */)
last_collision = nullptr;
while (true) {
- if (!dir_probe(&doc->first_key, stripe, &dir, &last_collision)) {
+ if (!stripe->directory.probe(&doc->first_key, stripe, &dir,
&last_collision)) {
goto Lskip;
}
if (!stripe->dir_agg_valid(&dir) || !dir_head(&dir) ||
@@ -787,7 +787,7 @@ CacheVC::scanObject(int /* event ATS_UNUSED */, Event * /*
e ATS_UNUSED */)
// verify that the earliest block exists, reducing 'false hit' callbacks
if (!(key == doc->key)) {
last_collision = nullptr;
- if (!dir_probe(&key, stripe, &earliest_dir, &last_collision)) {
+ if (!stripe->directory.probe(&key, stripe, &earliest_dir,
&last_collision)) {
continue;
}
}
@@ -968,7 +968,7 @@ CacheVC::scanOpenWrite(int /* event ATS_UNUSED */, Event *
/* e ATS_UNUSED */)
}
while (true) {
- if (!dir_probe(&first_key, stripe, &d, &l)) {
+ if (!stripe->directory.probe(&first_key, stripe, &d, &l)) {
stripe->close_write(this);
_action.continuation->handleEvent(CACHE_EVENT_SCAN_OPERATION_FAILED,
nullptr);
SET_HANDLER(&CacheVC::scanObject);
@@ -1005,9 +1005,9 @@ CacheVC::scanUpdateDone(int /* event ATS_UNUSED */, Event
* /* e ATS_UNUSED */)
CACHE_TRY_LOCK(lock, stripe->mutex, mutex->thread_holding);
if (lock.is_locked()) {
// insert a directory entry for the previous fragment
- dir_overwrite(&first_key, stripe, &dir, &od->first_dir, false);
+ stripe->directory.overwrite(&first_key, stripe, &dir, &od->first_dir,
false);
if (od->move_resident_alt) {
- dir_insert(&od->single_doc_key, stripe, &od->single_doc_dir);
+ stripe->directory.insert(&od->single_doc_key, stripe,
&od->single_doc_dir);
}
ink_assert(stripe->open_read(&first_key));
ink_assert(this->od);
diff --git a/src/iocore/cache/CacheWrite.cc b/src/iocore/cache/CacheWrite.cc
index 6f8e0f56aa..6e0962fc95 100644
--- a/src/iocore/cache/CacheWrite.cc
+++ b/src/iocore/cache/CacheWrite.cc
@@ -97,7 +97,7 @@ CacheVC::updateVector(int /* event ATS_UNUSED */, Event * /*
e ATS_UNUSED */)
write_vector->remove(alternate_index, true);
alternate_index = CACHE_ALT_REMOVED;
if (!write_vector->count()) {
- dir_delete(&first_key, stripe, &od->first_dir);
+ stripe->directory.remove(&first_key, stripe, &od->first_dir);
}
}
// the alternate is not there any more. somebody might have
@@ -279,7 +279,7 @@ CacheVC::openWriteCloseDir(int /* event ATS_UNUSED */,
Event * /* e ATS_UNUSED *
}
stripe->close_write(this);
if (closed < 0 && fragment) {
- dir_delete(&earliest_key, stripe, &earliest_dir);
+ stripe->directory.remove(&earliest_key, stripe, &earliest_dir);
}
}
if (dbg_ctl_cache_update.on()) {
@@ -337,14 +337,14 @@ CacheVC::openWriteCloseHeadDone(int event, Event *e)
ink_assert(f.use_first_key);
if (!od->dont_update_directory) {
if (dir_is_empty(&od->first_dir)) {
- dir_insert(&first_key, stripe, &dir);
+ stripe->directory.insert(&first_key, stripe, &dir);
} else {
// multiple fragment vector write
- dir_overwrite(&first_key, stripe, &dir, &od->first_dir, false);
+ stripe->directory.overwrite(&first_key, stripe, &dir, &od->first_dir,
false);
// insert moved resident alternate
if (od->move_resident_alt) {
if (stripe->dir_valid(&od->single_doc_dir)) {
- dir_insert(&od->single_doc_key, stripe, &od->single_doc_dir);
+ stripe->directory.insert(&od->single_doc_key, stripe,
&od->single_doc_dir);
}
od->move_resident_alt = false;
}
@@ -421,7 +421,7 @@ CacheVC::openWriteCloseDataDone(int event, Event *e)
}
fragment++;
write_pos += write_len;
- dir_insert(&key, stripe, &dir);
+ stripe->directory.insert(&key, stripe, &dir);
blocks = iobufferblock_skip(blocks.get(), &offset, &length, write_len);
next_CacheKey(&key, &key);
if (length) {
@@ -517,7 +517,7 @@ CacheVC::openWriteWriteDone(int event, Event *e)
}
++fragment;
write_pos += write_len;
- dir_insert(&key, stripe, &dir);
+ stripe->directory.insert(&key, stripe, &dir);
DDbg(dbg_ctl_cache_insert, "WriteDone: %X, %X, %d", key.slice32(0),
first_key.slice32(0), write_len);
blocks = iobufferblock_skip(blocks.get(), &offset, &length, write_len);
next_CacheKey(&key, &key);
@@ -647,7 +647,7 @@ Lcollision: {
if (!lock.is_locked()) {
VC_LOCK_RETRY_EVENT();
}
- int res = dir_probe(&first_key, stripe, &dir, &last_collision);
+ int res = stripe->directory.probe(&first_key, stripe, &dir, &last_collision);
if (res > 0) {
if ((res = do_read_call(&first_key)) == EVENT_RETURN) {
goto Lcallreturn;
@@ -738,7 +738,7 @@ CacheVC::openWriteStartDone(int event, Event *e)
}
}
// check for collision
- if (dir_probe(&first_key, stripe, &dir, &last_collision)) {
+ if (stripe->directory.probe(&first_key, stripe, &dir, &last_collision)) {
od->reading_vec = true;
int ret = do_read_call(&first_key);
if (ret == EVENT_RETURN) {
diff --git a/src/iocore/cache/P_CacheDir.h b/src/iocore/cache/P_CacheDir.h
index f0965b44b2..2ddbedc4f7 100644
--- a/src/iocore/cache/P_CacheDir.h
+++ b/src/iocore/cache/P_CacheDir.h
@@ -73,7 +73,7 @@ class CacheEvacuateDocVC;
// Macros
#ifdef DO_CHECK_DIR
-#define CHECK_DIR(_d) ink_assert(check_dir(_d))
+#define CHECK_DIR(_d) ink_assert(_d->check())
#else
#define CHECK_DIR(_d) ((void)0)
#endif
@@ -285,6 +285,19 @@ struct Directory {
/* Returns the first dir in segment @a s.
*/
Dir *get_segment(int s) const;
+
+ int probe(const CacheKey *, StripeSM *, Dir *, Dir **);
+ int insert(const CacheKey *key, StripeSM *stripe, Dir *to_part);
+ int overwrite(const CacheKey *key, StripeSM *stripe, Dir *to_part, Dir
*overwrite, bool must_overwrite = true);
+ int remove(const CacheKey *key, StripeSM *stripe, Dir *del);
+ void free_entry(Dir *e, int s);
+ int check();
+ void cleanup(Stripe *stripe);
+ void clear_range(off_t start, off_t end, Stripe *stripe);
+ uint64_t entries_used();
+ int bucket_length(Dir *b, int s);
+ int freelist_length(int s);
+ void clean_segment(int s, Stripe *stripe);
};
inline int
@@ -301,26 +314,13 @@ Directory::get_segment(int s) const
// Global Functions
-int dir_probe(const CacheKey *, StripeSM *, Dir *, Dir **);
-int dir_insert(const CacheKey *key, StripeSM *stripe, Dir *to_part);
-int dir_overwrite(const CacheKey *key, StripeSM *stripe, Dir *to_part,
Dir *overwrite, bool must_overwrite = true);
-int dir_delete(const CacheKey *key, StripeSM *stripe, Dir *del);
-int dir_lookaside_probe(const CacheKey *key, StripeSM *stripe, Dir
*result, EvacuationBlock **eblock);
-int dir_lookaside_insert(EvacuationBlock *b, StripeSM *stripe, Dir *to);
-int dir_lookaside_fixup(const CacheKey *key, StripeSM *stripe);
-void dir_lookaside_cleanup(StripeSM *stripe);
-void dir_lookaside_remove(const CacheKey *key, StripeSM *stripe);
-void dir_free_entry(Dir *e, int s, Stripe *stripe);
-void dir_sync_init();
-int check_dir(Stripe *stripe);
-void dir_clean_vol(Stripe *stripe);
-void dir_clear_range(off_t start, off_t end, Stripe *stripe);
-uint64_t dir_entries_used(Stripe *stripe);
-void sync_cache_dir_on_shutdown();
-
-int dir_bucket_length(Dir *b, int s, Stripe *stripe);
-int dir_freelist_length(Stripe *stripe, int s);
-void dir_clean_segment(int s, Stripe *stripe);
+int dir_lookaside_probe(const CacheKey *key, StripeSM *stripe, Dir *result,
EvacuationBlock **eblock);
+int dir_lookaside_insert(EvacuationBlock *b, StripeSM *stripe, Dir *to);
+int dir_lookaside_fixup(const CacheKey *key, StripeSM *stripe);
+void dir_lookaside_cleanup(StripeSM *stripe);
+void dir_lookaside_remove(const CacheKey *key, StripeSM *stripe);
+void dir_sync_init();
+void sync_cache_dir_on_shutdown();
// Inline Functions
diff --git a/src/iocore/cache/Stripe.cc b/src/iocore/cache/Stripe.cc
index 8ae9c15767..825efe4c53 100644
--- a/src/iocore/cache/Stripe.cc
+++ b/src/iocore/cache/Stripe.cc
@@ -260,7 +260,7 @@ Stripe::dir_check()
++hist[std::min(h, SEGMENT_HISTOGRAM_WIDTH)];
seg_chain_max = std::max(seg_chain_max, h);
}
- int fl_size = dir_freelist_length(this, s);
+ int fl_size = directory.freelist_length(s);
in_use += seg_in_use;
empty += seg_empty;
stale += seg_stale;
@@ -350,7 +350,7 @@ Stripe::_init_dir()
for (l = 1; l < DIR_DEPTH; l++) {
for (b = 0; b < this->directory.buckets; b++) {
Dir *bucket = dir_bucket(b, seg);
- dir_free_entry(dir_bucket_row(bucket, l), s, this);
+ this->directory.free_entry(dir_bucket_row(bucket, l), s);
}
}
}
diff --git a/src/iocore/cache/StripeSM.cc b/src/iocore/cache/StripeSM.cc
index b4066e8cc6..40a3877d2f 100644
--- a/src/iocore/cache/StripeSM.cc
+++ b/src/iocore/cache/StripeSM.cc
@@ -548,10 +548,10 @@ Ldone: {
off_t clear_start = this->offset_to_vol_offset(directory.header->write_pos);
off_t clear_end = this->offset_to_vol_offset(recover_pos);
if (clear_start <= clear_end) {
- dir_clear_range(clear_start, clear_end, this);
+ this->directory.clear_range(clear_start, clear_end, this);
} else {
- dir_clear_range(clear_start, DIR_OFFSET_MAX, this);
- dir_clear_range(1, clear_end, this);
+ this->directory.clear_range(clear_start, DIR_OFFSET_MAX, this);
+ this->directory.clear_range(1, clear_end, this);
}
Note("recovery clearing offsets of Stripe %s : [%" PRIu64 ", %" PRIu64 "]
sync_serial %d next %d\n", hash_text.get(),
@@ -741,7 +741,7 @@ StripeSM::aggWriteDone(int event, Event *e)
for (int done = 0; done < this->_write_buffer.get_buffer_pos();) {
Doc *doc = reinterpret_cast<Doc *>(this->_write_buffer.get_buffer() +
done);
dir_set_offset(&del_dir, directory.header->write_pos + done);
- dir_delete(&doc->key, this, &del_dir);
+ this->directory.remove(&doc->key, this, &del_dir);
done += round_to_approx_size(doc->len);
}
this->_write_buffer.reset_buffer_pos();
@@ -1074,7 +1074,7 @@ StripeSM::agg_wrap()
directory.header->cycle++;
directory.header->agg_pos = directory.header->write_pos;
dir_lookaside_cleanup(this);
- dir_clean_vol(this);
+ this->directory.cleanup(this);
{
StripeSM *stripe = this;
ts::Metrics::Counter::increment(cache_rsb.directory_wrap);
@@ -1230,7 +1230,7 @@ evacuate_fragments(CacheKey *key, CacheKey *earliest_key,
int force, StripeSM *s
{
Dir dir, *last_collision = nullptr;
int i = 0;
- while (dir_probe(key, stripe, &dir, &last_collision)) {
+ while (stripe->directory.probe(key, stripe, &dir, &last_collision)) {
// next fragment cannot be a head...if it is, it must have been a
// directory collision.
if (dir_head(&dir)) {
diff --git a/src/iocore/cache/unit_tests/test_Alternate_L_to_S_remove_L.cc
b/src/iocore/cache/unit_tests/test_Alternate_L_to_S_remove_L.cc
index 1d4c3ef2ce..60c2efaaa7 100644
--- a/src/iocore/cache/unit_tests/test_Alternate_L_to_S_remove_L.cc
+++ b/src/iocore/cache/unit_tests/test_Alternate_L_to_S_remove_L.cc
@@ -224,8 +224,8 @@ public:
Dir *last_collision = nullptr;
SCOPED_MUTEX_LOCK(lock, vc->stripe->mutex, this->mutex->thread_holding);
vc->vector.data[0].alternate.object_key_get(&key);
- REQUIRE(dir_probe(&key, vc->stripe, &dir, &last_collision) != 0);
- REQUIRE(dir_delete(&key, vc->stripe, &dir));
+ REQUIRE(vc->stripe->directory.probe(&key, vc->stripe, &dir,
&last_collision) != 0);
+ REQUIRE(vc->stripe->directory.remove(&key, vc->stripe, &dir));
}
};
diff --git a/src/iocore/cache/unit_tests/test_Alternate_L_to_S_remove_S.cc
b/src/iocore/cache/unit_tests/test_Alternate_L_to_S_remove_S.cc
index 33b8607cca..b92bed0667 100644
--- a/src/iocore/cache/unit_tests/test_Alternate_L_to_S_remove_S.cc
+++ b/src/iocore/cache/unit_tests/test_Alternate_L_to_S_remove_S.cc
@@ -225,8 +225,8 @@ public:
Dir *last_collision = nullptr;
SCOPED_MUTEX_LOCK(lock, vc->stripe->mutex, this->mutex->thread_holding);
vc->vector.data[1].alternate.object_key_get(&key);
- REQUIRE(dir_probe(&key, vc->stripe, &dir, &last_collision) != 0);
- REQUIRE(dir_delete(&key, vc->stripe, &dir));
+ REQUIRE(vc->stripe->directory.probe(&key, vc->stripe, &dir,
&last_collision) != 0);
+ REQUIRE(vc->stripe->directory.remove(&key, vc->stripe, &dir));
}
};
diff --git a/src/iocore/cache/unit_tests/test_Alternate_S_to_L_remove_L.cc
b/src/iocore/cache/unit_tests/test_Alternate_S_to_L_remove_L.cc
index f68bfd308c..1838138e1f 100644
--- a/src/iocore/cache/unit_tests/test_Alternate_S_to_L_remove_L.cc
+++ b/src/iocore/cache/unit_tests/test_Alternate_S_to_L_remove_L.cc
@@ -229,8 +229,8 @@ public:
Dir *last_collision = nullptr;
SCOPED_MUTEX_LOCK(lock, vc->stripe->mutex, this->mutex->thread_holding);
vc->vector.data[1].alternate.object_key_get(&key);
- REQUIRE(dir_probe(&key, vc->stripe, &dir, &last_collision) != 0);
- REQUIRE(dir_delete(&key, vc->stripe, &dir));
+ REQUIRE(vc->stripe->directory.probe(&key, vc->stripe, &dir,
&last_collision) != 0);
+ REQUIRE(vc->stripe->directory.remove(&key, vc->stripe, &dir));
}
};
diff --git a/src/iocore/cache/unit_tests/test_Alternate_S_to_L_remove_S.cc
b/src/iocore/cache/unit_tests/test_Alternate_S_to_L_remove_S.cc
index 95f2bf53a8..df9aca3c33 100644
--- a/src/iocore/cache/unit_tests/test_Alternate_S_to_L_remove_S.cc
+++ b/src/iocore/cache/unit_tests/test_Alternate_S_to_L_remove_S.cc
@@ -227,8 +227,8 @@ public:
Dir *last_collision = nullptr;
SCOPED_MUTEX_LOCK(lock, vc->stripe->mutex, this->mutex->thread_holding);
vc->vector.data[0].alternate.object_key_get(&key);
- REQUIRE(dir_probe(&key, vc->stripe, &dir, &last_collision) != 0);
- REQUIRE(dir_delete(&key, vc->stripe, &dir));
+ REQUIRE(vc->stripe->directory.probe(&key, vc->stripe, &dir,
&last_collision) != 0);
+ REQUIRE(vc->stripe->directory.remove(&key, vc->stripe, &dir));
}
};
diff --git a/src/iocore/cache/unit_tests/test_CacheDir.cc
b/src/iocore/cache/unit_tests/test_CacheDir.cc
index c98b3e6421..5fabd608bb 100644
--- a/src/iocore/cache/unit_tests/test_CacheDir.cc
+++ b/src/iocore/cache/unit_tests/test_CacheDir.cc
@@ -57,7 +57,7 @@ regress_rand_CacheKey(CacheKey *key)
void
dir_corrupt_bucket(Dir *b, int s, StripeSM *stripe)
{
- int l = (static_cast<int>(dir_bucket_length(b, s, stripe) *
ts::Random::drandom()));
+ int l = (static_cast<int>(stripe->directory.bucket_length(b, s) *
ts::Random::drandom()));
Dir *e = b;
Dir *seg = stripe->directory.get_segment(s);
for (int i = 0; i < l; i++) {
@@ -108,10 +108,10 @@ public:
// test insert
int inserted = 0;
- int free = dir_freelist_length(stripe, s);
+ int free = stripe->directory.freelist_length(s);
int n = free;
while (n--) {
- if (!dir_insert(&key, stripe, &dir)) {
+ if (!stripe->directory.insert(&key, stripe, &dir)) {
break;
}
inserted++;
@@ -124,8 +124,8 @@ public:
dir_set_offset(dir_bucket_row(dir_bucket(i, seg), j), 0); // delete
}
}
- dir_clean_segment(s, stripe);
- int newfree = dir_freelist_length(stripe, s);
+ stripe->directory.clean_segment(s, stripe);
+ int newfree = stripe->directory.freelist_length(s);
CHECK(static_cast<unsigned int>(newfree - free) <= 1);
// test insert-delete
@@ -133,7 +133,7 @@ public:
ttime = ink_get_hrtime();
for (i = 0; i < newfree; i++) {
regress_rand_CacheKey(&key);
- dir_insert(&key, stripe, &dir);
+ stripe->directory.insert(&key, stripe, &dir);
}
uint64_t us = (ink_get_hrtime() - ttime) / HRTIME_USECOND;
// On windows us is sometimes 0. I don't know why.
@@ -146,7 +146,7 @@ public:
for (i = 0; i < newfree; i++) {
Dir *last_collision = nullptr;
regress_rand_CacheKey(&key);
- CHECK(dir_probe(&key, stripe, &dir, &last_collision));
+ CHECK(stripe->directory.probe(&key, stripe, &dir, &last_collision));
}
us = (ink_get_hrtime() - ttime) / HRTIME_USECOND;
// On windows us is sometimes 0. I don't know why.
@@ -157,7 +157,7 @@ public:
for (int c = 0; c < stripe->directory.entries() * 0.75; c++) {
regress_rand_CacheKey(&key);
- dir_insert(&key, stripe, &dir);
+ stripe->directory.insert(&key, stripe, &dir);
}
Dir dir1;
@@ -167,14 +167,14 @@ public:
Dbg(dbg_ctl_cache_dir_test, "corrupt_bucket test");
for (int ntimes = 0; ntimes < 10; ntimes++) {
#ifdef LOOP_CHECK_MODE
- // dir_probe in bucket with loop
+ // probe in bucket with loop
rand_CacheKey(&key);
s1 = key.slice32(0) % vol->segments;
b1 = key.slice32(1) % vol->buckets;
dir_corrupt_bucket(dir_bucket(b1, vol->directory.get_segment(s1)), s1,
vol);
- dir_insert(&key, vol, &dir);
+ stripe->directory.insert(&key, vol, &dir);
Dir *last_collision = 0;
- dir_probe(&key, vol, &dir, &last_collision);
+ vol->directory.probe(&key, vol, &dir, &last_collision);
rand_CacheKey(&key);
s1 = key.slice32(0) % vol->segments;
@@ -182,9 +182,9 @@ public:
dir_corrupt_bucket(dir_bucket(b1, vol->directory.get_segment(s1)), s1,
vol);
last_collision = 0;
- dir_probe(&key, vol, &dir, &last_collision);
+ vol->directory.probe(&key, vol, &dir, &last_collision);
- // dir_overwrite in bucket with loop
+ // overwrite in bucket with loop
rand_CacheKey(&key);
s1 = key.slice32(0) % vol->segments;
b1 = key.slice32(1) % vol->buckets;
@@ -192,48 +192,48 @@ public:
key1.b[1] = 127;
dir1 = dir;
dir_set_offset(&dir1, 23);
- dir_insert(&key1, vol, &dir1);
- dir_insert(&key, vol, &dir);
+ stripe->directory.insert(&key1, vol, &dir1);
+ stripe->directory.insert(&key, vol, &dir);
key1.b[1] = 80;
- dir_insert(&key1, vol, &dir1);
+ stripe->directory.insert(&key1, vol, &dir1);
dir_corrupt_bucket(dir_bucket(b1, vol->directory.get_segment(s1)), s1,
vol);
- dir_overwrite(&key, vol, &dir, &dir, 1);
+ vol->directory.overwrite(&key, vol, &dir, &dir, 1);
rand_CacheKey(&key);
s1 = key.slice32(0) % vol->segments;
b1 = key.slice32(1) % vol->buckets;
key.b[1] = 23;
- dir_insert(&key, vol, &dir1);
+ stripe->directory.insert(&key, vol, &dir1);
dir_corrupt_bucket(dir_bucket(b1, vol->directory.get_segment(s1)), s1,
vol);
- dir_overwrite(&key, vol, &dir, &dir, 0);
+ vol->directory.overwrite(&key, vol, &dir, &dir, 0);
rand_CacheKey(&key);
s1 = key.slice32(0) % vol->segments;
Dir *seg1 = vol->directory.get_segment(s1);
- // dir_freelist_length in freelist with loop
+ // freelist_length in freelist with loop
dir_corrupt_bucket(dir_from_offset(vol->header->freelist[s], seg1), s1,
vol);
- dir_freelist_length(vol, s1);
+ vol->directory.freelist_length(s1);
rand_CacheKey(&key);
s1 = key.slice32(0) % vol->segments;
b1 = key.slice32(1) % vol->buckets;
- // dir_bucket_length in bucket with loop
+ // bucket_length in bucket with loop
dir_corrupt_bucket(dir_bucket(b1, vol->directory.get_segment(s1)), s1,
vol);
- dir_bucket_length(dir_bucket(b1, vol->directory.get_segment(s1)), s1,
vol);
- CHECK(check_dir(vol));
+ vol->directory.bucket_length(dir_bucket(b1,
vol->directory.get_segment(s1)), s1, vol);
+ CHECK(vol->directory.check());
#else
// test corruption detection
rand_CacheKey(&key);
s1 = key.slice32(0) % stripe->directory.segments;
b1 = key.slice32(1) % stripe->directory.buckets;
- dir_insert(&key, stripe, &dir1);
- dir_insert(&key, stripe, &dir1);
- dir_insert(&key, stripe, &dir1);
- dir_insert(&key, stripe, &dir1);
- dir_insert(&key, stripe, &dir1);
+ stripe->directory.insert(&key, stripe, &dir1);
+ stripe->directory.insert(&key, stripe, &dir1);
+ stripe->directory.insert(&key, stripe, &dir1);
+ stripe->directory.insert(&key, stripe, &dir1);
+ stripe->directory.insert(&key, stripe, &dir1);
dir_corrupt_bucket(dir_bucket(b1, stripe->directory.get_segment(s1)),
s1, stripe);
- CHECK(!check_dir(stripe));
+ CHECK(!stripe->directory.check());
#endif
}
stripe->clear_dir();