Skip to content

Commit 659f5e1

Browse files
committed
CXX-275 Backport server r2.7.2..r2.7.3 changes
1 parent bf98e8a commit 659f5e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1413
-259
lines changed

src/SConscript.client

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ clientSourceBasic = [
101101
'mongo/db/jsobj.cpp',
102102
'mongo/db/json.cpp',
103103
'mongo/db/dbmessage.cpp',
104+
'mongo/logger/component_message_log_domain.cpp',
105+
'mongo/logger/log_component.cpp',
106+
'mongo/logger/log_component_settings.cpp',
104107
'mongo/logger/log_manager.cpp',
105108
'mongo/logger/log_severity.cpp',
106109
'mongo/logger/logger.cpp',
@@ -121,6 +124,7 @@ clientSourceBasic = [
121124
'mongo/util/log.cpp',
122125
'mongo/util/md5.cpp',
123126
'mongo/util/password_digest.cpp',
127+
'mongo/util/net/hostandport.cpp',
124128
'mongo/util/net/httpclient.cpp',
125129
'mongo/util/net/message.cpp',
126130
'mongo/util/net/message_port.cpp',
@@ -216,7 +220,10 @@ clientHeaders = [
216220
'mongo/db/jsobj.h',
217221
'mongo/db/json.h',
218222
'mongo/logger/appender.h',
223+
'mongo/logger/component_message_log_domain.h',
219224
'mongo/logger/labeled_level.h',
225+
'mongo/logger/log_component.h',
226+
'mongo/logger/log_component_settings.h',
220227
'mongo/logger/log_domain.h',
221228
'mongo/logger/log_manager.h',
222229
'mongo/logger/log_severity-inl.h',

src/mongo/SConscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ unittests = [
5555
'platform/atomic_word_test',
5656
'platform/process_id_test',
5757
'platform/random_test',
58+
'util/net/hostandport_test',
5859
'util/net/sock_test',
5960
'util/stringutils_test',
6061
'util/time_support_test',

src/mongo/base/error_codes.err

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ error_code("SplitFailed", 88)
9191
error_code("NetworkTimeout", 89)
9292
error_code("CallbackCanceled", 90)
9393
error_code("ShutdownInProgress", 91)
94+
error_code("SecondaryAheadOfPrimary", 92)
95+
error_code("InvalidReplicaSetConfig", 93)
96+
error_code("NotYetInitialized", 94)
97+
error_code("NotSecondary", 95)
98+
error_code("OperationFailed", 96)
99+
94100

95101
# Non-sequential error codes (for compatibility only)
96102
error_code("NotMaster", 10107) #this comes from assert_util.h
@@ -101,6 +107,8 @@ error_code("OutOfDiskSpace", 14031 )
101107
error_code("KeyTooLong", 17280);
102108
error_code("BackgroundOperationInProgressForDatabase", 12586);
103109
error_code("BackgroundOperationInProgressForNamespace", 12587);
110+
error_code("NotMasterOrSecondaryCode", 13436);
111+
error_code("NotMasterNoSlaveOkCode", 13435);
104112

105113
error_class("NetworkError", ["HostUnreachable", "HostNotFound", "NetworkTimeout"])
106114
error_class("Interruption", ["Interrupted", "InterruptedAtShutdown", "ExceededTimeLimit"])

src/mongo/base/parse_number.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ namespace mongo {
131131
if (limits::is_signed) {
132132
for (size_t i = 0; i < str.size(); ++i) {
133133
NumberType digitValue = NumberType(_digitValue(str[i]));
134-
if (int(digitValue) >= base)
135-
return Status(ErrorCodes::FailedToParse, "Bad digit");
134+
if (int(digitValue) >= base) {
135+
return Status(ErrorCodes::FailedToParse,
136+
"Bad digit \"" + str.substr(i, 1).toString() +
137+
"\" while parsing " + stringValue.toString());
138+
}
136139

137140
// MSVC: warning C4146: unary minus operator applied to unsigned type, result still unsigned
138141
// This code is statically known to be dead when NumberType is unsigned, so the warning is not real
@@ -156,8 +159,11 @@ namespace mongo {
156159
else {
157160
for (size_t i = 0; i < str.size(); ++i) {
158161
NumberType digitValue = NumberType(_digitValue(str[i]));
159-
if (int(digitValue) >= base)
160-
return Status(ErrorCodes::FailedToParse, "Bad digit");
162+
if (int(digitValue) >= base) {
163+
return Status(ErrorCodes::FailedToParse,
164+
"Bad digit \"" + str.substr(i, 1).toString() +
165+
"\" while parsing " + stringValue.toString());
166+
}
161167
if ((NumberType(limits::max() / base) < n) ||
162168
(NumberType(limits::max() - n * base) < digitValue)) {
163169

src/mongo/bson/bsonelement.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ namespace mongo {
6767
std::string foo = obj["foo"].String(); // std::exception if not a std::string type or DNE
6868
*/
6969
std::string String() const { return chk(mongo::String).str(); }
70+
const StringData checkAndGetStringData() const {
71+
return chk(mongo::String).valueStringData();
72+
}
7073
Date_t Date() const { return chk(mongo::Date).date(); }
7174
double Number() const { return chk(isNumber()).number(); }
7275
double Double() const { return chk(NumberDouble)._numberDouble(); }
@@ -265,6 +268,14 @@ namespace mongo {
265268
return type() == mongo::String ? std::string(valuestr(), valuestrsize()-1) : std::string();
266269
}
267270

271+
/**
272+
* Returns a StringData pointing into this element's data. Does not validate that the
273+
* element is actually of type String.
274+
*/
275+
const StringData valueStringData() const {
276+
return StringData(valuestr(), valuestrsize() - 1);
277+
}
278+
268279
/** Get javascript code of a CodeWScope data element. */
269280
const char * codeWScopeCode() const {
270281
massert( 16177 , "not codeWScope" , type() == CodeWScope );

src/mongo/client/connection_string_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ namespace {
6262

6363
{ "mongodb://127.0.0.1:1234,127.0.0.1:1234/dbName?foo=a&c=b&replicaSet=replName", "", "", kSet, "replName", 2, 3, "dbName" },
6464

65+
#if 0
66+
// TODO: Re-enable these tests when HostAndPort can properly parse IPv6
67+
6568
{ "mongodb://user:pwd@[::1]", "user", "pwd", kMaster, "", 1, 0, "" },
6669

6770
{ "mongodb://user@[::1]", "user", "", kMaster, "", 1, 0, "" },
@@ -109,6 +112,7 @@ namespace {
109112
{ "mongodb://user@[::1]:1234,127.0.0.2:1234/?replicaSet=replName", "user", "", kSet, "replName", 2, 1, "" },
110113

111114
{ "mongodb://[::1]:1234,[::1]:1234/dbName?foo=a&c=b&replicaSet=replName", "", "", kSet, "replName", 2, 3, "dbName"},
115+
#endif
112116
};
113117

114118

src/mongo/client/connpool.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
#include <boost/thread/locks.hpp>
2626

2727
#include "mongo/client/replica_set_monitor.h"
28+
#include "mongo/util/log.h"
2829

2930
namespace mongo {
3031

32+
MONGO_LOG_DEFAULT_COMPONENT_FILE(::mongo::logger::LogComponent::kNetworking);
33+
3134
using std::endl;
3235
using std::list;
3336
using std::map;
@@ -264,7 +267,19 @@ namespace mongo {
264267
return _finishCreate( host , socketTimeout , c );
265268
}
266269

270+
void DBConnectionPool::onRelease(DBClientBase* conn) {
271+
if (_hooks->empty()) {
272+
return;
273+
}
274+
275+
for (list<DBConnectionHook*>::iterator i = _hooks->begin(); i != _hooks->end(); i++) {
276+
(*i)->onRelease( conn );
277+
}
278+
}
279+
267280
void DBConnectionPool::release(const string& host, DBClientBase *c) {
281+
onRelease(c);
282+
268283
boost::lock_guard<boost::mutex> L(_mutex);
269284
_pools[PoolKey(host,c->getSoTimeout())].done(this,c);
270285
}

src/mongo/client/connpool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ namespace mongo {
133133
virtual ~DBConnectionHook() {}
134134
virtual void onCreate( DBClientBase * conn ) {}
135135
virtual void onHandedOut( DBClientBase * conn ) {}
136+
virtual void onRelease(DBClientBase* conn) {}
136137
virtual void onDestroy( DBClientBase * conn ) {}
137138
};
138139

@@ -180,6 +181,7 @@ namespace mongo {
180181
void onCreate( DBClientBase * conn );
181182
void onHandedOut( DBClientBase * conn );
182183
void onDestroy( DBClientBase * conn );
184+
void onRelease(DBClientBase* conn);
183185

184186
void flush();
185187

src/mongo/client/dbclient.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "mongo/db/json.h"
3939
#include "mongo/db/namespace_string.h"
4040
#include "mongo/util/assert_util.h"
41+
#include "mongo/util/log.h"
4142
#include "mongo/util/net/ssl_manager.h"
4243
#include "mongo/util/password_digest.h"
4344

@@ -59,6 +60,8 @@ namespace mongo {
5960
using std::stringstream;
6061
using std::vector;
6162

63+
MONGO_LOG_DEFAULT_COMPONENT_FILE(::mongo::logger::LogComponent::kNetworking);
64+
6265
AtomicInt64 DBClientBase::ConnectionIdSequence;
6366

6467
const char* const saslCommandUserSourceFieldName = "userSource";
@@ -108,10 +111,10 @@ namespace mongo {
108111

109112
string::size_type idx;
110113
while ( ( idx = s.find( ',' ) ) != string::npos ) {
111-
_servers.push_back( s.substr( 0 , idx ) );
114+
_servers.push_back(HostAndPort(s.substr(0, idx)));
112115
s = s.substr( idx + 1 );
113116
}
114-
_servers.push_back( s );
117+
_servers.push_back(HostAndPort(s));
115118

116119
}
117120

@@ -1995,7 +1998,7 @@ namespace mongo {
19951998
bool serverAlive( const string &uri ) {
19961999
DBClientConnection c( false, 0, 20 ); // potentially the connection to server could fail while we're checking if it's alive - so use timeouts
19972000
string err;
1998-
if ( !c.connect( uri, err ) )
2001+
if ( !c.connect( HostAndPort(uri), err ) )
19992002
return false;
20002003
if ( !c.simpleCommand( "admin", 0, "ping" ) )
20012004
return false;

0 commit comments

Comments
 (0)