Fix crash due to MultiGet async IO and direct IO (#10024)

Summary:
MultiGet with async IO is not officially supported with Posix yet. Avoid a crash by using synchronous MultiRead when direct IO is enabled.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10024

Test Plan: Run db_crashtest.py manually

Reviewed By: akankshamahajan15

Differential Revision: D36551053

Pulled By: anand1976

fbshipit-source-id: 72190418fa92dd0397e87825df618b12c9bdecda
This commit is contained in:
anand76 2022-05-20 12:38:21 -07:00 committed by Facebook GitHub Bot
parent cc23b46da1
commit e015206dd6
4 changed files with 13 additions and 6 deletions

View File

@ -51,6 +51,7 @@ static void DeleteEntry(const Slice& /*key*/, void* value) {
#undef WITHOUT_COROUTINES #undef WITHOUT_COROUTINES
#define WITH_COROUTINES #define WITH_COROUTINES
#include "db/table_cache_sync_and_async.h" #include "db/table_cache_sync_and_async.h"
#undef WITH_COROUTINES
// clang-format on // clang-format on
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {

View File

@ -82,6 +82,7 @@
#undef WITHOUT_COROUTINES #undef WITHOUT_COROUTINES
#define WITH_COROUTINES #define WITH_COROUTINES
#include "db/version_set_sync_and_async.h" #include "db/version_set_sync_and_async.h"
#undef WITH_COROUTINES
// clang-format on // clang-format on
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {

View File

@ -96,6 +96,7 @@ CacheAllocationPtr CopyBufferToHeap(MemoryAllocator* allocator, Slice& buf) {
#undef WITHOUT_COROUTINES #undef WITHOUT_COROUTINES
#define WITH_COROUTINES #define WITH_COROUTINES
#include "table/block_based/block_based_table_reader_sync_and_async.h" #include "table/block_based/block_based_table_reader_sync_and_async.h"
#undef WITH_COROUTINES
// clang-format on // clang-format on
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {

View File

@ -140,12 +140,16 @@ DEFINE_SYNC_AND_ASYNC(void, BlockBasedTable::RetrieveMultipleBlocks)
IOOptions opts; IOOptions opts;
IOStatus s = file->PrepareIOOptions(options, opts); IOStatus s = file->PrepareIOOptions(options, opts);
if (s.ok()) { if (s.ok()) {
#if defined(WITHOUT_COROUTINES) #if defined(WITH_COROUTINES)
s = file->MultiRead(opts, &read_reqs[0], read_reqs.size(), &direct_io_buf, if (file->use_direct_io()) {
options.rate_limiter_priority); #endif // WITH_COROUTINES
#else // WITH_COROUTINES s = file->MultiRead(opts, &read_reqs[0], read_reqs.size(),
&direct_io_buf, options.rate_limiter_priority);
#if defined(WITH_COROUTINES)
} else {
co_await batch->context()->reader().MultiReadAsync( co_await batch->context()->reader().MultiReadAsync(
file, opts, &read_reqs[0], read_reqs.size(), &direct_io_buf); file, opts, &read_reqs[0], read_reqs.size(), &direct_io_buf);
}
#endif // WITH_COROUTINES #endif // WITH_COROUTINES
} }
if (!s.ok()) { if (!s.ok()) {