1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
9 #include <unordered_map>
12 #include "rocksdb/env.h"
13 #include "rocksdb/options.h"
14 #include "rocksdb/trace_reader_writer.h"
18 class ColumnFamilyHandle
;
19 class ColumnFamilyData
;
25 extern const std::string kTraceMagic
;
26 const unsigned int kTraceTimestampSize
= 8;
27 const unsigned int kTraceTypeSize
= 1;
28 const unsigned int kTracePayloadLengthSize
= 4;
29 const unsigned int kTraceMetadataSize
=
30 kTraceTimestampSize
+ kTraceTypeSize
+ kTracePayloadLengthSize
;
32 enum TraceType
: char {
37 kTraceIteratorSeek
= 5,
38 kTraceIteratorSeekForPrev
= 6,
42 // TODO: This should also be made part of public interface to help users build
43 // custom TracerReaders and TraceWriters.
56 // Trace RocksDB operations using a TraceWriter.
59 Tracer(Env
* env
, const TraceOptions
& trace_options
,
60 std::unique_ptr
<TraceWriter
>&& trace_writer
);
63 Status
Write(WriteBatch
* write_batch
);
64 Status
Get(ColumnFamilyHandle
* cfname
, const Slice
& key
);
65 Status
IteratorSeek(const uint32_t& cf_id
, const Slice
& key
);
66 Status
IteratorSeekForPrev(const uint32_t& cf_id
, const Slice
& key
);
67 bool IsTraceFileOverMax();
74 Status
WriteTrace(const Trace
& trace
);
75 bool ShouldSkipTrace(const TraceType
& type
);
78 TraceOptions trace_options_
;
79 std::unique_ptr
<TraceWriter
> trace_writer_
;
80 uint64_t trace_request_count_
;
83 // Replay RocksDB operations from a trace.
86 Replayer(DB
* db
, const std::vector
<ColumnFamilyHandle
*>& handles
,
87 std::unique_ptr
<TraceReader
>&& reader
);
93 Status
ReadHeader(Trace
* header
);
94 Status
ReadFooter(Trace
* footer
);
95 Status
ReadTrace(Trace
* trace
);
98 std::unique_ptr
<TraceReader
> trace_reader_
;
99 std::unordered_map
<uint32_t, ColumnFamilyHandle
*> cf_map_
;
102 } // namespace rocksdb