Skip to content

Commit

Permalink
producer_state_manager: make period configurable for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bharathv committed Dec 9, 2024
1 parent 247c698 commit 48371f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/v/cluster/producer_state_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ producer_state_manager::producer_state_manager(

ss::future<> producer_state_manager::start() {
_reaper.set_callback([this] { evict_excess_producers(); });
_reaper.arm(period);
_reaper.arm(_reaper_period);
vlog(clusterlog.info, "Started producer state manager");
return ss::now();
}
Expand Down Expand Up @@ -69,6 +69,12 @@ void producer_state_manager::setup_metrics() {
sm::description("Number of evicted producers so far."))});
}

void producer_state_manager::rearm_eviction_timer_for_testing(
std::chrono::milliseconds new_period) {
_reaper_period = new_period;
_reaper.rearm(ss::lowres_clock::now() + _reaper_period);
}

void producer_state_manager::register_producer(
producer_state& state, std::optional<model::vcluster_id> vcluster) {
vlog(
Expand Down Expand Up @@ -97,7 +103,7 @@ void producer_state_manager::evict_excess_producers() {
_cache.evict_older_than<ss::lowres_system_clock>(
ss::lowres_system_clock::now() - _producer_expiration_ms());
if (!_gate.is_closed()) {
_reaper.arm(period);
_reaper.arm(_reaper_period);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/v/cluster/producer_state_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ class producer_state_manager {
*/
void touch(producer_state&, std::optional<model::vcluster_id>);

void rearm_eviction_timer_for_testing(std::chrono::milliseconds);

private:
static constexpr std::chrono::seconds period{5};
std::chrono::milliseconds _reaper_period{5000};
/**
* Constant to be used when a partition has no vcluster_id assigned.
*/
Expand Down Expand Up @@ -83,7 +85,7 @@ class producer_state_manager {
config::binding<size_t> _virtual_cluster_min_producer_ids;
// cache of all producers on this shard
cache_t _cache;
ss::timer<ss::steady_clock_type> _reaper;
ss::timer<ss::lowres_clock> _reaper;
ss::gate _gate;
metrics::internal_metric_groups _metrics;

Expand Down

0 comments on commit 48371f4

Please sign in to comment.