-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor: Introduce EvictionManager and use it for the inbound eviction logic #25572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK.
Added a high-level question about NodeEvictionCandidate
to kick things off, will continue with review.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
return ::SelectNodeToEvict(std::move(candidates)); | ||
} | ||
|
||
void EvictionManagerImpl::UpdateMinPingTime(NodeId id, std::chrono::microseconds ping_time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/me idly wonders whether these setters can be templated to avoid repetitive boilerplate code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to come up with a cool way of doing this with templates but didn't end with anything useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think something like this would work:
class EvictionManagerImpl
{
...
template <typename Fn>
auto CandidateOp(NodeId id, Fn&& fn)
{
LOCK(m_candidates_mutex);
auto it = m_candidates.find(offset);
if (it != m_candidates.end()) {
return fn(it->second);
} else {
// return a dummy value of the right type, including void
return ([]() -> decltype(fn(it->second)) { return {}; })();
// EDIT: maybe nicer to write:
using T = decltype(fn(it->second));
return T();
}
}
...
};
void EvictionManager::UpdateLastBlockTime(NodeId id, std::chrono::seconds block_time)
{
m_impl->CandidateOp(id, [](NodeEvictionCandidate& nec) {
nec.m_last_block_time = block_time;
});
}
void EvictionManager::GetLastBlockTime(NodeId id) const
{
return m_impl->CandidateOp(id, [](const NodeEvictionCandidate& nec) {
return nec.m_last_block_time;
});
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big concept ACK!
Minor cosmetic comments inline.
2f93a9f
to
c53efed
Compare
c53efed
to
ebdb034
Compare
Rebased. |
ebdb034
to
4f8be70
Compare
Needs rebase if still relevant |
ac60275
to
108e7a0
Compare
108e7a0
to
a7a5b4e
Compare
We temporarily introduce a method to get a specific NodeEvictionCandidate from the eviction manager for use in `CConnman::AttemptToEvictConnection()`. `EvictionManager::GetCandidate` is removed once we are done moving the remaining eviction state from `CNode` to the eviction manager.
Now that the eviction manager is aware of the keyed net group and whether or not a peer is prefered for eviction, we can get rid of the corresponding CNode members, since they are not used elsewhere.
a7a5b4e
to
2977ca3
Compare
🐙 This pull request conflicts with the target branch and needs rebase. |
This PR splits off the next couple commits from #25268 that introduce the
EvictionManager
and use it for the inbound eviction logic.One instance of the
EvictionManager
is created at start up and passed as a reference to the connection and peer managers. The connection and peer managers report all eviction relevant information (for inbound connections) to the eviction manager who ultimately suggests nodes to evict as the result ofEvictionManager::SelectNodeToEvict
.