Skip to content

Commit

Permalink
Add source to MultiTimeout::update_timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Mar 8, 2023
1 parent 17540f1 commit 1bf2d63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions tdactor/td/actor/MultiTimeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ void MultiTimeout::set_timeout_at(int64 key, double timeout) {
bool need_update_timeout = heap_node->is_top();
timeout_queue_.fix(timeout, heap_node);
if (need_update_timeout || heap_node->is_top()) {
update_timeout();
update_timeout("set_timeout");
}
} else {
CHECK(item.second);
timeout_queue_.insert(timeout, heap_node);
if (heap_node->is_top()) {
update_timeout();
update_timeout("set_timeout 2");
}
}
}
Expand All @@ -44,7 +44,7 @@ void MultiTimeout::add_timeout_at(int64 key, double timeout) {
CHECK(item.second);
timeout_queue_.insert(timeout, heap_node);
if (heap_node->is_top()) {
update_timeout();
update_timeout("add_timeout");
}
}
}
Expand All @@ -60,16 +60,16 @@ void MultiTimeout::cancel_timeout(int64 key) {
items_.erase(item);

if (need_update_timeout) {
update_timeout();
update_timeout("cancel_timeout");
}
}
}

void MultiTimeout::update_timeout() {
void MultiTimeout::update_timeout(const char *source) {
if (items_.empty()) {
LOG(DEBUG) << "Cancel timeout of " << get_name();
LOG_CHECK(timeout_queue_.empty()) << get_name();
LOG_CHECK(Actor::has_timeout()) << get_name();
LOG_CHECK(timeout_queue_.empty()) << get_name() << ' ' << source;
LOG_CHECK(Actor::has_timeout()) << get_name() << ' ' << source;
Actor::cancel_timeout();
} else {
LOG(DEBUG) << "Set timeout of " << get_name() << " in " << timeout_queue_.top_key() - Time::now_cached();
Expand All @@ -90,7 +90,7 @@ vector<int64> MultiTimeout::get_expired_keys(double now) {
void MultiTimeout::timeout_expired() {
vector<int64> expired_keys = get_expired_keys(Time::now_cached());
if (!items_.empty()) {
update_timeout();
update_timeout("timeout_expired");
}
for (auto key : expired_keys) {
callback_(data_, key);
Expand All @@ -100,7 +100,7 @@ void MultiTimeout::timeout_expired() {
void MultiTimeout::run_all() {
vector<int64> expired_keys = get_expired_keys(Time::now_cached() + 1e10);
if (!expired_keys.empty()) {
update_timeout();
update_timeout("run_all");
}
for (auto key : expired_keys) {
callback_(data_, key);
Expand Down
2 changes: 1 addition & 1 deletion tdactor/td/actor/MultiTimeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class MultiTimeout final : public Actor {
KHeap<double> timeout_queue_;
std::set<Item> items_;

void update_timeout();
void update_timeout(const char *source);

void timeout_expired() final;

Expand Down

0 comments on commit 1bf2d63

Please sign in to comment.