Skip to content

Commit

Permalink
Decouple disk from stripe (#11737)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
JosiahWI authored Dec 6, 2024
1 parent 65531cb commit dc59c4c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/iocore/cache/CacheDir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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);
Expand Down
20 changes: 9 additions & 11 deletions src/iocore/cache/Stripe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions src/iocore/cache/Stripe.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class Stripe
{
public:
ats_scoped_str hash_text;
int fd{-1};
int frag_size{-1};

char *raw_dir{nullptr};
Expand All @@ -100,8 +99,7 @@ class Stripe
off_t len{};
off_t data_blocks{};

CacheDisk *const disk{};
uint32_t sector_size{};
uint32_t sector_size{};

CacheVol *cache_vol{};

Expand Down Expand Up @@ -172,12 +170,12 @@ class Stripe
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);
Expand Down
8 changes: 5 additions & 3 deletions src/iocore/cache/StripeSM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/iocore/cache/StripeSM.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class StripeSM : public Continuation, public Stripe
{
public:
CryptoHash hash_id;
int fd{-1};

int hit_evacuate_window{};

Expand All @@ -77,6 +78,8 @@ class StripeSM : public Continuation, public Stripe

Event *trigger = nullptr;

CacheDisk *disk{};

OpenDir open_dir;
RamCache *ram_cache = nullptr;
DLL<EvacuationBlock> lookaside[LOOKASIDE_SIZE];
Expand Down

0 comments on commit dc59c4c

Please sign in to comment.