/* comment MUST only be set when initiating the set by the initiator */ void ReplSetConfig::saveConfigLocally(bo comment) { checkRsConfig(); log() << "replSet info saving a newer config version to local.system.replset" << rsLog; { writelock lk(""); Client::Context cx( rsConfigNs ); cx.db()->flushFiles(true); //theReplSet->lastOpTimeWritten = ??; //rather than above, do a logOp()? probably BSONObj o = asBson(); Helpers::putSingletonGod(rsConfigNs.c_str(), o, false/*logOp=false; local db so would work regardless...*/); if( !comment.isEmpty() && (!theReplSet || theReplSet->isPrimary()) ) logOpInitiate(comment); cx.db()->flushFiles(true); } log() << "replSet saveConfigLocally done" << rsLog; }
/* comment MUST only be set when initiating the set by the initiator */ void ReplSetConfig::saveConfigLocally(bo comment, bool onInitiate) { checkRsConfig(); log() << "replSet info saving a newer config version to local.system.replset" << rsLog; { // TODO: does this really need to be a global lock? Lock::GlobalWrite lk; Client::Context cx( rsConfigNs ); Client::Transaction transaction(DB_SERIALIZABLE); if (onInitiate) { cc().txn().txnIntiatingRs(); } BSONObj o = asBson(); Helpers::putSingleton(rsConfigNs.c_str(), o); if( !comment.isEmpty() && (!theReplSet || theReplSet->isPrimary()) ) { OpLogHelpers::logComment(comment, &cc().txn()); } transaction.commit(0); } log() << "replSet saveConfigLocally done" << rsLog; }
/* comment MUST only be set when initiating the set by the initiator */ void ReplSetConfig::saveConfigLocally(bo comment) { checkRsConfig(); BSONObj newConfigBSON = asBson(); log() << "replSet info saving a newer config version to local.system.replset: " << newConfigBSON << rsLog; { OperationContextImpl txn; Client::WriteContext cx(&txn, rsConfigNs); //theReplSet->lastOpTimeWritten = ??; //rather than above, do a logOp()? probably Helpers::putSingletonGod(&txn, rsConfigNs.c_str(), newConfigBSON, false/*logOp=false; local db so would work regardless...*/); if( !comment.isEmpty() && (!theReplSet || theReplSet->isPrimary()) ) logOpInitiate(&txn, comment); } log() << "replSet saveConfigLocally done" << rsLog; }
int main(int argc, char *argv[]) { try { cout << "mongoperf" << endl; if( argc > 1 ) { cout << "\n" "usage:\n" "\n" " mongoperf < myjsonconfigfile\n" "\n" " {\n" " nThreads:<n>, // number of threads (default 1)\n" " fileSizeMB:<n>, // test file size (default 1MB)\n" " sleepMicros:<n>, // pause for sleepMicros/nThreads between each operation (default 0)\n" " mmf:<bool>, // if true do i/o's via memory mapped files (default false)\n" " r:<bool>, // do reads (default false)\n" " w:<bool>, // do writes (default false)\n" " recSizeKB:<n>, // size of each write (default 4KB)\n" " syncDelay:<n> // secs between fsyncs, like --syncdelay in mongod. (default 0/never)\n" " }\n" "\n" "mongoperf is a performance testing tool. the initial tests are of disk subsystem performance; \n" " tests of mongos and mongod will be added later.\n" "most fields are optional.\n" "non-mmf io is direct io (no caching). use a large file size to test making the heads\n" " move significantly and to avoid i/o coalescing\n" "mmf io uses caching (the file system cache).\n" "\n" << endl; return EXIT_SUCCESS; } cout << "use -h for help" << endl; char input[1024]; memset(input, 0, sizeof(input)); cin.read(input, 1000); if( *input == 0 ) { cout << "error no options found on stdin for mongoperf" << endl; return EXIT_FAILURE; } string s = input; mongoutils::str::stripTrailing(s, " \n\r\0x1a"); try { options = fromjson(s); } catch(...) { cout << "couldn't parse json options. input was:\n|" << s << "|" << endl; return EXIT_FAILURE; } cout << "parsed options:\n" << options.toString() << endl; go(); } catch(DBException& e) { cout << "caught DBException " << e.toString() << endl; return EXIT_FAILURE; } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { try { cout << "mongoperf" << endl; if( argc > 1 ) { cout << "\n" "usage:\n" "\n" " mongoperf < myjsonconfigfile\n" "\n" " {\n" " nThreads:<n>, // number of threads\n" " fileSizeMB:<n>, // test file size\n" " sleepMicros:<n>, // pause for sleepMicros/nThreads between each operation\n" " mmf:<bool>, // if true do i/o's via memory mapped files\n" " r:<bool>, // do reads\n" " w:<bool> // do writes\n" " }\n" "\n" "most fields are optional.\n" "non-mmf io is direct io (no caching). use a large file size to test making the heads\n" " move significantly and to avoid i/o coalescing\n" "mmf io uses caching (the file system cache).\n" "\n" << endl; return 0; } cout << "use -h for help" << endl; char input[1024]; memset(input, 0, sizeof(input)); cin.read(input, 1000); if( *input == 0 ) { cout << "error no options found on stdin for mongoperf" << endl; return 2; } string s = input; str::stripTrailing(s, "\n\r\0x1a"); try { options = fromjson(s); } catch(...) { cout << s << endl; cout << "couldn't parse json options" << endl; return -1; } cout << "options:\n" << options.toString() << endl; go(); #if 0 cout << "connecting to localhost..." << endl; DBClientConnection c; c.connect("localhost"); cout << "connected ok" << endl; unsigned long long count = c.count("test.foo"); cout << "count of exiting documents in collection test.foo : " << count << endl; bo o = BSON( "hello" << "world" ); c.insert("test.foo", o); string e = c.getLastError(); if( !e.empty() ) { cout << "insert #1 failed: " << e << endl; } // make an index with a unique key constraint c.ensureIndex("test.foo", BSON("hello"<<1), /*unique*/true); c.insert("test.foo", o); // will cause a dup key error on "hello" field cout << "we expect a dup key error here:" << endl; cout << " " << c.getLastErrorDetailed().toString() << endl; #endif } catch(DBException& e) { cout << "caught DBException " << e.toString() << endl; return 1; } return 0; }