diff --git a/db/table_cache.cc b/db/table_cache.cc index 827d39e0b..e121e66b2 100644 --- a/db/table_cache.cc +++ b/db/table_cache.cc @@ -42,13 +42,15 @@ static void DeleteEntry(const Slice& /*key*/, void* value) { } // namespace ROCKSDB_NAMESPACE // Generate the regular and coroutine versions of some methods by -// including table_cache_coro.h twice +// including table_cache_sync_and_async.h twice +// Macros in the header will expand differently based on whether +// WITH_COROUTINES or WITHOUT_COROUTINES is defined // clang-format off #define WITHOUT_COROUTINES -#include "db/table_cache_coro.h" +#include "db/table_cache_sync_and_async.h" #undef WITHOUT_COROUTINES #define WITH_COROUTINES -#include "db/table_cache_coro.h" +#include "db/table_cache_sync_and_async.h" // clang-format on namespace ROCKSDB_NAMESPACE { diff --git a/db/table_cache_coro.h b/db/table_cache_sync_and_async.h similarity index 100% rename from db/table_cache_coro.h rename to db/table_cache_sync_and_async.h diff --git a/db/version_set.cc b/db/version_set.cc index 70953f0e2..46fee2ab6 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -72,13 +72,15 @@ #include "util/user_comparator_wrapper.h" // Generate the regular and coroutine versions of some methods by -// including version_set_coro.h twice +// including version_set_sync_and_async.h twice +// Macros in the header will expand differently based on whether +// WITH_COROUTINES or WITHOUT_COROUTINES is defined // clang-format off #define WITHOUT_COROUTINES -#include "db/version_set_coro.h" +#include "db/version_set_sync_and_async.h" #undef WITHOUT_COROUTINES #define WITH_COROUTINES -#include "db/version_set_coro.h" +#include "db/version_set_sync_and_async.h" // clang-format on namespace ROCKSDB_NAMESPACE { diff --git a/db/version_set_coro.h b/db/version_set_sync_and_async.h similarity index 100% rename from db/version_set_coro.h rename to db/version_set_sync_and_async.h diff --git a/table/block_based/block_based_table_reader.cc b/table/block_based/block_based_table_reader.cc index e1a5abd96..9351c7c1b 100644 --- a/table/block_based/block_based_table_reader.cc +++ b/table/block_based/block_based_table_reader.cc @@ -86,13 +86,15 @@ CacheAllocationPtr CopyBufferToHeap(MemoryAllocator* allocator, Slice& buf) { } // namespace ROCKSDB_NAMESPACE // Generate the regular and coroutine versions of some methods by -// including block_based_table_reader_coro.h twice +// including block_based_table_reader_sync_and_async.h twice +// Macros in the header will expand differently based on whether +// WITH_COROUTINES or WITHOUT_COROUTINES is defined // clang-format off #define WITHOUT_COROUTINES -#include "table/block_based/block_based_table_reader_coro.h" +#include "table/block_based/block_based_table_reader_sync_and_async.h" #undef WITHOUT_COROUTINES #define WITH_COROUTINES -#include "table/block_based/block_based_table_reader_coro.h" +#include "table/block_based/block_based_table_reader_sync_and_async.h" // clang-format on namespace ROCKSDB_NAMESPACE { diff --git a/table/block_based/block_based_table_reader_coro.h b/table/block_based/block_based_table_reader_sync_and_async.h similarity index 100% rename from table/block_based/block_based_table_reader_coro.h rename to table/block_based/block_based_table_reader_sync_and_async.h diff --git a/util/async_file_reader.cc b/util/async_file_reader.cc index f6d76842e..f4fede2de 100644 --- a/util/async_file_reader.cc +++ b/util/async_file_reader.cc @@ -36,7 +36,7 @@ bool AsyncFileReader::MultiReadAsyncImpl(ReadAwaiter* awaiter) { return true; } -void AsyncFileReader::Poll() { +void AsyncFileReader::Wait() { if (!head_) { return; } diff --git a/util/async_file_reader.h b/util/async_file_reader.h index ef71a45b7..82b240339 100644 --- a/util/async_file_reader.h +++ b/util/async_file_reader.h @@ -21,7 +21,7 @@ class SingleThreadExecutor; // coroutines to co_await it. When the AsyncFileReader Awaitable is // resumed, it initiates the fie reads requested by the awaiting caller // by calling RandomAccessFileReader's ReadAsync. It then suspends the -// awaiting coroutine. The suspended awaiter is later resumed by Poll(). +// awaiting coroutine. The suspended awaiter is later resumed by Wait(). class AsyncFileReader { class ReadAwaiter; template @@ -84,6 +84,11 @@ class AsyncFileReader { autovector io_handle_; autovector del_fn_; std::experimental::coroutine_handle<> awaiting_coro_; + // Use this to link to the next ReadAwaiter in the suspended coroutine + // list. The head and tail of the list are tracked by AsyncFileReader. + // We use this approach rather than an STL container in order to avoid + // extra memory allocations. The coroutine call already allocates a + // ReadAwaiter object. ReadAwaiter* next_; }; @@ -123,7 +128,7 @@ class AsyncFileReader { // Called by the SingleThreadExecutor to poll for async IO completion. // This also resumes the awaiting coroutines. - void Poll(); + void Wait(); // Head of the queue of awaiters waiting for async IO completion ReadAwaiter* head_ = nullptr; diff --git a/util/single_thread_executor.h b/util/single_thread_executor.h index 8f8079ebd..b82ddda2b 100644 --- a/util/single_thread_executor.h +++ b/util/single_thread_executor.h @@ -37,9 +37,9 @@ class SingleThreadExecutor : public folly::Executor { q.pop(); if (q.empty()) { - // Prevent recursion, as the Poll may queue resumed coroutines + // Prevent recursion, as the Wait may queue resumed coroutines busy_ = true; - reader_.Poll(); + reader_.Wait(); busy_ = false; } }