]>
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.
13 #include "rocksdb/db.h"
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 Slice
user_key() const {
41 return Slice(kstart_
, static_cast<size_t>(end_
- kstart_
- 8));
45 // We construct a char array of the form:
46 // klength varint32 <-- start_
47 // userkey char[klength] <-- kstart_
50 // The array is a suitable MemTable key.
51 // The suffix starting with "userkey" can be used as an InternalKey.
55 char space_
[200]; // Avoid allocation for short keys
58 LookupKey(const LookupKey
&);
59 void operator=(const LookupKey
&);
62 inline LookupKey::~LookupKey() {
63 if (start_
!= space_
) delete[] start_
;
66 } // namespace ROCKSDB_NAMESPACE