2020-07-13 23:35:29 +00:00
|
|
|
// Copyright (c) 2019-present, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "rocksdb/file_system.h"
|
2021-01-26 06:07:26 +00:00
|
|
|
#include "rocksdb/system_clock.h"
|
2020-07-13 23:35:29 +00:00
|
|
|
#include "trace_replay/io_tracer.h"
|
|
|
|
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
|
|
|
|
// FileSystemTracingWrapper is a wrapper class above FileSystem that forwards
|
|
|
|
// the call to the underlying storage system. It then invokes IOTracer to record
|
|
|
|
// file operations and other contextual information in a binary format for
|
|
|
|
// tracing. It overrides methods we are interested in tracing and extends
|
|
|
|
// FileSystemWrapper, which forwards all methods that are not explicitly
|
|
|
|
// overridden.
|
|
|
|
class FileSystemTracingWrapper : public FileSystemWrapper {
|
|
|
|
public:
|
2021-01-26 06:07:26 +00:00
|
|
|
FileSystemTracingWrapper(const std::shared_ptr<FileSystem>& t,
|
|
|
|
const std::shared_ptr<IOTracer>& io_tracer)
|
|
|
|
: FileSystemWrapper(t),
|
|
|
|
io_tracer_(io_tracer),
|
2021-03-15 11:32:24 +00:00
|
|
|
clock_(SystemClock::Default().get()) {}
|
2020-07-13 23:35:29 +00:00
|
|
|
|
|
|
|
~FileSystemTracingWrapper() override {}
|
|
|
|
|
2021-11-02 16:06:02 +00:00
|
|
|
static const char* kClassName() { return "FileSystemTracing"; }
|
|
|
|
const char* Name() const override { return kClassName(); }
|
|
|
|
|
2020-10-14 17:14:12 +00:00
|
|
|
IOStatus NewSequentialFile(const std::string& fname,
|
|
|
|
const FileOptions& file_opts,
|
|
|
|
std::unique_ptr<FSSequentialFile>* result,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus NewRandomAccessFile(const std::string& fname,
|
|
|
|
const FileOptions& file_opts,
|
|
|
|
std::unique_ptr<FSRandomAccessFile>* result,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
2020-07-13 23:35:29 +00:00
|
|
|
IOStatus NewWritableFile(const std::string& fname,
|
|
|
|
const FileOptions& file_opts,
|
|
|
|
std::unique_ptr<FSWritableFile>* result,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
2020-10-14 17:14:12 +00:00
|
|
|
IOStatus ReopenWritableFile(const std::string& fname,
|
|
|
|
const FileOptions& file_opts,
|
|
|
|
std::unique_ptr<FSWritableFile>* result,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus ReuseWritableFile(const std::string& fname,
|
|
|
|
const std::string& old_fname,
|
|
|
|
const FileOptions& file_opts,
|
|
|
|
std::unique_ptr<FSWritableFile>* result,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus NewRandomRWFile(const std::string& fname, const FileOptions& options,
|
|
|
|
std::unique_ptr<FSRandomRWFile>* result,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
2020-07-13 23:35:29 +00:00
|
|
|
IOStatus NewDirectory(const std::string& name, const IOOptions& io_opts,
|
|
|
|
std::unique_ptr<FSDirectory>* result,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus GetChildren(const std::string& dir, const IOOptions& io_opts,
|
|
|
|
std::vector<std::string>* r,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus DeleteFile(const std::string& fname, const IOOptions& options,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus CreateDir(const std::string& dirname, const IOOptions& options,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus CreateDirIfMissing(const std::string& dirname,
|
|
|
|
const IOOptions& options,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus DeleteDir(const std::string& dirname, const IOOptions& options,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus GetFileSize(const std::string& fname, const IOOptions& options,
|
|
|
|
uint64_t* file_size, IODebugContext* dbg) override;
|
|
|
|
|
2020-10-14 17:14:12 +00:00
|
|
|
IOStatus Truncate(const std::string& fname, size_t size,
|
|
|
|
const IOOptions& options, IODebugContext* dbg) override;
|
|
|
|
|
2020-07-13 23:35:29 +00:00
|
|
|
private:
|
|
|
|
std::shared_ptr<IOTracer> io_tracer_;
|
2021-03-15 11:32:24 +00:00
|
|
|
SystemClock* clock_;
|
2020-07-13 23:35:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// The FileSystemPtr is a wrapper class that takes pointer to storage systems
|
|
|
|
// (such as posix filesystems). It overloads operator -> and returns a pointer
|
|
|
|
// of either FileSystem or FileSystemTracingWrapper based on whether tracing is
|
|
|
|
// enabled or not. It is added to bypass FileSystemTracingWrapper when tracing
|
|
|
|
// is disabled.
|
|
|
|
class FileSystemPtr {
|
|
|
|
public:
|
|
|
|
FileSystemPtr(std::shared_ptr<FileSystem> fs,
|
2020-08-13 00:28:10 +00:00
|
|
|
const std::shared_ptr<IOTracer>& io_tracer)
|
|
|
|
: fs_(fs), io_tracer_(io_tracer) {
|
|
|
|
fs_tracer_ = std::make_shared<FileSystemTracingWrapper>(fs_, io_tracer_);
|
|
|
|
}
|
2020-07-13 23:35:29 +00:00
|
|
|
|
|
|
|
std::shared_ptr<FileSystem> operator->() const {
|
|
|
|
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
|
|
|
|
return fs_tracer_;
|
|
|
|
} else {
|
|
|
|
return fs_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 00:28:10 +00:00
|
|
|
/* Returns the underlying File System pointer */
|
|
|
|
FileSystem* get() const {
|
|
|
|
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
|
|
|
|
return fs_tracer_.get();
|
|
|
|
} else {
|
|
|
|
return fs_.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-13 23:35:29 +00:00
|
|
|
private:
|
|
|
|
std::shared_ptr<FileSystem> fs_;
|
|
|
|
std::shared_ptr<IOTracer> io_tracer_;
|
|
|
|
std::shared_ptr<FileSystemTracingWrapper> fs_tracer_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// FSSequentialFileTracingWrapper is a wrapper class above FSSequentialFile that
|
|
|
|
// forwards the call to the underlying storage system. It then invokes IOTracer
|
|
|
|
// to record file operations and other contextual information in a binary format
|
|
|
|
// for tracing. It overrides methods we are interested in tracing and extends
|
|
|
|
// FSSequentialFileWrapper, which forwards all methods that are not explicitly
|
|
|
|
// overridden.
|
2021-09-13 15:45:13 +00:00
|
|
|
class FSSequentialFileTracingWrapper : public FSSequentialFileOwnerWrapper {
|
2020-07-13 23:35:29 +00:00
|
|
|
public:
|
2021-09-13 15:45:13 +00:00
|
|
|
FSSequentialFileTracingWrapper(std::unique_ptr<FSSequentialFile>&& t,
|
2021-01-25 22:35:45 +00:00
|
|
|
std::shared_ptr<IOTracer> io_tracer,
|
|
|
|
const std::string& file_name)
|
2021-09-13 15:45:13 +00:00
|
|
|
: FSSequentialFileOwnerWrapper(std::move(t)),
|
2020-07-13 23:35:29 +00:00
|
|
|
io_tracer_(io_tracer),
|
2021-03-15 11:32:24 +00:00
|
|
|
clock_(SystemClock::Default().get()),
|
2021-01-25 22:35:45 +00:00
|
|
|
file_name_(file_name) {}
|
2020-07-13 23:35:29 +00:00
|
|
|
|
|
|
|
~FSSequentialFileTracingWrapper() override {}
|
|
|
|
|
|
|
|
IOStatus Read(size_t n, const IOOptions& options, Slice* result,
|
|
|
|
char* scratch, IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus InvalidateCache(size_t offset, size_t length) override;
|
|
|
|
|
|
|
|
IOStatus PositionedRead(uint64_t offset, size_t n, const IOOptions& options,
|
|
|
|
Slice* result, char* scratch,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<IOTracer> io_tracer_;
|
2021-03-15 11:32:24 +00:00
|
|
|
SystemClock* clock_;
|
2021-01-25 22:35:45 +00:00
|
|
|
std::string file_name_;
|
2020-07-13 23:35:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// The FSSequentialFilePtr is a wrapper class that takes pointer to storage
|
|
|
|
// systems (such as posix filesystems). It overloads operator -> and returns a
|
|
|
|
// pointer of either FSSequentialFile or FSSequentialFileTracingWrapper based on
|
|
|
|
// whether tracing is enabled or not. It is added to bypass
|
|
|
|
// FSSequentialFileTracingWrapper when tracing is disabled.
|
|
|
|
class FSSequentialFilePtr {
|
|
|
|
public:
|
2020-08-27 18:20:08 +00:00
|
|
|
FSSequentialFilePtr() = delete;
|
2020-08-18 23:19:22 +00:00
|
|
|
FSSequentialFilePtr(std::unique_ptr<FSSequentialFile>&& fs,
|
2021-01-25 22:35:45 +00:00
|
|
|
const std::shared_ptr<IOTracer>& io_tracer,
|
|
|
|
const std::string& file_name)
|
2021-09-13 15:45:13 +00:00
|
|
|
: io_tracer_(io_tracer),
|
|
|
|
fs_tracer_(std::move(fs), io_tracer_,
|
2021-01-25 22:35:45 +00:00
|
|
|
file_name.substr(file_name.find_last_of("/\\") +
|
|
|
|
1) /* pass file name */) {}
|
2020-07-13 23:35:29 +00:00
|
|
|
|
|
|
|
FSSequentialFile* operator->() const {
|
|
|
|
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
|
2020-08-27 18:20:08 +00:00
|
|
|
return const_cast<FSSequentialFileTracingWrapper*>(&fs_tracer_);
|
2020-07-13 23:35:29 +00:00
|
|
|
} else {
|
2021-09-13 15:45:13 +00:00
|
|
|
return fs_tracer_.target();
|
2020-08-18 23:19:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FSSequentialFile* get() const {
|
|
|
|
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
|
2020-08-27 18:20:08 +00:00
|
|
|
return const_cast<FSSequentialFileTracingWrapper*>(&fs_tracer_);
|
2020-08-18 23:19:22 +00:00
|
|
|
} else {
|
2021-09-13 15:45:13 +00:00
|
|
|
return fs_tracer_.target();
|
2020-07-13 23:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<IOTracer> io_tracer_;
|
2020-08-27 18:20:08 +00:00
|
|
|
FSSequentialFileTracingWrapper fs_tracer_;
|
2020-07-13 23:35:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// FSRandomAccessFileTracingWrapper is a wrapper class above FSRandomAccessFile
|
|
|
|
// that forwards the call to the underlying storage system. It then invokes
|
|
|
|
// IOTracer to record file operations and other contextual information in a
|
|
|
|
// binary format for tracing. It overrides methods we are interested in tracing
|
|
|
|
// and extends FSRandomAccessFileWrapper, which forwards all methods that are
|
|
|
|
// not explicitly overridden.
|
2021-09-13 15:45:13 +00:00
|
|
|
class FSRandomAccessFileTracingWrapper : public FSRandomAccessFileOwnerWrapper {
|
2020-07-13 23:35:29 +00:00
|
|
|
public:
|
2021-09-13 15:45:13 +00:00
|
|
|
FSRandomAccessFileTracingWrapper(std::unique_ptr<FSRandomAccessFile>&& t,
|
2021-01-25 22:35:45 +00:00
|
|
|
std::shared_ptr<IOTracer> io_tracer,
|
|
|
|
const std::string& file_name)
|
2021-09-13 15:45:13 +00:00
|
|
|
: FSRandomAccessFileOwnerWrapper(std::move(t)),
|
2020-07-13 23:35:29 +00:00
|
|
|
io_tracer_(io_tracer),
|
2021-03-15 11:32:24 +00:00
|
|
|
clock_(SystemClock::Default().get()),
|
2021-01-25 22:35:45 +00:00
|
|
|
file_name_(file_name) {}
|
2020-07-13 23:35:29 +00:00
|
|
|
|
|
|
|
~FSRandomAccessFileTracingWrapper() override {}
|
|
|
|
|
|
|
|
IOStatus Read(uint64_t offset, size_t n, const IOOptions& options,
|
|
|
|
Slice* result, char* scratch,
|
|
|
|
IODebugContext* dbg) const override;
|
|
|
|
|
|
|
|
IOStatus MultiRead(FSReadRequest* reqs, size_t num_reqs,
|
|
|
|
const IOOptions& options, IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus Prefetch(uint64_t offset, size_t n, const IOOptions& options,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus InvalidateCache(size_t offset, size_t length) override;
|
|
|
|
|
Provide support for IOTracing for ReadAsync API (#9833)
Summary:
Same as title
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9833
Test Plan:
Add unit test and manually check the output of tracing logs
For fixed readahead_size it logs as:
```
Access Time : 193352113447923 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 15075 , IO Status: OK, Length: 12288, Offset: 659456
Access Time : 193352113465232 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 14425 , IO Status: OK, Length: 12288, Offset: 671744
Access Time : 193352113481539 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13062 , IO Status: OK, Length: 12288, Offset: 684032
Access Time : 193352113497692 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13649 , IO Status: OK, Length: 12288, Offset: 696320
Access Time : 193352113520043 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 19384 , IO Status: OK, Length: 12288, Offset: 708608
Access Time : 193352113538401 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 15406 , IO Status: OK, Length: 12288, Offset: 720896
Access Time : 193352113554855 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13670 , IO Status: OK, Length: 12288, Offset: 733184
Access Time : 193352113571624 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13855 , IO Status: OK, Length: 12288, Offset: 745472
Access Time : 193352113587924 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13953 , IO Status: OK, Length: 12288, Offset: 757760
Access Time : 193352113603285 , File Name: 000026.sst , File Operation: Prefetch , Latency: 59 , IO Status: Not implemented: Prefetch not supported, Length: 8868, Offset: 898349
```
For implicit readahead:
```
Access Time : 193351865156587 , File Name: 000026.sst , File Operation: Prefetch , Latency: 48 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 391174
Access Time : 193351865160354 , File Name: 000026.sst , File Operation: Prefetch , Latency: 51 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 395248
Access Time : 193351865164253 , File Name: 000026.sst , File Operation: Prefetch , Latency: 49 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 399322
Access Time : 193351865165461 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 222871 , IO Status: OK, Length: 135168, Offset: 401408
```
Reviewed By: anand1976
Differential Revision: D35601634
Pulled By: akankshamahajan15
fbshipit-source-id: 5a4f32a850af878efa0767bd5706380152a1f26e
2022-05-26 02:47:03 +00:00
|
|
|
IOStatus ReadAsync(FSReadRequest& req, const IOOptions& opts,
|
2024-02-16 17:14:55 +00:00
|
|
|
std::function<void(FSReadRequest&, void*)> cb,
|
Provide support for IOTracing for ReadAsync API (#9833)
Summary:
Same as title
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9833
Test Plan:
Add unit test and manually check the output of tracing logs
For fixed readahead_size it logs as:
```
Access Time : 193352113447923 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 15075 , IO Status: OK, Length: 12288, Offset: 659456
Access Time : 193352113465232 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 14425 , IO Status: OK, Length: 12288, Offset: 671744
Access Time : 193352113481539 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13062 , IO Status: OK, Length: 12288, Offset: 684032
Access Time : 193352113497692 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13649 , IO Status: OK, Length: 12288, Offset: 696320
Access Time : 193352113520043 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 19384 , IO Status: OK, Length: 12288, Offset: 708608
Access Time : 193352113538401 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 15406 , IO Status: OK, Length: 12288, Offset: 720896
Access Time : 193352113554855 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13670 , IO Status: OK, Length: 12288, Offset: 733184
Access Time : 193352113571624 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13855 , IO Status: OK, Length: 12288, Offset: 745472
Access Time : 193352113587924 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13953 , IO Status: OK, Length: 12288, Offset: 757760
Access Time : 193352113603285 , File Name: 000026.sst , File Operation: Prefetch , Latency: 59 , IO Status: Not implemented: Prefetch not supported, Length: 8868, Offset: 898349
```
For implicit readahead:
```
Access Time : 193351865156587 , File Name: 000026.sst , File Operation: Prefetch , Latency: 48 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 391174
Access Time : 193351865160354 , File Name: 000026.sst , File Operation: Prefetch , Latency: 51 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 395248
Access Time : 193351865164253 , File Name: 000026.sst , File Operation: Prefetch , Latency: 49 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 399322
Access Time : 193351865165461 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 222871 , IO Status: OK, Length: 135168, Offset: 401408
```
Reviewed By: anand1976
Differential Revision: D35601634
Pulled By: akankshamahajan15
fbshipit-source-id: 5a4f32a850af878efa0767bd5706380152a1f26e
2022-05-26 02:47:03 +00:00
|
|
|
void* cb_arg, void** io_handle, IOHandleDeleter* del_fn,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
2024-02-16 17:14:55 +00:00
|
|
|
void ReadAsyncCallback(FSReadRequest& req, void* cb_arg);
|
Provide support for IOTracing for ReadAsync API (#9833)
Summary:
Same as title
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9833
Test Plan:
Add unit test and manually check the output of tracing logs
For fixed readahead_size it logs as:
```
Access Time : 193352113447923 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 15075 , IO Status: OK, Length: 12288, Offset: 659456
Access Time : 193352113465232 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 14425 , IO Status: OK, Length: 12288, Offset: 671744
Access Time : 193352113481539 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13062 , IO Status: OK, Length: 12288, Offset: 684032
Access Time : 193352113497692 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13649 , IO Status: OK, Length: 12288, Offset: 696320
Access Time : 193352113520043 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 19384 , IO Status: OK, Length: 12288, Offset: 708608
Access Time : 193352113538401 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 15406 , IO Status: OK, Length: 12288, Offset: 720896
Access Time : 193352113554855 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13670 , IO Status: OK, Length: 12288, Offset: 733184
Access Time : 193352113571624 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13855 , IO Status: OK, Length: 12288, Offset: 745472
Access Time : 193352113587924 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13953 , IO Status: OK, Length: 12288, Offset: 757760
Access Time : 193352113603285 , File Name: 000026.sst , File Operation: Prefetch , Latency: 59 , IO Status: Not implemented: Prefetch not supported, Length: 8868, Offset: 898349
```
For implicit readahead:
```
Access Time : 193351865156587 , File Name: 000026.sst , File Operation: Prefetch , Latency: 48 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 391174
Access Time : 193351865160354 , File Name: 000026.sst , File Operation: Prefetch , Latency: 51 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 395248
Access Time : 193351865164253 , File Name: 000026.sst , File Operation: Prefetch , Latency: 49 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 399322
Access Time : 193351865165461 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 222871 , IO Status: OK, Length: 135168, Offset: 401408
```
Reviewed By: anand1976
Differential Revision: D35601634
Pulled By: akankshamahajan15
fbshipit-source-id: 5a4f32a850af878efa0767bd5706380152a1f26e
2022-05-26 02:47:03 +00:00
|
|
|
|
2020-07-13 23:35:29 +00:00
|
|
|
private:
|
|
|
|
std::shared_ptr<IOTracer> io_tracer_;
|
2021-03-15 11:32:24 +00:00
|
|
|
SystemClock* clock_;
|
2021-01-25 22:35:45 +00:00
|
|
|
// Stores file name instead of full path.
|
|
|
|
std::string file_name_;
|
Provide support for IOTracing for ReadAsync API (#9833)
Summary:
Same as title
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9833
Test Plan:
Add unit test and manually check the output of tracing logs
For fixed readahead_size it logs as:
```
Access Time : 193352113447923 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 15075 , IO Status: OK, Length: 12288, Offset: 659456
Access Time : 193352113465232 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 14425 , IO Status: OK, Length: 12288, Offset: 671744
Access Time : 193352113481539 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13062 , IO Status: OK, Length: 12288, Offset: 684032
Access Time : 193352113497692 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13649 , IO Status: OK, Length: 12288, Offset: 696320
Access Time : 193352113520043 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 19384 , IO Status: OK, Length: 12288, Offset: 708608
Access Time : 193352113538401 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 15406 , IO Status: OK, Length: 12288, Offset: 720896
Access Time : 193352113554855 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13670 , IO Status: OK, Length: 12288, Offset: 733184
Access Time : 193352113571624 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13855 , IO Status: OK, Length: 12288, Offset: 745472
Access Time : 193352113587924 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13953 , IO Status: OK, Length: 12288, Offset: 757760
Access Time : 193352113603285 , File Name: 000026.sst , File Operation: Prefetch , Latency: 59 , IO Status: Not implemented: Prefetch not supported, Length: 8868, Offset: 898349
```
For implicit readahead:
```
Access Time : 193351865156587 , File Name: 000026.sst , File Operation: Prefetch , Latency: 48 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 391174
Access Time : 193351865160354 , File Name: 000026.sst , File Operation: Prefetch , Latency: 51 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 395248
Access Time : 193351865164253 , File Name: 000026.sst , File Operation: Prefetch , Latency: 49 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 399322
Access Time : 193351865165461 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 222871 , IO Status: OK, Length: 135168, Offset: 401408
```
Reviewed By: anand1976
Differential Revision: D35601634
Pulled By: akankshamahajan15
fbshipit-source-id: 5a4f32a850af878efa0767bd5706380152a1f26e
2022-05-26 02:47:03 +00:00
|
|
|
|
|
|
|
struct ReadAsyncCallbackInfo {
|
|
|
|
uint64_t start_time_;
|
2024-02-16 17:14:55 +00:00
|
|
|
std::function<void(FSReadRequest&, void*)> cb_;
|
Provide support for IOTracing for ReadAsync API (#9833)
Summary:
Same as title
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9833
Test Plan:
Add unit test and manually check the output of tracing logs
For fixed readahead_size it logs as:
```
Access Time : 193352113447923 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 15075 , IO Status: OK, Length: 12288, Offset: 659456
Access Time : 193352113465232 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 14425 , IO Status: OK, Length: 12288, Offset: 671744
Access Time : 193352113481539 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13062 , IO Status: OK, Length: 12288, Offset: 684032
Access Time : 193352113497692 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13649 , IO Status: OK, Length: 12288, Offset: 696320
Access Time : 193352113520043 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 19384 , IO Status: OK, Length: 12288, Offset: 708608
Access Time : 193352113538401 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 15406 , IO Status: OK, Length: 12288, Offset: 720896
Access Time : 193352113554855 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13670 , IO Status: OK, Length: 12288, Offset: 733184
Access Time : 193352113571624 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13855 , IO Status: OK, Length: 12288, Offset: 745472
Access Time : 193352113587924 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 13953 , IO Status: OK, Length: 12288, Offset: 757760
Access Time : 193352113603285 , File Name: 000026.sst , File Operation: Prefetch , Latency: 59 , IO Status: Not implemented: Prefetch not supported, Length: 8868, Offset: 898349
```
For implicit readahead:
```
Access Time : 193351865156587 , File Name: 000026.sst , File Operation: Prefetch , Latency: 48 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 391174
Access Time : 193351865160354 , File Name: 000026.sst , File Operation: Prefetch , Latency: 51 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 395248
Access Time : 193351865164253 , File Name: 000026.sst , File Operation: Prefetch , Latency: 49 , IO Status: Not implemented: Prefetch not supported, Length: 12266, Offset: 399322
Access Time : 193351865165461 , File Name: 000026.sst , File Operation: ReadAsync , Latency: 222871 , IO Status: OK, Length: 135168, Offset: 401408
```
Reviewed By: anand1976
Differential Revision: D35601634
Pulled By: akankshamahajan15
fbshipit-source-id: 5a4f32a850af878efa0767bd5706380152a1f26e
2022-05-26 02:47:03 +00:00
|
|
|
void* cb_arg_;
|
|
|
|
std::string file_op_;
|
|
|
|
};
|
2020-07-13 23:35:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// The FSRandomAccessFilePtr is a wrapper class that takes pointer to storage
|
|
|
|
// systems (such as posix filesystems). It overloads operator -> and returns a
|
|
|
|
// pointer of either FSRandomAccessFile or FSRandomAccessFileTracingWrapper
|
|
|
|
// based on whether tracing is enabled or not. It is added to bypass
|
|
|
|
// FSRandomAccessFileTracingWrapper when tracing is disabled.
|
|
|
|
class FSRandomAccessFilePtr {
|
|
|
|
public:
|
2020-08-27 18:20:08 +00:00
|
|
|
FSRandomAccessFilePtr(std::unique_ptr<FSRandomAccessFile>&& fs,
|
2021-01-25 22:35:45 +00:00
|
|
|
const std::shared_ptr<IOTracer>& io_tracer,
|
|
|
|
const std::string& file_name)
|
2021-09-13 15:45:13 +00:00
|
|
|
: io_tracer_(io_tracer),
|
|
|
|
fs_tracer_(std::move(fs), io_tracer_,
|
2021-01-25 22:35:45 +00:00
|
|
|
file_name.substr(file_name.find_last_of("/\\") +
|
|
|
|
1) /* pass file name */) {}
|
2020-07-13 23:35:29 +00:00
|
|
|
|
|
|
|
FSRandomAccessFile* operator->() const {
|
|
|
|
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
|
2020-08-27 18:20:08 +00:00
|
|
|
return const_cast<FSRandomAccessFileTracingWrapper*>(&fs_tracer_);
|
2020-07-13 23:35:29 +00:00
|
|
|
} else {
|
2021-09-13 15:45:13 +00:00
|
|
|
return fs_tracer_.target();
|
2020-08-27 18:20:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FSRandomAccessFile* get() const {
|
|
|
|
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
|
|
|
|
return const_cast<FSRandomAccessFileTracingWrapper*>(&fs_tracer_);
|
|
|
|
} else {
|
2021-09-13 15:45:13 +00:00
|
|
|
return fs_tracer_.target();
|
2020-07-13 23:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<IOTracer> io_tracer_;
|
2020-08-27 18:20:08 +00:00
|
|
|
FSRandomAccessFileTracingWrapper fs_tracer_;
|
2020-07-13 23:35:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// FSWritableFileTracingWrapper is a wrapper class above FSWritableFile that
|
|
|
|
// forwards the call to the underlying storage system. It then invokes IOTracer
|
|
|
|
// to record file operations and other contextual information in a binary format
|
|
|
|
// for tracing. It overrides methods we are interested in tracing and extends
|
|
|
|
// FSWritableFileWrapper, which forwards all methods that are not explicitly
|
|
|
|
// overridden.
|
2021-09-13 15:45:13 +00:00
|
|
|
class FSWritableFileTracingWrapper : public FSWritableFileOwnerWrapper {
|
2020-07-13 23:35:29 +00:00
|
|
|
public:
|
2021-09-13 15:45:13 +00:00
|
|
|
FSWritableFileTracingWrapper(std::unique_ptr<FSWritableFile>&& t,
|
2021-01-25 22:35:45 +00:00
|
|
|
std::shared_ptr<IOTracer> io_tracer,
|
|
|
|
const std::string& file_name)
|
2021-09-13 15:45:13 +00:00
|
|
|
: FSWritableFileOwnerWrapper(std::move(t)),
|
2021-01-25 22:35:45 +00:00
|
|
|
io_tracer_(io_tracer),
|
2021-03-15 11:32:24 +00:00
|
|
|
clock_(SystemClock::Default().get()),
|
2021-01-25 22:35:45 +00:00
|
|
|
file_name_(file_name) {}
|
2020-07-13 23:35:29 +00:00
|
|
|
|
|
|
|
~FSWritableFileTracingWrapper() override {}
|
|
|
|
|
|
|
|
IOStatus Append(const Slice& data, const IOOptions& options,
|
|
|
|
IODebugContext* dbg) override;
|
2020-09-24 02:00:30 +00:00
|
|
|
IOStatus Append(const Slice& data, const IOOptions& options,
|
|
|
|
const DataVerificationInfo& /*verification_info*/,
|
|
|
|
IODebugContext* dbg) override {
|
|
|
|
return Append(data, options, dbg);
|
|
|
|
}
|
2020-07-13 23:35:29 +00:00
|
|
|
|
|
|
|
IOStatus PositionedAppend(const Slice& data, uint64_t offset,
|
|
|
|
const IOOptions& options,
|
|
|
|
IODebugContext* dbg) override;
|
2020-09-24 02:00:30 +00:00
|
|
|
IOStatus PositionedAppend(const Slice& data, uint64_t offset,
|
|
|
|
const IOOptions& options,
|
|
|
|
const DataVerificationInfo& /*verification_info*/,
|
|
|
|
IODebugContext* dbg) override {
|
|
|
|
return PositionedAppend(data, offset, options, dbg);
|
|
|
|
}
|
2020-07-13 23:35:29 +00:00
|
|
|
|
|
|
|
IOStatus Truncate(uint64_t size, const IOOptions& options,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus Close(const IOOptions& options, IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
uint64_t GetFileSize(const IOOptions& options, IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus InvalidateCache(size_t offset, size_t length) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<IOTracer> io_tracer_;
|
2021-03-15 11:32:24 +00:00
|
|
|
SystemClock* clock_;
|
2021-01-25 22:35:45 +00:00
|
|
|
// Stores file name instead of full path.
|
|
|
|
std::string file_name_;
|
2020-07-13 23:35:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// The FSWritableFilePtr is a wrapper class that takes pointer to storage
|
|
|
|
// systems (such as posix filesystems). It overloads operator -> and returns a
|
|
|
|
// pointer of either FSWritableFile or FSWritableFileTracingWrapper based on
|
|
|
|
// whether tracing is enabled or not. It is added to bypass
|
|
|
|
// FSWritableFileTracingWrapper when tracing is disabled.
|
|
|
|
class FSWritableFilePtr {
|
|
|
|
public:
|
2020-09-08 17:49:01 +00:00
|
|
|
FSWritableFilePtr(std::unique_ptr<FSWritableFile>&& fs,
|
2021-01-25 22:35:45 +00:00
|
|
|
const std::shared_ptr<IOTracer>& io_tracer,
|
|
|
|
const std::string& file_name)
|
2021-09-13 15:45:13 +00:00
|
|
|
: io_tracer_(io_tracer) {
|
2021-01-25 22:35:45 +00:00
|
|
|
fs_tracer_.reset(new FSWritableFileTracingWrapper(
|
2021-09-13 15:45:13 +00:00
|
|
|
std::move(fs), io_tracer_,
|
2021-01-25 22:35:45 +00:00
|
|
|
file_name.substr(file_name.find_last_of("/\\") +
|
|
|
|
1) /* pass file name */));
|
2020-09-08 17:49:01 +00:00
|
|
|
}
|
2020-07-13 23:35:29 +00:00
|
|
|
|
|
|
|
FSWritableFile* operator->() const {
|
|
|
|
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
|
2020-09-08 17:49:01 +00:00
|
|
|
return fs_tracer_.get();
|
2020-07-13 23:35:29 +00:00
|
|
|
} else {
|
2021-09-13 15:45:13 +00:00
|
|
|
return fs_tracer_->target();
|
2020-09-08 17:49:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FSWritableFile* get() const {
|
|
|
|
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
|
|
|
|
return fs_tracer_.get();
|
2021-09-13 15:45:13 +00:00
|
|
|
} else if (fs_tracer_) {
|
|
|
|
return fs_tracer_->target();
|
2020-09-08 17:49:01 +00:00
|
|
|
} else {
|
2021-09-13 15:45:13 +00:00
|
|
|
return nullptr;
|
2020-07-13 23:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-08 17:49:01 +00:00
|
|
|
void reset() {
|
|
|
|
fs_tracer_.reset();
|
|
|
|
io_tracer_ = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-07-13 23:35:29 +00:00
|
|
|
private:
|
|
|
|
std::shared_ptr<IOTracer> io_tracer_;
|
2020-09-08 17:49:01 +00:00
|
|
|
std::unique_ptr<FSWritableFileTracingWrapper> fs_tracer_;
|
2020-07-13 23:35:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// FSRandomRWFileTracingWrapper is a wrapper class above FSRandomRWFile that
|
|
|
|
// forwards the call to the underlying storage system. It then invokes IOTracer
|
|
|
|
// to record file operations and other contextual information in a binary format
|
|
|
|
// for tracing. It overrides methods we are interested in tracing and extends
|
|
|
|
// FSRandomRWFileWrapper, which forwards all methods that are not explicitly
|
|
|
|
// overridden.
|
2021-09-13 15:45:13 +00:00
|
|
|
class FSRandomRWFileTracingWrapper : public FSRandomRWFileOwnerWrapper {
|
2020-07-13 23:35:29 +00:00
|
|
|
public:
|
2021-09-13 15:45:13 +00:00
|
|
|
FSRandomRWFileTracingWrapper(std::unique_ptr<FSRandomRWFile>&& t,
|
2021-01-25 22:35:45 +00:00
|
|
|
std::shared_ptr<IOTracer> io_tracer,
|
|
|
|
const std::string& file_name)
|
2021-09-13 15:45:13 +00:00
|
|
|
: FSRandomRWFileOwnerWrapper(std::move(t)),
|
2021-01-25 22:35:45 +00:00
|
|
|
io_tracer_(io_tracer),
|
2021-03-15 11:32:24 +00:00
|
|
|
clock_(SystemClock::Default().get()),
|
2021-01-25 22:35:45 +00:00
|
|
|
file_name_(file_name) {}
|
2020-07-13 23:35:29 +00:00
|
|
|
|
|
|
|
~FSRandomRWFileTracingWrapper() override {}
|
|
|
|
|
|
|
|
IOStatus Write(uint64_t offset, const Slice& data, const IOOptions& options,
|
|
|
|
IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus Read(uint64_t offset, size_t n, const IOOptions& options,
|
|
|
|
Slice* result, char* scratch,
|
|
|
|
IODebugContext* dbg) const override;
|
|
|
|
|
2020-10-14 17:14:12 +00:00
|
|
|
IOStatus Flush(const IOOptions& options, IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus Close(const IOOptions& options, IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus Sync(const IOOptions& options, IODebugContext* dbg) override;
|
|
|
|
|
|
|
|
IOStatus Fsync(const IOOptions& options, IODebugContext* dbg) override;
|
|
|
|
|
2020-07-13 23:35:29 +00:00
|
|
|
private:
|
|
|
|
std::shared_ptr<IOTracer> io_tracer_;
|
2021-03-15 11:32:24 +00:00
|
|
|
SystemClock* clock_;
|
2021-01-25 22:35:45 +00:00
|
|
|
// Stores file name instead of full path.
|
|
|
|
std::string file_name_;
|
2020-07-13 23:35:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// The FSRandomRWFilePtr is a wrapper class that takes pointer to storage
|
|
|
|
// systems (such as posix filesystems). It overloads operator -> and returns a
|
|
|
|
// pointer of either FSRandomRWFile or FSRandomRWFileTracingWrapper based on
|
|
|
|
// whether tracing is enabled or not. It is added to bypass
|
|
|
|
// FSRandomRWFileTracingWrapper when tracing is disabled.
|
|
|
|
class FSRandomRWFilePtr {
|
|
|
|
public:
|
2020-09-08 19:20:20 +00:00
|
|
|
FSRandomRWFilePtr(std::unique_ptr<FSRandomRWFile>&& fs,
|
2021-01-25 22:35:45 +00:00
|
|
|
std::shared_ptr<IOTracer> io_tracer,
|
|
|
|
const std::string& file_name)
|
2021-09-13 15:45:13 +00:00
|
|
|
: io_tracer_(io_tracer),
|
|
|
|
fs_tracer_(std::move(fs), io_tracer_,
|
2021-01-25 22:35:45 +00:00
|
|
|
file_name.substr(file_name.find_last_of("/\\") +
|
|
|
|
1) /* pass file name */) {}
|
2020-07-13 23:35:29 +00:00
|
|
|
|
|
|
|
FSRandomRWFile* operator->() const {
|
|
|
|
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
|
2020-09-08 19:20:20 +00:00
|
|
|
return const_cast<FSRandomRWFileTracingWrapper*>(&fs_tracer_);
|
2020-07-13 23:35:29 +00:00
|
|
|
} else {
|
2021-09-13 15:45:13 +00:00
|
|
|
return fs_tracer_.target();
|
2020-09-08 19:20:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FSRandomRWFile* get() const {
|
|
|
|
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
|
|
|
|
return const_cast<FSRandomRWFileTracingWrapper*>(&fs_tracer_);
|
|
|
|
} else {
|
2021-09-13 15:45:13 +00:00
|
|
|
return fs_tracer_.target();
|
2020-07-13 23:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<IOTracer> io_tracer_;
|
2020-09-08 19:20:20 +00:00
|
|
|
FSRandomRWFileTracingWrapper fs_tracer_;
|
2020-07-13 23:35:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|