From 1ec1b32b0696cca08b1d24f98e1526a885c635e0 Mon Sep 17 00:00:00 2001 From: Dmitri Petrov Date: Wed, 20 Dec 2023 03:04:13 +0000 Subject: [PATCH] Switch to sync default implementation of AsyncMultiRead. --- include/rocksdb/file_system.h | 48 +++++++++++------------------------ 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/include/rocksdb/file_system.h b/include/rocksdb/file_system.h index 0a40656ec681..27c600598e37 100644 --- a/include/rocksdb/file_system.h +++ b/include/rocksdb/file_system.h @@ -673,8 +673,13 @@ class FileSystem : public Customizable { // // Default implementation is to return IOStatus::OK. - virtual IOStatus Poll(std::vector& /*io_handles*/, + virtual IOStatus Poll(std::vector& io_handles, size_t /*min_completions*/) { + + // RocksDB-Cloud contribution begin + // Default implementations are synchronous and do not return any io_handles. + assert(io_handles.empty()); + // RocksDB-Cloud contribution end return IOStatus::OK(); } @@ -950,44 +955,21 @@ class FSRandomAccessFile { // request and result and status fields are output parameter set by underlying // FileSystem. The data should always be read into scratch field. // - // Default implementation delegates to ReadAsync for each request. + // Default implementation is syncrhonous and delegates to MultiRead. virtual IOStatus MultiReadAsync( FSReadRequest* reqs, size_t num_reqs, const IOOptions& opts, std::function cb, void* cb_arg, - void** io_handles, size_t* num_io_handles, IOHandleDeleter* del_fns, - IODebugContext* dbg) { + void** /*io_handles*/, size_t* num_io_handles, + IOHandleDeleter* /*del_fns*/, IODebugContext* dbg) { assert(*num_io_handles == num_reqs); *num_io_handles = 0; - // Counter that we use keep track of how many individual async reads are - // still in progress. - std::atomic in_flight = 0; - for (size_t idx = 0; idx < num_reqs; idx++) { - auto& req = reqs[idx]; - auto local_cb = [&in_flight](const FSReadRequest&, void*) { - // We are done with this read, decrement the counter and signal. - in_flight--; - in_flight.notify_one(); - }; - auto status = ReadAsync(req, opts, local_cb, nullptr, &io_handles[idx], - &del_fns[idx], dbg); - if (status != IOStatus::OK()) { - // Delete in-progress IO-handles. - for (size_t k = 0; k < *num_io_handles; k++) { - if (io_handles[k] && del_fns[k]) { - del_fns[k](io_handles[k]); - io_handles[k] = nullptr; - } - } - *num_io_handles = 0; - return status; - } - (*num_io_handles)++; - in_flight++; - } - for (auto cv = in_flight.load(); cv != 0; - in_flight.wait(cv), cv = in_flight.load()) { + + auto status = MultiRead(reqs, num_reqs, opts, dbg); + if (!status.ok()) { + return status; } - // the operation is completed, call the 'op_cb' + + // the operation has completed successfully, execute callbacks cb(reqs, num_reqs, cb_arg); return IOStatus::OK(); }