summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/concurrency/mutex.h2
-rw-r--r--util/concurrency/task.cpp11
-rw-r--r--util/concurrency/vars.cpp4
-rw-r--r--util/goodies.h8
-rw-r--r--util/log.cpp6
-rw-r--r--util/log.h77
-rw-r--r--util/message.cpp41
-rw-r--r--util/message.h34
-rw-r--r--util/mmap.h4
-rwxr-xr-xutil/mongoutils/README12
-rw-r--r--util/optime.h2
-rw-r--r--util/sock.h15
-rw-r--r--util/util.cpp20
-rw-r--r--util/version.cpp29
-rw-r--r--util/version.h2
15 files changed, 151 insertions, 116 deletions
diff --git a/util/concurrency/mutex.h b/util/concurrency/mutex.h
index 9ab3960..797ab77 100644
--- a/util/concurrency/mutex.h
+++ b/util/concurrency/mutex.h
@@ -115,7 +115,7 @@ namespace mongo {
}
}
};
- extern MutexDebugger mutexDebugger;
+ extern MutexDebugger &mutexDebugger;
// If you create a local static instance of this class, that instance will be destroyed
// before all global static objects are destroyed, so __destroyingStatics will be set
diff --git a/util/concurrency/task.cpp b/util/concurrency/task.cpp
index 05e43e5..99288bb 100644
--- a/util/concurrency/task.cpp
+++ b/util/concurrency/task.cpp
@@ -139,9 +139,14 @@ namespace mongo {
}
}
} catch(std::exception& e) {
- log() << "Server::doWork() exception " << e.what() << endl;
- } catch(...) {
- log() << "Server::doWork() unknown exception!" << endl;
+ log() << "Server::doWork task:" << name() << " exception:" << e.what() << endl;
+ }
+ catch(const char *p) {
+ log() << "Server::doWork task:" << name() << " unknown c exception:" <<
+ ((p&&strlen(p)<800)?p:"?") << endl;
+ }
+ catch(...) {
+ log() << "Server::doWork unknown exception task:" << name() << endl;
}
}
}
diff --git a/util/concurrency/vars.cpp b/util/concurrency/vars.cpp
index 2b46946..8863a27 100644
--- a/util/concurrency/vars.cpp
+++ b/util/concurrency/vars.cpp
@@ -23,7 +23,9 @@
namespace mongo {
mutex _atomicMutex("_atomicMutex");
- MutexDebugger mutexDebugger;
+
+ // intentional leak. otherwise destructor orders can be problematic at termination.
+ MutexDebugger &mutexDebugger = *(new MutexDebugger());
MutexDebugger::MutexDebugger() :
x( *(new boost::mutex()) ), magic(0x12345678) {
diff --git a/util/goodies.h b/util/goodies.h
index 1dfabdc..c43f356 100644
--- a/util/goodies.h
+++ b/util/goodies.h
@@ -61,7 +61,7 @@ namespace mongo {
o << '\n';
for (i = 0; i < size; i++)
o << ' ' << strings[i] << '\n';
-
+ o.flush();
free (strings);
}
#else
@@ -543,14 +543,16 @@ namespace mongo {
_num = _outof - used;
}
- int available(){
+ int available() const {
return _num;
}
- int used(){
+ int used() const {
return _outof - _num;
}
+ int outof() const { return _outof; }
+
private:
int _outof;
int _num;
diff --git a/util/log.cpp b/util/log.cpp
index bfd9154..334c66b 100644
--- a/util/log.cpp
+++ b/util/log.cpp
@@ -83,7 +83,7 @@ namespace mongo {
}
- FILE* tmp = fopen(_path.c_str(), (_append ? "a" : "w"));
+ FILE* tmp = freopen(_path.c_str(), (_append ? "a" : "w"), stdout);
if (!tmp){
cerr << "can't open: " << _path.c_str() << " for log file" << endl;
dbexit( EXIT_BADOPTIONS );
@@ -92,10 +92,6 @@ namespace mongo {
Logstream::setLogFile(tmp); // after this point no thread will be using old file
- if (_file){
- fclose(_file);
- }
-
_file = tmp;
_opened = time(0);
}
diff --git a/util/log.h b/util/log.h
index 1f11c81..87b7b7e 100644
--- a/util/log.h
+++ b/util/log.h
@@ -295,10 +295,13 @@ namespace mongo {
inline Nullstream& log() {
return Logstream::get().prolog();
}
+
+ inline Nullstream& error() {
+ return log( LL_ERROR );
+ }
- /* TODOCONCURRENCY */
- inline ostream& stdcout() {
- return cout;
+ inline Nullstream& warning() {
+ return log( LL_WARNING );
}
/* default impl returns "" -- mongod overrides */
@@ -326,40 +329,40 @@ namespace mongo {
s << "errno:" << x << ' ';
#if defined(_WIN32)
- LPTSTR errorText = NULL;
- FormatMessage(
- FORMAT_MESSAGE_FROM_SYSTEM
- |FORMAT_MESSAGE_ALLOCATE_BUFFER
- |FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- x, 0,
- (LPTSTR) &errorText, // output
- 0, // minimum size for output buffer
- NULL);
- if( errorText ) {
- string x = toUtf8String(errorText);
- for( string::iterator i = x.begin(); i != x.end(); i++ ) {
- if( *i == '\n' || *i == '\r' )
- break;
- s << *i;
- }
- LocalFree(errorText);
- }
- else
- s << strerror(x);
- /*
- DWORD n = FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, x,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR) &lpMsgBuf, 0, NULL);
- */
-#else
- s << strerror(x);
-#endif
- return s.str();
+ LPTSTR errorText = NULL;
+ FormatMessage(
+ FORMAT_MESSAGE_FROM_SYSTEM
+ |FORMAT_MESSAGE_ALLOCATE_BUFFER
+ |FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ x, 0,
+ (LPTSTR) &errorText, // output
+ 0, // minimum size for output buffer
+ NULL);
+ if( errorText ) {
+ string x = toUtf8String(errorText);
+ for( string::iterator i = x.begin(); i != x.end(); i++ ) {
+ if( *i == '\n' || *i == '\r' )
+ break;
+ s << *i;
+ }
+ LocalFree(errorText);
+ }
+ else
+ s << strerror(x);
+ /*
+ DWORD n = FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, x,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &lpMsgBuf, 0, NULL);
+ */
+#else
+ s << strerror(x);
+#endif
+ return s.str();
}
/** output the error # and error message with prefix.
diff --git a/util/message.cpp b/util/message.cpp
index cfff420..a809c1f 100644
--- a/util/message.cpp
+++ b/util/message.cpp
@@ -201,10 +201,12 @@ namespace mongo {
if ( x == ECONNABORTED || x == EBADF ) {
log() << "Listener on port " << _port << " aborted" << endl;
return;
- } if ( x == 0 && inShutdown() ){
+ }
+ if ( x == 0 && inShutdown() ) {
return; // socket closed
}
- log() << "Listener: accept() returns " << s << " " << errnoWithDescription(x) << endl;
+ if( !inShutdown() )
+ log() << "Listener: accept() returns " << s << " " << errnoWithDescription(x) << endl;
continue;
}
if (from.getType() != AF_UNIX)
@@ -255,14 +257,10 @@ namespace mongo {
_cur = _buf;
}
- int len() {
- return _cur - _buf;
- }
+ int len() const { return _cur - _buf; }
private:
-
MessagingPort* _port;
-
char * _buf;
char * _cur;
};
@@ -272,10 +270,13 @@ namespace mongo {
mongo::mutex m;
public:
Ports() : ports(), m("Ports") {}
- void closeAll() { \
+ void closeAll(unsigned skip_mask) {
scoped_lock bl(m);
- for ( set<MessagingPort*>::iterator i = ports.begin(); i != ports.end(); i++ )
+ for ( set<MessagingPort*>::iterator i = ports.begin(); i != ports.end(); i++ ) {
+ if( (*i)->tag & skip_mask )
+ continue;
(*i)->shutdown();
+ }
}
void insert(MessagingPort* p) {
scoped_lock bl(m);
@@ -291,18 +292,16 @@ namespace mongo {
// are being destructed during termination.
Ports& ports = *(new Ports());
-
-
- void closeAllSockets() {
- ports.closeAll();
+ void MessagingPort::closeAllSockets(unsigned mask) {
+ ports.closeAll(mask);
}
- MessagingPort::MessagingPort(int _sock, const SockAddr& _far) : sock(_sock), piggyBackData(0), farEnd(_far), _timeout() {
+ MessagingPort::MessagingPort(int _sock, const SockAddr& _far) : sock(_sock), piggyBackData(0), farEnd(_far), _timeout(), tag(0) {
_logLevel = 0;
ports.insert(this);
}
- MessagingPort::MessagingPort( int timeout, int ll ) {
+ MessagingPort::MessagingPort( int timeout, int ll ) : tag(0) {
_logLevel = ll;
ports.insert(this);
sock = -1;
@@ -341,7 +340,7 @@ namespace mongo {
sock = socket(farEnd.getType(), SOCK_STREAM, 0);
if ( sock == INVALID_SOCKET ) {
- log(_logLevel) << "ERROR: connect(): invalid socket? " << errnoWithDescription() << endl;
+ log(_logLevel) << "ERROR: connect invalid socket " << errnoWithDescription() << endl;
return false;
}
@@ -630,7 +629,6 @@ namespace mongo {
MSGID NextMsgId;
- bool usingClientIds = 0;
ThreadLocalValue<int> clientId;
struct MsgStart {
@@ -642,12 +640,6 @@ namespace mongo {
MSGID nextMessageId(){
MSGID msgid = NextMsgId++;
-
- if ( usingClientIds ){
- msgid = msgid & 0xFFFF;
- msgid = msgid | clientId.get();
- }
-
return msgid;
}
@@ -656,9 +648,6 @@ namespace mongo {
}
void setClientId( int id ){
- usingClientIds = true;
- id = id & 0xFFFF0000;
- massert( 10445 , "invalid id" , id );
clientId.set( id );
}
diff --git a/util/message.h b/util/message.h
index 13f31df..203ad83 100644
--- a/util/message.h
+++ b/util/message.h
@@ -30,7 +30,7 @@ namespace mongo {
class PiggyBackData;
typedef AtomicUInt MSGID;
- class Listener {
+ class Listener : boost::noncopyable {
public:
Listener(const string &ip, int p, bool logConnect=true ) : _port(p), _ip(ip), _logConnect(logConnect), _elapsedTime(0){ }
virtual ~Listener() {
@@ -74,7 +74,7 @@ namespace mongo {
static const Listener* _timeTracker;
};
- class AbstractMessagingPort {
+ class AbstractMessagingPort : boost::noncopyable {
public:
virtual ~AbstractMessagingPort() { }
virtual void reply(Message& received, Message& response, MSGID responseTo) = 0; // like the reply below, but doesn't rely on received.data still being available
@@ -86,6 +86,7 @@ namespace mongo {
virtual int getClientId(){
int x = remotePort();
x = x << 16;
+ x |= ( ( 0xFF0 & (long long)this ) >> 8 ); // lowest byte in pointer often meaningless
return x;
}
};
@@ -135,6 +136,11 @@ namespace mongo {
int _timeout;
int _logLevel; // passed to log() when logging errors
+ static void closeAllSockets(unsigned tagMask = 0xffffffff);
+
+ /* ports can be tagged with various classes. see closeAllSockets(tag). defaults to 0. */
+ unsigned tag;
+
friend class PiggyBackData;
};
@@ -169,6 +175,30 @@ namespace mongo {
return "";
}
}
+
+ inline bool opIsWrite( int op ){
+ switch ( op ){
+
+ case 0:
+ case opReply:
+ case dbMsg:
+ case dbQuery:
+ case dbGetMore:
+ case dbKillCursors:
+ return false;
+
+ case dbUpdate:
+ case dbInsert:
+ case dbDelete:
+ return false;
+
+ default:
+ PRINT(op);
+ assert(0);
+ return "";
+ }
+
+ }
#pragma pack(1)
/* see http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol
diff --git a/util/mmap.h b/util/mmap.h
index f4875be..c954ef7 100644
--- a/util/mmap.h
+++ b/util/mmap.h
@@ -168,7 +168,9 @@ namespace mongo {
long length() {
return len;
}
-
+
+ string filename() const { return _filename; }
+
private:
static void updateLength( const char *filename, long &length );
diff --git a/util/mongoutils/README b/util/mongoutils/README
index d3d874b..ab614b6 100755
--- a/util/mongoutils/README
+++ b/util/mongoutils/README
@@ -1,7 +1,7 @@
-mongoutils namespace requirements:
+ mongoutils namespace requirements:
-(1) code is not database specific, rather, true utilities
-(2) are cross platform
-(3) may require boost headers, but not libs
-(4) are clean and easy to use in any c++ project without pulling in lots of other stuff
-(5) apache license
+ (1) code is not database specific, rather, true utilities
+ (2) are cross platform
+ (3) may require boost headers, but not libs
+ (4) are clean and easy to use in any c++ project without pulling in lots of other stuff
+ (5) apache license
diff --git a/util/optime.h b/util/optime.h
index 4645968..9214479 100644
--- a/util/optime.h
+++ b/util/optime.h
@@ -104,7 +104,7 @@ namespace mongo {
char buf[64];
time_t_to_String(secs, buf);
stringstream ss;
- ss << buf << ' ';
+ ss << time_t_to_String_short(secs) << ' ';
ss << hex << secs << ':' << i;
return ss.str();
}
diff --git a/util/sock.h b/util/sock.h
index 300c24d..4b4290d 100644
--- a/util/sock.h
+++ b/util/sock.h
@@ -253,9 +253,7 @@ namespace mongo {
class ListeningSockets {
public:
- ListeningSockets() : _mutex("ListeningSockets"), _sockets( new set<int>() ){
- }
-
+ ListeningSockets() : _mutex("ListeningSockets"), _sockets( new set<int>() ) { }
void add( int sock ){
scoped_lock lk( _mutex );
_sockets->insert( sock );
@@ -264,7 +262,6 @@ namespace mongo {
scoped_lock lk( _mutex );
_sockets->erase( sock );
}
-
void closeAll(){
set<int>* s;
{
@@ -272,17 +269,13 @@ namespace mongo {
s = _sockets;
_sockets = new set<int>();
}
-
- for ( set<int>::iterator i=s->begin(); i!=s->end(); i++ ){
+ for ( set<int>::iterator i=s->begin(); i!=s->end(); i++ ) {
int sock = *i;
- log() << "\t going to close listening socket: " << sock << endl;
+ log() << "closing listening socket: " << sock << endl;
closesocket( sock );
- }
-
+ }
}
-
static ListeningSockets* get();
-
private:
mongo::mutex _mutex;
set<int>* _sockets;
diff --git a/util/util.cpp b/util/util.cpp
index 02abfa9..b4b1053 100644
--- a/util/util.cpp
+++ b/util/util.cpp
@@ -156,20 +156,22 @@ namespace mongo {
}
printStackTrace();
}
-
+
+ /* note: can't use malloc herein - may be in signal handler.
+ logLockless() likely does not comply and should still be fixed todo
+ */
void rawOut( const string &s ) {
if( s.empty() ) return;
- boost::scoped_array<char> buf_holder(new char[32 + s.size()]);
- char * buf = buf_holder.get();
-
+ char buf[64];
time_t_to_String( time(0) , buf );
- buf[20] = ' ';
- strncpy( buf + 21 , s.c_str() , s.size() );
- buf[21+s.size()] = '\n';
- buf[21+s.size()+1] = 0;
+ /* truncate / don't show the year: */
+ buf[19] = ' ';
+ buf[20] = 0;
- Logstream::logLockless( buf );
+ Logstream::logLockless(buf);
+ Logstream::logLockless(s);
+ Logstream::logLockless("\n");
}
ostream& operator<<( ostream &s, const ThreadSafeString &o ){
diff --git a/util/version.cpp b/util/version.cpp
index bba3dd1..4987e19 100644
--- a/util/version.cpp
+++ b/util/version.cpp
@@ -14,7 +14,7 @@ namespace mongo {
// mongo processes version support
//
- const char versionString[] = "1.6.2";
+ const char versionString[] = "1.6.3";
string mongodVersion() {
stringstream ss;
@@ -61,26 +61,37 @@ namespace mongo {
// 32 bit systems warning
//
- void show_32_warning(){
+ void show_warnings(){
+ // each message adds a leading but not a trailing newline
+
bool warned = false;
{
const char * foo = strchr( versionString , '.' ) + 1;
int bar = atoi( foo );
if ( ( 2 * ( bar / 2 ) ) != bar ) {
cout << "\n** NOTE: This is a development version (" << versionString << ") of MongoDB.";
- cout << "\n** Not recommended for production. \n" << endl;
+ cout << "\n** Not recommended for production." << endl;
warned = true;
}
}
- if ( sizeof(int*) != 4 )
- return;
+ if ( sizeof(int*) == 4 ) {
+ cout << endl;
+ cout << "** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data" << endl;
+ cout << "** see http://blog.mongodb.org/post/137788967/32-bit-limitations" << endl;
+ warned = true;
+ }
+
+#ifdef __linux__
+ if (boost::filesystem::exists("/proc/vz") && !boost::filesystem::exists("/proc/bc")){
+ cout << endl;
+ cout << "** WARNING: You are running in OpenVZ. This is known to be broken!!!" << endl;
+ warned = true;
+ }
+#endif
- if( !warned ) // prettier this way
+ if (warned)
cout << endl;
- cout << "** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data" << endl;
- cout << "** see http://blog.mongodb.org/post/137788967/32-bit-limitations" << endl;
- cout << endl;
}
}
diff --git a/util/version.h b/util/version.h
index 70ddeb8..ea22a35 100644
--- a/util/version.h
+++ b/util/version.h
@@ -17,7 +17,7 @@ namespace mongo {
string sysInfo();
void printSysInfo();
- void show_32_warning();
+ void show_warnings();
} // namespace mongo