Skip to content

Commit f604d32

Browse files
committed
bm_sim: fix spurious duplicate ageing notifications across sweeps
Signed-off-by: Devansh-567 <devansh.jay.singh@gmail.com>
1 parent 693e69e commit f604d32

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

src/bm_sim/ageing.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,14 @@ AgeingMonitor::do_sweep() {
174174
entries.push_back(handle);
175175
}
176176
}
177-
entries_tmp.clear();
177+
// Save the full set of aged entries seen in this sweep so already-reported
178+
// entries aren't re-notified as new on subsequent sweeps.
178179
prev_sweep_entries.clear();
180+
prev_sweep_entries.insert(entries_tmp.begin(), entries_tmp.end());
181+
entries_tmp.clear();
179182

180183
if (entries.empty()) continue;
181184

182-
for (entry_handle_t handle : entries) {
183-
prev_sweep_entries.insert(handle);
184-
}
185-
186185
BMLOG_TRACE("Sending ageing notification for table '{}' ({})",
187186
t->get_name(), entry.first);
188187

tests/test_ageing.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,13 @@ TEST_F(AgeingTest, NoDuplicate) {
177177
ASSERT_GT(elapsed, sweep_int - 20u);
178178
ASSERT_LT(elapsed, 2 * sweep_int + 20u);
179179

180-
auto tp3 = clock::now();
181-
ageing_writer->read(buffer, sizeof(buffer));
182-
auto tp4 = clock::now();
183-
184-
// we make sure that the next sweep does not generate a message
185-
186-
elapsed = duration_cast<milliseconds>(tp4 - tp3).count();
187-
ASSERT_GT(elapsed, (unsigned int) (sweep_int * 1.5));
180+
// Poll non-blocking over multiple sweep intervals to verify no duplicate
181+
// notifications are produced for untreated aged entries.
182+
auto deadline = clock::now() + milliseconds(4 * sweep_int);
183+
while (clock::now() < deadline) {
184+
ASSERT_NE(MemoryAccessor::Status::CAN_READ, ageing_writer->check_status());
185+
sleep_for(milliseconds(10));
186+
}
188187
}
189188

190189
TEST_F(AgeingTest, GetTableNameFromId) {

0 commit comments

Comments
 (0)