mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
be paranoid about removing data in moveChunk SERVER-1428
option to turn it off
This commit is contained in:
parent
f001dea20c
commit
41f0163961
@ -45,6 +45,7 @@ namespace mongo {
|
||||
int slowMS; // --time in ms that is "slow"
|
||||
|
||||
int pretouch; // --pretouch for replication application (experimental)
|
||||
bool moveParanoia; // for move chunk paranoia
|
||||
|
||||
enum {
|
||||
DefaultDBPort = 27017,
|
||||
@ -54,7 +55,7 @@ namespace mongo {
|
||||
|
||||
CmdLine() :
|
||||
port(DefaultDBPort), rest(false), quiet(false), notablescan(false), prealloc(true), smallfiles(false),
|
||||
quota(false), quotaFiles(8), cpu(false), oplogSize(0), defaultProfile(0), slowMS(100)
|
||||
quota(false), quotaFiles(8), cpu(false), oplogSize(0), defaultProfile(0), slowMS(100), pretouch(0), moveParanoia( true )
|
||||
{ }
|
||||
|
||||
|
||||
|
@ -738,6 +738,7 @@ int main(int argc, char* argv[], char *envp[] )
|
||||
sharding_options.add_options()
|
||||
("configsvr", "declare this is a config db of a cluster")
|
||||
("shardsvr", "declare this is a shard db of a cluster")
|
||||
("noMoveParanoia" , "turn off paranoid saving of data for moveChunk. this is on by default for now, but default will switch" )
|
||||
;
|
||||
|
||||
hidden_options.add_options()
|
||||
@ -987,7 +988,9 @@ int main(int argc, char* argv[], char *envp[] )
|
||||
if (params.count("ipv6")){
|
||||
enableIPv6();
|
||||
}
|
||||
|
||||
if (params.count("noMoveParanoia")){
|
||||
cmdLine.moveParanoia = false;
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
if (params.count("serviceName")){
|
||||
string x = params["serviceName"].as<string>();
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "../db/jsobj.h"
|
||||
#include "../db/dbmessage.h"
|
||||
#include "../db/query.h"
|
||||
#include "../db/cmdline.h"
|
||||
|
||||
#include "../client/connpool.h"
|
||||
#include "../client/distlock.h"
|
||||
@ -46,6 +47,57 @@ using namespace std;
|
||||
|
||||
namespace mongo {
|
||||
|
||||
class RemoveSaver : public Helpers::RemoveCallback , boost::noncopyable {
|
||||
public:
|
||||
RemoveSaver( const string& ns , const string& why) : _out(0){
|
||||
static int NUM = 0;
|
||||
|
||||
_root = dbpath;
|
||||
_root /= "moveChunk";
|
||||
_root /= ns;
|
||||
|
||||
_file = _root;
|
||||
|
||||
stringstream ss;
|
||||
ss << why << "." << terseCurrentTime() << "." << NUM++ << ".bson";
|
||||
_file /= ss.str();
|
||||
|
||||
}
|
||||
|
||||
~RemoveSaver(){
|
||||
if ( _out ){
|
||||
_out->close();
|
||||
delete _out;
|
||||
_out = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void goingToDelete( const BSONObj& o ){
|
||||
if ( ! cmdLine.moveParanoia )
|
||||
return;
|
||||
|
||||
if ( ! _out ){
|
||||
create_directories( _root );
|
||||
_out = new ofstream();
|
||||
_out->open( _file.string().c_str() , ios_base::out | ios_base::binary );
|
||||
if ( ! _out->good() ){
|
||||
log( LL_WARNING ) << "couldn't create file: " << _file.string() << " for temp moveChunk logging" << endl;
|
||||
delete _out;
|
||||
_out = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
_out->write( o.objdata() , o.objsize() );
|
||||
}
|
||||
|
||||
private:
|
||||
path _root;
|
||||
path _file;
|
||||
ofstream* _out;
|
||||
|
||||
};
|
||||
|
||||
class ChunkCommandHelper : public Command {
|
||||
public:
|
||||
ChunkCommandHelper( const char * name )
|
||||
@ -507,7 +559,8 @@ namespace mongo {
|
||||
{
|
||||
ShardForceModeBlock sf;
|
||||
writelock lk(ns);
|
||||
long long num = Helpers::removeRange( ns , min , max , true );
|
||||
RemoveSaver rs(ns,"post-cleanup");
|
||||
long long num = Helpers::removeRange( ns , min , max , true , false , &rs );
|
||||
log() << "moveChunk deleted: " << num << endl;
|
||||
result.appendNumber( "numDeleted" , num );
|
||||
}
|
||||
@ -597,7 +650,8 @@ namespace mongo {
|
||||
|
||||
{ // delete any data already in range
|
||||
writelock lk( ns );
|
||||
long long num = Helpers::removeRange( ns , min , max , true );
|
||||
RemoveSaver rs( ns , "preCleanup" );
|
||||
long long num = Helpers::removeRange( ns , min , max , true , false , &rs );
|
||||
if ( num )
|
||||
log( LL_WARNING ) << "moveChunkCmd deleted data already in chunk # objects: " << num << endl;
|
||||
}
|
||||
@ -679,10 +733,12 @@ namespace mongo {
|
||||
writelock lk(ns);
|
||||
Client::Context cx(ns);
|
||||
|
||||
RemoveSaver rs( ns , "removedDuring" );
|
||||
|
||||
BSONObjIterator i( xfer["deleted"].Obj() );
|
||||
while ( i.more() ){
|
||||
BSONObj id = i.next().Obj();
|
||||
Helpers::removeRange( ns , id , id, false , true );
|
||||
Helpers::removeRange( ns , id , id, false , true , &rs );
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user