From 9dc336e2307826e5492d6e48760536e3ef9d61cc Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Tue, 7 Jan 2025 09:51:11 -0600 Subject: [PATCH 01/14] Move `dir_probe` to `Directory::dir_probe` --- src/iocore/cache/Cache.cc | 6 +++--- src/iocore/cache/CacheDir.cc | 8 ++++---- src/iocore/cache/CacheEvacuateDocVC.cc | 4 ++-- src/iocore/cache/CacheRead.cc | 13 +++++++------ src/iocore/cache/CacheVC.cc | 8 ++++---- src/iocore/cache/CacheWrite.cc | 4 ++-- src/iocore/cache/P_CacheDir.h | 3 ++- src/iocore/cache/StripeSM.cc | 2 +- .../unit_tests/test_Alternate_L_to_S_remove_L.cc | 2 +- .../unit_tests/test_Alternate_L_to_S_remove_S.cc | 2 +- .../unit_tests/test_Alternate_S_to_L_remove_L.cc | 2 +- .../unit_tests/test_Alternate_S_to_L_remove_S.cc | 2 +- src/iocore/cache/unit_tests/test_CacheDir.cc | 8 ++++---- 13 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/iocore/cache/Cache.cc b/src/iocore/cache/Cache.cc index 275eb480fe9..0ba2ffdbe4a 100644 --- a/src/iocore/cache/Cache.cc +++ b/src/iocore/cache/Cache.cc @@ -344,7 +344,7 @@ Cache::open_read(Continuation *cont, const CacheKey *key, CacheFragType type, co 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; @@ -548,7 +548,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; @@ -691,7 +691,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 4298b8ff86d..759ff02ea49 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -488,12 +488,12 @@ dir_free_entry(Dir *e, int s, Stripe *stripe) } 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 diff --git a/src/iocore/cache/CacheEvacuateDocVC.cc b/src/iocore/cache/CacheEvacuateDocVC.cc index a525c766752..65acb5b2f0e 100644 --- a/src/iocore/cache/CacheEvacuateDocVC.cc +++ b/src/iocore/cache/CacheEvacuateDocVC.cc @@ -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/CacheRead.cc b/src/iocore/cache/CacheRead.cc index 2465562bd3f..f8d4bb708fc 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; @@ -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; @@ -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; @@ -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) { diff --git a/src/iocore/cache/CacheVC.cc b/src/iocore/cache/CacheVC.cc index e81d5c345c2..e0f15708475 100644 --- a/src/iocore/cache/CacheVC.cc +++ b/src/iocore/cache/CacheVC.cc @@ -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) || @@ -785,7 +785,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; } } @@ -965,7 +965,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); diff --git a/src/iocore/cache/CacheWrite.cc b/src/iocore/cache/CacheWrite.cc index eaaa8515454..cf25cc16414 100644 --- a/src/iocore/cache/CacheWrite.cc +++ b/src/iocore/cache/CacheWrite.cc @@ -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 b6b484c9489..1b472f20cab 100644 --- a/src/iocore/cache/P_CacheDir.h +++ b/src/iocore/cache/P_CacheDir.h @@ -287,6 +287,8 @@ struct Directory { /* Returns the first dir in segment @a s. */ Dir *get_segment(int s) const; + + int probe(const CacheKey *, StripeSM *, Dir *, Dir **); }; inline int @@ -303,7 +305,6 @@ 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); diff --git a/src/iocore/cache/StripeSM.cc b/src/iocore/cache/StripeSM.cc index bcbf3360f62..90de21ef341 100644 --- a/src/iocore/cache/StripeSM.cc +++ b/src/iocore/cache/StripeSM.cc @@ -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 d51ff5116e6..31188413702 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,7 +224,7 @@ class CacheAltTest_L_to_S_remove_L : public CacheTestHandler 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(vc->stripe->directory.probe(&key, vc->stripe, &dir, &last_collision) != 0); REQUIRE(dir_delete(&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 6867cadcd17..74fcf5b6f7e 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,7 +225,7 @@ class CacheAltTest_L_to_S_remove_S : public CacheTestHandler 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(vc->stripe->directory.probe(&key, vc->stripe, &dir, &last_collision) != 0); REQUIRE(dir_delete(&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 d6082dd761e..7dc3c80f23a 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,7 +229,7 @@ class CacheAltTest_S_to_L_remove_L : public CacheTestHandler 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(vc->stripe->directory.probe(&key, vc->stripe, &dir, &last_collision) != 0); REQUIRE(dir_delete(&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 9b68dbbf658..3832c92a6e5 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,7 +227,7 @@ class test_Alternate_S_to_L_remove_S : public CacheTestHandler 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(vc->stripe->directory.probe(&key, vc->stripe, &dir, &last_collision) != 0); REQUIRE(dir_delete(&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 dcb68aef6bb..08ed42c2ff7 100644 --- a/src/iocore/cache/unit_tests/test_CacheDir.cc +++ b/src/iocore/cache/unit_tests/test_CacheDir.cc @@ -146,7 +146,7 @@ class CacheDirTest : public CacheInit 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. @@ -167,14 +167,14 @@ class CacheDirTest : public CacheInit 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); 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,7 +182,7 @@ class CacheDirTest : public CacheInit 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 rand_CacheKey(&key); From 1c1b08280e0c138be3e4c1aa380c1216409bf442 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Tue, 7 Jan 2025 16:22:38 -0600 Subject: [PATCH 02/14] Move `dir_insert` to `Directory::insert` --- src/iocore/cache/CacheDir.cc | 10 ++++---- src/iocore/cache/CacheRead.cc | 2 +- src/iocore/cache/CacheVC.cc | 2 +- src/iocore/cache/CacheWrite.cc | 8 +++--- src/iocore/cache/P_CacheDir.h | 2 +- src/iocore/cache/unit_tests/test_CacheDir.cc | 26 ++++++++++---------- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc index 759ff02ea49..779950f7e14 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -557,13 +557,13 @@ Directory::probe(const CacheKey *key, StripeSM *stripe, Dir *result, Dir **last_ } 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) @@ -606,7 +606,7 @@ dir_insert(const CacheKey *key, StripeSM *stripe, Dir *to_part) 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)); diff --git a/src/iocore/cache/CacheRead.cc b/src/iocore/cache/CacheRead.cc index f8d4bb708fc..31dd5b56589 100644 --- a/src/iocore/cache/CacheRead.cc +++ b/src/iocore/cache/CacheRead.cc @@ -925,7 +925,7 @@ CacheVC::openReadVecWrite(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */ vio.op = VIO::READ; dir_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); diff --git a/src/iocore/cache/CacheVC.cc b/src/iocore/cache/CacheVC.cc index e0f15708475..3a00baca448 100644 --- a/src/iocore/cache/CacheVC.cc +++ b/src/iocore/cache/CacheVC.cc @@ -1004,7 +1004,7 @@ CacheVC::scanUpdateDone(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) // insert a directory entry for the previous fragment dir_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 cf25cc16414..57bb7e45ceb 100644 --- a/src/iocore/cache/CacheWrite.cc +++ b/src/iocore/cache/CacheWrite.cc @@ -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); // 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); diff --git a/src/iocore/cache/P_CacheDir.h b/src/iocore/cache/P_CacheDir.h index 1b472f20cab..c412c4d2b9f 100644 --- a/src/iocore/cache/P_CacheDir.h +++ b/src/iocore/cache/P_CacheDir.h @@ -289,6 +289,7 @@ struct Directory { Dir *get_segment(int s) const; int probe(const CacheKey *, StripeSM *, Dir *, Dir **); + int insert(const CacheKey *key, StripeSM *stripe, Dir *to_part); }; inline int @@ -305,7 +306,6 @@ Directory::get_segment(int s) const // Global Functions -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); diff --git a/src/iocore/cache/unit_tests/test_CacheDir.cc b/src/iocore/cache/unit_tests/test_CacheDir.cc index 08ed42c2ff7..06c13e777be 100644 --- a/src/iocore/cache/unit_tests/test_CacheDir.cc +++ b/src/iocore/cache/unit_tests/test_CacheDir.cc @@ -111,7 +111,7 @@ class CacheDirTest : public CacheInit int free = dir_freelist_length(stripe, s); int n = free; while (n--) { - if (!dir_insert(&key, stripe, &dir)) { + if (!stripe->directory.insert(&key, stripe, &dir)) { break; } inserted++; @@ -133,7 +133,7 @@ class CacheDirTest : public CacheInit 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. @@ -157,7 +157,7 @@ class CacheDirTest : public CacheInit 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; @@ -172,7 +172,7 @@ class CacheDirTest : public CacheInit 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; vol->directory.probe(&key, vol, &dir, &last_collision); @@ -192,10 +192,10 @@ class CacheDirTest : public CacheInit 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); @@ -203,7 +203,7 @@ class CacheDirTest : public CacheInit 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); @@ -227,11 +227,11 @@ class CacheDirTest : public CacheInit 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)); #endif From 1d7fa906fd23c0612bac0a8e8da182f1e4150357 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Tue, 7 Jan 2025 16:30:25 -0600 Subject: [PATCH 03/14] Move `dir_overwrite` to `Directory::overwrite` --- src/iocore/cache/CacheDir.cc | 16 ++++++++-------- src/iocore/cache/CacheEvacuateDocVC.cc | 4 ++-- src/iocore/cache/CacheRead.cc | 2 +- src/iocore/cache/CacheVC.cc | 2 +- src/iocore/cache/CacheWrite.cc | 2 +- src/iocore/cache/P_CacheDir.h | 2 +- src/iocore/cache/unit_tests/test_CacheDir.cc | 6 +++--- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc index 779950f7e14..907dc8d56b2 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -625,12 +625,12 @@ Directory::insert(const CacheKey *key, StripeSM *stripe, Dir *to_part) } 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)); @@ -696,7 +696,7 @@ dir_overwrite(const CacheKey *key, StripeSM *stripe, Dir *dir, Dir *overwrite, b 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)); @@ -707,7 +707,7 @@ dir_overwrite(const CacheKey *key, StripeSM *stripe, Dir *dir, Dir *overwrite, b 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; } @@ -801,7 +801,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); @@ -995,7 +995,7 @@ CacheSync::mainEvent(int event, Event *e) /* 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 65acb5b2f0e..3e18610e089 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(o), static_cast(n)); } diff --git a/src/iocore/cache/CacheRead.cc b/src/iocore/cache/CacheRead.cc index 31dd5b56589..48226a9fe89 100644 --- a/src/iocore/cache/CacheRead.cc +++ b/src/iocore/cache/CacheRead.cc @@ -923,7 +923,7 @@ 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) { stripe->directory.insert(&od->single_doc_key, stripe, &od->single_doc_dir); } diff --git a/src/iocore/cache/CacheVC.cc b/src/iocore/cache/CacheVC.cc index 3a00baca448..53336e5a0af 100644 --- a/src/iocore/cache/CacheVC.cc +++ b/src/iocore/cache/CacheVC.cc @@ -1002,7 +1002,7 @@ 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) { stripe->directory.insert(&od->single_doc_key, stripe, &od->single_doc_dir); } diff --git a/src/iocore/cache/CacheWrite.cc b/src/iocore/cache/CacheWrite.cc index 57bb7e45ceb..b0c010ba22a 100644 --- a/src/iocore/cache/CacheWrite.cc +++ b/src/iocore/cache/CacheWrite.cc @@ -340,7 +340,7 @@ CacheVC::openWriteCloseHeadDone(int event, Event *e) 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)) { diff --git a/src/iocore/cache/P_CacheDir.h b/src/iocore/cache/P_CacheDir.h index c412c4d2b9f..cf47c14fd1c 100644 --- a/src/iocore/cache/P_CacheDir.h +++ b/src/iocore/cache/P_CacheDir.h @@ -290,6 +290,7 @@ struct Directory { 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); }; inline int @@ -306,7 +307,6 @@ Directory::get_segment(int s) const // Global Functions -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); diff --git a/src/iocore/cache/unit_tests/test_CacheDir.cc b/src/iocore/cache/unit_tests/test_CacheDir.cc index 06c13e777be..9a91b273db0 100644 --- a/src/iocore/cache/unit_tests/test_CacheDir.cc +++ b/src/iocore/cache/unit_tests/test_CacheDir.cc @@ -184,7 +184,7 @@ class CacheDirTest : public CacheInit last_collision = 0; 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; @@ -197,7 +197,7 @@ class CacheDirTest : public CacheInit key1.b[1] = 80; 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; @@ -205,7 +205,7 @@ class CacheDirTest : public CacheInit key.b[1] = 23; 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; From a2c68d2b9e7b60a2c35e62e0bd831224c9d682ee Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Tue, 7 Jan 2025 16:39:18 -0600 Subject: [PATCH 04/14] Move `dir_delete` to `Directory::remove` --- src/iocore/cache/CacheDir.cc | 8 ++++---- src/iocore/cache/CacheRead.cc | 18 +++++++++--------- src/iocore/cache/CacheVC.cc | 2 +- src/iocore/cache/CacheWrite.cc | 4 ++-- src/iocore/cache/P_CacheDir.h | 2 +- src/iocore/cache/StripeSM.cc | 2 +- .../test_Alternate_L_to_S_remove_L.cc | 2 +- .../test_Alternate_L_to_S_remove_S.cc | 2 +- .../test_Alternate_S_to_L_remove_L.cc | 2 +- .../test_Alternate_S_to_L_remove_S.cc | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc index 907dc8d56b2..5a351cfc19a 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -712,12 +712,12 @@ Directory::overwrite(const CacheKey *key, StripeSM *stripe, Dir *dir, Dir *overw } 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; diff --git a/src/iocore/cache/CacheRead.cc b/src/iocore/cache/CacheRead.cc index 48226a9fe89..2a607c26764 100644 --- a/src/iocore/cache/CacheRead.cc +++ b/src/iocore/cache/CacheRead.cc @@ -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; } } @@ -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 @@ -834,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; @@ -996,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 @@ -1040,7 +1040,7 @@ CacheVC::openReadStartHead(int event, Event *e) CACHE_ALT_MAGIC_MARSHALED == alt->m_magic ? "serial" : CACHE_ALT_MAGIC_DEAD == alt->m_magic ? "dead" : "bogus")); - dir_delete(&key, stripe, &dir); + stripe->directory.remove(&key, stripe, &dir); } err = ECACHE_BAD_META_DATA; goto Ldone; @@ -1058,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; } @@ -1188,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 53336e5a0af..77d6d84cae2 100644 --- a/src/iocore/cache/CacheVC.cc +++ b/src/iocore/cache/CacheVC.cc @@ -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); } diff --git a/src/iocore/cache/CacheWrite.cc b/src/iocore/cache/CacheWrite.cc index b0c010ba22a..d88bc07a94c 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()) { diff --git a/src/iocore/cache/P_CacheDir.h b/src/iocore/cache/P_CacheDir.h index cf47c14fd1c..696d59691f6 100644 --- a/src/iocore/cache/P_CacheDir.h +++ b/src/iocore/cache/P_CacheDir.h @@ -291,6 +291,7 @@ struct Directory { 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); }; inline int @@ -307,7 +308,6 @@ Directory::get_segment(int s) const // Global Functions -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); diff --git a/src/iocore/cache/StripeSM.cc b/src/iocore/cache/StripeSM.cc index 90de21ef341..664c69e55ee 100644 --- a/src/iocore/cache/StripeSM.cc +++ b/src/iocore/cache/StripeSM.cc @@ -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(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(); 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 31188413702..93047482f33 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 @@ -225,7 +225,7 @@ class CacheAltTest_L_to_S_remove_L : public CacheTestHandler SCOPED_MUTEX_LOCK(lock, vc->stripe->mutex, this->mutex->thread_holding); vc->vector.data[0].alternate.object_key_get(&key); REQUIRE(vc->stripe->directory.probe(&key, vc->stripe, &dir, &last_collision) != 0); - REQUIRE(dir_delete(&key, vc->stripe, &dir)); + 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 74fcf5b6f7e..b367166c1be 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 @@ -226,7 +226,7 @@ class CacheAltTest_L_to_S_remove_S : public CacheTestHandler SCOPED_MUTEX_LOCK(lock, vc->stripe->mutex, this->mutex->thread_holding); vc->vector.data[1].alternate.object_key_get(&key); REQUIRE(vc->stripe->directory.probe(&key, vc->stripe, &dir, &last_collision) != 0); - REQUIRE(dir_delete(&key, vc->stripe, &dir)); + 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 7dc3c80f23a..7e0bc536844 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 @@ -230,7 +230,7 @@ class CacheAltTest_S_to_L_remove_L : public CacheTestHandler SCOPED_MUTEX_LOCK(lock, vc->stripe->mutex, this->mutex->thread_holding); vc->vector.data[1].alternate.object_key_get(&key); REQUIRE(vc->stripe->directory.probe(&key, vc->stripe, &dir, &last_collision) != 0); - REQUIRE(dir_delete(&key, vc->stripe, &dir)); + 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 3832c92a6e5..77c77ba153e 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 @@ -228,7 +228,7 @@ class test_Alternate_S_to_L_remove_S : public CacheTestHandler SCOPED_MUTEX_LOCK(lock, vc->stripe->mutex, this->mutex->thread_holding); vc->vector.data[0].alternate.object_key_get(&key); REQUIRE(vc->stripe->directory.probe(&key, vc->stripe, &dir, &last_collision) != 0); - REQUIRE(dir_delete(&key, vc->stripe, &dir)); + REQUIRE(vc->stripe->directory.remove(&key, vc->stripe, &dir)); } }; From 0e9e4f68f3946a3bc730d7e6bf89e8353886219c Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Tue, 7 Jan 2025 16:44:29 -0600 Subject: [PATCH 05/14] Move `dir_free_entry` to `Directory::free_entry` --- src/iocore/cache/CacheDir.cc | 10 +++++----- src/iocore/cache/P_CacheDir.h | 10 +++++----- src/iocore/cache/Stripe.cc | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc index 5a351cfc19a..8cfc8df6cc4 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -226,7 +226,7 @@ dir_init_segment(int s, Stripe *stripe) for (l = 1; l < DIR_DEPTH; l++) { for (b = 0; b < stripe->directory.buckets; b++) { Dir *bucket = dir_bucket(b, seg); - dir_free_entry(dir_bucket_row(bucket, l), s, stripe); + stripe->directory.free_entry(dir_bucket_row(bucket, l), s); } } } @@ -475,16 +475,16 @@ 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 diff --git a/src/iocore/cache/P_CacheDir.h b/src/iocore/cache/P_CacheDir.h index 696d59691f6..84276abcf33 100644 --- a/src/iocore/cache/P_CacheDir.h +++ b/src/iocore/cache/P_CacheDir.h @@ -288,10 +288,11 @@ struct Directory { */ 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); + 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); }; inline int @@ -313,7 +314,6 @@ 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); diff --git a/src/iocore/cache/Stripe.cc b/src/iocore/cache/Stripe.cc index 8ae9c157677..57aed2f0952 100644 --- a/src/iocore/cache/Stripe.cc +++ b/src/iocore/cache/Stripe.cc @@ -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); } } } From 7a84a9e170fa91fc8d4b39a5a866d5c17c50e541 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Tue, 7 Jan 2025 16:51:33 -0600 Subject: [PATCH 06/14] Move `check_dir` to `Directory::check` --- src/iocore/cache/CacheDir.cc | 8 ++++---- src/iocore/cache/P_CacheDir.h | 4 ++-- src/iocore/cache/unit_tests/test_CacheDir.cc | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc index 8cfc8df6cc4..e8c97fdfcce 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -281,13 +281,13 @@ dir_bucket_length(Dir *b, int s, Stripe *stripe) } int -check_dir(Stripe *stripe) +Directory::check(Stripe *stripe) { 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)) { return 0; diff --git a/src/iocore/cache/P_CacheDir.h b/src/iocore/cache/P_CacheDir.h index 84276abcf33..52524141623 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 @@ -293,6 +293,7 @@ struct Directory { 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(Stripe *stripe); }; inline int @@ -315,7 +316,6 @@ 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(); -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); diff --git a/src/iocore/cache/unit_tests/test_CacheDir.cc b/src/iocore/cache/unit_tests/test_CacheDir.cc index 9a91b273db0..09769839fdb 100644 --- a/src/iocore/cache/unit_tests/test_CacheDir.cc +++ b/src/iocore/cache/unit_tests/test_CacheDir.cc @@ -220,7 +220,7 @@ class CacheDirTest : public CacheInit // dir_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)); + CHECK(vol->directory.check(vol)); #else // test corruption detection rand_CacheKey(&key); @@ -233,7 +233,7 @@ class CacheDirTest : public CacheInit 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(stripe)); #endif } stripe->clear_dir(); From 39f0c6f594fe818611e845e98bce9a9fa1c967a4 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Tue, 7 Jan 2025 16:57:56 -0600 Subject: [PATCH 07/14] Move `dir_clean_vol` to `Directory::cleanup` --- src/iocore/cache/CacheDir.cc | 6 +++--- src/iocore/cache/P_CacheDir.h | 2 +- src/iocore/cache/StripeSM.cc | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc index e8c97fdfcce..9e0a45edb97 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -393,9 +393,9 @@ dir_clean_segment(int s, Stripe *stripe) } void -dir_clean_vol(Stripe *stripe) +Directory::cleanup(Stripe *stripe) { - for (int64_t i = 0; i < stripe->directory.segments; i++) { + for (int64_t i = 0; i < this->segments; i++) { dir_clean_segment(i, stripe); } CHECK_DIR(d); @@ -412,7 +412,7 @@ dir_clear_range(off_t start, off_t end, Stripe *stripe) dir_set_offset(e, 0); // delete } } - dir_clean_vol(stripe); + stripe->directory.cleanup(stripe); } void diff --git a/src/iocore/cache/P_CacheDir.h b/src/iocore/cache/P_CacheDir.h index 52524141623..95cd53ed4fa 100644 --- a/src/iocore/cache/P_CacheDir.h +++ b/src/iocore/cache/P_CacheDir.h @@ -294,6 +294,7 @@ struct Directory { int remove(const CacheKey *key, StripeSM *stripe, Dir *del); void free_entry(Dir *e, int s); int check(Stripe *stripe); + void cleanup(Stripe *stripe); }; inline int @@ -316,7 +317,6 @@ 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 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(); diff --git a/src/iocore/cache/StripeSM.cc b/src/iocore/cache/StripeSM.cc index 664c69e55ee..00da0a347de 100644 --- a/src/iocore/cache/StripeSM.cc +++ b/src/iocore/cache/StripeSM.cc @@ -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); From 9a6faf178c0ae5075335eba0d1386ecdd78651f3 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Tue, 7 Jan 2025 17:01:09 -0600 Subject: [PATCH 08/14] Move `dir_clear_range` to `Directory::clear_range` --- src/iocore/cache/CacheDir.cc | 6 +++--- src/iocore/cache/P_CacheDir.h | 2 +- src/iocore/cache/StripeSM.cc | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc index 9e0a45edb97..ba0fb4cf2b3 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -402,9 +402,9 @@ Directory::cleanup(Stripe *stripe) } 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(start) && dir_offset(e) < static_cast(end)) { ts::Metrics::Gauge::decrement(cache_rsb.direntries_used); @@ -412,7 +412,7 @@ dir_clear_range(off_t start, off_t end, Stripe *stripe) dir_set_offset(e, 0); // delete } } - stripe->directory.cleanup(stripe); + this->cleanup(stripe); } void diff --git a/src/iocore/cache/P_CacheDir.h b/src/iocore/cache/P_CacheDir.h index 95cd53ed4fa..f7a0bb9638d 100644 --- a/src/iocore/cache/P_CacheDir.h +++ b/src/iocore/cache/P_CacheDir.h @@ -295,6 +295,7 @@ struct Directory { void free_entry(Dir *e, int s); int check(Stripe *stripe); void cleanup(Stripe *stripe); + void clear_range(off_t start, off_t end, Stripe *stripe); }; inline int @@ -317,7 +318,6 @@ 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 dir_clear_range(off_t start, off_t end, Stripe *stripe); uint64_t dir_entries_used(Stripe *stripe); void sync_cache_dir_on_shutdown(); diff --git a/src/iocore/cache/StripeSM.cc b/src/iocore/cache/StripeSM.cc index 00da0a347de..0ec046c3929 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(), From a81e3a7e0fcf8578a8740edae1340cb828a341c9 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Wed, 8 Jan 2025 13:30:34 -0600 Subject: [PATCH 09/14] Move `dir_entries_used` to Directory struct --- src/iocore/cache/CacheDir.cc | 8 ++++---- src/iocore/cache/CacheProcessor.cc | 4 ++-- src/iocore/cache/P_CacheDir.h | 32 +++++++++++++++--------------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc index ba0fb4cf2b3..c2c1e933149 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -882,14 +882,14 @@ CacheSync::aio_write(int fd, char *b, int n, off_t o) } uint64_t -dir_entries_used(Stripe *stripe) +Directory::entries_used(Stripe *stripe) { 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)) { sfull = 0; diff --git a/src/iocore/cache/CacheProcessor.cc b/src/iocore/cache/CacheProcessor.cc index 7b759c1b1fb..7a19e2b7641 100644 --- a/src/iocore/cache/CacheProcessor.cc +++ b/src/iocore/cache/CacheProcessor.cc @@ -457,7 +457,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(gstripes[p]); total_bytes_delete += gstripes[p]->len - gstripes[p]->dirlen(); } } @@ -1518,7 +1518,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(stripe); 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/P_CacheDir.h b/src/iocore/cache/P_CacheDir.h index f7a0bb9638d..8dfd5b8bc95 100644 --- a/src/iocore/cache/P_CacheDir.h +++ b/src/iocore/cache/P_CacheDir.h @@ -288,14 +288,15 @@ struct Directory { */ 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(Stripe *stripe); - void cleanup(Stripe *stripe); - void clear_range(off_t start, off_t end, Stripe *stripe); + 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(Stripe *stripe); + void cleanup(Stripe *stripe); + void clear_range(off_t start, off_t end, Stripe *stripe); + uint64_t entries_used(Stripe *stripe); }; inline int @@ -312,14 +313,13 @@ Directory::get_segment(int s) const // Global Functions -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(); -uint64_t dir_entries_used(Stripe *stripe); -void sync_cache_dir_on_shutdown(); +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(); int dir_bucket_length(Dir *b, int s, Stripe *stripe); int dir_freelist_length(Stripe *stripe, int s); From 035c0d77ad780688c04c4307caa0ab110f38cbf4 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Wed, 8 Jan 2025 13:38:04 -0600 Subject: [PATCH 10/14] Move `dir_bucket_length` to Directory struct --- src/iocore/cache/CacheDir.cc | 10 +++++----- src/iocore/cache/P_CacheDir.h | 2 +- src/iocore/cache/unit_tests/test_CacheDir.cc | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc index c2c1e933149..9c5d4ff47e6 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -261,11 +261,11 @@ 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)) return 1; @@ -281,7 +281,7 @@ dir_bucket_length(Dir *b, int s, Stripe *stripe) } int -Directory::check(Stripe *stripe) +Directory::check(Stripe * /* ATS_UNUSED */) { int i, s; Dbg(dbg_ctl_cache_check_dir, "inside check dir"); @@ -289,7 +289,7 @@ Directory::check(Stripe *stripe) 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))) { @@ -368,7 +368,7 @@ dir_clean_bucket(Dir *b, int s, Stripe *stripe) 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); diff --git a/src/iocore/cache/P_CacheDir.h b/src/iocore/cache/P_CacheDir.h index 8dfd5b8bc95..9503236a2ac 100644 --- a/src/iocore/cache/P_CacheDir.h +++ b/src/iocore/cache/P_CacheDir.h @@ -297,6 +297,7 @@ struct Directory { void cleanup(Stripe *stripe); void clear_range(off_t start, off_t end, Stripe *stripe); uint64_t entries_used(Stripe *stripe); + int bucket_length(Dir *b, int s); }; inline int @@ -321,7 +322,6 @@ void dir_lookaside_remove(const CacheKey *key, StripeSM *stripe); void dir_sync_init(); 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); diff --git a/src/iocore/cache/unit_tests/test_CacheDir.cc b/src/iocore/cache/unit_tests/test_CacheDir.cc index 09769839fdb..a3bebbb5be5 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(dir_bucket_length(b, s, stripe) * ts::Random::drandom())); + int l = (static_cast(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++) { @@ -217,9 +217,9 @@ class CacheDirTest : public CacheInit 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); + vol->directory.bucket_length(dir_bucket(b1, vol->directory.get_segment(s1)), s1, vol); CHECK(vol->directory.check(vol)); #else // test corruption detection From fa98ef15223ab5115144c6384594bc3100d48f51 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Wed, 8 Jan 2025 13:42:01 -0600 Subject: [PATCH 11/14] Move `dir_freelist_length` to Directory struct --- src/iocore/cache/CacheDir.cc | 8 ++++---- src/iocore/cache/P_CacheDir.h | 2 +- src/iocore/cache/Stripe.cc | 2 +- src/iocore/cache/unit_tests/test_CacheDir.cc | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc index 9c5d4ff47e6..9b4c139a859 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -245,13 +245,13 @@ dir_bucket_loop_fix(Dir *start_dir, int s, Stripe *stripe) } int -dir_freelist_length(Stripe *stripe, int s) +Directory::freelist_length(Stripe *stripe, int s) { int free = 0; - Dir *seg = stripe->directory.get_segment(s); - Dir *e = dir_from_offset(stripe->directory.header->freelist[s], seg); + Dir *seg = this->get_segment(s); + Dir *e = dir_from_offset(this->header->freelist[s], seg); if (dir_bucket_loop_fix(e, s, stripe)) { - return (DIR_DEPTH - 1) * stripe->directory.buckets; + return (DIR_DEPTH - 1) * this->buckets; } while (e) { free++; diff --git a/src/iocore/cache/P_CacheDir.h b/src/iocore/cache/P_CacheDir.h index 9503236a2ac..27dbd1b49a8 100644 --- a/src/iocore/cache/P_CacheDir.h +++ b/src/iocore/cache/P_CacheDir.h @@ -298,6 +298,7 @@ struct Directory { void clear_range(off_t start, off_t end, Stripe *stripe); uint64_t entries_used(Stripe *stripe); int bucket_length(Dir *b, int s); + int freelist_length(Stripe *stripe, int s); }; inline int @@ -322,7 +323,6 @@ void dir_lookaside_remove(const CacheKey *key, StripeSM *stripe); void dir_sync_init(); void sync_cache_dir_on_shutdown(); -int dir_freelist_length(Stripe *stripe, int s); void dir_clean_segment(int s, Stripe *stripe); // Inline Functions diff --git a/src/iocore/cache/Stripe.cc b/src/iocore/cache/Stripe.cc index 57aed2f0952..a832d396715 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(this, s); in_use += seg_in_use; empty += seg_empty; stale += seg_stale; diff --git a/src/iocore/cache/unit_tests/test_CacheDir.cc b/src/iocore/cache/unit_tests/test_CacheDir.cc index a3bebbb5be5..8cf6f99be10 100644 --- a/src/iocore/cache/unit_tests/test_CacheDir.cc +++ b/src/iocore/cache/unit_tests/test_CacheDir.cc @@ -108,7 +108,7 @@ class CacheDirTest : public CacheInit // test insert int inserted = 0; - int free = dir_freelist_length(stripe, s); + int free = stripe->directory.freelist_length(stripe, s); int n = free; while (n--) { if (!stripe->directory.insert(&key, stripe, &dir)) { @@ -125,7 +125,7 @@ class CacheDirTest : public CacheInit } } dir_clean_segment(s, stripe); - int newfree = dir_freelist_length(stripe, s); + int newfree = stripe->directory.freelist_length(stripe, s); CHECK(static_cast(newfree - free) <= 1); // test insert-delete @@ -210,9 +210,9 @@ class CacheDirTest : public CacheInit 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(vol, s1); rand_CacheKey(&key); s1 = key.slice32(0) % vol->segments; From f022120ad7594081803dbd920bb40c7bd98cb44e Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Wed, 8 Jan 2025 13:47:21 -0600 Subject: [PATCH 12/14] Move `dir_clean_segment` to Directory struct --- src/iocore/cache/CacheDir.cc | 12 ++++++------ src/iocore/cache/P_CacheDir.h | 3 +-- src/iocore/cache/unit_tests/test_CacheDir.cc | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc index 9b4c139a859..0c70de72492 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -383,10 +383,10 @@ 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))); } @@ -396,7 +396,7 @@ void Directory::cleanup(Stripe *stripe) { for (int64_t i = 0; i < this->segments; i++) { - dir_clean_segment(i, stripe); + this->clean_segment(i, stripe); } CHECK_DIR(d); } @@ -431,7 +431,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; } @@ -449,7 +449,7 @@ freelist_clean(int s, StripeSM *stripe) } } } - dir_clean_segment(s, stripe); + stripe->directory.clean_segment(s, stripe); } inline Dir * diff --git a/src/iocore/cache/P_CacheDir.h b/src/iocore/cache/P_CacheDir.h index 27dbd1b49a8..5a8e961f0ff 100644 --- a/src/iocore/cache/P_CacheDir.h +++ b/src/iocore/cache/P_CacheDir.h @@ -299,6 +299,7 @@ struct Directory { uint64_t entries_used(Stripe *stripe); int bucket_length(Dir *b, int s); int freelist_length(Stripe *stripe, int s); + void clean_segment(int s, Stripe *stripe); }; inline int @@ -323,8 +324,6 @@ void dir_lookaside_remove(const CacheKey *key, StripeSM *stripe); void dir_sync_init(); void sync_cache_dir_on_shutdown(); -void dir_clean_segment(int s, Stripe *stripe); - // Inline Functions #define dir_in_seg(_s, _i) ((Dir *)(((char *)(_s)) + (SIZEOF_DIR * (_i)))) diff --git a/src/iocore/cache/unit_tests/test_CacheDir.cc b/src/iocore/cache/unit_tests/test_CacheDir.cc index 8cf6f99be10..0c5f4ffe785 100644 --- a/src/iocore/cache/unit_tests/test_CacheDir.cc +++ b/src/iocore/cache/unit_tests/test_CacheDir.cc @@ -124,7 +124,7 @@ class CacheDirTest : public CacheInit dir_set_offset(dir_bucket_row(dir_bucket(i, seg), j), 0); // delete } } - dir_clean_segment(s, stripe); + stripe->directory.clean_segment(s, stripe); int newfree = stripe->directory.freelist_length(stripe, s); CHECK(static_cast(newfree - free) <= 1); From 640943d436cad1a7a4614b71a4b0c52852729401 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Wed, 8 Jan 2025 14:17:00 -0600 Subject: [PATCH 13/14] Use `Directory` instead of `Stripe` where possible Some static functions can now take `Directory` parameters instead of `Stripe`. --- src/iocore/cache/CacheDir.cc | 68 ++++++++++++++++++------------------ src/iocore/cache/CacheVC.cc | 4 +-- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc index 0c70de72492..6c03a26b158 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -217,16 +217,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(seg), 0, SIZEOF_DIR * DIR_DEPTH * stripe->directory.buckets); + memset(static_cast(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); - stripe->directory.free_entry(dir_bucket_row(bucket, l), s); + directory->free_entry(dir_bucket_row(bucket, l), s); } } } @@ -234,23 +234,23 @@ 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 -Directory::freelist_length(Stripe *stripe, int s) +Directory::freelist_length(Stripe * /* ATS_UNUSED */, int s) { int free = 0; Dir *seg = this->get_segment(s); Dir *e = dir_from_offset(this->header->freelist[s], seg); - if (dir_bucket_loop_fix(e, s, stripe)) { + if (dir_bucket_loop_fix(e, s, this)) { return (DIR_DEPTH - 1) * this->buckets; } while (e) { @@ -267,7 +267,7 @@ Directory::bucket_length(Dir *b, int s) int i = 0; 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) { @@ -304,14 +304,14 @@ Directory::check(Stripe * /* ATS_UNUSED */) } 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) { @@ -320,13 +320,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); @@ -334,12 +334,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); @@ -361,7 +361,7 @@ 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 @@ -374,7 +374,7 @@ dir_clean_bucket(Dir *b, int s, Stripe *stripe) 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; @@ -464,7 +464,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); @@ -497,7 +497,7 @@ Directory::probe(const CacheKey *key, StripeSM *stripe, Dir *result, Dir **last_ 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: @@ -533,7 +533,7 @@ Directory::probe(const CacheKey *key, StripeSM *stripe, Dir *result, Dir **last_ } 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 { @@ -585,7 +585,7 @@ Directory::insert(const CacheKey *key, StripeSM *stripe, Dir *to_part) 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; } } @@ -650,7 +650,7 @@ Directory::overwrite(const CacheKey *key, StripeSM *stripe, Dir *dir, Dir *overw #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; } @@ -676,7 +676,7 @@ Directory::overwrite(const CacheKey *key, StripeSM *stripe, Dir *dir, Dir *overw 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; } } @@ -730,14 +730,14 @@ Directory::remove(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; } @@ -882,7 +882,7 @@ CacheSync::aio_write(int fd, char *b, int n, off_t o) } uint64_t -Directory::entries_used(Stripe *stripe) +Directory::entries_used(Stripe * /* ATS_UNUSED */) { uint64_t full = 0; uint64_t sfull = 0; @@ -891,7 +891,7 @@ Directory::entries_used(Stripe *stripe) sfull = 0; 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; } diff --git a/src/iocore/cache/CacheVC.cc b/src/iocore/cache/CacheVC.cc index 77d6d84cae2..12920a94bdb 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) { From 7959b7871ec220ad453628822cd2f136943628fc Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Wed, 8 Jan 2025 14:23:24 -0600 Subject: [PATCH 14/14] Remove unused `Stripe` parameters --- src/iocore/cache/CacheDir.cc | 6 +++--- src/iocore/cache/CacheProcessor.cc | 4 ++-- src/iocore/cache/P_CacheDir.h | 6 +++--- src/iocore/cache/Stripe.cc | 2 +- src/iocore/cache/unit_tests/test_CacheDir.cc | 10 +++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc index 6c03a26b158..c3a7755736c 100644 --- a/src/iocore/cache/CacheDir.cc +++ b/src/iocore/cache/CacheDir.cc @@ -245,7 +245,7 @@ dir_bucket_loop_fix(Dir *start_dir, int s, Directory *directory) } int -Directory::freelist_length(Stripe * /* ATS_UNUSED */, int s) +Directory::freelist_length(int s) { int free = 0; Dir *seg = this->get_segment(s); @@ -281,7 +281,7 @@ Directory::bucket_length(Dir *b, int s) } int -Directory::check(Stripe * /* ATS_UNUSED */) +Directory::check() { int i, s; Dbg(dbg_ctl_cache_check_dir, "inside check dir"); @@ -882,7 +882,7 @@ CacheSync::aio_write(int fd, char *b, int n, off_t o) } uint64_t -Directory::entries_used(Stripe * /* ATS_UNUSED */) +Directory::entries_used() { uint64_t full = 0; uint64_t sfull = 0; diff --git a/src/iocore/cache/CacheProcessor.cc b/src/iocore/cache/CacheProcessor.cc index 7a19e2b7641..9af1c317da9 100644 --- a/src/iocore/cache/CacheProcessor.cc +++ b/src/iocore/cache/CacheProcessor.cc @@ -457,7 +457,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 += gstripes[p]->directory.entries_used(gstripes[p]); + used_dir_delete += gstripes[p]->directory.entries_used(); total_bytes_delete += gstripes[p]->len - gstripes[p]->dirlen(); } } @@ -1518,7 +1518,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 = stripe->directory.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/P_CacheDir.h b/src/iocore/cache/P_CacheDir.h index 5a8e961f0ff..f45df3a2074 100644 --- a/src/iocore/cache/P_CacheDir.h +++ b/src/iocore/cache/P_CacheDir.h @@ -293,12 +293,12 @@ struct Directory { 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(Stripe *stripe); + int check(); void cleanup(Stripe *stripe); void clear_range(off_t start, off_t end, Stripe *stripe); - uint64_t entries_used(Stripe *stripe); + uint64_t entries_used(); int bucket_length(Dir *b, int s); - int freelist_length(Stripe *stripe, int s); + int freelist_length(int s); void clean_segment(int s, Stripe *stripe); }; diff --git a/src/iocore/cache/Stripe.cc b/src/iocore/cache/Stripe.cc index a832d396715..825efe4c531 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 = directory.freelist_length(this, s); + int fl_size = directory.freelist_length(s); in_use += seg_in_use; empty += seg_empty; stale += seg_stale; diff --git a/src/iocore/cache/unit_tests/test_CacheDir.cc b/src/iocore/cache/unit_tests/test_CacheDir.cc index 0c5f4ffe785..9e7cd41c055 100644 --- a/src/iocore/cache/unit_tests/test_CacheDir.cc +++ b/src/iocore/cache/unit_tests/test_CacheDir.cc @@ -108,7 +108,7 @@ class CacheDirTest : public CacheInit // test insert int inserted = 0; - int free = stripe->directory.freelist_length(stripe, s); + int free = stripe->directory.freelist_length(s); int n = free; while (n--) { if (!stripe->directory.insert(&key, stripe, &dir)) { @@ -125,7 +125,7 @@ class CacheDirTest : public CacheInit } } stripe->directory.clean_segment(s, stripe); - int newfree = stripe->directory.freelist_length(stripe, s); + int newfree = stripe->directory.freelist_length(s); CHECK(static_cast(newfree - free) <= 1); // test insert-delete @@ -212,7 +212,7 @@ class CacheDirTest : public CacheInit Dir *seg1 = vol->directory.get_segment(s1); // freelist_length in freelist with loop dir_corrupt_bucket(dir_from_offset(vol->header->freelist[s], seg1), s1, vol); - vol->directory.freelist_length(vol, s1); + vol->directory.freelist_length(s1); rand_CacheKey(&key); s1 = key.slice32(0) % vol->segments; @@ -220,7 +220,7 @@ class CacheDirTest : public CacheInit // bucket_length in bucket with loop dir_corrupt_bucket(dir_bucket(b1, vol->directory.get_segment(s1)), s1, vol); vol->directory.bucket_length(dir_bucket(b1, vol->directory.get_segment(s1)), s1, vol); - CHECK(vol->directory.check(vol)); + CHECK(vol->directory.check()); #else // test corruption detection rand_CacheKey(&key); @@ -233,7 +233,7 @@ class CacheDirTest : public CacheInit 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(!stripe->directory.check(stripe)); + CHECK(!stripe->directory.check()); #endif } stripe->clear_dir();