Storage Engine API
namespace_index.h
Go to the documentation of this file.
1 // namespace_index.h
2 
31 #pragma once
32 
33 #include <list>
34 #include <string>
35 
36 #include "mongo/base/disallow_copying.h"
40 
41 namespace mongo {
42 
43 class NamespaceDetails;
44 class NamespaceHashTable;
45 class OperationContext;
46 
47 /* NamespaceIndex is the ".ns" file you see in the data directory. It is the "system catalog"
48  if you will: at least the core parts. (Additional info in system.* collections.)
49 */
52 
53 public:
54  NamespaceIndex(OperationContext* opCtx, const std::string& dir, const std::string& database);
56 
60  void close(OperationContext* opCtx) {
61  LockMongoFilesExclusive lock(opCtx);
62  _f.close(opCtx);
63  }
64 
65  /* returns true if the file represented by this file exists on disk */
66  bool pathExists() const;
67 
68  void init(OperationContext* opCtx);
69 
70  void add_ns(OperationContext* opCtx, StringData ns, const DiskLoc& loc, bool capped);
71  void add_ns(OperationContext* opCtx, StringData ns, const NamespaceDetails* details);
72  void add_ns(OperationContext* opCtx, const Namespace& ns, const NamespaceDetails* details);
73 
74  NamespaceDetails* details(StringData ns) const;
75  NamespaceDetails* details(const Namespace& ns) const;
76 
77  void kill_ns(OperationContext* opCtx, StringData ns);
78 
79  bool allocated() const {
80  return _ht.get() != 0;
81  }
82 
83  void getCollectionNamespaces(std::list<std::string>* tofill) const;
84 
85  boost::filesystem::path path() const;
86 
87  unsigned long long fileLength() const {
88  return _f.length();
89  }
90 
91 private:
92  void maybeMkdir() const;
93 
94  const std::string _dir;
95  const std::string _database;
96 
98  std::unique_ptr<NamespaceHashTable> _ht;
99 };
100 }
bool allocated() const
Definition: namespace_index.h:79
void kill_ns(OperationContext *opCtx, StringData ns)
Definition: namespace_index.cpp:97
Collection *const const NamespaceString & ns
Definition: collection_info_cache_impl.cpp:53
void getCollectionNamespaces(std::list< std::string > *tofill) const
Definition: namespace_index.cpp:131
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
void maybeMkdir() const
Definition: namespace_index.cpp:141
Definition: namespace_index.h:50
represents a disk location/offset on disk in a database.
Definition: diskloc.h:53
void init(OperationContext *opCtx)
Definition: namespace_index.cpp:151
Definition: namespace_details.h:47
~NamespaceIndex()
Definition: namespace_index.cpp:60
std::unique_ptr< NamespaceHashTable > _ht
Definition: namespace_index.h:98
DurableMappedFile adds some layers atop memory mapped files - specifically our handling of private vi...
Definition: durable_mapped_file.h:47
This is used for storing a namespace on disk in a fixed witdh form and should only be used for that...
Definition: namespace.h:49
unsigned long long length() const
Definition: durable_mapped_file.h:66
Definition: mmap.h:96
unsigned long long fileLength() const
Definition: namespace_index.h:87
const std::string _dir
Definition: namespace_index.h:94
void add_ns(OperationContext *opCtx, StringData ns, const DiskLoc &loc, bool capped)
Definition: namespace_index.cpp:71
NamespaceDetails * details(StringData ns) const
Definition: namespace_index.cpp:62
bool pathExists() const
Definition: namespace_index.cpp:119
void close(OperationContext *opCtx)
Must be called before destruction.
Definition: namespace_index.h:60
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
boost::filesystem::path path() const
Definition: namespace_index.cpp:123
DurableMappedFile _f
Definition: namespace_index.h:97
NamespaceIndex(OperationContext *opCtx, const std::string &dir, const std::string &database)
Definition: namespace_index.cpp:55
virtual void close(OperationContext *opCtx)
Callers must be holding a LockMongoFilesExclusive.
Definition: durable_mapped_file.cpp:288
const std::string _database
Definition: namespace_index.h:95
MONGO_DISALLOW_COPYING(NamespaceIndex)