]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/lookup_key.h
update source to Ceph Pacific 16.2.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 #include "rocksdb/db.h"
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 Slice user_key() const {
41 return Slice(kstart_, static_cast<size_t>(end_ - kstart_ - 8));
42 }
43
44 private:
45 // We construct a char array of the form:
46 // klength varint32 <-- start_
47 // userkey char[klength] <-- kstart_
48 // tag uint64
49 // <-- end_
50 // The array is a suitable MemTable key.
51 // The suffix starting with "userkey" can be used as an InternalKey.
52 const char* start_;
53 const char* kstart_;
54 const char* end_;
55 char space_[200]; // Avoid allocation for short keys
56
57 // No copying allowed
58 LookupKey(const LookupKey&);
59 void operator=(const LookupKey&);
60 };
61
62 inline LookupKey::~LookupKey() {
63 if (start_ != space_) delete[] start_;
64 }
65
66 } // namespace ROCKSDB_NAMESPACE