mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
Merge branch 'master' of github.com:mongodb/mongo
This commit is contained in:
commit
c513597ca9
@ -82,9 +82,10 @@ namespace mongo {
|
||||
*/
|
||||
return s.str();
|
||||
}
|
||||
|
||||
|
||||
static OID gen() { OID o; o.init(); return o; }
|
||||
|
||||
static unsigned staticMachine(){ return _machine; }
|
||||
/**
|
||||
sets the contents to a new oid / randomized value
|
||||
*/
|
||||
|
@ -1523,7 +1523,8 @@ namespace mongo {
|
||||
|
||||
string ns = dbname + '.' + cmdObj.firstElement().valuestr();
|
||||
|
||||
Query q (cmdObj.getObjectField("query")); // defaults to {}
|
||||
BSONObj origQuery = cmdObj.getObjectField("query"); // defaults to {}
|
||||
Query q (origQuery);
|
||||
BSONElement sort = cmdObj["sort"];
|
||||
if (!sort.eoo())
|
||||
q.sort(sort.embeddedObjectUserCheck());
|
||||
@ -1537,18 +1538,30 @@ namespace mongo {
|
||||
return false;
|
||||
}
|
||||
|
||||
q = QUERY( "_id" << out["_id"]);
|
||||
Query idQuery = QUERY( "_id" << out["_id"]);
|
||||
|
||||
if (cmdObj["remove"].trueValue()){
|
||||
uassert(12515, "can't remove and update", cmdObj["update"].eoo());
|
||||
db.remove(ns, q, 1);
|
||||
} else {
|
||||
db.remove(ns, idQuery, 1);
|
||||
|
||||
} else { // update
|
||||
|
||||
if (origQuery.isEmpty()){
|
||||
q = idQuery;
|
||||
} else if (origQuery["_id"].eoo()){
|
||||
// need to include original query for $ positional operator
|
||||
BSONObjBuilder b;
|
||||
b.append(out["_id"]);
|
||||
b.appendElements(origQuery);
|
||||
q = Query(b.obj());
|
||||
} // else use existing q object with _id field
|
||||
|
||||
BSONElement update = cmdObj["update"];
|
||||
uassert(12516, "must specify remove or update", !update.eoo());
|
||||
db.update(ns, q, update.embeddedObjectUserCheck());
|
||||
|
||||
if (cmdObj["new"].trueValue())
|
||||
out = db.findOne(ns, q, fields);
|
||||
out = db.findOne(ns, idQuery, fields);
|
||||
}
|
||||
|
||||
result.append("value", out);
|
||||
|
@ -133,6 +133,11 @@ namespace mongo {
|
||||
result.append( "utf8" , globalScriptEngine->utf8Ok() );
|
||||
bb.done();
|
||||
}
|
||||
if ( cmdObj["oidReset"].trueValue() ){
|
||||
result.append( "oidMachineOld" , OID::staticMachine() );
|
||||
OID::newState();
|
||||
}
|
||||
result.append( "oidMachine" , OID::staticMachine() );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1243,8 +1243,10 @@ namespace mongo {
|
||||
|
||||
unsigned OID::_machine = (unsigned) security.getNonceInitSafe();
|
||||
void OID::newState(){
|
||||
unsigned before = _machine;
|
||||
// using fresh Security object to avoid buffered devrandom
|
||||
_machine = (unsigned) Security().getNonce();
|
||||
_machine = (unsigned)security.getNonce();
|
||||
assert( _machine != before );
|
||||
}
|
||||
|
||||
void OID::init( string s ){
|
||||
|
21
jstests/find_and_modify3.js
Normal file
21
jstests/find_and_modify3.js
Normal file
@ -0,0 +1,21 @@
|
||||
t = db.find_and_modify3;
|
||||
t.drop();
|
||||
|
||||
t.insert({_id:0, other:0, comments:[{i:0, j:0}, {i:1, j:1}]});
|
||||
t.insert({_id:1, other:1, comments:[{i:0, j:0}, {i:1, j:1}]}); // this is the only one that gets modded
|
||||
t.insert({_id:2, other:2, comments:[{i:0, j:0}, {i:1, j:1}]});
|
||||
|
||||
orig0 = t.findOne({_id:0})
|
||||
orig2 = t.findOne({_id:2})
|
||||
|
||||
out = t.findAndModify({query: {_id:1, 'comments.i':0}, update: {$set: {'comments.$.j':2}}, 'new': true});
|
||||
assert.eq(out.comments[0], {i:0, j:2});
|
||||
assert.eq(out.comments[1], {i:1, j:1});
|
||||
assert.eq(t.findOne({_id:0}), orig0);
|
||||
assert.eq(t.findOne({_id:2}), orig2);
|
||||
|
||||
out = t.findAndModify({query: {other:1, 'comments.i':1}, update: {$set: {'comments.$.j':3}}, 'new': true});
|
||||
assert.eq(out.comments[0], {i:0, j:2});
|
||||
assert.eq(out.comments[1], {i:1, j:3});
|
||||
assert.eq(t.findOne({_id:0}), orig0);
|
||||
assert.eq(t.findOne({_id:2}), orig2);
|
@ -4,3 +4,11 @@ t.drop();
|
||||
|
||||
t.save( { _id : 5.5 } );
|
||||
assert.eq( 18 , Object.bsonsize( t.findOne() ) , "A" );
|
||||
|
||||
|
||||
x = db.runCommand( { features : 1 } )
|
||||
y = db.runCommand( { features : 1 , oidReset : 1 } )
|
||||
|
||||
assert( x.oidMachine , "B1" )
|
||||
assert.neq( x.oidMachine , y.oidMachine , "B2" )
|
||||
assert.eq( x.oidMachine , y.oidMachineOld , "B3" )
|
||||
|
@ -215,6 +215,34 @@ namespace mongo {
|
||||
|
||||
conn.setWriteConcern( w);
|
||||
}
|
||||
|
||||
bool Balancer::checkOIDs(){
|
||||
vector<Shard> all;
|
||||
Shard::getAllShards( all );
|
||||
|
||||
map<int,Shard> oids;
|
||||
|
||||
for ( vector<Shard>::iterator i=all.begin(); i!=all.end(); ++i ){
|
||||
Shard s = *i;
|
||||
BSONObj f = s.runCommand( "admin" , "features" );
|
||||
if ( f["oidMachine"].isNumber() ){
|
||||
int x = f["oidMachine"].numberInt();
|
||||
if ( oids.count(x) == 0 ){
|
||||
oids[x] = s;
|
||||
}
|
||||
else {
|
||||
log() << "error: 2 machines have " << x << " as oid machine piece " << s.toString() << " and " << oids[x].toString() << endl;
|
||||
s.runCommand( "admin" , BSON( "features" << 1 << "oidReset" << 1 ) );
|
||||
oids[x].runCommand( "admin" , BSON( "features" << 1 << "oidReset" << 1 ) );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
log() << "warning: oidMachine not set on: " << s.toString() << endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Balancer::run(){
|
||||
|
||||
@ -228,6 +256,7 @@ namespace mongo {
|
||||
}
|
||||
|
||||
ping();
|
||||
checkOIDs();
|
||||
|
||||
while ( ! inShutdown() ){
|
||||
sleepsecs( 15 );
|
||||
@ -236,6 +265,10 @@ namespace mongo {
|
||||
ShardConnection conn( configServer.getPrimary() );
|
||||
ping( conn.conn() );
|
||||
|
||||
if ( ! checkOIDs() ){
|
||||
uassert( 13258 , "oids broken after resetting!" , checkOIDs() );
|
||||
}
|
||||
|
||||
int numBalanced = 0;
|
||||
if ( shouldIBalance( conn.conn() ) ){
|
||||
numBalanced = balance( conn.conn() );
|
||||
|
@ -32,6 +32,11 @@ namespace mongo {
|
||||
|
||||
private:
|
||||
bool shouldIBalance( DBClientBase& conn );
|
||||
|
||||
/**
|
||||
* @return true if everything is ok
|
||||
*/
|
||||
bool checkOIDs();
|
||||
|
||||
/**
|
||||
* @return number of collections balanced
|
||||
|
@ -142,10 +142,13 @@ namespace mongo {
|
||||
|
||||
private:
|
||||
string _addr;
|
||||
static map<string,WriteBackListener*> _cache;
|
||||
|
||||
static map<string,WriteBackListener*> _cache;
|
||||
static mongo::mutex _lock;
|
||||
|
||||
public:
|
||||
static void init( DBClientBase& conn ){
|
||||
scoped_lock lk( _lock );
|
||||
WriteBackListener*& l = _cache[conn.getServerAddress()];
|
||||
if ( l )
|
||||
return;
|
||||
@ -156,7 +159,7 @@ namespace mongo {
|
||||
};
|
||||
|
||||
map<string,WriteBackListener*> WriteBackListener::_cache;
|
||||
|
||||
mongo::mutex WriteBackListener::_lock;
|
||||
|
||||
void checkShardVersion( DBClientBase& conn , const string& ns , bool authoritative ){
|
||||
// TODO: cache, optimize, etc...
|
||||
|
Loading…
Reference in New Issue
Block a user