Storage Engine API
kv_prefix.h
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include "mongo/bson/bsonelement.h"
32 #include "mongo/bson/util/builder.h"
33 #include "mongo/db/namespace_string.h"
35 #include "mongo/stdx/mutex.h"
36 
37 namespace mongo {
38 
44 class KVPrefix {
45 public:
46  // Represents a table that is not grouped and should not have its keys prefixed.
47  static const KVPrefix kNotPrefixed;
48 
49  bool isPrefixed() const {
50  return _value >= 0;
51  }
52 
53  int64_t toBSONValue() const {
54  return _value;
55  }
56 
57  int64_t repr() const {
58  return _value;
59  }
60 
61  std::string toString() const;
62 
63  inline bool operator<(const KVPrefix& rhs) const {
64  return _value < rhs._value;
65  }
66 
67  inline bool operator==(const KVPrefix& rhs) const {
68  return _value == rhs._value;
69  }
70 
71  inline bool operator!=(const KVPrefix& rhs) const {
72  return _value != rhs._value;
73  }
74 
75  static KVPrefix fromBSONElement(const BSONElement value);
76 
77  static void setLargestPrefix(KVPrefix largestPrefix);
78 
84  static KVPrefix getNextPrefix(const NamespaceString& ns);
85 
90 
91 private:
92  explicit KVPrefix(int64_t value) : _value(value) {}
93  int64_t _value;
94 
95  static stdx::mutex _nextValueMutex;
96  static int64_t _nextValue;
97 };
98 
99 inline std::ostream& operator<<(std::ostream& s, const KVPrefix& prefix) {
100  return (s << prefix.toString());
101 }
102 }
std::string toString() const
Definition: kv_prefix.cpp:36
bool operator<(const KVPrefix &rhs) const
Definition: kv_prefix.h:63
Collection *const const NamespaceString & ns
Definition: collection_info_cache_impl.cpp:53
bool operator!=(const KVPrefix &rhs) const
Definition: kv_prefix.h:71
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
bool isPrefixed() const
Definition: kv_prefix.h:49
bool operator==(const KVPrefix &rhs) const
Definition: kv_prefix.h:67
KVPrefix(int64_t value)
Definition: kv_prefix.h:92
static int64_t _nextValue
Definition: kv_prefix.h:96
static KVPrefix fromBSONElement(const BSONElement value)
Definition: kv_prefix.cpp:43
static void setLargestPrefix(KVPrefix largestPrefix)
Definition: kv_prefix.cpp:51
static const KVPrefix kNotPrefixed
Definition: kv_prefix.h:47
std::ostream & operator<<(std::ostream &stream, const IndexKeyEntry &entry)
Definition: index_entry_comparison.cpp:37
int64_t toBSONValue() const
Definition: kv_prefix.h:53
static stdx::mutex _nextValueMutex
Definition: kv_prefix.h:95
static KVPrefix getNextPrefix(const NamespaceString &ns)
Returns &#39;KVPrefix::kNotPrefixed&#39; if &#39;storageGlobalParams.groupCollections&#39; is false or the input &#39;ns&#39;...
Definition: kv_prefix.cpp:60
static KVPrefix generateNextPrefix()
Unconditionally returns a new prefix.
Definition: kv_prefix.cpp:68
A KVPrefix may be prepended to the keys of entries in an underlying KV store.
Definition: kv_prefix.h:44
int64_t _value
Definition: kv_prefix.h:93
int64_t repr() const
Definition: kv_prefix.h:57