Skip to content

Commit dc59c4c

Browse files
authored
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`
1 parent 65531cb commit dc59c4c

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

src/iocore/cache/CacheDir.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ check_bucket_not_contains(Dir *b, Dir *e, Dir *seg)
428428
}
429429

430430
void
431-
freelist_clean(int s, Stripe *stripe)
431+
freelist_clean(int s, StripeSM *stripe)
432432
{
433433
dir_clean_segment(s, stripe);
434434
if (stripe->header->freelist[s]) {
@@ -452,7 +452,7 @@ freelist_clean(int s, Stripe *stripe)
452452
}
453453

454454
inline Dir *
455-
freelist_pop(int s, Stripe *stripe)
455+
freelist_pop(int s, StripeSM *stripe)
456456
{
457457
Dir *seg = stripe->dir_segment(s);
458458
Dir *e = dir_from_offset(stripe->header->freelist[s], seg);

src/iocore/cache/Stripe.cc

+9-11
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,22 @@ struct StripeInitInfo {
8585
//
8686

8787
Stripe::Stripe(CacheDisk *disk, off_t blocks, off_t dir_skip, int avg_obj_size, int fragment_size)
88-
: fd{disk->fd},
89-
frag_size{fragment_size},
88+
: frag_size{fragment_size},
9089
skip{ROUND_TO_STORE_BLOCK((dir_skip < START_POS ? START_POS : dir_skip))},
9190
start{skip},
92-
len{blocks * STORE_BLOCK_SIZE},
93-
disk{disk}
91+
len{blocks * STORE_BLOCK_SIZE}
9492
{
9593
ink_assert(this->len < MAX_STRIPE_SIZE);
9694

97-
this->_init_hash_text(disk->path, blocks, dir_skip);
95+
this->_init_hash_text(disk, blocks, dir_skip);
9896
this->_init_data(STORE_BLOCK_SIZE, avg_obj_size);
9997
this->_init_directory(this->dirlen(), this->headerlen(), DIRECTORY_FOOTER_SIZE);
10098
}
10199

102100
void
103-
Stripe::_init_hash_text(char const *seed, off_t blocks, off_t dir_skip)
101+
Stripe::_init_hash_text(CacheDisk const *disk, off_t blocks, off_t dir_skip)
104102
{
105-
char const *seed_str = this->disk->hash_base_string ? this->disk->hash_base_string : seed;
103+
char const *seed_str = disk->hash_base_string ? disk->hash_base_string : disk->path;
106104
const size_t hash_seed_size = strlen(seed_str);
107105
const size_t hash_text_size = hash_seed_size + 32;
108106

@@ -323,7 +321,7 @@ Stripe::dir_check()
323321
}
324322

325323
void
326-
Stripe::_clear_init()
324+
Stripe::_clear_init(std::uint32_t hw_sector_size)
327325
{
328326
size_t dir_len = this->dirlen();
329327
memset(this->raw_dir, 0, dir_len);
@@ -337,7 +335,7 @@ Stripe::_clear_init()
337335
this->header->cycle = 0;
338336
this->header->create_time = time(nullptr);
339337
this->header->dirty = 0;
340-
this->sector_size = this->header->sector_size = this->disk->hw_sector_size;
338+
this->sector_size = this->header->sector_size = hw_sector_size;
341339
*this->footer = *this->header;
342340
}
343341

@@ -359,12 +357,12 @@ Stripe::_init_dir()
359357
}
360358

361359
bool
362-
Stripe::flush_aggregate_write_buffer()
360+
Stripe::flush_aggregate_write_buffer(int fd)
363361
{
364362
// set write limit
365363
this->header->agg_pos = this->header->write_pos + this->_write_buffer.get_buffer_pos();
366364

367-
if (!this->_write_buffer.flush(this->fd, this->header->write_pos)) {
365+
if (!this->_write_buffer.flush(fd, this->header->write_pos)) {
368366
return false;
369367
}
370368
this->header->last_write_pos = this->header->write_pos;

src/iocore/cache/Stripe.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class Stripe
8585
{
8686
public:
8787
ats_scoped_str hash_text;
88-
int fd{-1};
8988
int frag_size{-1};
9089

9190
char *raw_dir{nullptr};
@@ -100,8 +99,7 @@ class Stripe
10099
off_t len{};
101100
off_t data_blocks{};
102101

103-
CacheDisk *const disk{};
104-
uint32_t sector_size{};
102+
uint32_t sector_size{};
105103

106104
CacheVol *cache_vol{};
107105

@@ -172,12 +170,12 @@ class Stripe
172170
protected:
173171
AggregateWriteBuffer _write_buffer;
174172

175-
void _clear_init();
173+
void _clear_init(std::uint32_t hw_sector_size);
176174
void _init_dir();
177-
bool flush_aggregate_write_buffer();
175+
bool flush_aggregate_write_buffer(int fd);
178176

179177
private:
180-
void _init_hash_text(char const *seed, off_t blocks, off_t dir_skip);
178+
void _init_hash_text(CacheDisk const *disk, off_t blocks, off_t dir_skip);
181179
void _init_data(off_t store_block_size, int avg_obj_size = -1);
182180
void _init_data_internal(int avg_obj_size = -1); // Defaults to cache_config_min_average_object_size;
183181
void _init_directory(std::size_t directory_size, int header_size, int footer_size);

src/iocore/cache/StripeSM.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ struct StripeInitInfo {
115115
StripeSM::StripeSM(CacheDisk *disk, off_t blocks, off_t dir_skip, int avg_obj_size, int fragment_size)
116116
: Continuation(new_ProxyMutex()),
117117
Stripe{disk, blocks, dir_skip, avg_obj_size, fragment_size},
118+
fd{disk->fd},
119+
disk{disk},
118120
_preserved_dirs{static_cast<int>(len)}
119121
{
120122
open_dir.mutex = this->mutex;
@@ -152,7 +154,7 @@ int
152154
StripeSM::clear_dir()
153155
{
154156
size_t dir_len = this->dirlen();
155-
this->_clear_init();
157+
this->_clear_init(this->disk->hw_sector_size);
156158

157159
if (pwrite(this->fd, this->raw_dir, dir_len, this->skip) < 0) {
158160
Warning("unable to clear cache directory '%s'", this->hash_text.get());
@@ -272,7 +274,7 @@ int
272274
StripeSM::clear_dir_aio()
273275
{
274276
size_t dir_len = this->dirlen();
275-
this->_clear_init();
277+
this->_clear_init(this->disk->hw_sector_size);
276278

277279
SET_HANDLER(&StripeSM::handle_dir_clear);
278280

@@ -1339,7 +1341,7 @@ StripeSM::shutdown(EThread *shutdown_thread)
13391341
// directories have not been inserted for these writes
13401342
if (!this->_write_buffer.is_empty()) {
13411343
Dbg(dbg_ctl_cache_dir_sync, "Dir %s: flushing agg buffer first", this->hash_text.get());
1342-
this->flush_aggregate_write_buffer();
1344+
this->flush_aggregate_write_buffer(this->fd);
13431345
}
13441346

13451347
// We already asserted that dirlen > 0.

src/iocore/cache/StripeSM.h

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class StripeSM : public Continuation, public Stripe
6666
{
6767
public:
6868
CryptoHash hash_id;
69+
int fd{-1};
6970

7071
int hit_evacuate_window{};
7172

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

7879
Event *trigger = nullptr;
7980

81+
CacheDisk *disk{};
82+
8083
OpenDir open_dir;
8184
RamCache *ram_cache = nullptr;
8285
DLL<EvacuationBlock> lookaside[LOOKASIDE_SIZE];

0 commit comments

Comments
 (0)