]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/lookup_key.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / db / lookup_key.h
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 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
9
10 #pragma once
11 #include <string>
12 #include <utility>
13
14 #include "rocksdb/slice.h"
15 #include "rocksdb/types.h"
16
17 namespace ROCKSDB_NAMESPACE {
18
19 // A helper class useful for DBImpl::Get()
20 class LookupKey {
21 public:
22 // Initialize *this for looking up user_key at a snapshot with
23 // the specified sequence number.
24 LookupKey(const Slice& _user_key, SequenceNumber sequence,
25 const Slice* ts = nullptr);
26
27 ~LookupKey();
28
29 // Return a key suitable for lookup in a MemTable.
30 Slice memtable_key() const {
31 return Slice(start_, static_cast<size_t>(end_ - start_));
32 }
33
34 // Return an internal key (suitable for passing to an internal iterator)
35 Slice internal_key() const {
36 return Slice(kstart_, static_cast<size_t>(end_ - kstart_));
37 }
38
39 // Return the user key.
40 // If user-defined timestamp is enabled, then timestamp is included in the
41 // result.
42 Slice user_key() const {
43 return Slice(kstart_, static_cast<size_t>(end_ - kstart_ - 8));
44 }
45
46 private:
47 // We construct a char array of the form:
48 // klength varint32 <-- start_
49 // userkey char[klength] <-- kstart_
50 // tag uint64
51 // <-- end_
52 // The array is a suitable MemTable key.
53 // The suffix starting with "userkey" can be used as an InternalKey.
54 const char* start_;
55 const char* kstart_;
56 const char* end_;
57 char space_[200]; // Avoid allocation for short keys
58
59 // No copying allowed
60 LookupKey(const LookupKey&);
61 void operator=(const LookupKey&);
62 };
63
64 inline LookupKey::~LookupKey() {
65 if (start_ != space_) delete[] start_;
66 }
67
68 } // namespace ROCKSDB_NAMESPACE