diff options
author | Dwight <dmerriman@gmail.com> | 2009-08-25 10:24:44 -0400 |
---|---|---|
committer | Dwight <dmerriman@gmail.com> | 2009-08-25 10:24:44 -0400 |
commit | 2706a281233e0cef00cc92437865269a057b0707 (patch) | |
tree | bc119c609a68a9337e728b7b401bf59deffa3357 | |
parent | 360dc900a0e45481b535662acb5fd9970eba55ab (diff) | |
download | mongo-2706a281233e0cef00cc92437865269a057b0707.tar.gz |
begin cmdline.h
-rw-r--r-- | client/dbclient.cpp | 3 | ||||
-rw-r--r-- | db/btree.cpp | 2 | ||||
-rw-r--r-- | db/btreecursor.cpp | 3 | ||||
-rw-r--r-- | db/cloner.cpp | 7 | ||||
-rw-r--r-- | db/cmdline.h | 35 | ||||
-rw-r--r-- | db/db.cpp | 14 | ||||
-rw-r--r-- | db/db.vcproj | 4 | ||||
-rw-r--r-- | db/dbwebserver.cpp | 5 | ||||
-rw-r--r-- | db/instance.cpp | 4 | ||||
-rw-r--r-- | db/instance.h | 1 | ||||
-rw-r--r-- | db/pdfile.cpp | 3 | ||||
-rw-r--r-- | db/repl.cpp | 2 | ||||
-rw-r--r-- | db/replset.h | 8 | ||||
-rw-r--r-- | db/storage.h | 3 | ||||
-rw-r--r-- | dbtests/pairingtests.cpp | 11 | ||||
-rw-r--r-- | util/message.h | 1 |
16 files changed, 72 insertions, 34 deletions
diff --git a/client/dbclient.cpp b/client/dbclient.cpp index af87cd463d6..e776d144f5f 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -25,6 +25,7 @@ #include "../db/instance.h" #include "../util/md5.hpp" #include "../db/dbmessage.h" +#include "../db/cmdline.h" namespace mongo { @@ -417,7 +418,7 @@ namespace mongo { ip = serverAddress.substr( 0 , idx ); ip = hostbyname(ip.c_str()); } else { - port = DBPort; + port = CmdLine::DefaultDBPort; ip = hostbyname( serverAddress.c_str() ); } massert( "Unable to parse hostname", !ip.empty() ); diff --git a/db/btree.cpp b/db/btree.cpp index 93fbba6c6dd..250ed07d277 100644 --- a/db/btree.cpp +++ b/db/btree.cpp @@ -293,8 +293,6 @@ namespace mongo { } } - extern DiskLoc minDiskLoc; - bool BtreeBucket::exists(const IndexDetails& idx, DiskLoc thisLoc, const BSONObj& key, BSONObj order) { int pos; bool found; diff --git a/db/btreecursor.cpp b/db/btreecursor.cpp index e3e942dfe60..7dd5fc733fa 100644 --- a/db/btreecursor.cpp +++ b/db/btreecursor.cpp @@ -25,9 +25,6 @@ namespace mongo { extern int otherTraceLevel; - DiskLoc maxDiskLoc(0x7fffffff, 0x7fffffff); - DiskLoc minDiskLoc(0, 1); - BtreeCursor::BtreeCursor( NamespaceDetails *_d, int _idxNo, const IndexDetails &_id, const BSONObj &_startKey, const BSONObj &_endKey, bool endKeyInclusive, int _direction ) : d(_d), idxNo(_idxNo), diff --git a/db/cloner.cpp b/db/cloner.cpp index c848a6b9619..b91552c63a1 100644 --- a/db/cloner.cpp +++ b/db/cloner.cpp @@ -30,7 +30,6 @@ namespace mongo { void ensureHaveIdIndex(const char *ns); - extern int port; bool replAuthenticate(DBClientConnection *); @@ -142,8 +141,8 @@ namespace mongo { string todb = database->name; stringstream a,b; - a << "localhost:" << port; - b << "127.0.0.1:" << port; + a << "localhost:" << cmdLine.port; + b << "127.0.0.1:" << cmdLine.port; bool masterSameProcess = ( a.str() == masterHost || b.str() == masterHost ); if ( masterSameProcess ) { if ( fromdb == todb && database->path == dbpath ) { @@ -552,7 +551,7 @@ namespace mongo { if ( fromhost.empty() ) { /* copy from self */ stringstream ss; - ss << "localhost:" << port; + ss << "localhost:" << cmdLine.port; fromhost = ss.str(); } string fromdb = cmdObj.getStringField("fromdb"); diff --git a/db/cmdline.h b/db/cmdline.h new file mode 100644 index 00000000000..d597624a3e9 --- /dev/null +++ b/db/cmdline.h @@ -0,0 +1,35 @@ +/** +* Copyright (C) 2008 10gen Inc. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License, version 3, +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once + +namespace mongo { + + struct CmdLine { + int port; + + enum { + DefaultDBPort = 27017 + }; + + CmdLine() : + port(27017) + { } + + }; + + extern CmdLine cmdLine; +} diff --git a/db/db.cpp b/db/db.cpp index efad0d2e41b..b3284eb0606 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -38,6 +38,7 @@ #include "../scripting/engine.h" #include "mms.h" +#include "cmdline.h" namespace mongo { @@ -51,7 +52,6 @@ namespace mongo { bool noHttpInterface = false; - extern int port; extern string bind_ip; extern char *appsrvPath; extern int curOp; @@ -291,7 +291,7 @@ namespace mongo { } void msg(const char *m, int extras = 0) { - msg(m, "127.0.0.1", DBPort, extras); + msg(m, "127.0.0.1", CmdLine::DefaultDBPort, extras); } void repairDatabases() { @@ -360,7 +360,7 @@ namespace mongo { bool is32bit = sizeof(int*) == 4; - log() << "Mongo DB : starting : pid = " << pid << " port = " << port << " dbpath = " << dbpath + log() << "Mongo DB : starting : pid = " << pid << " port = " << cmdLine.port << " dbpath = " << dbpath << " master = " << master << " slave = " << (int) slave << " " << ( is32bit ? "32" : "64" ) << "-bit " << endl; show_32_warning(); @@ -417,7 +417,7 @@ namespace mongo { #if defined(_WIN32) bool initService() { ServiceController::reportStatus( SERVICE_RUNNING ); - initAndListen( port, appsrvPath ); + initAndListen( cmdLine.port, appsrvPath ); return true; } #endif @@ -467,7 +467,7 @@ int main(int argc, char* argv[], char *envp[] ) general_options.add_options() ("help,h", "show this usage information") ("config,f", po::value<string>(), "configuration file specifying additional options") - ("port", po::value<int>(&port)->default_value(DBPort), "specify port number") + ("port", po::value<int>(&cmdLine.port)->default_value(CmdLine::DefaultDBPort), "specify port number") ("bind_ip", po::value<string>(&bind_ip), "local ip address to bind listener - all local ips bound by default") ("verbose,v", "be more verbose (include multiple times for more verbosity e.g. -vvvvv)") @@ -751,7 +751,7 @@ int main(int argc, char* argv[], char *envp[] ) return 0; } - initAndListen(port); + initAndListen(cmdLine.port); return 0; } @@ -782,7 +782,7 @@ int main(int argc, char* argv[], char *envp[] ) cout << dbExecCommand << " --help for help and startup options" << endl; } - initAndListen(port, appsrvPath); + initAndListen(cmdLine.port, appsrvPath); dbexit(EXIT_CLEAN); return 0; } diff --git a/db/db.vcproj b/db/db.vcproj index 46e8606c3b3..8b2f683e3ba 100644 --- a/db/db.vcproj +++ b/db/db.vcproj @@ -1366,6 +1366,10 @@ >
</File>
<File
+ RelativePath=".\cmdline.h"
+ >
+ </File>
+ <File
RelativePath=".\commands.h"
>
</File>
diff --git a/db/dbwebserver.cpp b/db/dbwebserver.cpp index c0cc0d6599c..804e579b792 100644 --- a/db/dbwebserver.cpp +++ b/db/dbwebserver.cpp @@ -31,7 +31,6 @@ namespace mongo { - extern int port; extern string bind_ip; extern const char *replInfo; @@ -267,7 +266,7 @@ namespace mongo { string dbname; { stringstream z; - z << "mongodb " << getHostName() << ':' << mongo::port << ' '; + z << "mongodb " << getHostName() << ':' << mongo::cmdLine.port << ' '; dbname = z.str(); } ss << dbname << "</title></head><body><h2>" << dbname << "</h2><p>\n<pre>"; @@ -465,7 +464,7 @@ namespace mongo { AuthenticationInfo *ai = new AuthenticationInfo(); authInfo.reset(ai); DbWebServer mini; - int p = port + 1000; + int p = cmdLine.port + 1000; if ( mini.init(bind_ip, p) ) { registerListenerSocket( mini.socket() ); log() << "web admin interface listening on port " << p << '\n'; diff --git a/db/instance.cpp b/db/instance.cpp index 596ef13988a..bc5dd80202e 100644 --- a/db/instance.cpp +++ b/db/instance.cpp @@ -31,12 +31,15 @@ #include "replset.h" #include "../s/d_logic.h" #include "../util/file_allocator.h" +#include "cmdline.h" #if !defined(_WIN32) #include <sys/file.h> #endif namespace mongo { + CmdLine cmdLine; + int nloggedsome = 0; #define LOGSOME if( ++nloggedsome < 1000 || nloggedsome % 100 == 0 ) @@ -52,7 +55,6 @@ namespace mongo { string dbExecCommand; - int port = DBPort; string bind_ip = ""; /* 0 = off; 1 = writes, 2 = reads, 3 = both 7 = log a few reads, and all writes. diff --git a/db/instance.h b/db/instance.h index efa2085ca8a..dfb6d87077e 100644 --- a/db/instance.h +++ b/db/instance.h @@ -22,6 +22,7 @@ #include "../client/dbclient.h" #include "curop.h" #include "security.h" +#include "cmdline.h" namespace mongo { diff --git a/db/pdfile.cpp b/db/pdfile.cpp index 4aca0d078e2..c0c91560144 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -42,7 +42,6 @@ _ disallow system* manipulations from the database. namespace mongo { extern bool quota; - extern int port; string dbpath = "/data/db/"; @@ -1540,7 +1539,7 @@ namespace mongo { bool repairDatabase( const char *ns, string &errmsg, bool preserveClonedFilesOnFailure, bool backupOriginalFiles ) { stringstream ss; - ss << "localhost:" << port; + ss << "localhost:" << cmdLine.port; string localhost = ss.str(); // ns is of the form "<dbname>.$cmd" diff --git a/db/repl.cpp b/db/repl.cpp index 05b8673cc70..e25b412dbd3 100644 --- a/db/repl.cpp +++ b/db/repl.cpp @@ -1325,7 +1325,7 @@ namespace mongo { nClonedThisPass = 0; // FIXME Handle cases where this db isn't on default port, or default port is spec'd in hostName. - if ( (string("localhost") == hostName || string("127.0.0.1") == hostName) && port == DBPort ) { + if ( (string("localhost") == hostName || string("127.0.0.1") == hostName) && cmdLine.port == CmdLine::DefaultDBPort ) { log() << "pull: can't sync from self (localhost). sources configuration may be wrong." << endl; sleepsecs(5); return false; diff --git a/db/replset.h b/db/replset.h index 45790af0828..aff4cfef6ea 100644 --- a/db/replset.h +++ b/db/replset.h @@ -21,10 +21,10 @@ #include "json.h" #include "../client/dbclient.h" #include "repl.h" +#include "cmdline.h" namespace mongo { - extern int port; extern const char *replAllDead; /* ReplPair is a pair of db servers replicating to one another and cooperating. @@ -76,7 +76,7 @@ namespace mongo { bool dominant(const string& myname) { if ( myname == remoteHost ) - return port > remotePort; + return cmdLine.port > remotePort; return myname > remoteHost; } @@ -136,14 +136,14 @@ namespace mongo { inline ReplPair::ReplPair(const char *remoteEnd, const char *arb) { state = -1; remote = remoteEnd; - remotePort = DBPort; + remotePort = CmdLine::DefaultDBPort; remoteHost = remoteEnd; const char *p = strchr(remoteEnd, ':'); if ( p ) { remoteHost = string(remoteEnd, p-remoteEnd); remotePort = atoi(p+1); uassert("bad port #", remotePort > 0 && remotePort < 0x10000 ); - if ( remotePort == DBPort ) + if ( remotePort == CmdLine::DefaultDBPort ) remote = remoteHost; // don't include ":27017" as it is default; in case ran in diff ways over time to normalizke the hostname format in sources collection } diff --git a/db/storage.h b/db/storage.h index bc37632f30a..ac436f71021 100644 --- a/db/storage.h +++ b/db/storage.h @@ -147,4 +147,7 @@ namespace mongo { #pragma pack() + const DiskLoc minDiskLoc(0, 1); + const DiskLoc maxDiskLoc(0x7fffffff, 0x7fffffff); + } // namespace mongo diff --git a/dbtests/pairingtests.cpp b/dbtests/pairingtests.cpp index 35986dd2e16..3446d9f491a 100644 --- a/dbtests/pairingtests.cpp +++ b/dbtests/pairingtests.cpp @@ -21,6 +21,7 @@ #include "../db/replset.h" #include "dbtests.h" #include "mockdbclient.h" +#include "../db/cmdline.h" namespace mongo { extern PairSync *pairSync; @@ -84,14 +85,14 @@ namespace PairingTests { public: void run() { ReplPair rp1( "foo", "bar" ); - checkFields( rp1, "foo", "foo", DBPort, "bar" ); + checkFields( rp1, "foo", "foo", CmdLine::DefaultDBPort, "bar" ); ReplPair rp2( "foo:1", "bar" ); checkFields( rp2, "foo:1", "foo", 1, "bar" ); // FIXME Should we accept this input? ReplPair rp3( "", "bar" ); - checkFields( rp3, "", "", DBPort, "bar" ); + checkFields( rp3, "", "", CmdLine::DefaultDBPort, "bar" ); ASSERT_EXCEPTION( ReplPair( "foo:", "bar" ), UserException ); @@ -121,11 +122,11 @@ namespace PairingTests { class Dominant : public Base { public: - Dominant() : oldPort_( port ) { - port = 10; + Dominant() : oldPort_( cmdLine.port ) { + cmdLine.port = 10; } ~Dominant() { - port = oldPort_; + cmdLine.port = oldPort_; } void run() { ASSERT( ReplPair( "b:9", "-" ).dominant( "b" ) ); diff --git a/util/message.h b/util/message.h index f2a135a3ed6..276e14e9d49 100644 --- a/util/message.h +++ b/util/message.h @@ -26,7 +26,6 @@ namespace mongo { class MessagingPort; class PiggyBackData; typedef WrappingInt MSGID; - const int DBPort = 27017; class Listener { public: |