Skip to content

Commit

Permalink
Address nit comments
Browse files Browse the repository at this point in the history
  • Loading branch information
archang19 committed Dec 27, 2024
1 parent 8a386c6 commit dc8bb5d
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions file/prefetch_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3475,14 +3475,15 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchStatsInternals) {
bool use_async_prefetch = std::get<0>(GetParam());
bool for_compaction = std::get<1>(GetParam());
// We disallow async IO for compaction reads since they are background
// operations anyways and their latencies are not visible to the end user
// operations anyways and not as latency sensitive as user-initiated reads
if (use_async_prefetch && for_compaction) {
return;
}
size_t num_buffers = use_async_prefetch ? 2 : 1;
readahead_params.num_buffers = num_buffers;

FilePrefetchBuffer fpb(readahead_params, true, false, fs(), clock(),
FilePrefetchBuffer fpb(readahead_params, true /* enable */,
false /* track_min_offset */, fs(), clock(),
stats.get());

int overlap_buffer_write_ct = 0;
Expand All @@ -3496,8 +3497,9 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchStatsInternals) {
Status s;
std::vector<std::tuple<uint64_t, size_t, bool>> buffer_info(num_buffers);
std::pair<uint64_t, size_t> overlap_buffer_info;
bool could_read_from_cache = fpb.TryReadFromCache(
IOOptions(), r.get(), 0, 4096, &result, &s, for_compaction);
bool could_read_from_cache =
fpb.TryReadFromCache(IOOptions(), r.get(), 0 /* offset */, 4096 /* n */,
&result, &s, for_compaction);
// Platforms that don't have IO uring may not support async IO.
if (use_async_prefetch && s.IsNotSupported()) {
return;
Expand Down Expand Up @@ -3533,8 +3535,8 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchStatsInternals) {

// Simulate a block cache hit
fpb.UpdateReadPattern(4096, 4096, false);
ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 8192, 8192, &result,
&s, for_compaction));
ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 8192 /* offset */,
8192 /* n */, &result, &s, for_compaction));
ASSERT_EQ(s, Status::OK());
ASSERT_EQ(stats->getAndResetTickerCount(PREFETCH_HITS), 0);
ASSERT_EQ(stats->getAndResetTickerCount(PREFETCH_BYTES_USEFUL),
Expand Down Expand Up @@ -3570,8 +3572,8 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchStatsInternals) {
ASSERT_EQ(std::get<1>(buffer_info[0]), 12288);
}

ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 12288, 4096, &result,
&s, for_compaction));
ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 12288 /* offset */,
4096 /* n */, &result, &s, for_compaction));
ASSERT_EQ(s, Status::OK());

ASSERT_EQ(stats->getAndResetTickerCount(PREFETCH_HITS), 1);
Expand Down Expand Up @@ -3604,8 +3606,8 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchStatsInternals) {
}

// Read from 16000-26000 (start and end do not meet normal alignment)
ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 16000, 10000, &result,
&s, for_compaction));
ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 16000 /* offset */,
10000 /* n */, &result, &s, for_compaction));
ASSERT_EQ(s, Status::OK());

ASSERT_EQ(stats->getAndResetTickerCount(PREFETCH_HITS), 0);
Expand Down Expand Up @@ -3670,7 +3672,8 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchUnalignedReads) {
}
size_t num_buffers = use_async_prefetch ? 2 : 1;
readahead_params.num_buffers = num_buffers;
FilePrefetchBuffer fpb(readahead_params, true, false, fs(), clock(),
FilePrefetchBuffer fpb(readahead_params, true /* enable */,
false /* track_min_offset */, fs(), clock(),
stats.get());

int overlap_buffer_write_ct = 0;
Expand All @@ -3684,8 +3687,9 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchUnalignedReads) {
Status s;
std::vector<std::tuple<uint64_t, size_t, bool>> buffer_info(num_buffers);
std::pair<uint64_t, size_t> overlap_buffer_info;
bool could_read_from_cache = fpb.TryReadFromCache(
IOOptions(), r.get(), 5, 3, &result, &s, for_compaction);
bool could_read_from_cache =
fpb.TryReadFromCache(IOOptions(), r.get(), 5 /* offset */, 3 /* n */,
&result, &s, for_compaction);
// Platforms that don't have IO uring may not support async IO.
if (use_async_prefetch && s.IsNotSupported()) {
return;
Expand Down Expand Up @@ -3717,8 +3721,8 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchUnalignedReads) {
ASSERT_EQ(std::get<1>(buffer_info[0]), 3 + 5);
}

ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 16, 7, &result, &s,
for_compaction));
ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 16 /* offset */,
7 /* n */, &result, &s, for_compaction));
ASSERT_EQ(s, Status::OK());
ASSERT_EQ(strncmp(result.data(), content.substr(16, 7).c_str(), 7), 0);
fpb.TEST_GetOverlapBufferOffsetandSize(overlap_buffer_info);
Expand All @@ -3742,18 +3746,18 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchUnalignedReads) {

// Go backwards
if (use_async_prefetch) {
ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 10, 8, &result, &s,
for_compaction));
ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 10 /* offset */,
8 /* n */, &result, &s, for_compaction));
} else {
// TryReadFromCacheUntracked returns false since the offset
// requested is less than the start of our buffer
ASSERT_FALSE(fpb.TryReadFromCache(IOOptions(), r.get(), 10, 8, &result, &s,
for_compaction));
ASSERT_FALSE(fpb.TryReadFromCache(IOOptions(), r.get(), 10 /* offset */,
8 /* n */, &result, &s, for_compaction));
}
ASSERT_EQ(s, Status::OK());

ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 27, 6, &result, &s,
for_compaction));
ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 27 /* offset */,
6 /* n */, &result, &s, for_compaction));
ASSERT_EQ(s, Status::OK());
ASSERT_EQ(strncmp(result.data(), content.substr(27, 6).c_str(), 6), 0);
fpb.TEST_GetOverlapBufferOffsetandSize(overlap_buffer_info);
Expand All @@ -3774,8 +3778,8 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchUnalignedReads) {
ASSERT_EQ(std::get<1>(buffer_info[0]), 7 + 10);
}

ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 30, 20, &result, &s,
for_compaction));
ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 30 /* offset */,
20 /* n */, &result, &s, for_compaction));
ASSERT_EQ(s, Status::OK());
ASSERT_EQ(strncmp(result.data(), content.substr(30, 20).c_str(), 20), 0);
fpb.TEST_GetOverlapBufferOffsetandSize(overlap_buffer_info);
Expand Down Expand Up @@ -3823,7 +3827,8 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchRandomized) {
size_t num_buffers = use_async_prefetch ? 2 : 1;
readahead_params.num_buffers = num_buffers;

FilePrefetchBuffer fpb(readahead_params, true, false, fs(), clock(),
FilePrefetchBuffer fpb(readahead_params, true /* enable */,
false /* track_min_offset */, fs(), clock(),
stats.get());

Slice result;
Expand Down

0 comments on commit dc8bb5d

Please sign in to comment.