Skip to content

Commit 62b0831

Browse files
bcaimanoEvergreen Agent
authored andcommitted
SERVER-47073 Clean up log lines in mongo/client and mongo/executor
1 parent a6424fa commit 62b0831

25 files changed

+400
-343
lines changed

src/mongo/client/async_client.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ void AsyncDBClient::_parseIsMasterResponse(BSONObj request,
112112
rpc::validateWireVersion(WireSpec::instance().outgoing, protocolSet.version);
113113
if (!validateStatus.isOK()) {
114114
LOGV2_WARNING(23741,
115-
"remote host has incompatible wire version: {validateStatus}",
116-
"validateStatus"_attr = validateStatus);
115+
"Remote host has incompatible wire version: {error}",
116+
"Remote host has incompatible wire version",
117+
"error"_attr = validateStatus);
117118
uasserted(validateStatus.code(),
118119
str::stream() << "remote host has incompatible wire version: "
119120
<< validateStatus.reason());

src/mongo/client/authenticate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ Future<void> authenticateClient(const BSONObj& params,
151151
if (serverGlobalParams.transitionToAuth && !ErrorCodes::isNetworkError(status)) {
152152
// If auth failed in transitionToAuth, just pretend it succeeded.
153153
LOGV2(20108,
154-
"Failed to authenticate in transitionToAuth, falling back to no "
155-
"authentication.");
154+
"Failed to authenticate in transitionToAuth, "
155+
"falling back to no authentication");
156156

157157
return Status::OK();
158158
}

src/mongo/client/connection_string_connect.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ std::unique_ptr<DBClientBase> ConnectionString::connect(StringData applicationNa
6161
auto c = std::make_unique<DBClientConnection>(true, 0, newURI);
6262

6363
c->setSoTimeout(socketTimeout);
64-
LOGV2_DEBUG(
65-
20109, 1, "creating new connection to:{server}", "server"_attr = server);
64+
LOGV2_DEBUG(20109,
65+
1,
66+
"Creating new connection to: {hostAndPort}",
67+
"Creating new connection",
68+
"hostAndPort"_attr = server);
6669
if (!c->connect(server, applicationName, errmsg)) {
6770
continue;
6871
}
69-
LOGV2_DEBUG(20110, 1, "connected connection!");
72+
LOGV2_DEBUG(20110, 1, "Connected connection!");
7073
return std::move(c);
7174
}
7275
return nullptr;
@@ -98,10 +101,10 @@ std::unique_ptr<DBClientBase> ConnectionString::connect(StringData applicationNa
98101
auto replacementConn = _connectHook->connect(*this, errmsg, socketTimeout);
99102

100103
LOGV2(20111,
101-
"replacing connection to {this} with "
102-
"{replacementConn_replacementConn_getServerAddress_empty}",
103-
"this"_attr = this->toString(),
104-
"replacementConn_replacementConn_getServerAddress_empty"_attr =
104+
"Replacing connection to {oldConnString} with {newConnString}",
105+
"Replacing connection string",
106+
"oldConnString"_attr = this->toString(),
107+
"newConnString"_attr =
105108
(replacementConn ? replacementConn->getServerAddress() : "(empty)"));
106109

107110
return replacementConn;

src/mongo/client/connpool.cpp

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ namespace mongo {
6262
namespace {
6363
const int kDefaultIdleTimeout = std::numeric_limits<int>::max();
6464
const int kDefaultMaxInUse = std::numeric_limits<int>::max();
65+
66+
auto makeDuration(double secs) {
67+
return Milliseconds(static_cast<Milliseconds::rep>(1000 * secs));
68+
}
6569
} // namespace
6670

6771
using std::endl;
@@ -91,10 +95,11 @@ PoolForHost::~PoolForHost() {
9195
void PoolForHost::clear() {
9296
if (!_parentDestroyed) {
9397
LOGV2(24124,
94-
"Dropping all pooled connections to {hostName}(with timeout of {socketTimeoutSecs} "
95-
"seconds)",
96-
"hostName"_attr = _hostName,
97-
"socketTimeoutSecs"_attr = _socketTimeoutSecs);
98+
"Dropping all pooled connections to {connString} "
99+
"(with timeout of {timeoutSecs} seconds)",
100+
"Dropping all pooled connections to a host",
101+
"connString"_attr = _hostName,
102+
"socketTimeout"_attr = makeDuration(_socketTimeoutSecs));
98103
}
99104

100105
_pool = decltype(_pool){};
@@ -114,23 +119,24 @@ auto PoolForHost::done(DBConnectionPool* pool, DBClientBase* c) -> ConnectionHea
114119
bool isBroken = c->getSockCreationMicroSec() < _minValidCreationTimeMicroSec;
115120
if (isFailed || isBroken) {
116121
_badConns++;
117-
LOGV2(
118-
24125,
119-
"Ending connection to host {hostName}(with timeout of {socketTimeoutSecs} seconds) due "
120-
"to bad connection status; {openConnections} connections to that host remain open",
121-
"hostName"_attr = _hostName,
122-
"socketTimeoutSecs"_attr = _socketTimeoutSecs,
123-
"openConnections"_attr = openConnections());
122+
LOGV2(24125,
123+
"Ending connection to {connString} (with timeout of {socketTimeout}) "
124+
"due to bad connection status; {numOpenConns} connections to that host remain open",
125+
"Ending connection to a host due to a bad connection status",
126+
"connString"_attr = _hostName,
127+
"socketTimeout"_attr = makeDuration(_socketTimeoutSecs),
128+
"numOpenConns"_attr = openConnections());
124129
return ConnectionHealth::kFailed;
125130
} else if (_maxPoolSize >= 0 && static_cast<int>(_pool.size()) >= _maxPoolSize) {
126131
// We have a pool size that we need to enforce
127132
LOGV2(24126,
128-
"Ending idle connection to host {hostName}(with timeout of {socketTimeoutSecs} "
129-
"seconds) because the pool meets constraints; {openConnections} connections to that "
130-
"host remain open",
131-
"hostName"_attr = _hostName,
132-
"socketTimeoutSecs"_attr = _socketTimeoutSecs,
133-
"openConnections"_attr = openConnections());
133+
"Ending idle connection to {connString} (with timeout of {socketTimeout}) "
134+
"because its pool meets constraints; "
135+
"{numOpenConns} connections to that host remain open",
136+
"Ending idle connection to a host because its pool mees constraints",
137+
"connString"_attr = _hostName,
138+
"socketTimeout"_attr = makeDuration(_socketTimeoutSecs),
139+
"numOpenConns"_attr = openConnections());
134140
return ConnectionHealth::kTooMany;
135141
}
136142

@@ -144,11 +150,13 @@ void PoolForHost::reportBadConnectionAt(uint64_t microSec) {
144150
microSec > _minValidCreationTimeMicroSec) {
145151
_minValidCreationTimeMicroSec = microSec;
146152
LOGV2(24127,
147-
"Detected bad connection created at {minValidCreationTimeMicroSec} microSec, "
148-
"clearing pool for {hostName} of {openConnections} connections",
149-
"minValidCreationTimeMicroSec"_attr = _minValidCreationTimeMicroSec,
150-
"hostName"_attr = _hostName,
151-
"openConnections"_attr = openConnections());
153+
"Detected bad connection created at {currentTime}, "
154+
"clearing pool for {connString} of {numOpenConns} connections",
155+
"Detected bad connection, clearing pool for host",
156+
"currentTime"_attr =
157+
Microseconds(static_cast<Microseconds::rep>(_minValidCreationTimeMicroSec)),
158+
"connString"_attr = _hostName,
159+
"numOpenConns"_attr = openConnections());
152160
clear();
153161
}
154162
}
@@ -280,9 +288,10 @@ class DBConnectionPool::Detail {
280288

281289
if (p.openConnections() >= _this->_maxInUse) {
282290
LOGV2(20112,
283-
"Too many in-use connections; waiting until there are fewer than "
284-
"{this_maxInUse}",
285-
"this_maxInUse"_attr = _this->_maxInUse);
291+
"Too many in-use connections; "
292+
"waiting until there are fewer than {maxInUseConns}",
293+
"Too many in-use connections; waiting until there are fewer than maximum",
294+
"maxInUseConns"_attr = _this->_maxInUse);
286295
p.waitForFreeConnection(timeout, lk);
287296
} else {
288297
// Drop the lock here, so we can connect without holding it.
@@ -367,12 +376,13 @@ DBClientBase* DBConnectionPool::_finishCreate(const string& ident,
367376
}
368377

369378
LOGV2(20113,
370-
"Successfully connected to {ident} ({openConnections_ident_socketTimeout} connections "
371-
"now open to {ident2} with a {socketTimeout} second timeout)",
372-
"ident"_attr = ident,
373-
"openConnections_ident_socketTimeout"_attr = openConnections(ident, socketTimeout),
374-
"ident2"_attr = ident,
375-
"socketTimeout"_attr = socketTimeout);
379+
"Successfully connected to {connString} "
380+
"({numOpenConns} connections now open to that host "
381+
"with a {socketTimeoutSecs} second timeout)",
382+
"Successfully connected to host",
383+
"connString"_attr = ident,
384+
"numOpenConns"_attr = openConnections(ident, socketTimeout),
385+
"socketTimeoutSecs"_attr = socketTimeout);
376386

377387
return conn;
378388
}
@@ -490,16 +500,23 @@ void DBConnectionPool::flush() {
490500

491501
void DBConnectionPool::clear() {
492502
stdx::lock_guard<Latch> L(_mutex);
493-
LOGV2_DEBUG(20114, 2, "Removing connections on all pools owned by {name}", "name"_attr = _name);
503+
LOGV2_DEBUG(20114,
504+
2,
505+
"Removing connections on all pools owned by {poolName}",
506+
"Removing all connectionns associated with this set of pools",
507+
"poolName"_attr = _name);
494508
for (PoolMap::iterator iter = _pools.begin(); iter != _pools.end(); ++iter) {
495509
iter->second.clear();
496510
}
497511
}
498512

499513
void DBConnectionPool::removeHost(const string& host) {
500514
stdx::lock_guard<Latch> L(_mutex);
501-
LOGV2_DEBUG(
502-
20115, 2, "Removing connections from all pools for host: {host}", "host"_attr = host);
515+
LOGV2_DEBUG(20115,
516+
2,
517+
"Removing connections from all pools to {connString}",
518+
"Removing connections from all pools to a host",
519+
"connString"_attr = host);
503520
for (PoolMap::iterator i = _pools.begin(); i != _pools.end(); ++i) {
504521
const string& poolHost = i->first.ident;
505522
if (!serverNameCompare()(host, poolHost) && !serverNameCompare()(poolHost, host)) {
@@ -701,8 +718,9 @@ ScopedDbConnection::~ScopedDbConnection() {
701718
} else {
702719
/* see done() comments above for why we log this line */
703720
LOGV2(24128,
704-
"scoped connection to {conn_getServerAddress} not being returned to the pool",
705-
"conn_getServerAddress"_attr = _conn->getServerAddress());
721+
"Scoped connection to {connString} not being returned to the pool",
722+
"Scoped connection not being returned to the pool",
723+
"connString"_attr = _conn->getServerAddress());
706724
kill();
707725
}
708726
}

src/mongo/client/dbclient_base.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,12 @@ Status DBClientBase::authenticateInternalUser() {
501501
return status;
502502
}
503503

504-
if (serverGlobalParams.quiet.load()) {
504+
if (!serverGlobalParams.quiet.load()) {
505505
LOGV2(20117,
506-
"can't authenticate to {} as internal user, error: {status_reason}",
507-
""_attr = toString(),
508-
"status_reason"_attr = status.reason());
506+
"Can't authenticate to {connString} as internal user, error: {error}",
507+
"Can't authenticate as internal user",
508+
"connString"_attr = toString(),
509+
"error"_attr = status);
509510
}
510511

511512
return status;
@@ -999,6 +1000,7 @@ void DBClientBase::dropIndex(const string& ns,
9991000
LOGV2_DEBUG(20118,
10001001
logSeverityV1toV2(_logLevel).toInt(),
10011002
"dropIndex failed: {info}",
1003+
"dropIndex failed",
10021004
"info"_attr = info);
10031005
uassert(10007, "dropIndex failed", 0);
10041006
}

src/mongo/client/dbclient_connection.cpp

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,9 @@ Status DBClientConnection::connect(const HostAndPort& serverAddress, StringData
342342
rpc::validateWireVersion(WireSpec::instance().outgoing, swProtocolSet.getValue().version);
343343
if (!validateStatus.isOK()) {
344344
LOGV2_WARNING(20126,
345-
"remote host has incompatible wire version: {validateStatus}",
346-
"validateStatus"_attr = validateStatus);
345+
"Remote host has incompatible wire version: {error}",
346+
"Remote host has incompatible wire version",
347+
"error"_attr = validateStatus);
347348

348349
return validateStatus;
349350
}
@@ -426,7 +427,11 @@ Status DBClientConnection::connectSocketOnly(const HostAndPort& serverAddress) {
426427
_lastConnectivityCheck = Date_t::now();
427428
_session->setTimeout(_socketTimeout);
428429
_session->setTags(_tagMask);
429-
LOGV2_DEBUG(20119, 1, "connected to server {}", ""_attr = toString());
430+
LOGV2_DEBUG(20119,
431+
1,
432+
"Connected to host {connString}",
433+
"Connected to host",
434+
"connString"_attr = toString());
430435
return Status::OK();
431436
}
432437

@@ -555,26 +560,31 @@ void DBClientConnection::_checkConnection() {
555560

556561
LOGV2_DEBUG(20120,
557562
logSeverityV1toV2(_logLevel).toInt(),
558-
"trying reconnect to {}",
559-
""_attr = toString());
563+
"Trying to reconnect to {connString}",
564+
"Trying to reconnnect",
565+
"connString"_attr = toString());
560566
string errmsg;
561567
auto connectStatus = connect(_serverAddress, _applicationName);
562568
if (!connectStatus.isOK()) {
563569
_markFailed(kSetFlag);
564570
LOGV2_DEBUG(20121,
565571
logSeverityV1toV2(_logLevel).toInt(),
566-
"reconnect {} failed {errmsg}",
567-
""_attr = toString(),
568-
"errmsg"_attr = errmsg);
572+
"Reconnect attempt to {connString} failed: {reason}",
573+
"Reconnect attempt failed",
574+
"connString"_attr = toString(),
575+
"error"_attr = errmsg);
569576
if (connectStatus == ErrorCodes::IncompatibleCatalogManager) {
570577
uassertStatusOK(connectStatus); // Will always throw
571578
} else {
572579
throwSocketError(SocketErrorKind::CONNECT_ERROR, connectStatus.reason());
573580
}
574581
}
575582

576-
LOGV2_DEBUG(
577-
20122, logSeverityV1toV2(_logLevel).toInt(), "reconnect {} ok", ""_attr = toString());
583+
LOGV2_DEBUG(20122,
584+
logSeverityV1toV2(_logLevel).toInt(),
585+
"Reconnected to {connString}",
586+
"Reconnected",
587+
"connString"_attr = toString());
578588
if (_internalAuthOnReconnect) {
579589
uassertStatusOK(authenticateInternalUser());
580590
} else {
@@ -584,14 +594,11 @@ void DBClientConnection::_checkConnection() {
584594
} catch (ExceptionFor<ErrorCodes::AuthenticationFailed>& ex) {
585595
LOGV2_DEBUG(20123,
586596
logSeverityV1toV2(_logLevel).toInt(),
587-
"reconnect: auth failed "
588-
"{kv_second_auth_getSaslCommandUserDBFieldName}{kv_second_auth_"
589-
"getSaslCommandUserFieldName} {ex_what}",
590-
"kv_second_auth_getSaslCommandUserDBFieldName"_attr =
591-
kv.second[auth::getSaslCommandUserDBFieldName()],
592-
"kv_second_auth_getSaslCommandUserFieldName"_attr =
593-
kv.second[auth::getSaslCommandUserFieldName()],
594-
"ex_what"_attr = ex.what());
597+
"Reconnect: auth failed for on {db} using {user}: {reason}",
598+
"Reconnect: auth failed",
599+
"db"_attr = kv.second[auth::getSaslCommandUserDBFieldName()],
600+
"user"_attr = kv.second[auth::getSaslCommandUserFieldName()],
601+
"error"_attr = ex.what());
595602
}
596603
}
597604
}
@@ -747,9 +754,10 @@ bool DBClientConnection::call(Message& toSend,
747754
auto sinkStatus = _session->sinkMessage(swm.getValue());
748755
if (!sinkStatus.isOK()) {
749756
LOGV2(20124,
750-
"DBClientConnection failed to send message to {getServerAddress} - {sinkStatus}",
751-
"getServerAddress"_attr = getServerAddress(),
752-
"sinkStatus"_attr = redact(sinkStatus));
757+
"DBClientConnection failed to send message to {connString}: {error}",
758+
"DBClientConnection failed to send message",
759+
"connString"_attr = getServerAddress(),
760+
"error"_attr = redact(sinkStatus));
753761
return maybeThrow(sinkStatus);
754762
}
755763

