mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
Merge branch 'master' of github.com:mongodb/mongo
This commit is contained in:
commit
4d7db8ced4
@ -30,6 +30,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../util/concurrency/locks.h"
|
||||
#include "../util/mmap.h"
|
||||
|
||||
namespace mongo {
|
||||
|
||||
@ -128,6 +129,8 @@ namespace mongo {
|
||||
curopGotLock();
|
||||
|
||||
_minfo.entered();
|
||||
|
||||
MongoFile::lockAll();
|
||||
}
|
||||
|
||||
bool lock_try( int millis ) {
|
||||
@ -141,6 +144,7 @@ namespace mongo {
|
||||
if ( got ){
|
||||
_minfo.entered();
|
||||
_state.set(1);
|
||||
MongoFile::lockAll();
|
||||
}
|
||||
|
||||
return got;
|
||||
@ -161,6 +165,9 @@ namespace mongo {
|
||||
}
|
||||
massert( 12599, "internal error: attempt to unlock when wasn't in a write lock", false);
|
||||
}
|
||||
|
||||
MongoFile::unlockAll();
|
||||
|
||||
_state.set(0);
|
||||
_minfo.leaving();
|
||||
_m.unlock();
|
||||
|
@ -117,11 +117,9 @@ namespace mongo {
|
||||
uassert(13132,
|
||||
"nonmatching repl set name in _id field; check --replSet command line",
|
||||
startsWith(cmdLine.replSet, _id + '/'));
|
||||
uassert(13133,
|
||||
"replSet config value is not valid",
|
||||
members.size() >= 1 && members.size() <= 64 &&
|
||||
version > 0);
|
||||
|
||||
uassert(13308, "replSet bad config version #", version > 0);
|
||||
uassert(13133, "replSet bad config no members", members.size() >= 1);
|
||||
uassert(13309, "replSet bad config maximum number of members is 7 (for now)", members.size() <= 7);
|
||||
}
|
||||
|
||||
void ReplSetConfig::from(BSONObj o) {
|
||||
|
@ -85,7 +85,7 @@ namespace mongo {
|
||||
to = min.first;
|
||||
|
||||
} else if ( ! drainingShards.empty() ){
|
||||
from = drainingShards[ random() % drainingShards.size() ];
|
||||
from = drainingShards[ rand() % drainingShards.size() ];
|
||||
to = min.first;
|
||||
|
||||
} else {
|
||||
|
@ -113,4 +113,23 @@ namespace mongo {
|
||||
mmfiles.insert(this);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
void MongoFile::lockAll() {
|
||||
rwlock lk( mmmutex , false );
|
||||
for ( set<MongoFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ ){
|
||||
MongoFile * mmf = *i;
|
||||
if (mmf) mmf->_lock();
|
||||
}
|
||||
}
|
||||
|
||||
void MongoFile::unlockAll() {
|
||||
rwlock lk( mmmutex , false );
|
||||
for ( set<MongoFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ ){
|
||||
MongoFile * mmf = *i;
|
||||
if (mmf) mmf->_lock();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace mongo
|
||||
|
22
util/mmap.h
22
util/mmap.h
@ -27,6 +27,11 @@ namespace mongo {
|
||||
|
||||
void created(); /* subclass must call after create */
|
||||
void destroyed(); /* subclass must call in destructor */
|
||||
|
||||
// only supporting on posix mmap
|
||||
virtual void _lock() {}
|
||||
virtual void _unlock() {}
|
||||
|
||||
public:
|
||||
virtual ~MongoFile() {}
|
||||
virtual long length() = 0;
|
||||
@ -39,12 +44,23 @@ namespace mongo {
|
||||
static long long totalMappedLength();
|
||||
static void closeAllFiles( stringstream &message );
|
||||
|
||||
// Locking allows writes. Reads are always allowed
|
||||
static void lockAll();
|
||||
static void unlockAll();
|
||||
|
||||
/* can be "overriden" if necessary */
|
||||
static bool exists(boost::filesystem::path p) {
|
||||
return boost::filesystem::exists(p);
|
||||
}
|
||||
};
|
||||
|
||||
#ifndef _DEBUG
|
||||
// no-ops in production
|
||||
inline void MongoFile::lockAll() {}
|
||||
inline void MongoFile::unlockAll() {}
|
||||
#endif
|
||||
|
||||
|
||||
/** template for what a new storage engine's class definition must implement
|
||||
PRELIMINARY - subject to change.
|
||||
*/
|
||||
@ -137,6 +153,12 @@ namespace mongo {
|
||||
void *view;
|
||||
long len;
|
||||
string _filename;
|
||||
|
||||
protected:
|
||||
// only posix mmap implementations will support this
|
||||
virtual void _lock();
|
||||
virtual void _unlock();
|
||||
|
||||
};
|
||||
|
||||
void printMemInfo( const char * where );
|
||||
|
@ -45,6 +45,8 @@ namespace mongo {
|
||||
void MemoryMappedFile::flush(bool sync) {
|
||||
}
|
||||
|
||||
void MemoryMappedFile::_lock() {}
|
||||
void MemoryMappedFile::_unlock() {}
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "pch.h"
|
||||
#include "mmap.h"
|
||||
#include "file_allocator.h"
|
||||
#include "../db/concurrency.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
@ -90,6 +91,11 @@ namespace mongo {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
DEV if (! dbMutex.info().isLocked()){
|
||||
_unlock();
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@ -100,6 +106,13 @@ namespace mongo {
|
||||
problem() << "msync " << errnoWithDescription() << endl;
|
||||
}
|
||||
|
||||
void MemoryMappedFile::_lock() {
|
||||
if (view) assert(mprotect(view, len, PROT_READ | PROT_WRITE) == 0);
|
||||
}
|
||||
|
||||
void MemoryMappedFile::_unlock() {
|
||||
if (view) assert(mprotect(view, len, PROT_READ) == 0);
|
||||
}
|
||||
|
||||
} // namespace mongo
|
||||
|
||||
|
@ -112,4 +112,8 @@ namespace mongo {
|
||||
out() << "FlushFileBuffers failed " << err << " file: " << _filename << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryMappedFile::_lock() {}
|
||||
void MemoryMappedFile::_unlock() {}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user