Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mongodb/mongo
Browse files Browse the repository at this point in the history
  • Loading branch information
dwight committed Apr 19, 2011
2 parents 4f8f0c6 + f32e60a commit 6c9fe3b
Show file tree
Hide file tree
Showing 20 changed files with 257 additions and 245 deletions.
65 changes: 58 additions & 7 deletions db/db.cpp
Expand Up @@ -24,6 +24,7 @@
#include "../util/unittest.h"
#include "../util/file_allocator.h"
#include "../util/background.h"
#include "../util/text.h"
#include "dbmessage.h"
#include "instance.h"
#include "clientcursor.h"
Expand Down Expand Up @@ -51,6 +52,10 @@

namespace mongo {

namespace dur {
extern unsigned long long DataLimitPerJournalFile;
}

/* only off if --nocursors which is for debugging. */
extern bool useCursors;

Expand Down Expand Up @@ -774,6 +779,8 @@ int main(int argc, char* argv[]) {
}
if (params.count("smallfiles")) {
cmdLine.smallfiles = true;
assert( dur::DataLimitPerJournalFile >= 128 * 1024 * 1024 );
dur::DataLimitPerJournalFile = 128 * 1024 * 1024;
}
if (params.count("diaglog")) {
int x = params["diaglog"].as<int>();
Expand Down Expand Up @@ -1045,7 +1052,7 @@ namespace mongo {
void myterminate() {
rawOut( "terminate() called, printing stack:" );
printStackTrace();
abort();
::abort();
}

void setupSignals_ignoreHelper( int signal ) {}
Expand Down Expand Up @@ -1114,19 +1121,63 @@ namespace mongo {
}
}

LPTOP_LEVEL_EXCEPTION_FILTER filtLast = 0;
::HANDLE standardOut = GetStdHandle(STD_OUTPUT_HANDLE);
LONG WINAPI exceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo) {
{
// given the severity of the event we write to console in addition to the --logFile
// (rawOut writes to the logfile, if a special one were specified)
DWORD written;
WriteFile(standardOut, "unhandled exception\n", 20, &written, 0);
FlushFileBuffers(standardOut);
}

DWORD ec = ExceptionInfo->ExceptionRecord->ExceptionCode;
if( ec == EXCEPTION_ACCESS_VIOLATION ) {
rawOut("access violation");
}
else {
rawOut("unhandled exception");
char buf[64];
strcpy(buf, "ec=0x");
_ui64toa(ec, buf+5, 16);
rawOut(buf);
}
if( filtLast )
return filtLast(ExceptionInfo);
return EXCEPTION_EXECUTE_HANDLER;
}

// called by mongoAbort()
extern void (*reportEventToSystem)(const char *msg);
void reportEventToSystemImpl(const char *msg) {
static ::HANDLE hEventLog = RegisterEventSource( NULL, TEXT("mongod") );
if( hEventLog ) {
std::wstring s = toNativeString(msg);
LPCTSTR txt = s.c_str();
BOOL ok = ReportEvent(
hEventLog, EVENTLOG_ERROR_TYPE,
0, 0, NULL,
1,
0,
&txt,
0);
wassert(ok);
}
}

void myPurecallHandler() {
rawOut( "pure virtual method called, printing stack:" );
printStackTrace();
abort();
mongoAbort("pure virtual");
}

void setupSignals( bool inFork ) {
if( SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE ) )
;
else
massert( 10297 , "Couldn't register Windows Ctrl-C handler", false);
reportEventToSystem = reportEventToSystemImpl;
filtLast = SetUnhandledExceptionFilter(exceptionFilter);
massert(10297 , "Couldn't register Windows Ctrl-C handler", SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE));
_set_purecall_handler( myPurecallHandler );
}

