Skip to content

Commit

Permalink
Working around flush issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Sep 6, 2023
1 parent 6041adf commit 51f7972
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
7 changes: 6 additions & 1 deletion nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ nano::election_insertion_result nano::active_transactions::insert (const std::sh
std::function<nano::election_insertion_result (std::shared_ptr<nano::block> const & block, nano::election_behavior behavior)> nano::active_transactions::insert_fn ()
{
return [this] (std::shared_ptr<nano::block> const & block, nano::election_behavior behavior) {
return insert (block, behavior);
auto result = insert (block, behavior);
return result;
};
}

Expand Down Expand Up @@ -449,6 +450,10 @@ nano::election_insertion_result nano::active_transactions::insert_impl (nano::un
}
trim ();
}
if (result.election == nullptr)
{
std::cerr << '\0';
}
return result;
}

Expand Down
12 changes: 11 additions & 1 deletion nano/node/scheduler/buckets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ nano::scheduler::buckets::bucket::bucket (std::shared_ptr<nano::scheduler::limit
{
}

bool nano::scheduler::buckets::bucket::available () const
{
return limiter->available () && !queue.empty ();
}

bool nano::scheduler::buckets::value_type::operator< (value_type const & other_a) const
{
return time < other_a.time || (time == other_a.time && block->hash () < other_a.block->hash ());
Expand All @@ -35,7 +40,7 @@ void nano::scheduler::buckets::next ()
void nano::scheduler::buckets::seek ()
{
next ();
for (std::size_t i = 0, n = schedule.size (); buckets_m[*current].queue.empty () && i < n; ++i)
for (std::size_t i = 0, n = schedule.size (); !buckets_m[*current].available () && i < n; ++i)
{
next ();
}
Expand Down Expand Up @@ -160,6 +165,11 @@ bool nano::scheduler::buckets::empty () const
return std::all_of (buckets_m.begin (), buckets_m.end (), [] (auto const & bucket_a) { return bucket_a.queue.empty (); });
}

bool nano::scheduler::buckets::any_available () const
{
return std::any_of (buckets_m.begin (), buckets_m.end (), [] (auto const & bucket_a) { return bucket_a.available (); });
}

/** Print the state of the class in stderr */
void nano::scheduler::buckets::dump () const
{
Expand Down
4 changes: 3 additions & 1 deletion nano/node/scheduler/buckets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class buckets final
{
public:
bucket (std::shared_ptr<nano::scheduler::limiter> const & limiter);
bool available () const;
std::set<value_type> queue;
std::shared_ptr<nano::scheduler::limiter> limiter;
};
Expand All @@ -62,7 +63,6 @@ class buckets final
uint64_t const maximum;

void next ();
void seek ();
void populate_schedule ();

public:
Expand All @@ -73,10 +73,12 @@ class buckets final
void push (uint64_t time, std::shared_ptr<nano::block> block, nano::amount const & priority);
std::pair<std::shared_ptr<nano::block>, std::shared_ptr<nano::scheduler::limiter>> top () const;
void pop ();
void seek ();
std::size_t size () const;
std::size_t bucket_count () const;
std::size_t bucket_size (std::size_t index) const;
bool empty () const;
bool any_available () const;
void dump () const;
std::size_t index (nano::uint128_t const & balance) const;

Expand Down
20 changes: 14 additions & 6 deletions nano/node/scheduler/priority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ std::size_t nano::scheduler::priority::priority_queue_size () const

bool nano::scheduler::priority::priority_queue_predicate () const
{
return node.active.vacancy () > 0 && !buckets.empty ();
return node.active.vacancy () > 0 && buckets.any_available ();
}

bool nano::scheduler::priority::manual_queue_predicate () const
Expand All @@ -124,19 +124,26 @@ void nano::scheduler::priority::run ()
if (manual_queue_predicate ())
{
auto const [block, previous_balance, election_behavior] = manual_queue.front ();
manual_queue.pop_front ();
lock.unlock ();
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_manual);
auto result = node.active.insert (block, election_behavior);
if (result.election != nullptr)
if (result.election)
{
result.election->transition_active ();
manual_queue.pop_front ();
}
else
{
std::cerr << '\0';
}
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_manual);
}
else if (priority_queue_predicate ())
{
if (!buckets.top ().second->available ());
{
buckets.seek ();
}
auto [block, limiter] = buckets.top ();
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority);
debug_assert (limiter->available ());
auto result = limiter->activate (block);
if (result.election != nullptr)
{
Expand All @@ -152,6 +159,7 @@ void nano::scheduler::priority::run ()
{
lock.unlock ();
}
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority);
}
else
{
Expand Down

0 comments on commit 51f7972

Please sign in to comment.