00001
00002
00019 #pragma once
00020
00021 #include "cmdline.h"
00022
00023 namespace mongo {
00024
00025 class ClientCursor;
00026 struct ByLocKey;
00027 typedef map<ByLocKey, ClientCursor*> CCByLoc;
00028
00034 class Database {
00035 public:
00036 static bool _openAllFiles;
00037
00038 Database(const char *nm, bool& newDb, const string& _path = dbpath);
00039 private:
00040 ~Database();
00041 public:
00042
00043
00044
00045 static void closeDatabase( const char *db, const string& path );
00046
00047 void openAllFiles();
00048
00049 void finishInit();
00050
00054 bool isOk() const { return magic == 781231; }
00055
00056 bool isEmpty() { return ! namespaceIndex.allocated(); }
00057
00061 long long fileSize() const;
00062
00063 int numFiles() const { return (int)files.size(); }
00064
00068 boost::filesystem::path fileName( int n ) const;
00069
00070 bool exists(int n) const { return boost::filesystem::exists( fileName( n ) ); }
00071
00075 MongoDataFile* getFile( int n, int sizeNeeded = 0, bool preallocateOnly = false );
00076
00077 MongoDataFile* addAFile( int sizeNeeded, bool preallocateNextFile );
00078
00083 void preallocateAFile() { getFile( numFiles() , 0, true ); }
00084
00085 MongoDataFile* suitableFile( int sizeNeeded, bool preallocate );
00086
00087 Extent* allocExtent( const char *ns, int size, bool capped );
00088
00089 MongoDataFile* newestFile();
00090
00094 bool setProfilingLevel( int newLevel , string& errmsg );
00095
00096
00097 void flushFiles( bool sync ) const;
00098
00103 bool ownsNS( const string& ns ) const {
00104 if ( ! startsWith( ns , name ) )
00105 return false;
00106 return ns[name.size()] == '.';
00107 }
00108
00109 static bool validDBName( const string& ns );
00110
00111 public:
00112
00113 vector<MongoDataFile*> files;
00114 const string name;
00115 const string path;
00116 NamespaceIndex namespaceIndex;
00117 int profile;
00118 const string profileName;
00119 CCByLoc ccByLoc;
00120 int magic;
00121 };
00122
00123 }