Skip to content

Commit

Permalink
SERVER-30166 Replace string with explicit std::string. Enables compul…
Browse files Browse the repository at this point in the history
…ation when using --use-system-pcre which presusably used to do 'using std::string' in an earlier version of pcre

Closes #1167

Signed-off-by: Mark Benvenuto <mark.benvenuto@mongodb.com>
  • Loading branch information
Steven Green authored and markbenvenuto committed Aug 22, 2017
1 parent d4008e6 commit b7cebf8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/mongo/db/matcher/expression_leaf.cpp
Expand Up @@ -207,7 +207,7 @@ void ComparisonMatchExpression::debugString(StringBuilder& debug, int level) con
}

void ComparisonMatchExpression::serialize(BSONObjBuilder* out) const {
string opString = "";
std::string opString = "";
switch (matchType()) {
case LT:
opString = "$lt";
Expand Down Expand Up @@ -763,7 +763,7 @@ void BitTestMatchExpression::debugString(StringBuilder& debug, int level) const
}

void BitTestMatchExpression::serialize(BSONObjBuilder* out) const {
string opString = "";
std::string opString = "";

switch (matchType()) {
case BITS_ALL_SET:
Expand Down
39 changes: 20 additions & 19 deletions src/mongo/db/repl/master_slave.cpp
Expand Up @@ -170,7 +170,7 @@ BSONObj ReplSource::jsobj() {

BSONObjBuilder dbsNextPassBuilder;
int n = 0;
for (set<string>::iterator i = addDbNextPass.begin(); i != addDbNextPass.end(); i++) {
for (set<std::string>::iterator i = addDbNextPass.begin(); i != addDbNextPass.end(); i++) {
n++;
dbsNextPassBuilder.appendBool(*i, 1);
}
Expand All @@ -179,7 +179,8 @@ BSONObj ReplSource::jsobj() {

BSONObjBuilder incompleteCloneDbsBuilder;
n = 0;
for (set<string>::iterator i = incompleteCloneDbs.begin(); i != incompleteCloneDbs.end(); i++) {
for (set<std::string>::iterator i = incompleteCloneDbs.begin(); i != incompleteCloneDbs.end();
i++) {
n++;
incompleteCloneDbsBuilder.appendBool(*i, 1);
}
Expand All @@ -190,7 +191,7 @@ BSONObj ReplSource::jsobj() {
}

void ReplSource::ensureMe(OperationContext* opCtx) {
string myname = getHostName();
std::string myname = getHostName();

// local.me is an identifier for a server for getLastError w:2+
bool exists = Helpers::getSingleton(opCtx, "local.me", _me);
Expand Down Expand Up @@ -381,7 +382,7 @@ class HandshakeCmd : public BasicCommand {
}

virtual bool run(OperationContext* opCtx,
const string& ns,
const std::string& ns,
const BSONObj& cmdObj,
BSONObjBuilder& result) {
HandshakeArgs handshake;
Expand All @@ -399,7 +400,7 @@ class HandshakeCmd : public BasicCommand {
} handshakeCmd;

bool replHandshake(DBClientConnection* conn, const OID& myRID) {
string myname = getHostName();
std::string myname = getHostName();

BSONObjBuilder cmd;
cmd.append("handshake", myRID);
Expand Down Expand Up @@ -450,7 +451,7 @@ void ReplSource::forceResync(OperationContext* opCtx, const char* requester) {
BSONElement e = i.next();
if (e.eoo())
break;
string name = e.embeddedObject().getField("name").valuestr();
std::string name = e.embeddedObject().getField("name").valuestr();
if (!e.embeddedObject().getBoolField("empty")) {
if (name != "local") {
if (only.empty() || only == name) {
Expand Down Expand Up @@ -481,7 +482,7 @@ Status ReplSource::_updateIfDoneWithInitialSync() {
return Status::OK();
}

void ReplSource::resyncDrop(OperationContext* opCtx, const string& dbName) {
void ReplSource::resyncDrop(OperationContext* opCtx, const std::string& dbName) {
log() << "resync: dropping database " << dbName;
invariant(opCtx->lockState()->isW());

Expand Down Expand Up @@ -531,13 +532,13 @@ void ReplSource::resync(OperationContext* opCtx, const std::string& dbName) {

static DatabaseIgnorer ___databaseIgnorer;

void DatabaseIgnorer::doIgnoreUntilAfter(const string& db, const Timestamp& futureOplogTime) {
void DatabaseIgnorer::doIgnoreUntilAfter(const std::string& db, const Timestamp& futureOplogTime) {
if (futureOplogTime > _ignores[db]) {
_ignores[db] = futureOplogTime;
}
}

bool DatabaseIgnorer::ignoreAt(const string& db, const Timestamp& currentOplogTime) {
bool DatabaseIgnorer::ignoreAt(const std::string& db, const Timestamp& currentOplogTime) {
if (_ignores[db].isNull()) {
return false;
}
Expand Down Expand Up @@ -627,7 +628,7 @@ bool ReplSource::handleDuplicateDbName(OperationContext* opCtx,

// The database is present on the master and no conflicting databases
// are present on the master. Drop any local conflicts.
for (set<string>::const_iterator i = duplicates.begin(); i != duplicates.end(); ++i) {
for (set<std::string>::const_iterator i = duplicates.begin(); i != duplicates.end(); ++i) {
___databaseIgnorer.doIgnoreUntilAfter(*i, lastTime);
incompleteCloneDbs.erase(*i);
addDbNextPass.erase(*i);
Expand Down Expand Up @@ -822,10 +823,10 @@ void ReplSource::_sync_pullOpLog_applyOperation(OperationContext* opCtx,
}

void ReplSource::syncToTailOfRemoteLog() {
string _ns = ns();
std::string _ns = ns();
BSONObjBuilder b;
if (!only.empty()) {
b.appendRegex("ns", string("^") + pcrecpp::RE::QuoteMeta(only));
b.appendRegex("ns", std::string("^") + pcrecpp::RE::QuoteMeta(only));
}
BSONObj last = oplogReader.findOne(_ns.c_str(), Query(b.done()).sort(BSON("$natural" << -1)));
if (!last.isEmpty()) {
Expand Down Expand Up @@ -873,7 +874,7 @@ class ReplApplyBatchSize
*/
int ReplSource::_sync_pullOpLog(OperationContext* opCtx, int& nApplied) {
int okResultCode = restartSyncAfterSleep;
string ns = string("local.oplog.$") + sourceName();
std::string ns = std::string("local.oplog.$") + sourceName();
LOG(2) << "sync_pullOpLog " << ns << " syncedTo:" << syncedTo.toStringLong() << '\n';

bool tailing = true;
Expand All @@ -893,7 +894,7 @@ int ReplSource::_sync_pullOpLog(OperationContext* opCtx, int& nApplied) {
BSONElement e = i.next();
if (e.eoo())
break;
string name = e.embeddedObject().getField("name").valuestr();
std::string name = e.embeddedObject().getField("name").valuestr();
if (!e.embeddedObject().getBoolField("empty")) {
if (name != "local") {
if (only.empty() || only == name) {
Expand All @@ -916,7 +917,7 @@ int ReplSource::_sync_pullOpLog(OperationContext* opCtx, int& nApplied) {
if (!only.empty()) {
// note we may here skip a LOT of data table scanning, a lot of work for the master.
// maybe append "\\." here?
query.appendRegex("ns", string("^") + pcrecpp::RE::QuoteMeta(only));
query.appendRegex("ns", std::string("^") + pcrecpp::RE::QuoteMeta(only));
}
BSONObj queryObj = query.done();
// e.g. queryObj = { ts: { $gte: syncedTo } }
Expand All @@ -935,7 +936,7 @@ int ReplSource::_sync_pullOpLog(OperationContext* opCtx, int& nApplied) {

// show any deferred database creates from a previous pass
{
set<string>::iterator i = addDbNextPass.begin();
set<std::string>::iterator i = addDbNextPass.begin();
if (i != addDbNextPass.end()) {
BSONObjBuilder b;
b.append("ns", *i + '.');
Expand Down Expand Up @@ -978,7 +979,7 @@ int ReplSource::_sync_pullOpLog(OperationContext* opCtx, int& nApplied) {
BSONObj op = oplogReader.nextSafe();
BSONElement ts = op.getField("ts");
if (ts.type() != Date && ts.type() != bsonTimestamp) {
string err = op.getStringField("$err");
std::string err = op.getStringField("$err");
if (!err.empty()) {
// 13051 is "tailable cursor requested on non capped collection"
if (op.getIntField("code") == 13051) {
Expand Down Expand Up @@ -1143,7 +1144,7 @@ int ReplSource::sync(OperationContext* opCtx, int& nApplied) {

// FIXME Handle cases where this db isn't on default port, or default port is spec'd in
// hostName.
if ((string("localhost") == hostName || string("127.0.0.1") == hostName) &&
if ((std::string("localhost") == hostName || std::string("127.0.0.1") == hostName) &&
serverGlobalParams.port == ServerGlobalParams::DefaultDBPort) {
log() << "can't sync from self (localhost). sources configuration may be wrong." << endl;
sleepsecs(5);
Expand Down Expand Up @@ -1275,7 +1276,7 @@ static void replMain(OperationContext* opCtx) {
if (s) {
stringstream ss;
ss << "sleep " << s << " sec before next pass";
string msg = ss.str();
std::string msg = ss.str();
if (!serverGlobalParams.quiet.load())
log() << msg << endl;
ReplInfo r(msg.c_str());
Expand Down
18 changes: 9 additions & 9 deletions src/mongo/s/catalog/sharding_catalog_create_database_test.cpp
Expand Up @@ -64,7 +64,7 @@ using std::vector;
using CreateDatabaseTest = ConfigServerTestFixture;

TEST_F(CreateDatabaseTest, createDatabaseSuccess) {
const string dbname = "db1";
const std::string dbname = "db1";

ShardType s0;
s0.setName("shard0000");
Expand Down Expand Up @@ -110,7 +110,7 @@ TEST_F(CreateDatabaseTest, createDatabaseSuccess) {
onCommand([&](const RemoteCommandRequest& request) {
ASSERT_EQUALS(s0.getHost(), request.target.toString());
ASSERT_EQUALS("admin", request.dbname);
string cmdName = request.cmdObj.firstElement().fieldName();
std::string cmdName = request.cmdObj.firstElement().fieldName();
ASSERT_EQUALS("listDatabases", cmdName);
ASSERT_FALSE(request.cmdObj.hasField(repl::ReadConcernArgs::kReadConcernFieldName));

Expand All @@ -125,7 +125,7 @@ TEST_F(CreateDatabaseTest, createDatabaseSuccess) {
onCommand([&](const RemoteCommandRequest& request) {
ASSERT_EQUALS(s1.getHost(), request.target.toString());
ASSERT_EQUALS("admin", request.dbname);
string cmdName = request.cmdObj.firstElement().fieldName();
std::string cmdName = request.cmdObj.firstElement().fieldName();
ASSERT_EQUALS("listDatabases", cmdName);
ASSERT_FALSE(request.cmdObj.hasField(repl::ReadConcernArgs::kReadConcernFieldName));

Expand All @@ -140,7 +140,7 @@ TEST_F(CreateDatabaseTest, createDatabaseSuccess) {
onCommand([&](const RemoteCommandRequest& request) {
ASSERT_EQUALS(s2.getHost(), request.target.toString());
ASSERT_EQUALS("admin", request.dbname);
string cmdName = request.cmdObj.firstElement().fieldName();
std::string cmdName = request.cmdObj.firstElement().fieldName();
ASSERT_EQUALS("listDatabases", cmdName);

ASSERT_BSONOBJ_EQ(
Expand All @@ -154,7 +154,7 @@ TEST_F(CreateDatabaseTest, createDatabaseSuccess) {
}

TEST_F(CreateDatabaseTest, createDatabaseDistLockHeld) {
const string dbname = "db2";
const std::string dbname = "db2";

ASSERT_OK(distLockCatalog()
->grabLock(operationContext(),
Expand All @@ -172,7 +172,7 @@ TEST_F(CreateDatabaseTest, createDatabaseDistLockHeld) {
}

TEST_F(CreateDatabaseTest, createDatabaseDBExists) {
const string dbname = "db3";
const std::string dbname = "db3";

ShardType shard;
shard.setName("shard0");
Expand All @@ -188,8 +188,8 @@ TEST_F(CreateDatabaseTest, createDatabaseDBExists) {
}

TEST_F(CreateDatabaseTest, createDatabaseDBExistsDifferentCase) {
const string dbname = "db4";
const string dbnameDiffCase = "Db4";
const std::string dbname = "db4";
const std::string dbnameDiffCase = "Db4";

ShardType shard;
shard.setName("shard0");
Expand All @@ -205,7 +205,7 @@ TEST_F(CreateDatabaseTest, createDatabaseDBExistsDifferentCase) {
}

TEST_F(CreateDatabaseTest, createDatabaseNoShards) {
const string dbname = "db5";
const std::string dbname = "db5";

Status status =
ShardingCatalogManager::get(operationContext())->createDatabase(operationContext(), dbname);
Expand Down
14 changes: 7 additions & 7 deletions src/mongo/shell/bench.cpp
Expand Up @@ -683,7 +683,7 @@ void BenchRunWorker::generateLoadOnConnection(DBClientBase* conn) {
invariant(bsonTemplateEvaluator.setId(_id) == BsonTemplateEvaluator::StatusSuccess);

if (_config->username != "") {
string errmsg;
std::string errmsg;
if (!conn->auth("admin", _config->username, _config->password, errmsg)) {
uasserted(15931, "Authenticating to connection for _benchThread failed: " + errmsg);
}
Expand Down Expand Up @@ -955,7 +955,7 @@ void BenchRunWorker::generateLoadOnConnection(DBClientBase* conn) {
if (!result["err"].eoo() && result["err"].type() == String &&
(_config->throwGLE || op.throwGLE))
throw DBException(result["code"].eoo() ? 0 : result["code"].Int(),
(string) "From benchRun GLE" +
(std::string) "From benchRun GLE" +
causedBy(result["err"].String()));
}
} break;
Expand Down Expand Up @@ -1024,7 +1024,7 @@ void BenchRunWorker::generateLoadOnConnection(DBClientBase* conn) {
if (!result["err"].eoo() && result["err"].type() == String &&
(_config->throwGLE || op.throwGLE))
throw DBException(result["code"].eoo() ? 0 : result["code"].Int(),
(string) "From benchRun GLE" +
(std::string) "From benchRun GLE" +
causedBy(result["err"].String()));
}
} break;
Expand Down Expand Up @@ -1073,7 +1073,7 @@ void BenchRunWorker::generateLoadOnConnection(DBClientBase* conn) {
if (!result["err"].eoo() && result["err"].type() == String &&
(_config->throwGLE || op.throwGLE))
throw DBException(result["code"].eoo() ? 0 : result["code"].Int(),
(string) "From benchRun GLE " +
(std::string) "From benchRun GLE " +
causedBy(result["err"].String()));
}
} break;
Expand Down Expand Up @@ -1174,7 +1174,7 @@ void BenchRunWorker::run() {
try {
std::unique_ptr<DBClientBase> conn(_config->createConnection());
if (!_config->username.empty()) {
string errmsg;
std::string errmsg;
if (!conn->auth("admin", _config->username, _config->password, errmsg)) {
uasserted(15932, "Authenticating to connection for benchThread failed: " + errmsg);
}
Expand Down Expand Up @@ -1206,7 +1206,7 @@ void BenchRunner::start() {
std::unique_ptr<DBClientBase> conn(_config->createConnection());
// Must authenticate to admin db in order to run serverStatus command
if (_config->username != "") {
string errmsg;
std::string errmsg;
if (!conn->auth("admin", _config->username, _config->password, errmsg)) {
uasserted(
16704,
Expand Down Expand Up @@ -1242,7 +1242,7 @@ void BenchRunner::stop() {
{
std::unique_ptr<DBClientBase> conn(_config->createConnection());
if (_config->username != "") {
string errmsg;
std::string errmsg;
// this can only fail if admin access was revoked since start of run
if (!conn->auth("admin", _config->username, _config->password, errmsg)) {
uasserted(
Expand Down

0 comments on commit b7cebf8

Please sign in to comment.