104
104
WriteBackListener::init( *conn_in );
106
DBClientBase* conn = getVersionable( conn_in );
107
verify( conn ); // errors thrown above
109
BSONObjBuilder cmdBuilder;
111
cmdBuilder.append( "setShardVersion" , "" );
112
cmdBuilder.appendBool( "init", true );
113
cmdBuilder.append( "configdb" , configServer.modelServer() );
114
cmdBuilder.appendOID( "serverID" , &serverID );
115
cmdBuilder.appendBool( "authoritative" , true );
117
BSONObj cmd = cmdBuilder.obj();
119
LOG(1) << "initializing shard connection to " << conn->toString() << endl;
120
LOG(2) << "initial sharding settings : " << cmd << endl;
122
bool ok = conn->runCommand("admin", cmd, result, 0);
107
DBClientBase* conn = NULL;
109
// May throw if replica set primary is down
110
conn = getVersionable( conn_in );
111
dassert( conn ); // errors thrown above
113
BSONObjBuilder cmdBuilder;
115
cmdBuilder.append( "setShardVersion" , "" );
116
cmdBuilder.appendBool( "init", true );
117
cmdBuilder.append( "configdb" , configServer.modelServer() );
118
cmdBuilder.appendOID( "serverID" , &serverID );
119
cmdBuilder.appendBool( "authoritative" , true );
121
BSONObj cmd = cmdBuilder.obj();
123
LOG(1) << "initializing shard connection to " << conn->toString() << endl;
124
LOG(2) << "initial sharding settings : " << cmd << endl;
126
ok = conn->runCommand("admin", cmd, result, 0);
128
catch( const DBException& ex ) {
130
bool ignoreFailure = ShardConnection::ignoreInitialVersionFailure
131
&& conn_in->type() == ConnectionString::SET;
132
if ( !ignoreFailure )
135
// Using initShardVersion is not strictly required when talking to replica sets - it is
136
// preferred to do so because it registers mongos early with the mongod. This info is
137
// also sent by checkShardVersion before a connection is used for a write or read.
140
warning() << "failed to initialize new replica set connection version, "
141
<< "will initialize on first use" << endl;
124
147
// HACK for backwards compatibility with v1.8.x, v2.0.0 and v2.0.1
125
148
// Result is false, but will still initialize serverID and configdb