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).
5 
6 #pragma once
7 
8 #include <stdint.h>
9 #include "rocksdb/slice.h"
10 
11 namespace ROCKSDB_NAMESPACE {
12 
13 // Define all public custom types here.
14 
15 // Represents a sequence number in a WAL file.
16 typedef uint64_t SequenceNumber;
17 
18 const SequenceNumber kMinUnCommittedSeq = 1;  // 0 is always committed
19 
20 // User-oriented representation of internal key types.
21 enum EntryType {
22   kEntryPut,
23   kEntryDelete,
24   kEntrySingleDelete,
25   kEntryMerge,
26   kEntryRangeDeletion,
27   kEntryBlobIndex,
28   kEntryOther,
29 };
30 
31 // <user key, sequence number, and entry type> tuple.
32 struct FullKey {
33   Slice user_key;
34   SequenceNumber sequence;
35   EntryType type;
36 
FullKeyFullKey37   FullKey() : sequence(0) {}  // Intentionally left uninitialized (for speed)
FullKeyFullKey38   FullKey(const Slice& u, const SequenceNumber& seq, EntryType t)
39       : user_key(u), sequence(seq), type(t) {}
40   std::string DebugString(bool hex = false) const;
41 
clearFullKey42   void clear() {
43     user_key.clear();
44     sequence = 0;
45     type = EntryType::kEntryPut;
46   }
47 };
48 
49 // Parse slice representing internal key to FullKey
50 // Parsed FullKey is valid for as long as the memory pointed to by
51 // internal_key is alive.
52 bool ParseFullKey(const Slice& internal_key, FullKey* result);
53 
54 }  // namespace ROCKSDB_NAMESPACE
55