提交 b09c018b 编写于 作者: S Sagar Vemuri 提交者: Facebook Github Bot

Add comments to trace_replay.h (#5359)

Summary:
Add file, class, and function level comments in trace_replay.h
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5359

Differential Revision: D15505318

Pulled By: sagar0

fbshipit-source-id: 181e3d4ea805fd9a33f91b89e123bbd0c1ead2ce
上级 a466120c
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
namespace rocksdb { namespace rocksdb {
// This file contains Tracer and Replayer classes that enable capturing and
// replaying RocksDB traces.
class ColumnFamilyHandle; class ColumnFamilyHandle;
class ColumnFamilyData; class ColumnFamilyData;
class DB; class DB;
...@@ -29,6 +32,7 @@ const unsigned int kTracePayloadLengthSize = 4; ...@@ -29,6 +32,7 @@ const unsigned int kTracePayloadLengthSize = 4;
const unsigned int kTraceMetadataSize = const unsigned int kTraceMetadataSize =
kTraceTimestampSize + kTraceTypeSize + kTracePayloadLengthSize; kTraceTimestampSize + kTraceTypeSize + kTracePayloadLengthSize;
// Supported Trace types.
enum TraceType : char { enum TraceType : char {
kTraceBegin = 1, kTraceBegin = 1,
kTraceEnd = 2, kTraceEnd = 2,
...@@ -36,13 +40,16 @@ enum TraceType : char { ...@@ -36,13 +40,16 @@ enum TraceType : char {
kTraceGet = 4, kTraceGet = 4,
kTraceIteratorSeek = 5, kTraceIteratorSeek = 5,
kTraceIteratorSeekForPrev = 6, kTraceIteratorSeekForPrev = 6,
// All trace types should be added before kTraceMax
kTraceMax, kTraceMax,
}; };
// TODO: This should also be made part of public interface to help users build // TODO: This should also be made part of public interface to help users build
// custom TracerReaders and TraceWriters. // custom TracerReaders and TraceWriters.
//
// The data structure that defines a single trace.
struct Trace { struct Trace {
uint64_t ts; uint64_t ts; // timestamp
TraceType type; TraceType type;
std::string payload; std::string payload;
...@@ -53,25 +60,47 @@ struct Trace { ...@@ -53,25 +60,47 @@ struct Trace {
} }
}; };
// Trace RocksDB operations using a TraceWriter. // Tracer captures all RocksDB operations using a user-provided TraceWriter.
// Every RocksDB operation is written as a single trace. Each trace will have a
// timestamp and type, followed by the trace payload.
class Tracer { class Tracer {
public: public:
Tracer(Env* env, const TraceOptions& trace_options, Tracer(Env* env, const TraceOptions& trace_options,
std::unique_ptr<TraceWriter>&& trace_writer); std::unique_ptr<TraceWriter>&& trace_writer);
~Tracer(); ~Tracer();
// Trace all write operations -- Put, Merge, Delete, SingleDelete, Write
Status Write(WriteBatch* write_batch); Status Write(WriteBatch* write_batch);
// Trace Get operations.
Status Get(ColumnFamilyHandle* cfname, const Slice& key); Status Get(ColumnFamilyHandle* cfname, const Slice& key);
// Trace Iterators.
Status IteratorSeek(const uint32_t& cf_id, const Slice& key); Status IteratorSeek(const uint32_t& cf_id, const Slice& key);
Status IteratorSeekForPrev(const uint32_t& cf_id, const Slice& key); Status IteratorSeekForPrev(const uint32_t& cf_id, const Slice& key);
// Returns true if the trace is over the configured max trace file limit.
// False otherwise.
bool IsTraceFileOverMax(); bool IsTraceFileOverMax();
// Writes a trace footer at the end of the tracing
Status Close(); Status Close();
private: private:
// Write a trace header at the beginning, typically on initiating a trace,
// with some metadata like a magic number, trace version, RocksDB version, and
// trace format.
Status WriteHeader(); Status WriteHeader();
// Write a trace footer, typically on ending a trace, with some metadata.
Status WriteFooter(); Status WriteFooter();
// Write a single trace using the provided TraceWriter to the underlying
// system, say, a filesystem or a streaming service.
Status WriteTrace(const Trace& trace); Status WriteTrace(const Trace& trace);
// Helps in filtering and sampling of traces.
// Returns true if a trace should be skipped, false otherwise.
bool ShouldSkipTrace(const TraceType& type); bool ShouldSkipTrace(const TraceType& type);
Env* env_; Env* env_;
...@@ -80,14 +109,24 @@ class Tracer { ...@@ -80,14 +109,24 @@ class Tracer {
uint64_t trace_request_count_; uint64_t trace_request_count_;
}; };
// Replay RocksDB operations from a trace. // Replayer helps to replay the captured RocksDB operations, using a user
// provided TraceReader.
// The Replayer is instantiated via db_bench today, on using "replay" benchmark.
class Replayer { class Replayer {
public: public:
Replayer(DB* db, const std::vector<ColumnFamilyHandle*>& handles, Replayer(DB* db, const std::vector<ColumnFamilyHandle*>& handles,
std::unique_ptr<TraceReader>&& reader); std::unique_ptr<TraceReader>&& reader);
~Replayer(); ~Replayer();
// Replay all the traces from the provided trace stream, taking the delay
// between the traces into consideration.
Status Replay(); Status Replay();
// Enables fast forwarding a replay by reducing the delay between the ingested
// traces.
// fast_forward : Rate of replay speedup.
// If 1, replay the operations at the same rate as in the trace stream.
// If > 1, speed up the replay by this amount.
Status SetFastForward(uint32_t fast_forward); Status SetFastForward(uint32_t fast_forward);
private: private:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册