@@ -758,10 +766,10 @@ bool DBClientConnection::call(Message& toSend,
758766
response = std::move(swm.getValue());
759767
} else {
760768
LOGV2(20125,
761-
"DBClientConnection failed to receive message from {getServerAddress} - "
762-
"{swm_getStatus}",
763-
"getServerAddress"_attr = getServerAddress(),
764-
"swm_getStatus"_attr = redact(swm.getStatus()));
769+
"DBClientConnection failed to receive message from {connString}: {error}",
770+
"DBClientConnection failed to receive message",
771+
"connString"_attr = getServerAddress(),
772+
"error"_attr = redact(swm.getStatus()));
765773
return maybeThrow(swm.getStatus());
766774
}
767775

src/mongo/client/dbclient_cursor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,9 @@ bool DBClientCursor::initLazyFinish(bool& retry) {
242242
if (!recvStatus.isOK() || reply.empty()) {
243243
if (!recvStatus.isOK())
244244
LOGV2(20129,
245-
"DBClientCursor::init lazy say() failed: {recvStatus}",
246-
"recvStatus"_attr = redact(recvStatus));
245+
"DBClientCursor::init lazy say() failed: {error}",
246+
"DBClientCursor::init lazy say() failed",
247+
"error"_attr = redact(recvStatus));
247248
if (reply.empty())
248249
LOGV2(20130, "DBClientCursor::init message from say() was empty");
249250

0 commit comments

Comments
 (0)