Skip to content

Commit

Permalink
FileAllocator cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Jan 9, 2011
1 parent b3f7712 commit 51ca8ee
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion db/db.cpp
Expand Up @@ -546,7 +546,7 @@ namespace mongo {
acquirePathLock();
remove_all( dbpath + "/_tmp/" );

theFileAllocator().start();
FileAllocator::get()->start();

BOOST_CHECK_EXCEPTION( clearTmpFiles() );

Expand Down
2 changes: 1 addition & 1 deletion db/instance.cpp
Expand Up @@ -712,7 +712,7 @@ namespace mongo {
// we would only hang here if the file_allocator code generates a
// synchronous signal, which we don't expect
log() << "shutdown: waiting for fs preallocator..." << endl;
theFileAllocator().waitUntilFinished();
FileAllocator::get()->waitUntilFinished();

log() << "shutdown: closing all files..." << endl;
if( cmdLine.dur ) {
Expand Down
4 changes: 2 additions & 2 deletions db/pdfile.cpp
Expand Up @@ -391,7 +391,7 @@ namespace mongo {

if ( preallocateOnly ) {
if ( cmdLine.prealloc ) {
theFileAllocator().requestAllocation( filename, size );
FileAllocator::get()->requestAllocation( filename, size );
}
return;
}
Expand Down Expand Up @@ -1948,7 +1948,7 @@ namespace mongo {

void _applyOpToDataFiles( const char *database, FileOp &fo, bool afterAllocator, const string& path ) {
if ( afterAllocator )
theFileAllocator().waitUntilFinished();
FileAllocator::get()->waitUntilFinished();
string c = database;
c += '.';
boost::filesystem::path p(path);
Expand Down
2 changes: 1 addition & 1 deletion dbtests/framework.cpp
Expand Up @@ -257,7 +257,7 @@ namespace mongo {
printSysInfo();
log() << "random seed: " << seed << endl;

theFileAllocator().start();
FileAllocator::get()->start();

vector<string> suites;
if (params.count("suites")) {
Expand Down
2 changes: 1 addition & 1 deletion dbtests/perf/perftest.cpp
Expand Up @@ -74,7 +74,7 @@ class Runner {
<< "}" << endl;
}
~Runner() {
theFileAllocator().waitUntilFinished();
FileAllocator::get()->waitUntilFinished();
client_->dropDatabase( testDb< T >().c_str() );
}
};
Expand Down
2 changes: 1 addition & 1 deletion tools/tool.cpp
Expand Up @@ -203,7 +203,7 @@ namespace mongo {
return -1;
}

theFileAllocator().start();
FileAllocator::get()->start();
}

if ( _params.count( "db" ) )
Expand Down
10 changes: 7 additions & 3 deletions util/file_allocator.cpp
Expand Up @@ -258,8 +258,12 @@ namespace mongo {

#endif

// The mutex contained in this object may be held on shutdown.
FileAllocator &theFileAllocator_ = *(new FileAllocator());
FileAllocator &theFileAllocator() { return theFileAllocator_; }
FileAllocator* FileAllocator::_instance = 0;

FileAllocator* FileAllocator::get(){
if ( ! _instance )
_instance = new FileAllocator();
return _instance;
}

} // namespace mongo
15 changes: 11 additions & 4 deletions util/file_allocator.h
Expand Up @@ -22,16 +22,15 @@ namespace mongo {
/*
* Handles allocation of contiguous files on disk. Allocation may be
* requested asynchronously or synchronously.
* singleton
*/
class FileAllocator {
class FileAllocator : boost::noncopyable {
/*
* The public functions may not be called concurrently. The allocation
* functions may be called multiple times per file, but only the first
* size specified per file will be used.
*/
public:
FileAllocator();

void start();

/**
Expand All @@ -51,7 +50,13 @@ namespace mongo {

static void ensureLength(int fd , long size);

/** @return the singletone */
static FileAllocator * get();

private:

FileAllocator();

#if !defined(_WIN32)
void checkFailure();

Expand All @@ -73,7 +78,9 @@ namespace mongo {

bool _failed;
#endif

static FileAllocator* _instance;

};

FileAllocator &theFileAllocator();
} // namespace mongo
2 changes: 1 addition & 1 deletion util/mmap_posix.cpp
Expand Up @@ -55,7 +55,7 @@ namespace mongo {
void* MemoryMappedFile::map(const char *filename, unsigned long long &length, int options) {
// length may be updated by callee.
setFilename(filename);
theFileAllocator().allocateAsap( filename, length );
FileAllocator::get()->allocateAsap( filename, length );
len = length;

massert( 10446 , str::stream() << "mmap: can't map area of size 0 file: " << filename, length > 0 );
Expand Down

0 comments on commit 51ca8ee

Please sign in to comment.