From 369afe3124d5fc652e73e3d8ba9bcb7e04e5bca4 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Thu, 23 Sep 2021 12:32:36 +0300 Subject: [PATCH] treewide: use coroutine::maybe_yield() instead of co_await make_ready_future() The dedicated API shows the intent, and may be a tiny bit faster. Closes #9382 --- db/system_distributed_keyspace.cc | 7 ++++--- db/view/view.cc | 7 ++++--- locator/token_metadata.cc | 5 +++-- reader_concurrency_semaphore.cc | 3 ++- service/raft/raft_sys_table_storage.cc | 5 +++-- sstables/partition_index_cache.hh | 3 ++- sstables/sstables.cc | 5 +++-- table.cc | 3 ++- test/raft/randomized_nemesis_test.cc | 3 ++- utils/cached_file.hh | 3 ++- utils/logalloc.cc | 3 ++- 11 files changed, 29 insertions(+), 18 deletions(-) diff --git a/db/system_distributed_keyspace.cc b/db/system_distributed_keyspace.cc index 6dc7172a5b..229115b396 100644 --- a/db/system_distributed_keyspace.cc +++ b/db/system_distributed_keyspace.cc @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -480,7 +481,7 @@ static future> get_cdc_generation_mutations( res.back().set_cell(ckey, to_bytes("streams"), make_set_value(cdc_streams_set_type, std::move(streams)), ts); res.back().set_cell(ckey, to_bytes("ignore_msb"), int8_t(e.sharding_ignore_msb), ts); - co_await make_ready_future<>(); // maybe yield + co_await coroutine::maybe_yield(); } co_return res; @@ -577,7 +578,7 @@ static future> get_cdc_streams_descriptions_v2_mutation( res.back().set_cell(clustering_key::from_singular(*s, dht::token::to_int64(e.token_range_end)), to_bytes("streams"), make_set_value(cdc_streams_set_type, std::move(streams)), ts); - co_await make_ready_future<>(); // maybe yield + co_await coroutine::maybe_yield(); } co_return res; @@ -694,7 +695,7 @@ system_distributed_keyspace::cdc_get_versioned_streams(db_clock::time_point not_ utils::chunked_vector ids; for (auto& row : *streams_cql) { row.get_list_data("streams", std::back_inserter(ids)); - co_await make_ready_future<>(); // maybe yield + co_await coroutine::maybe_yield(); } result.emplace(ts, cdc::streams_version{std::move(ids), ts}); diff --git a/db/view/view.cc b/db/view/view.cc index c38ecc711f..6426212ae2 100644 --- a/db/view/view.cc +++ b/db/view/view.cc @@ -55,6 +55,7 @@ #include #include +#include #include "database.hh" #include "clustering_bounds_comparator.hh" @@ -1138,7 +1139,7 @@ future calculate_affected_clustering_ranges(const } for (auto&& r : v.view->view_info()->partition_slice().default_row_ranges()) { view_row_ranges.push_back(r.transform(std::mem_fn(&clustering_key_prefix::view))); - co_await make_ready_future<>(); // yield if needed + co_await coroutine::maybe_yield(); } } } @@ -1155,7 +1156,7 @@ future calculate_affected_clustering_ranges(const if (overlap) { row_ranges.push_back(std::move(overlap).value()); } - co_await make_ready_future<>(); // yield if needed + co_await coroutine::maybe_yield(); } } } @@ -1164,7 +1165,7 @@ future calculate_affected_clustering_ranges(const if (update_requires_read_before_write(base, views, key, row)) { row_ranges.emplace_back(row.key()); } - co_await make_ready_future<>(); // yield if needed + co_await coroutine::maybe_yield(); } // Note that the views could have restrictions on regular columns, diff --git a/locator/token_metadata.cc b/locator/token_metadata.cc index e0b0270d85..d4053245a9 100644 --- a/locator/token_metadata.cc +++ b/locator/token_metadata.cc @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "utils/stall_free.hh" @@ -481,7 +482,7 @@ future<> token_metadata_impl::update_normal_tokens(const std::unordered_map(); // maybe yield + co_await coroutine::maybe_yield(); if(it->second == endpoint) { it = _token_to_endpoint_map.erase(it); } else { @@ -495,7 +496,7 @@ future<> token_metadata_impl::update_normal_tokens(const std::unordered_map(); // maybe yield + co_await coroutine::maybe_yield(); auto prev = _token_to_endpoint_map.insert(std::pair(t, endpoint)); should_sort_tokens |= prev.second; // new token inserted -> sort if (prev.first->second != endpoint) { diff --git a/reader_concurrency_semaphore.cc b/reader_concurrency_semaphore.cc index 50ae2dd0af..c6534e89bd 100644 --- a/reader_concurrency_semaphore.cc +++ b/reader_concurrency_semaphore.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include "reader_concurrency_semaphore.hh" #include "utils/exceptions.hh" @@ -618,7 +619,7 @@ future<> reader_concurrency_semaphore::execution_loop() noexcept { } if (need_preempt()) { - co_await make_ready_future<>(); + co_await coroutine::maybe_yield(); } } } diff --git a/service/raft/raft_sys_table_storage.cc b/service/raft/raft_sys_table_storage.cc index 12f1bbdcd7..647836c5f4 100644 --- a/service/raft/raft_sys_table_storage.cc +++ b/service/raft/raft_sys_table_storage.cc @@ -37,6 +37,7 @@ #include #include +#include namespace service { @@ -97,7 +98,7 @@ future raft_sys_table_storage::load_log() { log.emplace_back(make_lw_shared( raft::log_entry{.term = term, .idx = idx, .data = std::move(data)})); - co_await make_ready_future<>(); + co_await coroutine::maybe_yield(); } co_return log; } @@ -227,7 +228,7 @@ future<> raft_sys_table_storage::do_store_log_entries(const std::vector(); + co_await coroutine::maybe_yield(); } auto batch_options = cql3::query_options::make_batch_options( diff --git a/sstables/partition_index_cache.hh b/sstables/partition_index_cache.hh index 2d808cb244..eae21bf1db 100644 --- a/sstables/partition_index_cache.hh +++ b/sstables/partition_index_cache.hh @@ -26,6 +26,7 @@ #include #include #include +#include #include "utils/loading_shared_values.hh" #include "utils/chunked_vector.hh" #include "utils/bptree.hh" @@ -274,7 +275,7 @@ public: }); if (need_preempt() && i != _cache.end()) { auto key = i->key(); - co_await make_ready_future<>(); + co_await coroutine::maybe_yield(); i = _cache.lower_bound(key); } } diff --git a/sstables/sstables.cc b/sstables/sstables.cc index 1e303b3239..cb38bc2808 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -37,6 +37,7 @@ #include #include #include +#include #include "dht/sharder.hh" #include "types.hh" @@ -521,7 +522,7 @@ future<> parse(const schema& schema, sstable_version_types v, random_access_read while (s.positions.size() != s.header.size) { s.positions.push_back(seastar::read_le(b)); b += sizeof(pos_type); - co_await make_ready_future<>(); // yield + co_await coroutine::maybe_yield(); } // Since the keys in the index are not sized, we need to calculate // the start position of the index i+1 to determine the boundaries @@ -682,7 +683,7 @@ future<> parse(const schema& s, sstable_version_types v, random_access_reader& i eh.bucket_offsets.push_back(offset); } eh.buckets.push_back(bucket); - co_await make_ready_future<>(); // yield + co_await coroutine::maybe_yield(); } } diff --git a/table.cc b/table.cc index 28e05f2d93..6c76748cd0 100644 --- a/table.cc +++ b/table.cc @@ -21,6 +21,7 @@ #include #include +#include #include #include "database.hh" @@ -762,7 +763,7 @@ table::sstable_list_builder::build_new_list(const sstables::sstable_set& current if (!s.contains(tab)) { new_sstable_list.insert(tab); } - co_await make_ready_future<>(); // yield if needed. + co_await coroutine::maybe_yield(); } co_return make_lw_shared(std::move(new_sstable_list)); } diff --git a/test/raft/randomized_nemesis_test.cc b/test/raft/randomized_nemesis_test.cc index 71a8252b93..2f7a566f3a 100644 --- a/test/raft/randomized_nemesis_test.cc +++ b/test/raft/randomized_nemesis_test.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -146,7 +147,7 @@ public: // In any case we simply drop the output. } - co_await make_ready_future<>(); // maybe yield + co_await coroutine::maybe_yield(); } }); } diff --git a/utils/cached_file.hh b/utils/cached_file.hh index 8d6d58d6bf..9cb542c370 100644 --- a/utils/cached_file.hh +++ b/utils/cached_file.hh @@ -29,6 +29,7 @@ #include #include +#include #include @@ -460,7 +461,7 @@ public: } if (need_preempt() && i != _cache.end()) { auto key = i->idx; - co_await make_ready_future<>(); + co_await coroutine::maybe_yield(); i = _cache.lower_bound(key); } } diff --git a/utils/logalloc.cc b/utils/logalloc.cc index 1a2e7dd0de..ff9befbb69 100644 --- a/utils/logalloc.cc +++ b/utils/logalloc.cc @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -413,7 +414,7 @@ private: break; } _reclaim(free_memory_threshold - memory::stats().free_memory()); - co_await make_ready_future<>(); + co_await coroutine::maybe_yield(); } llogger.debug("background_reclaimer::main_loop: exit"); }