summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordwight <dwight@Dwights-MacBook-2.local>2009-08-20 15:00:25 -0400
committerdwight <dwight@Dwights-MacBook-2.local>2009-08-20 15:00:25 -0400
commitb00247a8585c77215598cd0b6d72d76d94acc7c2 (patch)
treebc4eba7de0f589701bc61ff64b90520db3fcaac3
parent7831db0d557a6464032a7181b524097208a25a05 (diff)
downloadmongo-b00247a8585c77215598cd0b6d72d76d94acc7c2.tar.gz
--nssize parameter
-rw-r--r--db/db.cpp8
-rw-r--r--db/namespace.cpp27
-rw-r--r--db/namespace.h6
3 files changed, 33 insertions, 8 deletions
diff --git a/db/db.cpp b/db/db.cpp
index 3fdfdbb2625..efad0d2e41b 100644
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -61,6 +61,7 @@ namespace mongo {
extern int opLogging;
extern long long oplogSize;
extern OpLog _oplog;
+ extern int lenForNewNsFiles;
extern int ctr;
extern int callDepth;
@@ -483,6 +484,7 @@ int main(int argc, char* argv[], char *envp[] )
("nohttpinterface", "disable http interface")
("noscripting", "disable scripting engine")
("noprealloc", "disable data file preallocation")
+ ("nssize", po::value<int>()->default_value(16), ".ns file size (in MB) for new databases")
("oplog", po::value<int>(), "0=off 1=W 2=R 3=both 7=W+some reads")
("sysinfo", "print some diagnostic system information")
#if defined(_WIN32)
@@ -693,6 +695,12 @@ int main(int argc, char* argv[], char *envp[] )
if (params.count("autoresync")) {
autoresync = true;
}
+ if( params.count("nssize") ) {
+ int x = params["nssize"].as<int>();
+ uassert("bad --nssize arg", x > 0 && x <= (0x7fffffff/1024/1024));
+ lenForNewNsFiles = x * 1024 * 1024;
+ assert(lenForNewNsFiles > 0);
+ }
if (params.count("oplogSize")) {
long x = params["oplogSize"].as<long>();
uassert("bad --oplogSize arg", x > 0);
diff --git a/db/namespace.cpp b/db/namespace.cpp
index b34e379f7b7..3e5cc497901 100644
--- a/db/namespace.cpp
+++ b/db/namespace.cpp
@@ -42,12 +42,14 @@ namespace mongo {
};
bool NamespaceIndex::exists() const {
- return !boost::filesystem::exists(path());
+ return !boost::filesystem::exists(path());
}
boost::filesystem::path NamespaceIndex::path() const {
return boost::filesystem::path( dir_ ) / ( database_ + ".ns" );
}
+
+ int lenForNewNsFiles = 16 * 1024 * 1024;
void NamespaceIndex::init() {
if ( ht )
@@ -61,14 +63,29 @@ namespace mongo {
i.dbDropped();
}
- long LEN = 16 * 1024 * 1024;
- string pathString = path().string();
- void *p = f.map(pathString.c_str(), LEN);
+ int len = -1;
+ boost::filesystem::path nsPath = path();
+ string pathString = nsPath.string();
+ void *p;
+ if( boost::filesystem::exists(nsPath) ) {
+ p = f.map(pathString.c_str());
+ len = f.length();
+ uassert( "bad .ns file length, cannot open database", len % (1024*1024) == 0 );
+ }
+ else {
+ // use lenForNewNsFiles, we are making a new database
+ massert( "bad lenForNewNsFiles", lenForNewNsFiles >= 1024*1024 );
+ long l = lenForNewNsFiles;
+ p = f.map(pathString.c_str(), l);
+ len = (int) l;
+ assert( len == lenForNewNsFiles );
+ }
+
if ( p == 0 ) {
problem() << "couldn't open file " << pathString << " terminating" << endl;
dbexit( EXIT_FS );
}
- ht = new HashTable<Namespace,NamespaceDetails>(p, LEN, "namespace index");
+ ht = new HashTable<Namespace,NamespaceDetails>(p, len, "namespace index");
}
void NamespaceDetails::addDeletedRec(DeletedRecord *d, DiskLoc dloc) {
diff --git a/db/namespace.h b/db/namespace.h
index 4470aa63f09..2ae5e3f0fc3 100644
--- a/db/namespace.h
+++ b/db/namespace.h
@@ -33,7 +33,7 @@ namespace mongo {
/* in the mongo source code, "client" means "database". */
- const int MaxClientLen = 256; // max str len for the db name
+ const int MaxClientLen = 256; // max str len for the db name, including null char
// "database.a.b.c" -> "database"
inline void nsToClient(const char *ns, char *database) {
@@ -554,10 +554,10 @@ namespace mongo {
}
return false;
}
-
+
bool allocated() const {
return ht != 0;
- }
+ }
private:
boost::filesystem::path path() const;