diff --git a/db/db_basic_test.cc b/db/db_basic_test.cc index 40357a5e05..f207063330 100644 --- a/db/db_basic_test.cc +++ b/db/db_basic_test.cc @@ -4277,7 +4277,7 @@ class DeadlineRandomAccessFile : public FSRandomAccessFileOwnerWrapper { const IOOptions& options, IODebugContext* dbg) override; IOStatus ReadAsync(FSReadRequest& req, const IOOptions& opts, - std::function cb, + std::function cb, void* cb_arg, void** io_handle, IOHandleDeleter* del_fn, IODebugContext* dbg) override; @@ -4423,7 +4423,7 @@ IOStatus DeadlineRandomAccessFile::Read(uint64_t offset, size_t len, IOStatus DeadlineRandomAccessFile::ReadAsync( FSReadRequest& req, const IOOptions& opts, - std::function cb, void* cb_arg, + std::function cb, void* cb_arg, void** io_handle, IOHandleDeleter* del_fn, IODebugContext* dbg) { const std::chrono::microseconds deadline = fs_.GetDeadline(); const std::chrono::microseconds io_timeout = fs_.GetIOTimeout(); diff --git a/db_stress_tool/db_stress_env_wrapper.h b/db_stress_tool/db_stress_env_wrapper.h index ea9b9aa51a..ab4a074fc7 100644 --- a/db_stress_tool/db_stress_env_wrapper.h +++ b/db_stress_tool/db_stress_env_wrapper.h @@ -60,7 +60,7 @@ class DbStressRandomAccessFileWrapper : public FSRandomAccessFileOwnerWrapper { } IOStatus ReadAsync(FSReadRequest& req, const IOOptions& options, - std::function cb, + std::function cb, void* cb_arg, void** io_handle, IOHandleDeleter* del_fn, IODebugContext* dbg) override { #ifndef NDEBUG diff --git a/env/env_test.cc b/env/env_test.cc index 20a6f68813..ecce0d2953 100644 --- a/env/env_test.cc +++ b/env/env_test.cc @@ -3447,7 +3447,7 @@ TEST_F(CreateEnvTest, CreateCompositeEnv) { class ReadAsyncFS; struct MockIOHandle { - std::function cb; + std::function cb; void* cb_arg; bool create_io_error; }; @@ -3462,7 +3462,7 @@ class ReadAsyncRandomAccessFile : public FSRandomAccessFileOwnerWrapper { : FSRandomAccessFileOwnerWrapper(std::move(file)), fs_(fs) {} IOStatus ReadAsync(FSReadRequest& req, const IOOptions& opts, - std::function cb, + std::function cb, void* cb_arg, void** io_handle, IOHandleDeleter* del_fn, IODebugContext* dbg) override; @@ -3514,7 +3514,7 @@ class ReadAsyncFS : public FileSystemWrapper { IOStatus ReadAsyncRandomAccessFile::ReadAsync( FSReadRequest& req, const IOOptions& opts, - std::function cb, void* cb_arg, + std::function cb, void* cb_arg, void** io_handle, IOHandleDeleter* del_fn, IODebugContext* dbg) { IOHandleDeleter deletefn = [](void* args) -> void { delete (static_cast(args)); @@ -3602,8 +3602,8 @@ TEST_F(TestAsyncRead, ReadAsync) { } // callback function passed to async read. - std::function callback = - [&](const FSReadRequest& req, void* cb_arg) { + std::function callback = + [&](FSReadRequest& req, void* cb_arg) { assert(cb_arg != nullptr); size_t i = *(reinterpret_cast(cb_arg)); reqs[i].offset = req.offset; diff --git a/env/file_system_tracer.cc b/env/file_system_tracer.cc index d0c45c57ee..dc44107b58 100644 --- a/env/file_system_tracer.cc +++ b/env/file_system_tracer.cc @@ -340,7 +340,7 @@ IOStatus FSRandomAccessFileTracingWrapper::InvalidateCache(size_t offset, IOStatus FSRandomAccessFileTracingWrapper::ReadAsync( FSReadRequest& req, const IOOptions& opts, - std::function cb, void* cb_arg, + std::function cb, void* cb_arg, void** io_handle, IOHandleDeleter* del_fn, IODebugContext* dbg) { // Create a callback and populate info. auto read_async_callback = @@ -361,8 +361,8 @@ IOStatus FSRandomAccessFileTracingWrapper::ReadAsync( return s; } -void FSRandomAccessFileTracingWrapper::ReadAsyncCallback( - const FSReadRequest& req, void* cb_arg) { +void FSRandomAccessFileTracingWrapper::ReadAsyncCallback(FSReadRequest& req, + void* cb_arg) { ReadAsyncCallbackInfo* read_async_cb_info = static_cast(cb_arg); assert(read_async_cb_info); diff --git a/env/file_system_tracer.h b/env/file_system_tracer.h index 979a0bf120..7502496dc1 100644 --- a/env/file_system_tracer.h +++ b/env/file_system_tracer.h @@ -229,11 +229,11 @@ class FSRandomAccessFileTracingWrapper : public FSRandomAccessFileOwnerWrapper { IOStatus InvalidateCache(size_t offset, size_t length) override; IOStatus ReadAsync(FSReadRequest& req, const IOOptions& opts, - std::function cb, + std::function cb, void* cb_arg, void** io_handle, IOHandleDeleter* del_fn, IODebugContext* dbg) override; - void ReadAsyncCallback(const FSReadRequest& req, void* cb_arg); + void ReadAsyncCallback(FSReadRequest& req, void* cb_arg); private: std::shared_ptr io_tracer_; @@ -243,7 +243,7 @@ class FSRandomAccessFileTracingWrapper : public FSRandomAccessFileOwnerWrapper { struct ReadAsyncCallbackInfo { uint64_t start_time_; - std::function cb_; + std::function cb_; void* cb_arg_; std::string file_op_; }; diff --git a/env/io_posix.cc b/env/io_posix.cc index e92a3bccd9..29efb055ba 100644 --- a/env/io_posix.cc +++ b/env/io_posix.cc @@ -857,7 +857,7 @@ IOStatus PosixRandomAccessFile::InvalidateCache(size_t offset, size_t length) { IOStatus PosixRandomAccessFile::ReadAsync( FSReadRequest& req, const IOOptions& /*opts*/, - std::function cb, void* cb_arg, + std::function cb, void* cb_arg, void** io_handle, IOHandleDeleter* del_fn, IODebugContext* /*dbg*/) { if (use_direct_io()) { assert(IsSectorAligned(req.offset, GetRequiredBufferAlignment())); diff --git a/env/io_posix.h b/env/io_posix.h index 205bf2a539..603af2f885 100644 --- a/env/io_posix.h +++ b/env/io_posix.h @@ -76,8 +76,8 @@ inline bool IsSectorAligned(const void* ptr, size_t sector_size) { #if defined(ROCKSDB_IOURING_PRESENT) struct Posix_IOHandle { Posix_IOHandle(struct io_uring* _iu, - std::function _cb, - void* _cb_arg, uint64_t _offset, size_t _len, char* _scratch, + std::function _cb, void* _cb_arg, + uint64_t _offset, size_t _len, char* _scratch, bool _use_direct_io, size_t _alignment) : iu(_iu), cb(_cb), @@ -92,7 +92,7 @@ struct Posix_IOHandle { struct iovec iov; struct io_uring* iu; - std::function cb; + std::function cb; void* cb_arg; uint64_t offset; size_t len; @@ -317,11 +317,12 @@ class PosixRandomAccessFile : public FSRandomAccessFile { size_t GetRequiredBufferAlignment() const override { return logical_sector_size_; } - // EXPERIMENTAL - IOStatus ReadAsync(FSReadRequest& req, const IOOptions& opts, - std::function cb, - void* cb_arg, void** io_handle, IOHandleDeleter* del_fn, - IODebugContext* dbg) override; + + virtual IOStatus ReadAsync(FSReadRequest& req, const IOOptions& opts, + std::function cb, + void* cb_arg, void** io_handle, + IOHandleDeleter* del_fn, + IODebugContext* dbg) override; }; class PosixWritableFile : public FSWritableFile { diff --git a/file/file_prefetch_buffer.cc b/file/file_prefetch_buffer.cc index beab1300dd..73050aed79 100644 --- a/file/file_prefetch_buffer.cc +++ b/file/file_prefetch_buffer.cc @@ -790,7 +790,7 @@ bool FilePrefetchBuffer::TryReadFromCacheUntracked( return true; } -void FilePrefetchBuffer::PrefetchAsyncCallback(const FSReadRequest& req, +void FilePrefetchBuffer::PrefetchAsyncCallback(FSReadRequest& req, void* cb_arg) { BufferInfo* buf = static_cast(cb_arg); diff --git a/file/file_prefetch_buffer.h b/file/file_prefetch_buffer.h index 2565d55a2e..dfa8389294 100644 --- a/file/file_prefetch_buffer.h +++ b/file/file_prefetch_buffer.h @@ -376,7 +376,7 @@ class FilePrefetchBuffer { } // Callback function passed to underlying FS in case of asynchronous reads. - void PrefetchAsyncCallback(const FSReadRequest& req, void* cb_arg); + void PrefetchAsyncCallback(FSReadRequest& req, void* cb_arg); void TEST_GetBufferOffsetandSize( std::vector>& buffer_info) { diff --git a/file/random_access_file_reader.cc b/file/random_access_file_reader.cc index 880f82d497..688ef35660 100644 --- a/file/random_access_file_reader.cc +++ b/file/random_access_file_reader.cc @@ -486,7 +486,7 @@ IOStatus RandomAccessFileReader::PrepareIOOptions(const ReadOptions& ro, IOStatus RandomAccessFileReader::ReadAsync( FSReadRequest& req, const IOOptions& opts, - std::function cb, void* cb_arg, + std::function cb, void* cb_arg, void** io_handle, IOHandleDeleter* del_fn, AlignedBuf* aligned_buf) { IOStatus s; // Create a callback and populate info. @@ -557,7 +557,7 @@ IOStatus RandomAccessFileReader::ReadAsync( return s; } -void RandomAccessFileReader::ReadAsyncCallback(const FSReadRequest& req, +void RandomAccessFileReader::ReadAsyncCallback(FSReadRequest& req, void* cb_arg) { ReadAsyncInfo* read_async_info = static_cast(cb_arg); assert(read_async_info); diff --git a/file/random_access_file_reader.h b/file/random_access_file_reader.h index 93cbe0e1ac..3155136776 100644 --- a/file/random_access_file_reader.h +++ b/file/random_access_file_reader.h @@ -91,8 +91,8 @@ class RandomAccessFileReader { const bool is_last_level_; struct ReadAsyncInfo { - ReadAsyncInfo(std::function cb, - void* cb_arg, uint64_t start_time) + ReadAsyncInfo(std::function cb, void* cb_arg, + uint64_t start_time) : cb_(cb), cb_arg_(cb_arg), start_time_(start_time), @@ -102,7 +102,7 @@ class RandomAccessFileReader { user_len_(0), is_aligned_(false) {} - std::function cb_; + std::function cb_; void* cb_arg_; uint64_t start_time_; FileOperationInfo::StartTimePoint fs_start_ts_; @@ -188,10 +188,10 @@ class RandomAccessFileReader { IOStatus PrepareIOOptions(const ReadOptions& ro, IOOptions& opts) const; IOStatus ReadAsync(FSReadRequest& req, const IOOptions& opts, - std::function cb, + std::function cb, void* cb_arg, void** io_handle, IOHandleDeleter* del_fn, AlignedBuf* aligned_buf); - void ReadAsyncCallback(const FSReadRequest& req, void* cb_arg); + void ReadAsyncCallback(FSReadRequest& req, void* cb_arg); }; } // namespace ROCKSDB_NAMESPACE diff --git a/include/rocksdb/file_system.h b/include/rocksdb/file_system.h index 8443cccb49..6c4fee5748 100644 --- a/include/rocksdb/file_system.h +++ b/include/rocksdb/file_system.h @@ -962,10 +962,10 @@ class FSRandomAccessFile { // AbortIO API. // // Default implementation is to read the data synchronously. - virtual IOStatus ReadAsync( - FSReadRequest& req, const IOOptions& opts, - std::function cb, void* cb_arg, - void** /*io_handle*/, IOHandleDeleter* /*del_fn*/, IODebugContext* dbg) { + virtual IOStatus ReadAsync(FSReadRequest& req, const IOOptions& opts, + std::function cb, + void* cb_arg, void** /*io_handle*/, + IOHandleDeleter* /*del_fn*/, IODebugContext* dbg) { req.status = Read(req.offset, req.len, opts, &(req.result), req.scratch, dbg); cb(req, cb_arg); @@ -1687,7 +1687,7 @@ class FSRandomAccessFileWrapper : public FSRandomAccessFile { return target_->InvalidateCache(offset, length); } IOStatus ReadAsync(FSReadRequest& req, const IOOptions& opts, - std::function cb, + std::function cb, void* cb_arg, void** io_handle, IOHandleDeleter* del_fn, IODebugContext* dbg) override { return target()->ReadAsync(req, opts, cb, cb_arg, io_handle, del_fn, dbg); diff --git a/util/async_file_reader.cc b/util/async_file_reader.cc index 9ce13b99fe..8fa4d19933 100644 --- a/util/async_file_reader.cc +++ b/util/async_file_reader.cc @@ -22,14 +22,12 @@ bool AsyncFileReader::MultiReadAsyncImpl(ReadAwaiter* awaiter) { for (size_t i = 0; i < awaiter->num_reqs_; ++i) { IOStatus s = awaiter->file_->ReadAsync( awaiter->read_reqs_[i], awaiter->opts_, - [](const FSReadRequest& req, void* cb_arg) { + [](FSReadRequest& req, void* cb_arg) { FSReadRequest* read_req = static_cast(cb_arg); read_req->status = req.status; read_req->result = req.result; if (req.fs_scratch != nullptr) { - // TODO akanksha: Revisit to remove the const in the callback. - FSReadRequest& req_tmp = const_cast(req); - read_req->fs_scratch = std::move(req_tmp.fs_scratch); + read_req->fs_scratch = std::move(req.fs_scratch); } }, &awaiter->read_reqs_[i], &awaiter->io_handle_[i], &awaiter->del_fn_[i], diff --git a/utilities/fault_injection_fs.cc b/utilities/fault_injection_fs.cc index 6303fb6ea7..8c3c3a447e 100644 --- a/utilities/fault_injection_fs.cc +++ b/utilities/fault_injection_fs.cc @@ -416,7 +416,7 @@ IOStatus TestFSRandomAccessFile::Read(uint64_t offset, size_t n, IOStatus TestFSRandomAccessFile::ReadAsync( FSReadRequest& req, const IOOptions& opts, - std::function cb, void* cb_arg, + std::function cb, void* cb_arg, void** io_handle, IOHandleDeleter* del_fn, IODebugContext* /*dbg*/) { IOStatus ret; IOStatus s; diff --git a/utilities/fault_injection_fs.h b/utilities/fault_injection_fs.h index 3e27c7f4bf..356d21f570 100644 --- a/utilities/fault_injection_fs.h +++ b/utilities/fault_injection_fs.h @@ -143,7 +143,7 @@ class TestFSRandomAccessFile : public FSRandomAccessFile { Slice* result, char* scratch, IODebugContext* dbg) const override; IOStatus ReadAsync(FSReadRequest& req, const IOOptions& opts, - std::function cb, + std::function cb, void* cb_arg, void** io_handle, IOHandleDeleter* del_fn, IODebugContext* dbg) override; IOStatus MultiRead(FSReadRequest* reqs, size_t num_reqs,