Skip to content

Commit c411586

Browse files
committed
Add shared mutex field to IODebugContext (facebook#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: facebook#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
1 parent 09074d7 commit c411586

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

include/rocksdb/file_system.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <functional>
2525
#include <limits>
2626
#include <memory>
27+
#include <shared_mutex>
2728
#include <sstream>
2829
#include <string>
2930
#include <unordered_map>
@@ -254,6 +255,10 @@ struct IODebugContext {
254255
// Arbitrary structure containing cost information about the IO request
255256
std::any cost_info;
256257

258+
// FileSystem implementations can use this mutex to synchronize concurrent
259+
// reads/writes as needed (e.g. to update the counters or cost_info field)
260+
std::shared_mutex mutex;
261+
257262
IODebugContext() {}
258263

259264
// Copy constructor

0 commit comments

Comments
 (0)