0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-29 16:47:28 +01:00

SERVER-426 make repair path configurable

This commit is contained in:
Aaron 2010-01-25 11:32:51 -08:00
parent 1664c3da4f
commit 3b4a0b04dd
4 changed files with 55 additions and 6 deletions

View File

@ -58,6 +58,8 @@ namespace mongo {
extern int diagLogging;
extern int lenForNewNsFiles;
extern int lockFile;
extern string repairpath;
void setupSignals();
void closeAllSockets();
@ -462,10 +464,17 @@ namespace mongo {
show_32_warning();
stringstream ss;
ss << "dbpath (" << dbpath << ") does not exist";
massert( 10296 , ss.str().c_str(), boost::filesystem::exists( dbpath ) );
{
stringstream ss;
ss << "dbpath (" << dbpath << ") does not exist";
massert( 10296 , ss.str().c_str(), boost::filesystem::exists( dbpath ) );
}
{
stringstream ss;
ss << "repairpath (" << repairpath << ") does not exist";
massert( 12590 , ss.str().c_str(), boost::filesystem::exists( repairpath ) );
}
acquirePathLock();
remove_all( dbpath + "/_tmp/" );
@ -593,6 +602,7 @@ int main(int argc, char* argv[], char *envp[] )
("quiet", "quieter output")
("logpath", po::value<string>() , "file to send all output to instead of stdout" )
("logappend" , "appnd to logpath instead of over-writing" )
("repairpath", po::value<string>() , "root directory for repair files - defaults to dbpath" )
#ifndef _WIN32
("fork" , "fork server process" )
#endif
@ -794,6 +804,12 @@ int main(int argc, char* argv[], char *envp[] )
uassert( 10033 , "logpath has to be non-zero" , lp.size() );
initLogging( lp , params.count( "logappend" ) );
}
if (params.count("repairpath")) {
repairpath = params["repairpath"].as<string>();
uassert( 12589, "repairpath has to be non-zero", repairpath.size() );
} else {
repairpath = dbpath;
}
if (params.count("nocursors")) {
useCursors = false;
}

View File

@ -83,6 +83,7 @@ namespace mongo {
/* ----------------------------------------- */
string dbpath = "/data/db/";
string repairpath;
DataFileMgr theDataFileMgr;
DatabaseHolder dbHolder;
@ -1571,14 +1572,14 @@ namespace mongo {
// generate a directory name for storing temp data files
Path uniqueReservedPath( const char *prefix ) {
Path dbPath = Path( dbpath );
Path repairPath = Path( repairpath );
Path reservedPath;
int i = 0;
bool exists = false;
do {
stringstream ss;
ss << prefix << "_repairDatabase_" << i++;
reservedPath = dbPath / ss.str();
reservedPath = repairPath / ss.str();
BOOST_CHECK_EXCEPTION( exists = boost::filesystem::exists( reservedPath ) );
} while ( exists );
return reservedPath;

30
jstests/disk/repair.js Normal file
View File

@ -0,0 +1,30 @@
var baseName = "jstests_disk_repair";
port = allocatePorts( 1 )[ 0 ];
dbpath = "/data/db/" + baseName + "/";
repairpath = dbpath + "repairDir/"
resetDbpath( dbpath );
resetDbpath( repairpath );
m = startMongoProgram( "mongod", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
db = m.getDB( baseName );
db[ baseName ].save( {} );
db.runCommand( {repairDatabase:1, backupOriginalFiles:true} );
escape = function( s ) {
ret = "";
for( i in s ) {
if ( s[ i ] == "/" ) {
ret += "\/";
} else {
ret += s[ i ];
}
}
return ret;
}
files = listFiles( dbpath );
for( f in files ) {
assert( ! new RegExp( "^" + dbpath + "backup_" ).test( files[ f ].name ), "backup dir in dbpath" );
}

View File

@ -421,6 +421,7 @@
938A7A480F54873600FB7A07 /* reccache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = reccache.h; sourceTree = "<group>"; };
938A7A490F54873600FB7A07 /* reci.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = reci.h; sourceTree = "<group>"; };
938A7A4A0F54873600FB7A07 /* recstore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = recstore.h; sourceTree = "<group>"; };
938E5EB3110E1ED700A8760A /* repair.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = repair.js; sourceTree = "<group>"; };
93A13A210F4620A500AF1B0D /* commands.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = commands.cpp; sourceTree = "<group>"; };
93A13A230F4620A500AF1B0D /* config.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = config.cpp; sourceTree = "<group>"; };
93A13A240F4620A500AF1B0D /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
@ -960,6 +961,7 @@
934BEBCD10DFFA9600178102 /* disk */ = {
isa = PBXGroup;
children = (
938E5EB3110E1ED700A8760A /* repair.js */,
935C941B1106709800439EB1 /* preallocate.js */,
934BEBCE10DFFA9600178102 /* dbNoCreate.js */,
934BEBCF10DFFA9600178102 /* diskfull.js */,