]>
git.proxmox.com Git - ceph.git/blob - 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).
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.
14 #include "rocksdb/slice.h"
15 #include "rocksdb/types.h"
17 namespace ROCKSDB_NAMESPACE
{
19 // A helper class useful for DBImpl::Get()
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);
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_
));
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_
));
39 // Return the user key.
40 // If user-defined timestamp is enabled, then timestamp is included in the
42 Slice
user_key() const {
43 return Slice(kstart_
, static_cast<size_t>(end_
- kstart_
- 8));
47 // We construct a char array of the form:
48 // klength varint32 <-- start_
49 // userkey char[klength] <-- kstart_
52 // The array is a suitable MemTable key.
53 // The suffix starting with "userkey" can be used as an InternalKey.
57 char space_
[200]; // Avoid allocation for short keys
60 LookupKey(const LookupKey
&);
61 void operator=(const LookupKey
&);
64 inline LookupKey::~LookupKey() {
65 if (start_
!= space_
) delete[] start_
;
68 } // namespace ROCKSDB_NAMESPACE