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 dc59c4c1fc Decouple disk from stripe (#11737)
dc59c4c1fc is described below
commit dc59c4c1fc8243f60601127442ea6835c434ffdd
Author: JosiahWI <[email protected]>
AuthorDate: Thu Dec 5 21:22:45 2024 -0600
Decouple disk from stripe (#11737)
* Pass `fd` in to `flush_aggregate_write_buffer`
* Push down `fd` field to `StripeSM`
* Pass `hw_sector_size` in to `_clear_init`
* Push down `disk` field to `StripeSM`
---
src/iocore/cache/CacheDir.cc | 4 ++--
src/iocore/cache/Stripe.cc | 20 +++++++++-----------
src/iocore/cache/Stripe.h | 10 ++++------
src/iocore/cache/StripeSM.cc | 8 +++++---
src/iocore/cache/StripeSM.h | 3 +++
5 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc
index ad3d7652d8..efacf0c206 100644
--- a/src/iocore/cache/CacheDir.cc
+++ b/src/iocore/cache/CacheDir.cc
@@ -428,7 +428,7 @@ check_bucket_not_contains(Dir *b, Dir *e, Dir *seg)
}
void
-freelist_clean(int s, Stripe *stripe)
+freelist_clean(int s, StripeSM *stripe)
{
dir_clean_segment(s, stripe);
if (stripe->header->freelist[s]) {
@@ -452,7 +452,7 @@ freelist_clean(int s, Stripe *stripe)
}
inline Dir *
-freelist_pop(int s, Stripe *stripe)
+freelist_pop(int s, StripeSM *stripe)
{
Dir *seg = stripe->dir_segment(s);
Dir *e = dir_from_offset(stripe->header->freelist[s], seg);
diff --git a/src/iocore/cache/Stripe.cc b/src/iocore/cache/Stripe.cc
index b234457f36..e0dbe4fc82 100644
--- a/src/iocore/cache/Stripe.cc
+++ b/src/iocore/cache/Stripe.cc
@@ -85,24 +85,22 @@ struct StripeInitInfo {
//
Stripe::Stripe(CacheDisk *disk, off_t blocks, off_t dir_skip, int
avg_obj_size, int fragment_size)
- : fd{disk->fd},
- frag_size{fragment_size},
+ : frag_size{fragment_size},
skip{ROUND_TO_STORE_BLOCK((dir_skip < START_POS ? START_POS : dir_skip))},
start{skip},
- len{blocks * STORE_BLOCK_SIZE},
- disk{disk}
+ len{blocks * STORE_BLOCK_SIZE}
{
ink_assert(this->len < MAX_STRIPE_SIZE);
- this->_init_hash_text(disk->path, blocks, dir_skip);
+ this->_init_hash_text(disk, blocks, dir_skip);
this->_init_data(STORE_BLOCK_SIZE, avg_obj_size);
this->_init_directory(this->dirlen(), this->headerlen(),
DIRECTORY_FOOTER_SIZE);
}
void
-Stripe::_init_hash_text(char const *seed, off_t blocks, off_t dir_skip)
+Stripe::_init_hash_text(CacheDisk const *disk, off_t blocks, off_t dir_skip)
{
- char const *seed_str = this->disk->hash_base_string ?
this->disk->hash_base_string : seed;
+ char const *seed_str = disk->hash_base_string ?
disk->hash_base_string : disk->path;
const size_t hash_seed_size = strlen(seed_str);
const size_t hash_text_size = hash_seed_size + 32;
@@ -323,7 +321,7 @@ Stripe::dir_check()
}
void
-Stripe::_clear_init()
+Stripe::_clear_init(std::uint32_t hw_sector_size)
{
size_t dir_len = this->dirlen();
memset(this->raw_dir, 0, dir_len);
@@ -337,7 +335,7 @@ Stripe::_clear_init()
this->header->cycle = 0;
this->header->create_time =
time(nullptr);
this->header->dirty = 0;
- this->sector_size = this->header->sector_size = this->disk->hw_sector_size;
+ this->sector_size = this->header->sector_size = hw_sector_size;
*this->footer = *this->header;
}
@@ -359,12 +357,12 @@ Stripe::_init_dir()
}
bool
-Stripe::flush_aggregate_write_buffer()
+Stripe::flush_aggregate_write_buffer(int fd)
{
// set write limit
this->header->agg_pos = this->header->write_pos +
this->_write_buffer.get_buffer_pos();
- if (!this->_write_buffer.flush(this->fd, this->header->write_pos)) {
+ if (!this->_write_buffer.flush(fd, this->header->write_pos)) {
return false;
}
this->header->last_write_pos = this->header->write_pos;
diff --git a/src/iocore/cache/Stripe.h b/src/iocore/cache/Stripe.h
index f80566c162..1231810d6a 100644
--- a/src/iocore/cache/Stripe.h
+++ b/src/iocore/cache/Stripe.h
@@ -85,7 +85,6 @@ class Stripe
{
public:
ats_scoped_str hash_text;
- int fd{-1};
int frag_size{-1};
char *raw_dir{nullptr};
@@ -100,8 +99,7 @@ public:
off_t len{};
off_t data_blocks{};
- CacheDisk *const disk{};
- uint32_t sector_size{};
+ uint32_t sector_size{};
CacheVol *cache_vol{};
@@ -172,12 +170,12 @@ public:
protected:
AggregateWriteBuffer _write_buffer;
- void _clear_init();
+ void _clear_init(std::uint32_t hw_sector_size);
void _init_dir();
- bool flush_aggregate_write_buffer();
+ bool flush_aggregate_write_buffer(int fd);
private:
- void _init_hash_text(char const *seed, off_t blocks, off_t dir_skip);
+ void _init_hash_text(CacheDisk const *disk, off_t blocks, off_t dir_skip);
void _init_data(off_t store_block_size, int avg_obj_size = -1);
void _init_data_internal(int avg_obj_size = -1); // Defaults to
cache_config_min_average_object_size;
void _init_directory(std::size_t directory_size, int header_size, int
footer_size);
diff --git a/src/iocore/cache/StripeSM.cc b/src/iocore/cache/StripeSM.cc
index c7fe33ef1f..6c8873b15f 100644
--- a/src/iocore/cache/StripeSM.cc
+++ b/src/iocore/cache/StripeSM.cc
@@ -115,6 +115,8 @@ struct StripeInitInfo {
StripeSM::StripeSM(CacheDisk *disk, off_t blocks, off_t dir_skip, int
avg_obj_size, int fragment_size)
: Continuation(new_ProxyMutex()),
Stripe{disk, blocks, dir_skip, avg_obj_size, fragment_size},
+ fd{disk->fd},
+ disk{disk},
_preserved_dirs{static_cast<int>(len)}
{
open_dir.mutex = this->mutex;
@@ -152,7 +154,7 @@ int
StripeSM::clear_dir()
{
size_t dir_len = this->dirlen();
- this->_clear_init();
+ this->_clear_init(this->disk->hw_sector_size);
if (pwrite(this->fd, this->raw_dir, dir_len, this->skip) < 0) {
Warning("unable to clear cache directory '%s'", this->hash_text.get());
@@ -272,7 +274,7 @@ int
StripeSM::clear_dir_aio()
{
size_t dir_len = this->dirlen();
- this->_clear_init();
+ this->_clear_init(this->disk->hw_sector_size);
SET_HANDLER(&StripeSM::handle_dir_clear);
@@ -1339,7 +1341,7 @@ StripeSM::shutdown(EThread *shutdown_thread)
// directories have not been inserted for these writes
if (!this->_write_buffer.is_empty()) {
Dbg(dbg_ctl_cache_dir_sync, "Dir %s: flushing agg buffer first",
this->hash_text.get());
- this->flush_aggregate_write_buffer();
+ this->flush_aggregate_write_buffer(this->fd);
}
// We already asserted that dirlen > 0.
diff --git a/src/iocore/cache/StripeSM.h b/src/iocore/cache/StripeSM.h
index 5a34adb724..1863d17380 100644
--- a/src/iocore/cache/StripeSM.h
+++ b/src/iocore/cache/StripeSM.h
@@ -66,6 +66,7 @@ class StripeSM : public Continuation, public Stripe
{
public:
CryptoHash hash_id;
+ int fd{-1};
int hit_evacuate_window{};
@@ -77,6 +78,8 @@ public:
Event *trigger = nullptr;
+ CacheDisk *disk{};
+
OpenDir open_dir;
RamCache *ram_cache = nullptr;
DLL<EvacuationBlock> lookaside[LOOKASIDE_SIZE];