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/trace_reader_writer.h"
17 class ColumnFamilyHandle
;
18 class ColumnFamilyData
;
24 const std::string kTraceMagic
= "feedcafedeadbeef";
25 const unsigned int kTraceTimestampSize
= 8;
26 const unsigned int kTraceTypeSize
= 1;
27 const unsigned int kTracePayloadLengthSize
= 4;
28 const unsigned int kTraceMetadataSize
=
29 kTraceTimestampSize
+ kTraceTypeSize
+ kTracePayloadLengthSize
;
31 enum TraceType
: char {
36 kTraceIteratorSeek
= 5,
37 kTraceIteratorSeekForPrev
= 6,
41 // TODO: This should also be made part of public interface to help users build
42 // custom TracerReaders and TraceWriters.
55 // Trace RocksDB operations using a TraceWriter.
58 Tracer(Env
* env
, std::unique_ptr
<TraceWriter
>&& trace_writer
);
61 Status
Write(WriteBatch
* write_batch
);
62 Status
Get(ColumnFamilyHandle
* cfname
, const Slice
& key
);
63 Status
IteratorSeek(const uint32_t& cf_id
, const Slice
& key
);
64 Status
IteratorSeekForPrev(const uint32_t& cf_id
, const Slice
& key
);
71 Status
WriteTrace(const Trace
& trace
);
74 unique_ptr
<TraceWriter
> trace_writer_
;
77 // Replay RocksDB operations from a trace.
80 Replayer(DB
* db
, const std::vector
<ColumnFamilyHandle
*>& handles
,
81 std::unique_ptr
<TraceReader
>&& reader
);
87 Status
ReadHeader(Trace
* header
);
88 Status
ReadFooter(Trace
* footer
);
89 Status
ReadTrace(Trace
* trace
);
92 std::unique_ptr
<TraceReader
> trace_reader_
;
93 std::unordered_map
<uint32_t, ColumnFamilyHandle
*> cf_map_
;
96 } // namespace rocksdb