Skip to content

Commit

Permalink
SERVER-11020 Don't overload the meaning of _DEBUG, use our own debug …
Browse files Browse the repository at this point in the history
…macro
  • Loading branch information
acmorrow committed Mar 27, 2015
1 parent 1fc9d37 commit 67cf6c0
Show file tree
Hide file tree
Showing 29 changed files with 78 additions and 83 deletions.
4 changes: 3 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,9 @@ isBuildingLatest = False
def filterExists(paths):
return filter(os.path.exists, paths)

if debugBuild:
env.SetConfigHeaderDefine("MONGO_CONFIG_DEBUG_BUILD")

if darwin:
pass
elif linux:
Expand Down Expand Up @@ -1061,7 +1064,6 @@ if nix:
env.Append( LINKFLAGS=["-fstack-protector"] )
env.Append( SHLINKFLAGS=["-fstack-protector"] )
env['ENV']['GLIBCXX_FORCE_NEW'] = 1; # play nice with valgrind
env.Append( CPPDEFINES=["_DEBUG"] );

if has_option( "ssl" ):
env.SetConfigHeaderDefine("MONGO_CONFIG_SSL")
Expand Down
1 change: 1 addition & 0 deletions src/mongo/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ env.NoCache(buildInfo)

config_header_substs = (
('@mongo_config_byte_order@', 'MONGO_CONFIG_BYTE_ORDER'),
('@mongo_config_debug_build@', 'MONGO_CONFIG_DEBUG_BUILD'),
('@mongo_config_have___declspec_thread@', 'MONGO_CONFIG_HAVE___DECLSPEC_THREAD'),
('@mongo_config_have___thread@', 'MONGO_CONFIG_HAVE___THREAD'),
('@mongo_config_have_execinfo_backtrace@', 'MONGO_CONFIG_HAVE_EXECINFO_BACKTRACE'),
Expand Down
3 changes: 3 additions & 0 deletions src/mongo/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
// Define to target byte order (1234 vs 4321)
@mongo_config_byte_order@

// Define if building a debug build
@mongo_config_debug_build@

// Defined if __declspec(thread) is available
@mongo_config_have___declspec_thread@

Expand Down
9 changes: 4 additions & 5 deletions src/mongo/db/commands/pipeline_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,10 @@ namespace mongo {
// This is outside of the if block to keep the object alive until the pipeline is finished.
BSONObj parsed;
if (kDebugBuild && !pPipeline->isExplain() && !pCtx->inShard) {
// Make sure all operations round-trip through Pipeline::toBson()
// correctly by reparsing every command on DEBUG builds. This is
// important because sharded aggregations rely on this ability.
// Skipping when inShard because this has already been through the
// transformation (and this unsets pCtx->inShard).
// Make sure all operations round-trip through Pipeline::toBson() correctly by
// reparsing every command in debug builds. This is important because sharded
// aggregations rely on this ability. Skipping when inShard because this has
// already been through the transformation (and this unsets pCtx->inShard).
parsed = pPipeline->serialize().toBson();
pPipeline = Pipeline::parseCommand(errmsg, parsed, pCtx);
verify(pPipeline);
Expand Down
10 changes: 6 additions & 4 deletions src/mongo/db/concurrency/lock_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@

#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault

#include <vector>
#include "mongo/config.h"

#include "mongo/platform/basic.h"

#include <vector>

#include "mongo/db/concurrency/lock_manager.h"

#include "mongo/db/concurrency/locker.h"
Expand Down Expand Up @@ -1075,14 +1077,14 @@ namespace {

ResourceId::ResourceId(ResourceType type, StringData ns)
: _fullHash(fullHash(type, stringDataHashFunction(ns))) {
#ifdef _DEBUG
#ifdef MONGO_CONFIG_DEBUG_BUILD
_nsCopy = ns.toString();
#endif
}

ResourceId::ResourceId(ResourceType type, const string& ns)
: _fullHash(fullHash(type, stringDataHashFunction(ns))) {
#ifdef _DEBUG
#ifdef MONGO_CONFIG_DEBUG_BUILD
_nsCopy = ns;
#endif
}
Expand All @@ -1095,7 +1097,7 @@ namespace {
ss << "{" << _fullHash << ": " << resourceTypeName(getType())
<< ", " << getHashId();

#ifdef _DEBUG
#ifdef MONGO_CONFIG_DEBUG_BUILD
ss << ", " << _nsCopy;
#endif

Expand Down
2 changes: 2 additions & 0 deletions src/mongo/db/concurrency/lock_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#pragma once

#include "mongo/config.h"

#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>

Expand Down
6 changes: 4 additions & 2 deletions src/mongo/db/concurrency/lock_manager_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#pragma once

#include "mongo/config.h"

#include <boost/static_assert.hpp>
#include <string>
#include <limits>
Expand Down Expand Up @@ -202,14 +204,14 @@ namespace mongo {

static uint64_t fullHash(ResourceType type, uint64_t hashId);

#ifdef _DEBUG
#ifdef MONGO_CONFIG_DEBUG_BUILD
// Keep the complete namespace name for debugging purposes (TODO: this will be
// removed once we are confident in the robustness of the lock manager).
std::string _nsCopy;
#endif
};

#ifndef _DEBUG
#ifndef MONGO_CONFIG_DEBUG_BUILD
// Treat the resource ids as 64-bit integers in release mode in order to ensure we do
// not spend too much time doing comparisons for hashing.
BOOST_STATIC_ASSERT(sizeof(ResourceId) == sizeof(uint64_t));
Expand Down
6 changes: 4 additions & 2 deletions src/mongo/db/concurrency/lock_state_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault

#include "mongo/config.h"

#include "mongo/platform/basic.h"

#include <boost/shared_ptr.hpp>
Expand Down Expand Up @@ -256,7 +258,7 @@ namespace {

// These two tests exercise single-threaded performance of uncontended lock acquisition. It
// is not practical to run them on debug builds.
#ifndef _DEBUG
#ifndef MONGO_CONFIG_DEBUG_BUILD

TEST(Locker, PerformanceBoostSharedMutex) {
for (int numLockers = 1; numLockers <= 64; numLockers = numLockers * 2) {
Expand Down Expand Up @@ -314,6 +316,6 @@ namespace {
}
}

#endif // _DEBUG
#endif // MONGO_CONFIG_DEBUG_BUILD

} // namespace mongo
2 changes: 1 addition & 1 deletion src/mongo/db/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ namespace mongo {
l << ( is32bit ? " 32" : " 64" ) << "-bit host=" << getHostNameCached() << endl;
}

DEV log(LogComponent::kControl) << "_DEBUG build (which is slower)" << endl;
DEV log(LogComponent::kControl) << "DEBUG build (which is slower)" << endl;
logMongodStartupWarnings(storageGlobalParams);

#if defined(_WIN32)
Expand Down
4 changes: 3 additions & 1 deletion src/mongo/db/sorter/sorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
* Do this once for each unique set of parameters to MONGO_CREATE_SORTER.
*/

#include "mongo/config.h"

#include "mongo/db/sorter/sorter.h"

#include <boost/filesystem/operations.hpp>
Expand Down Expand Up @@ -90,7 +92,7 @@ namespace mongo {

template<typename Data, typename Comparator>
void dassertCompIsSane(const Comparator& comp, const Data& lhs, const Data& rhs) {
#if defined(_DEBUG) && !defined(_MSC_VER)
#if defined(MONGO_CONFIG_DEBUG_BUILD) && !defined(_MSC_VER)
// MSVC++ already does similar verification in debug mode in addition to using
// algorithms that do more comparisons. Doing our own verification in addition makes
// debug builds considerably slower without any additional safety.
Expand Down
4 changes: 3 additions & 1 deletion src/mongo/db/sorter/sorter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
* then also delete it in the license file.
*/

#include "mongo/config.h"

#include "mongo/platform/basic.h"

#include "mongo/db/sorter/sorter.h"
Expand Down Expand Up @@ -341,7 +343,7 @@ namespace mongo {

// The debug builds are too slow to run these tests.
// Among other things, MSVC++ makes all heap functions O(N) not O(logN).
#if !defined(_DEBUG)
#if !defined(MONGO_CONFIG_DEBUG_BUILD)
{ // merge all data ASC
boost::shared_ptr<IWSorter> sorters[] = {
makeSorter(opts, IWComparator(ASC)),
Expand Down
6 changes: 3 additions & 3 deletions src/mongo/db/storage/mmap_v1/dur.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ namespace dur {
// Declare write intents. Use these methods to declare "i'm about to write to x and it
// should be logged for redo."
//
// Failure to call writing...() is checked in _DEBUG mode by using a read only mapped view
// (i.e., you'll segfault if the code is covered in that situation). The _DEBUG check
// doesn't verify that your length is correct though.
// Failure to call writing...() is checked in MONGO_CONFIG_DEBUG_BUILD mode by using a
// read only mapped view (i.e., you'll segfault if the code is covered in that
// situation). The debug check doesn't verify that your length is correct though.

/**
* Declare intent to write to x for up to len.
Expand Down
13 changes: 8 additions & 5 deletions src/mongo/db/storage/mmap_v1/dur_journal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kJournal

#include "mongo/config.h"

#include "mongo/platform/basic.h"

#include "mongo/db/storage/mmap_v1/dur_journal.h"
Expand Down Expand Up @@ -78,7 +80,7 @@ namespace mongo {
// work. (and should as-is)
// --smallfiles makes the limit small.

#if defined(_DEBUG)
#if defined(MONGO_CONFIG_DEBUG_BUILD)
unsigned long long DataLimitPerJournalFile = 128 * 1024 * 1024;
#elif defined(__APPLE__)
// assuming a developer box if OS X
Expand Down Expand Up @@ -393,10 +395,11 @@ namespace mongo {

unsigned long long limit = DataLimitPerJournalFile;
if( kDebugBuild && 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
// limit for a file. also we want to be able to change in the future the constant without a lot of
// work anyway.
// 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
// MONGO_CONFIG_DEBUG_BUILD is set by arbitrarily stopping prealloc at a
// low limit for a file. also we want to be able to change in the future
// the constant without a lot of work anyway.
limit = 16 * 1024 * 1024;
}
preallocateFile(filepath, limit);
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/dbtests/framework_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ namespace mongo {
storageGlobalParams.dur = true;
}

DEV log() << "_DEBUG build" << endl;
DEV log() << "DEBUG build" << endl;
if( sizeof(void*)==4 )
log() << "32bit" << endl;
log() << "random seed: " << frameworkGlobalParams.seed << endl;
Expand Down
6 changes: 3 additions & 3 deletions src/mongo/dbtests/perftests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace PerfTests {
static boost::shared_ptr<DBClientConnection> conn;
static string _perfhostname;
void pstatsConnect() {
// no writing to perf db if _DEBUG
// no writing to perf db if this is a debug build
DEV return;

const char *fn = "../../settings.py";
Expand Down Expand Up @@ -314,7 +314,7 @@ namespace PerfTests {
int howLong() {
int hlm = howLongMillis();
DEV {
// don't run very long with _DEBUG - not very meaningful anyway on that build
// don't run very long with in debug mode - not very meaningful anyway on that build
hlm = min(hlm, 500);
}
return hlm;
Expand Down Expand Up @@ -1117,7 +1117,7 @@ namespace PerfTests {
c->findOne(ns(), q);
}
void post() {
#if !defined(_DEBUG)
#if !defined(MONGO_CONFIG_DEBUG_BUILD)
verify( client()->count(ns()) > 50 );
#endif
}
Expand Down
6 changes: 4 additions & 2 deletions src/mongo/dbtests/threadedtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kCommand

#include "mongo/config.h"

#include "mongo/platform/basic.h"

#include <boost/thread.hpp>
Expand Down Expand Up @@ -94,7 +96,7 @@ namespace ThreadedTests {
const int nthr=135;
#endif
class MongoMutexTest : public ThreadedTest<nthr> {
#if defined(_DEBUG)
#if defined(MONGO_CONFIG_DEBUG_BUILD)
enum { N = 2000 };
#else
enum { N = 4000/*0*/ };
Expand Down Expand Up @@ -531,7 +533,7 @@ namespace ThreadedTests {
if( t.millis() > 20 ) {
#endif
DEV {
// a _DEBUG buildbot might be slow, try to avoid false positives
// a debug buildbot might be slow, try to avoid false positives
mongo::unittest::log() <<
"warning lock upgrade was slow " << t.millis() << endl;
}
Expand Down
4 changes: 3 additions & 1 deletion src/mongo/s/chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding

#include "mongo/config.h"

#include "mongo/platform/basic.h"

#include "mongo/s/chunk.h"
Expand Down Expand Up @@ -603,7 +605,7 @@ namespace {
<< " shard: " << toString()
<< " into " << (splitCount + 1)
<< " (splitThreshold " << splitThreshold << ")"
#ifdef _DEBUG
#ifdef MONGO_CONFIG_DEBUG_BUILD
<< " size: " << getPhysicalSize() // slow - but can be useful when debugging
#endif
<< ( res["shouldMigrate"].eoo() ? "" : (string)" (migrate suggested" +
Expand Down
4 changes: 2 additions & 2 deletions src/mongo/s/version_mongos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace mongo {
ProcessId::getCurrent() << " port=" << serverGlobalParams.port <<
( sizeof(int*) == 4 ? " 32" : " 64" ) << "-bit host=" << getHostNameCached() <<
" (--help for usage)" << std::endl;
DEV std::cout << "_DEBUG build" << std::endl;
DEV std::cout << "DEBUG build" << std::endl;
std::cout << "git version: " << gitVersion() << std::endl;
std::cout << openSSLVersion("OpenSSL version: ") << std::endl;
std::cout << "build sys info: " << sysInfo() << std::endl;
Expand All @@ -59,7 +59,7 @@ namespace mongo {
ProcessId::getCurrent() << " port=" << serverGlobalParams.port <<
( sizeof( int* ) == 4 ? " 32" : " 64" ) << "-bit host=" << getHostNameCached() <<
" (--help for usage)" << std::endl;
DEV log() << "_DEBUG build" << std::endl;
DEV log() << "DEBUG build" << std::endl;
logProcessDetails();
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/mongo/util/assert_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault

#include "mongo/config.h"

#include "mongo/platform/basic.h"

#include "mongo/util/assert_util.h"
Expand Down Expand Up @@ -118,7 +120,7 @@ namespace mongo {
log() << "warning assertion failure " << expr << ' ' << file << ' ' << dec << line << endl;
logContext();
assertionCount.condrollover( ++assertionCount.warning );
#if defined(_DEBUG) || defined(_DURABLEDEFAULTON) || defined(_DURABLEDEFAULTOFF)
#if defined(MONGO_CONFIG_DEBUG_BUILD) || defined(_DURABLEDEFAULTON) || defined(_DURABLEDEFAULTOFF)
// this is so we notice in buildbot
log() << "\n\n***aborting after wassert() failure in a debug/test build\n\n" << endl;
quickExit(EXIT_ABRUPT);
Expand All @@ -133,7 +135,7 @@ namespace mongo {
temp << "assertion " << file << ":" << line;
AssertionException e(temp.str(),0);
breakpoint();
#if defined(_DEBUG) || defined(_DURABLEDEFAULTON) || defined(_DURABLEDEFAULTOFF)
#if defined(MONGO_CONFIG_DEBUG_BUILD) || defined(_DURABLEDEFAULTON) || defined(_DURABLEDEFAULTOFF)
// this is so we notice in buildbot
log() << "\n\n***aborting after verify() failure as this is a debug/test build\n\n" << endl;
quickExit(EXIT_ABRUPT);
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/util/concurrency/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace mongo {
};
#endif

/** This can be used instead of boost recursive mutex. The advantage is the _DEBUG checks
/** This can be used instead of boost recursive mutex. The advantage is the debug checks
* and ability to assertLocked(). This has not yet been tested for speed vs. the boost one.
*/
class RecursiveMutex : boost::noncopyable {
Expand Down
6 changes: 4 additions & 2 deletions src/mongo/util/concurrency/rwlockimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
*/


#include "mongo/config.h"

#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
Expand All @@ -55,8 +57,8 @@ namespace mongo {
SimpleRWLock::SimpleRWLock(StringData p) : name(p.toString()) {
InitializeSRWLock(&_lock);
}
# if defined(_DEBUG)
// the code below in _DEBUG build will check that we don't try to recursively lock,
# if defined(MONGO_CONFIG_DEBUG_BUILD)
// the code below in a debug build will check that we don't try to recursively lock,
// which is not supported by this class. also checks that you don't unlock without
// having locked
void SimpleRWLock::lock() {
Expand Down
Loading

0 comments on commit 67cf6c0

Please sign in to comment.