Add Timeout::get_timeout.

This commit is contained in:
levlam 2021-08-15 11:15:14 +03:00
parent 99375ff157
commit 5349e63c2b
7 changed files with 24 additions and 0 deletions

View File

@ -35,6 +35,9 @@ class Timeout final : public Actor {
bool has_timeout() const { bool has_timeout() const {
return Actor::has_timeout(); return Actor::has_timeout();
} }
double get_timeout() const {
return Actor::get_timeout();
}
void set_timeout_in(double timeout) { void set_timeout_in(double timeout) {
Actor::set_timeout_in(timeout); Actor::set_timeout_in(timeout);
} }

View File

@ -67,6 +67,7 @@ class Actor : public ObserverBase {
void stop(); void stop();
void do_stop(); void do_stop();
bool has_timeout() const; bool has_timeout() const;
double get_timeout() const;
void set_timeout_in(double timeout_in); void set_timeout_in(double timeout_in);
void set_timeout_at(double timeout_at); void set_timeout_at(double timeout_at);
void cancel_timeout(); void cancel_timeout();

View File

@ -54,6 +54,9 @@ inline void Actor::do_stop() {
inline bool Actor::has_timeout() const { inline bool Actor::has_timeout() const {
return Scheduler::instance()->has_actor_timeout(this); return Scheduler::instance()->has_actor_timeout(this);
} }
inline double Actor::get_timeout() const {
return Scheduler::instance()->get_actor_timeout(this);
}
inline void Actor::set_timeout_in(double timeout_in) { inline void Actor::set_timeout_in(double timeout_in) {
Scheduler::instance()->set_actor_timeout_in(this, timeout_in); Scheduler::instance()->set_actor_timeout_in(this, timeout_in);
} }

View File

@ -126,6 +126,7 @@ class Scheduler {
void finish_migrate_actor(Actor *actor); void finish_migrate_actor(Actor *actor);
bool has_actor_timeout(const Actor *actor) const; bool has_actor_timeout(const Actor *actor) const;
double get_actor_timeout(const Actor *actor) const;
void set_actor_timeout_in(Actor *actor, double timeout); void set_actor_timeout_in(Actor *actor, double timeout);
void set_actor_timeout_at(Actor *actor, double timeout_at); void set_actor_timeout_at(Actor *actor, double timeout_at);
void cancel_actor_timeout(Actor *actor); void cancel_actor_timeout(Actor *actor);
@ -176,6 +177,7 @@ class Scheduler {
void start_migrate_actor(ActorInfo *actor_info, int32 dest_sched_id); void start_migrate_actor(ActorInfo *actor_info, int32 dest_sched_id);
bool has_actor_timeout(const ActorInfo *actor_info) const; bool has_actor_timeout(const ActorInfo *actor_info) const;
double get_actor_timeout(const ActorInfo *actor_info) const;
void set_actor_timeout_in(ActorInfo *actor_info, double timeout); void set_actor_timeout_in(ActorInfo *actor_info, double timeout);
void set_actor_timeout_at(ActorInfo *actor_info, double timeout_at); void set_actor_timeout_at(ActorInfo *actor_info, double timeout_at);
void cancel_actor_timeout(ActorInfo *actor_info); void cancel_actor_timeout(ActorInfo *actor_info);

View File

@ -392,6 +392,7 @@ void Scheduler::do_migrate_actor(ActorInfo *actor_info, int32 dest_sched_id) {
void Scheduler::start_migrate_actor(Actor *actor, int32 dest_sched_id) { void Scheduler::start_migrate_actor(Actor *actor, int32 dest_sched_id) {
start_migrate_actor(actor->get_info(), dest_sched_id); start_migrate_actor(actor->get_info(), dest_sched_id);
} }
void Scheduler::start_migrate_actor(ActorInfo *actor_info, int32 dest_sched_id) { void Scheduler::start_migrate_actor(ActorInfo *actor_info, int32 dest_sched_id) {
VLOG(actor) << "Start migrate actor: " << tag("name", actor_info) << tag("ptr", actor_info) VLOG(actor) << "Start migrate actor: " << tag("name", actor_info) << tag("ptr", actor_info)
<< tag("actor_count", actor_count_); << tag("actor_count", actor_count_);
@ -406,6 +407,11 @@ void Scheduler::start_migrate_actor(ActorInfo *actor_info, int32 dest_sched_id)
cancel_actor_timeout(actor_info); cancel_actor_timeout(actor_info);
} }
double Scheduler::get_actor_timeout(const ActorInfo *actor_info) const {
const HeapNode *heap_node = actor_info->get_heap_node();
return heap_node->in_heap() ? timeout_queue_.get_key(heap_node) - Time::now() : 0.0;
}
void Scheduler::set_actor_timeout_in(ActorInfo *actor_info, double timeout) { void Scheduler::set_actor_timeout_in(ActorInfo *actor_info, double timeout) {
if (timeout > 1e10) { if (timeout > 1e10) {
timeout = 1e10; timeout = 1e10;

View File

@ -302,6 +302,9 @@ inline void Scheduler::finish_migrate_actor(Actor *actor) {
inline bool Scheduler::has_actor_timeout(const Actor *actor) const { inline bool Scheduler::has_actor_timeout(const Actor *actor) const {
return has_actor_timeout(actor->get_info()); return has_actor_timeout(actor->get_info());
} }
inline double Scheduler::get_actor_timeout(const Actor *actor) const {
return get_actor_timeout(actor->get_info());
}
inline void Scheduler::set_actor_timeout_in(Actor *actor, double timeout) { inline void Scheduler::set_actor_timeout_in(Actor *actor, double timeout) {
set_actor_timeout_in(actor->get_info(), timeout); set_actor_timeout_in(actor->get_info(), timeout);
} }

View File

@ -37,6 +37,12 @@ class KHeap {
return array_[0].key_; return array_[0].key_;
} }
KeyT get_key(const HeapNode *node) const {
size_t pos = static_cast<size_t>(node->pos_);
CHECK(pos < array_.size());
return array_[pos].key_;
}
const HeapNode *top() const { const HeapNode *top() const {
return array_[0].node_; return array_[0].node_;
} }