Add shared mutex field to IODebugContext (#13993)

Summary:
There can be concurrent reads/writes to fields in `IODebugContext`. One example we have seen is for the `cost_info` field which is of type `std::any`. In fact, in RocksDB's async MultiRead implementation, the same `IODebugContext` is re-used across separate async read requests.

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

Test Plan: Update code which reads/writes to `cost_data` to first acquire shared/exclusive lock on the `mutex` field. There should not be any race conditions when async MultiRead is used.

Reviewed By: pdillinger

Differential Revision: D83091423

Pulled By: archang19

fbshipit-source-id: 4db86d33cf162ed39114b1cd115fcd8964c8ff9b
This commit is contained in:
Andrew Chang
2025-09-24 16:31:13 -07:00
committed by Facebook GitHub Bot
parent 169f90cdea
commit 90241e18c8
+5
View File
@@ -24,6 +24,7 @@
#include <functional>
#include <limits>
#include <memory>
#include <shared_mutex>
#include <sstream>
#include <string>
#include <unordered_map>
@@ -254,6 +255,10 @@ struct IODebugContext {
// Arbitrary structure containing cost information about the IO request
std::any cost_info;
// FileSystem implementations can use this mutex to synchronize concurrent
// reads/writes as needed (e.g. to update the counters or cost_info field)
std::shared_mutex mutex;
IODebugContext() {}
// Copy constructor