#endif

} // namespace mongo
18 changes: 9 additions & 9 deletions db/dur.cpp
Expand Up @@ -516,19 +516,19 @@ namespace mongo {
}
catch(DBException& e ) {
log() << "dbexception in groupCommitLL causing immediate shutdown: " << e.toString() << endl;
abort();
mongoAbort("dur1");
}
catch(std::ios_base::failure& e) {
log() << "ios_base exception in groupCommitLL causing immediate shutdown: " << e.what() << endl;
abort();
mongoAbort("dur2");
}
catch(std::bad_alloc& e) {
log() << "bad_alloc exception in groupCommitLL causing immediate shutdown: " << e.what() << endl;
abort();
mongoAbort("dur3");
}
catch(std::exception& e) {
log() << "exception in dur::groupCommitLL causing immediate shutdown: " << e.what() << endl;
abort();
mongoAbort("dur4");
}
return false;
}
Expand Down Expand Up @@ -602,19 +602,19 @@ namespace mongo {
}
catch(DBException& e ) {
log() << "dbexception in groupCommit causing immediate shutdown: " << e.toString() << endl;
abort();
mongoAbort("gc1");
}
catch(std::ios_base::failure& e) {
log() << "ios_base exception in groupCommit causing immediate shutdown: " << e.what() << endl;
abort();
mongoAbort("gc2");
}
catch(std::bad_alloc& e) {
log() << "bad_alloc exception in groupCommit causing immediate shutdown: " << e.what() << endl;
abort();
mongoAbort("gc3");
}
catch(std::exception& e) {
log() << "exception in dur::groupCommit causing immediate shutdown: " << e.what() << endl;
abort(); // based on myTerminate()
mongoAbort("gc4");
}
}

Expand Down Expand Up @@ -695,7 +695,7 @@ namespace mongo {
}
catch(std::exception& e) {
log() << "exception in durThread causing immediate shutdown: " << e.what() << endl;
abort(); // based on myTerminate()
mongoAbort("exception in durThread");
}
}
cc().shutdown();
Expand Down
3 changes: 3 additions & 0 deletions db/dur.h
Expand Up @@ -9,6 +9,9 @@ namespace mongo {

class NamespaceDetails;

void mongoAbort(const char *msg);
void abort(); // not defined -- use mongoAbort() instead

namespace dur {

// a smaller limit is likely better on 32 bit
Expand Down
17 changes: 13 additions & 4 deletions db/dur_journal.cpp
Expand Up @@ -42,6 +42,17 @@ namespace mongo {
class AlignedBuilder;

namespace dur {
// Rotate after reaching this data size in a journal (j._<n>) file
// We use a smaller size for 32 bit as the journal is mmapped during recovery (only)
// Note if you take a set of datafiles, including journal files, from 32->64 or vice-versa, it must
// work. (and should as-is)
// --smallfiles makes the limit small.
#if defined(_DEBUG)
unsigned long long DataLimitPerJournalFile = 128 * 1024 * 1024;
#else
unsigned long long DataLimitPerJournalFile = (sizeof(void*)==4) ? 256 * 1024 * 1024 : 1 * 1024 * 1024 * 1024;
#endif

BOOST_STATIC_ASSERT( sizeof(Checksum) == 16 );
BOOST_STATIC_ASSERT( sizeof(JHeader) == 8192 );
BOOST_STATIC_ASSERT( sizeof(JSectHeader) == 20 );
Expand Down Expand Up @@ -289,7 +300,7 @@ namespace mongo {
string fn = str::stream() << "prealloc." << i;
filesystem::path filepath = getJournalDir() / fn;

unsigned long long limit = Journal::DataLimit;
unsigned long long limit = DataLimitPerJournalFile;
if( debug && i == 1 ) {
// moving 32->64, the prealloc files would be short. that is "ok", but we want to exercise that
// case, so we force exercising here when _DEBUG is set by arbitrarily stopping prealloc at a low
Expand Down Expand Up @@ -582,13 +593,11 @@ namespace mongo {

j.updateLSNFile();

if( _curLogFile && _written < DataLimit )
if( _curLogFile && _written < DataLimitPerJournalFile )
return;

if( _curLogFile ) {

closeCurrentJournalFile();

removeUnneededJournalFiles();
}

Expand Down
10 changes: 0 additions & 10 deletions db/dur_journalimpl.h
Expand Up @@ -49,16 +49,6 @@ namespace mongo {
unsigned long long lastFlushTime() const { return _lastFlushTime; }
void cleanup(bool log);

// Rotate after reaching this data size in a journal (j._<n>) file
// We use a smaller size for 32 bit as the journal is mmapped during recovery (only)
// Note if you take a set of datafiles, including journal files, from 32->64 or vice-versa, it must
// work. (and should as-is)
#if defined(_DEBUG)
static const unsigned long long DataLimit = 128 * 1024 * 1024;
#else
static const unsigned long long DataLimit = (sizeof(void*)==4) ? 256 * 1024 * 1024 : 1 * 1024 * 1024 * 1024;
#endif

unsigned long long curFileId() const { return _curFileId; }

void assureLogFileOpen() {
Expand Down

0 comments on commit 6c9fe3b

Please sign in to comment.