Skip to content

Commit 406c72a

Browse files
committed
Address pr comments on stats
1 parent 451d954 commit 406c72a

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

file/file_prefetch_buffer.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ bool FilePrefetchBuffer::TryReadFromCacheUntracked(
772772
const IOOptions& opts, RandomAccessFileReader* reader, uint64_t offset,
773773
size_t n, Slice* result, Status* status, bool for_compaction) {
774774
// We disallow async IO for compaction reads since they are performed in
775-
// the background anyways and are less latency sensitive compareed to
775+
// the background anyways and are less latency sensitive compared to
776776
// user-initiated reads
777777
(void)for_compaction;
778778
assert(!for_compaction || num_buffers_ == 1);
@@ -854,7 +854,8 @@ bool FilePrefetchBuffer::TryReadFromCacheUntracked(
854854
} else {
855855
return false;
856856
}
857-
} else {
857+
} else if (!for_compaction) {
858+
// These stats are meant to track prefetch effectiveness for user reads only
858859
UpdateStats(/*found_in_buffer=*/true, n);
859860
}
860861

file/prefetch_test.cc

+16-10
Original file line numberDiff line numberDiff line change
@@ -3539,9 +3539,11 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchStatsInternals) {
35393539
ASSERT_TRUE(fpb.TryReadFromCache(IOOptions(), r.get(), 8192 /* offset */,
35403540
8192 /* n */, &result, &s, for_compaction));
35413541
ASSERT_EQ(s, Status::OK());
3542-
ASSERT_EQ(stats->getAndResetTickerCount(PREFETCH_HITS), 0);
3543-
ASSERT_EQ(stats->getAndResetTickerCount(PREFETCH_BYTES_USEFUL),
3544-
4096); // 8192-12288
3542+
if (!for_compaction) {
3543+
ASSERT_EQ(stats->getAndResetTickerCount(PREFETCH_HITS), 0);
3544+
ASSERT_EQ(stats->getAndResetTickerCount(PREFETCH_BYTES_USEFUL),
3545+
4096); // 8192-12288
3546+
}
35453547

35463548
ASSERT_EQ(strncmp(result.data(), content.substr(8192, 8192).c_str(), 8192),
35473549
0);
@@ -3577,9 +3579,11 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchStatsInternals) {
35773579
4096 /* n */, &result, &s, for_compaction));
35783580
ASSERT_EQ(s, Status::OK());
35793581

3580-
ASSERT_EQ(stats->getAndResetTickerCount(PREFETCH_HITS), 1);
3581-
ASSERT_EQ(stats->getAndResetTickerCount(PREFETCH_BYTES_USEFUL),
3582-
4096); // 12288-16384
3582+
if (!for_compaction) {
3583+
ASSERT_EQ(stats->getAndResetTickerCount(PREFETCH_HITS), 1);
3584+
ASSERT_EQ(stats->getAndResetTickerCount(PREFETCH_BYTES_USEFUL),
3585+
4096); // 12288-16384
3586+
}
35833587

35843588
ASSERT_EQ(strncmp(result.data(), content.substr(12288, 4096).c_str(), 4096),
35853589
0);
@@ -3611,10 +3615,12 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchStatsInternals) {
36113615
10000 /* n */, &result, &s, for_compaction));
36123616
ASSERT_EQ(s, Status::OK());
36133617

3614-
ASSERT_EQ(stats->getAndResetTickerCount(PREFETCH_HITS), 0);
3615-
ASSERT_EQ(
3616-
stats->getAndResetTickerCount(PREFETCH_BYTES_USEFUL),
3617-
/* 24576(end offset of the buffer) - 16000(requested offset) =*/8576);
3618+
if (!for_compaction) {
3619+
ASSERT_EQ(stats->getAndResetTickerCount(PREFETCH_HITS), 0);
3620+
ASSERT_EQ(
3621+
stats->getAndResetTickerCount(PREFETCH_BYTES_USEFUL),
3622+
/* 24576(end offset of the buffer) - 16000(requested offset) =*/8576);
3623+
}
36183624

36193625
ASSERT_EQ(strncmp(result.data(), content.substr(16000, 10000).c_str(), 10000),
36203626
0);

0 commit comments

Comments
 (0)