Skip to content

Commit

Permalink
durability: added occasinal file sync
Browse files Browse the repository at this point in the history
default: sync every 60 seconds, confiruable with syncdelay
SERVER-442
  • Loading branch information
erh committed Nov 28, 2009
1 parent 779f12d commit c44bff0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions db/db.cpp
Expand Up @@ -24,6 +24,7 @@
#include "repl.h"
#include "../util/unittest.h"
#include "../util/file_allocator.h"
#include "../util/background.h"
#include "dbmessage.h"
#include "instance.h"
#include "clientcursor.h"
Expand Down Expand Up @@ -373,6 +374,26 @@ namespace mongo {
}
}

class DataFileSync : public BackgroundJob {
public:
DataFileSync() : _sleepsecs( 60 ){}

void run(){
while ( ! inShutdown() ){
if ( _sleepsecs == 0 ){
// in case at some point we add an option to change at runtime
sleepsecs(5);
continue;
}
sleepmillis( _sleepsecs * 1000 );
MemoryMappedFile::flushAll( false );
log(1) << "flushing mmmap" << endl;
}
}

double _sleepsecs;
} dataFileSync;

void show_32_warning(){
if ( sizeof(int*) != 4 )
return;
Expand Down Expand Up @@ -547,6 +568,7 @@ int main(int argc, char* argv[], char *envp[] )
("upgrade", "upgrade db if needed")
("repair", "run repair on all dbs")
("notablescan", "do not allow table scans")
("syncdelay",po::value<double>(&dataFileSync._sleepsecs)->default_value(60), "seconds between disk syncs (0 for never)")
#if defined(_WIN32)
("install", "install mongodb service")
("remove", "remove mongodb service")
Expand Down Expand Up @@ -833,6 +855,7 @@ int main(int argc, char* argv[], char *envp[] )
}

Module::configAll( params );
dataFileSync.go();

if (params.count("command")) {
vector<string> command = params["command"].as< vector<string> >();
Expand Down

0 comments on commit c44bff0

Please sign in to comment.