Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mongodb/mongo
Browse files Browse the repository at this point in the history
  • Loading branch information
banker committed Aug 4, 2010
2 parents 8781354 + ec84f26 commit b76a5d1
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 45 deletions.
32 changes: 32 additions & 0 deletions client/parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,38 @@ namespace mongo {
void ParallelSortClusteredCursor::_finishCons(){
_numServers = _servers.size();
_cursors = 0;

if ( ! _sortKey.isEmpty() && ! _fields.isEmpty() ){
// we need to make sure the sort key is in the project
bool isNegative = false;
BSONObjBuilder b;
{
BSONObjIterator i( _fields );
while ( i.more() ){
BSONElement e = i.next();
b.append( e );
if ( ! e.trueValue() )
isNegative = true;
}
}

{
BSONObjIterator i( _sortKey );
while ( i.more() ){
BSONElement e = i.next();
BSONElement f = _fields.getField( e.fieldName() );
if ( isNegative ){
uassert( 13431 , "have to have sort key in projection and removing it" , f.eoo() );
}
else if ( f.eoo() ){
// add to projection
b.append( e );
}
}
}

_fields = b.obj();
}
}

void ParallelSortClusteredCursor::_init(){
Expand Down
1 change: 1 addition & 0 deletions db/dbcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ namespace mongo {
assert( sprintf( buf , "w block pass: %lld" , ++passes ) < 30 );
c.curop()->setMessage( buf );
sleepmillis(1);
killCurrentOp.checkForInterrupt();
}
result.appendNumber( "wtime" , t.millis() );
}
Expand Down
5 changes: 3 additions & 2 deletions db/repl/health.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ namespace mongo {
}

void ReplSetImpl::_getOplogDiagsAsHtml(unsigned server_id, stringstream& ss) const {
Member *m = findById(server_id);
const Member *m = findById(server_id);
if( m == 0 ) {
ss << "Error : can't find a member with id: " << server_id << '\n';
return;
Expand Down Expand Up @@ -329,7 +329,7 @@ namespace mongo {
_rsLog.toHTML( s );
}

Member* ReplSetImpl::findById(unsigned id) const {
const Member* ReplSetImpl::findById(unsigned id) const {
if( id == _self->id() ) return _self;
for( Member *m = head(); m; m = m->next() )
if( m->id() == id )
Expand Down Expand Up @@ -371,6 +371,7 @@ namespace mongo {
v.push_back(bb.obj());
m = m->next();
}
sort(v.begin(), v.end());
b.append("set", name());
b.appendTimeT("date", time(0));
b.append("myState", box.getState().s);
Expand Down
6 changes: 3 additions & 3 deletions db/repl/replset_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace mongo {

void checkAllMembersUpForConfigChange(const ReplSetConfig& cfg, bool initial);
void checkMembersUpForConfigChange(const ReplSetConfig& cfg, bool initial);

/* commands in other files:
replSetHeartbeat - health.cpp
Expand Down Expand Up @@ -151,9 +151,9 @@ namespace mongo {
return false;
}

checkAllMembersUpForConfigChange(newConfig,false);
checkMembersUpForConfigChange(newConfig,false);

log() << "replSet replSetReconfig all members seem up" << rsLog;
log() << "replSet replSetReconfig [2]" << rsLog;

theReplSet->haveNewConfig(newConfig, true);
ReplSet::startupStatusMsg = "replSetReconfig'd";
Expand Down
4 changes: 2 additions & 2 deletions db/repl/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@ namespace mongo {
startupStatus = EMPTYCONFIG;
startupStatusMsg = "can't get " + rsConfigNs + " config from self or any seed (EMPTYCONFIG)";
log() << "replSet can't get " << rsConfigNs << " config from self or any seed (EMPTYCONFIG)" << rsLog;
log() << "replSet have you ran replSetInitiate yet?" << rsLog;
log(1) << "replSet have you ran replSetInitiate yet?" << rsLog;
if( _seeds->size() == 0 )
log() << "replSet no seed hosts were specified on the --replSet command line - that might be the issue" << rsLog;
log(1) << "replSet info no seed hosts were specified on the --replSet command line" << rsLog;
}
else {
startupStatus = EMPTYUNREACHABLE;
Expand Down
4 changes: 3 additions & 1 deletion db/repl/rs.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ namespace mongo {

private:
Member* head() const { return _members.head(); }
Member* findById(unsigned id) const;
public:
const Member* findById(unsigned id) const;
private:
void _getTargets(list<Target>&, int &configVersion);
void getTargets(list<Target>&, int &configVersion);
void startThreads();
Expand Down
6 changes: 3 additions & 3 deletions db/repl/rs_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace mongo {
mchk(_id >= 0 && _id <= 255);
mchk(priority >= 0 && priority <= 1000);
mchk(votes >= 0 && votes <= 100);
uassert(13419, "replica set config : this version of mongo only supports priorities 0 and 1", priority == 0 || priority == 1);
uassert(13419, "this version of mongod only supports priorities 0 and 1", priority == 0 || priority == 1);
}

/*static*/ bool ReplSetConfig::legalChange(const ReplSetConfig& o, const ReplSetConfig& n, string& errmsg) {
Expand All @@ -133,7 +133,7 @@ namespace mongo {

/* TODO : MORE CHECKS HERE */

cout << "TODO : don't allow removal of a node until we handle it at the removed node end." << endl;
log() << "replSet TODO : don't allow removal of a node until we handle it at the removed node end?" << endl;
// we could change its votes to zero perhaps instead as a short term...

return true;
Expand Down Expand Up @@ -220,7 +220,7 @@ namespace mongo {
catch(DBException& e) {
log() << "replSet cfg parsing exception for members[" << i << "] " << e.what() << rsLog;
stringstream ss;
ss << "replSet members[" << i << "] bad config object";
ss << "bad config for member[" << i << "] " << e.what();
uassert(13135, ss.str(), false);
}
if( !(ords.count(m._id) == 0 && hosts.count(m.h.toString()) == 0) ) {
Expand Down
51 changes: 40 additions & 11 deletions db/repl/rs_initiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ using namespace mongoutils;

namespace mongo {

/* throws
@param initial -
/* called on a reconfig AND on initiate
throws
@param initial true when initiating
*/
void checkAllMembersUpForConfigChange(const ReplSetConfig& cfg, bool initial) {
void checkMembersUpForConfigChange(const ReplSetConfig& cfg, bool initial) {
int failures = 0;
int me = 0;
for( vector<ReplSetConfig::MemberCfg>::const_iterator i = cfg.members.begin(); i != cfg.members.end(); i++ ) {
if( i->h.isSelf() ) {
Expand All @@ -45,7 +47,7 @@ namespace mongo {
}
}
}
uassert(13278, "bad config?", me <= 1);
uassert(13278, "bad config - dups?", me <= 1); // dups?
uassert(13279, "can't find self in the replset config", me == 1);

for( vector<ReplSetConfig::MemberCfg>::const_iterator i = cfg.members.begin(); i != cfg.members.end(); i++ ) {
Expand All @@ -62,12 +64,11 @@ namespace mongo {
}
}
catch(DBException& e) {
log() << "replSet requestHeartbeat " << i->h.toString() << " : " << e.toString() << rsLog;
log() << "replSet cmufcc requestHeartbeat " << i->h.toString() << " : " << e.toString() << rsLog;
}
catch(...) {
log() << "replSet error exception in requestHeartbeat?" << rsLog;
log() << "replSet cmufcc error exception in requestHeartbeat?" << rsLog;
}
cout << "TEMP hb res cfg change:" << res.toString() << endl;
if( res.getBoolField("mismatch") )
uasserted(13145, "set name does not match the set name host " + i->h.toString() + " expects");
if( *res.getStringField("set") ) {
Expand All @@ -83,9 +84,31 @@ namespace mongo {
}
}
if( !ok && !res["rs"].trueValue() ) {
if( !res.isEmpty() )
if( !res.isEmpty() ) {
/* strange. got a response, but not "ok". log it. */
log() << "replSet warning " << i->h.toString() << " replied: " << res.toString() << rsLog;
uasserted(13144, "need members up to initiate/reconfig, not ok: " + i->h.toString());
}

bool allowFailure = false;
failures++;
if( res.isEmpty() && !initial && failures == 1 ) {
/* for now we are only allowing 1 node to be down on a reconfig. this can be made to be a minority
trying to keep change small as release is near.
*/
const Member* m = theReplSet->findById( i->_id );
if( m ) {
// ok, so this was an existing member (wouldn't make sense to add to config a new member that is down)
assert( m->h().toString() == i->h.toString() );
allowFailure = true;
}
}

if( !allowFailure ) {
string msg = string("need members up to initiate, not ok : ") + i->h.toString();
if( !initial )
msg = string("need most members up to reconfigure, not ok : ") + i->h.toString();
uasserted(13144, msg);
}
}
}
if( initial ) {
Expand Down Expand Up @@ -175,8 +198,10 @@ namespace mongo {
configObj = cmdObj["replSetInitiate"].Obj();
}

bool parsed = false;
try {
ReplSetConfig newConfig(configObj);
parsed = true;

if( newConfig.version > 1 ) {
errmsg = "can't initiate with a version number greater than 1";
Expand All @@ -185,7 +210,7 @@ namespace mongo {

log() << "replSet replSetInitiate config object parses ok, " << newConfig.members.size() << " members specified" << rsLog;

checkAllMembersUpForConfigChange(newConfig, true);
checkMembersUpForConfigChange(newConfig, true);

log() << "replSet replSetInitiate all members seem up" << rsLog;

Expand All @@ -199,7 +224,11 @@ namespace mongo {
}
catch( DBException& e ) {
log() << "replSet replSetInitiate exception: " << e.what() << rsLog;
throw;
if( !parsed )
errmsg = string("couldn't parse cfg object ") + e.what();
else
errmsg = string("couldn't initiate : ") + e.what();
return false;
}

return true;
Expand Down
5 changes: 2 additions & 3 deletions db/repl/rs_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ namespace mongo {
OpTime ts = o["ts"]._opTime();
long long h = o["h"].numberLong();
if( ts != lastOpTimeWritten || h != lastH ) {
log() << "TEMP our last op time written: " << lastOpTimeWritten.toStringPretty() << endl;
log() << "TEMP primary's GTE: " << ts.toStringPretty() << endl;
log(1) << "TEMP our last op time written: " << lastOpTimeWritten.toStringPretty() << endl;
log(1) << "TEMP primary's GTE: " << ts.toStringPretty() << endl;
/*
}*/

Expand Down Expand Up @@ -243,7 +243,6 @@ namespace mongo {
}
else {
sethbmsg(str::stream() << "still syncing, not yet to minValid optime " << minvalid.toString());
//log() << "TEMP " << lastOpTimeWritten.toString() << rsLog;
}

/* todo: too stale capability */
Expand Down
45 changes: 41 additions & 4 deletions jstests/sharding/sort1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ s.adminCommand( { shardcollection : "test.data" , key : { num : 1 } } );

db = s.getDB( "test" );

for ( i=0; i<100; i++ ){
db.data.insert( { _id : i , num : i } );
N = 100

forward = []
backward = []
for ( i=0; i<N; i++ ){
db.data.insert( { _id : i , num : i , x : N - i } )
forward.push( i )
backward.push( ( N - 1 ) - i )
}
db.getLastError();

Expand All @@ -23,7 +29,7 @@ assert.eq( temp[0].shard , temp[2].shard , "A2" );
assert.neq( temp[0].shard , temp[1].shard , "A3" );

temp = db.data.find().sort( { num : 1 } ).toArray();
assert.eq( 100 , temp.length , "B1" );
assert.eq( N , temp.length , "B1" );
for ( i=0; i<100; i++ ){
assert.eq( i , temp[i].num , "B2" )
}
Expand All @@ -39,6 +45,37 @@ assert.eq( 67 , z.length , "C2" )

print( "a: " + a + " b:" + b + " mongos slow down: " + Math.ceil( 100 * ( ( a - b ) / b ) ) + "%" )

//assert.lt( a , b * 1.3 , "C3 - speed test" );
// -- secondary index sorting

function getSorted( by , want , dir , proj ){
var s = {}
s[by] = dir || 1;
printjson( s )
var cur = db.data.find( {} , proj || {} ).sort( s )
return terse( cur.map( function(z){ return z[want]; } ) );
}

function terse( a ){
var s = "";
for ( var i=0; i<a.length; i++ ){
if ( i > 0 )
s += ",";
s += a[i];
}
return s;
}

forward = terse(forward);
backward = terse(backward);

assert.eq( forward , getSorted( "num" , "num" , 1 ) , "D1" )
assert.eq( backward , getSorted( "num" , "num" , -1 ) , "D2" )

assert.eq( backward , getSorted( "x" , "num" , 1 ) , "D3" )
assert.eq( forward , getSorted( "x" , "num" , -1 ) , "D4" )

assert.eq( backward , getSorted( "x" , "num" , 1 , { num : 1 } ) , "D5" )
assert.eq( forward , getSorted( "x" , "num" , -1 , { num : 1 } ) , "D6" )


s.stop();
5 changes: 0 additions & 5 deletions rpm/mongo.spec
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ fi
%attr(0755,mongod,mongod) %dir /var/log/mongo
%attr(0640,mongod,mongod) %config(noreplace) %verify(not md5 size mtime) /var/log/mongo/mongod.log

%files devel
/usr/include/mongo
%{_libdir}/libmongoclient.a
#%{_libdir}/libmongotestfiles.a

%changelog
* Thu Jan 28 2010 Richard M Kreuter <richard@10gen.com>
- Minor fixes.
Expand Down
15 changes: 12 additions & 3 deletions s/shardconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace mongo {

/**
* holds all the actual db connections for a client to various servers
* 1 pre thread, so don't have to worry about thread safety
*/
class ClientConnections : boost::noncopyable {
public:
Expand Down Expand Up @@ -70,7 +71,8 @@ namespace mongo {
_hosts.clear();
}

DBClientBase * get( const string& addr ){
DBClientBase * get( const string& addr , const string& ns ){
_check( ns );
scoped_lock lk( _mutex );
Status* &s = _hosts[addr];
if ( ! s )
Expand Down Expand Up @@ -152,9 +154,16 @@ namespace mongo {
}
}

void _check( const string& ns ){
if ( ns.size() == 0 || _seenNS.count( ns ) )
return;
_seenNS.insert( ns );
checkVersions( ns );
}

map<string,Status*> _hosts;
mongo::mutex _mutex;

set<string> _seenNS;
// -----

static thread_specific_ptr<ClientConnections> _perThread;
Expand Down Expand Up @@ -188,7 +197,7 @@ namespace mongo {

void ShardConnection::_init(){
assert( _addr.size() );
_conn = ClientConnections::get()->get( _addr );
_conn = ClientConnections::get()->get( _addr , _ns );
_finishedInit = false;
}

Expand Down
Loading

0 comments on commit b76a5d1

Please sign in to comment.