mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 01:21:03 +01:00
Merge branch 'master' of ssh://aaron@git.10gen.com/data/gitroot/p
This commit is contained in:
commit
30573a6d91
@ -24,21 +24,22 @@
|
|||||||
#include "query.h"
|
#include "query.h"
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
|
#include "repl.h"
|
||||||
|
|
||||||
extern int port;
|
extern int port;
|
||||||
bool userCreateNS(const char *ns, BSONObj& j, string& err);
|
|
||||||
|
|
||||||
class Cloner: boost::noncopyable {
|
class Cloner: boost::noncopyable {
|
||||||
DBClientConnection conn;
|
DBClientConnection conn;
|
||||||
void copy(const char *from_ns, const char *to_ns, bool isindex = false);
|
void copy(const char *from_ns, const char *to_ns, bool isindex = false);
|
||||||
public:
|
public:
|
||||||
Cloner() { }
|
Cloner() { }
|
||||||
bool go(const char *masterHost, string& errmsg, const string& fromdb);
|
bool go(const char *masterHost, string& errmsg, const string& fromdb, bool logForRepl);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* for index info object:
|
/* for index info object:
|
||||||
{ "name" : "name_1" , "ns" : "foo.index3" , "key" : { "name" : 1.0 } }
|
{ "name" : "name_1" , "ns" : "foo.index3" , "key" : { "name" : 1.0 } }
|
||||||
we need to fix up the value in the "ns" parameter.
|
we need to fix up the value in the "ns" parameter so that the name prefix is correct on a
|
||||||
|
copy to a new name.
|
||||||
*/
|
*/
|
||||||
BSONObj fixindex(BSONObj o) {
|
BSONObj fixindex(BSONObj o) {
|
||||||
BSONObjBuilder b;
|
BSONObjBuilder b;
|
||||||
@ -69,6 +70,9 @@ BSONObj fixindex(BSONObj o) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* copy the specified collection
|
||||||
|
isindex - if true, this is system.indexes collection.
|
||||||
|
*/
|
||||||
void Cloner::copy(const char *from_collection, const char *to_collection, bool isindex) {
|
void Cloner::copy(const char *from_collection, const char *to_collection, bool isindex) {
|
||||||
auto_ptr<DBClientCursor> c;
|
auto_ptr<DBClientCursor> c;
|
||||||
{
|
{
|
||||||
@ -91,13 +95,17 @@ void Cloner::copy(const char *from_collection, const char *to_collection, bool i
|
|||||||
}
|
}
|
||||||
|
|
||||||
BSONObj js = tmp;
|
BSONObj js = tmp;
|
||||||
if( isindex )
|
if( isindex ) {
|
||||||
|
assert( strstr(from_collection, "system.indexes") );
|
||||||
js = fixindex(tmp);
|
js = fixindex(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
theDataFileMgr.insert(to_collection, (void*) js.objdata(), js.objsize());
|
theDataFileMgr.insert(to_collection, (void*) js.objdata(), js.objsize());
|
||||||
|
logOp("i", to_collection, js);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Cloner::go(const char *masterHost, string& errmsg, const string& fromdb) {
|
bool Cloner::go(const char *masterHost, string& errmsg, const string& fromdb, bool logForRepl) {
|
||||||
string todb = database->name;
|
string todb = database->name;
|
||||||
stringstream a,b;
|
stringstream a,b;
|
||||||
a << "localhost:" << port;
|
a << "localhost:" << port;
|
||||||
@ -150,7 +158,7 @@ bool Cloner::go(const char *masterHost, string& errmsg, const string& fromdb) {
|
|||||||
//if( !options.isEmpty() )
|
//if( !options.isEmpty() )
|
||||||
{
|
{
|
||||||
string err;
|
string err;
|
||||||
userCreateNS(to_name.c_str(), options, err);
|
userCreateNS(to_name.c_str(), options, err, logForRepl);
|
||||||
}
|
}
|
||||||
copy(from_name, to_name.c_str());
|
copy(from_name, to_name.c_str());
|
||||||
}
|
}
|
||||||
@ -163,10 +171,10 @@ bool Cloner::go(const char *masterHost, string& errmsg, const string& fromdb) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cloneFrom(const char *masterHost, string& errmsg, const string& fromdb)
|
bool cloneFrom(const char *masterHost, string& errmsg, const string& fromdb, bool logForReplication)
|
||||||
{
|
{
|
||||||
Cloner c;
|
Cloner c;
|
||||||
return c.go(masterHost, errmsg, fromdb);
|
return c.go(masterHost, errmsg, fromdb, logForReplication);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Usage:
|
/* Usage:
|
||||||
@ -180,7 +188,10 @@ public:
|
|||||||
string from = cmdObj.getStringField("clone");
|
string from = cmdObj.getStringField("clone");
|
||||||
if( from.empty() )
|
if( from.empty() )
|
||||||
return false;
|
return false;
|
||||||
return cloneFrom(from.c_str(), errmsg, database->name);
|
/* replication note: we must logOp() not the command, but the cloned data -- if the slave
|
||||||
|
were to clone it would get a different point-in-time and not match.
|
||||||
|
*/
|
||||||
|
return cloneFrom(from.c_str(), errmsg, database->name, true);
|
||||||
}
|
}
|
||||||
} cmdclone;
|
} cmdclone;
|
||||||
|
|
||||||
@ -207,9 +218,8 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
setClient(todb.c_str());
|
setClient(todb.c_str());
|
||||||
bool res = cloneFrom(fromhost.c_str(), errmsg, fromdb);
|
bool res = cloneFrom(fromhost.c_str(), errmsg, fromdb, true);
|
||||||
database = 0;
|
database = 0;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} cmdcopydb;
|
} cmdcopydb;
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
extern int queryTraceLevel;
|
extern int queryTraceLevel;
|
||||||
extern int otherTraceLevel;
|
extern int otherTraceLevel;
|
||||||
extern int opLogging;
|
extern int opLogging;
|
||||||
bool userCreateNS(const char *ns, BSONObj& j, string& err);
|
|
||||||
void flushOpLog();
|
void flushOpLog();
|
||||||
int runCount(const char *ns, BSONObj& cmd, string& err);
|
int runCount(const char *ns, BSONObj& cmd, string& err);
|
||||||
|
|
||||||
@ -319,9 +318,7 @@ bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &
|
|||||||
valid = true;
|
valid = true;
|
||||||
string ns = us + '.' + e.valuestr();
|
string ns = us + '.' + e.valuestr();
|
||||||
string err;
|
string err;
|
||||||
ok = userCreateNS(ns.c_str(), jsobj, err);
|
ok = userCreateNS(ns.c_str(), jsobj, err, true);
|
||||||
if( ok )
|
|
||||||
logOp("c", ns.c_str(), jsobj);
|
|
||||||
if( !ok && !err.empty() )
|
if( !ok && !err.empty() )
|
||||||
anObjBuilder.append("errmsg", err.c_str());
|
anObjBuilder.append("errmsg", err.c_str());
|
||||||
}
|
}
|
||||||
|
@ -300,6 +300,9 @@ public:
|
|||||||
int objsize() const { return details ? details->_objsize : 0; } // includes the embedded size field
|
int objsize() const { return details ? details->_objsize : 0; } // includes the embedded size field
|
||||||
bool isEmpty() const { return objsize() <= 5; }
|
bool isEmpty() const { return objsize() <= 5; }
|
||||||
|
|
||||||
|
/* sigh...details == 0 is such a pain we have to eliminate that possibility */
|
||||||
|
void validateEmpty();
|
||||||
|
|
||||||
void dump() {
|
void dump() {
|
||||||
cout << hex;
|
cout << hex;
|
||||||
const char *p = objdata();
|
const char *p = objdata();
|
||||||
@ -620,3 +623,9 @@ inline void BSONObjBuilder::appendElements(BSONObj x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern BSONObj emptyObj;
|
extern BSONObj emptyObj;
|
||||||
|
|
||||||
|
inline void BSONObj::validateEmpty() {
|
||||||
|
if( details == 0 )
|
||||||
|
*this = emptyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ _ disallow system* manipulations from the database.
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
|
#include "repl.h"
|
||||||
|
|
||||||
const char *dbpath = "/data/db/";
|
const char *dbpath = "/data/db/";
|
||||||
|
|
||||||
@ -92,9 +93,7 @@ int initialExtentSize(int len) {
|
|||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
// { ..., capped: true, size: ..., max: ... }
|
bool _userCreateNS(const char *ns, BSONObj& j, string& err) {
|
||||||
// returns true if successful
|
|
||||||
bool userCreateNS(const char *ns, BSONObj& j, string& err) {
|
|
||||||
if( nsdetails(ns) ) {
|
if( nsdetails(ns) ) {
|
||||||
err = "collection already exists";
|
err = "collection already exists";
|
||||||
return false;
|
return false;
|
||||||
@ -134,6 +133,16 @@ bool userCreateNS(const char *ns, BSONObj& j, string& err) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// { ..., capped: true, size: ..., max: ... }
|
||||||
|
// returns true if successful
|
||||||
|
bool userCreateNS(const char *ns, BSONObj j, string& err, bool logForReplication) {
|
||||||
|
j.validateEmpty();
|
||||||
|
bool ok = _userCreateNS(ns, j, err);
|
||||||
|
if( logForReplication && ok )
|
||||||
|
logOp("c", ns, j);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------*/
|
||||||
|
|
||||||
void PhysicalDataFile::open(int fn, const char *filename) {
|
void PhysicalDataFile::open(int fn, const char *filename) {
|
||||||
@ -752,7 +761,7 @@ DiskLoc DataFileMgr::insert(const char *ns, const void *buf, int len, bool god)
|
|||||||
if( tableToIndex == 0 ) {
|
if( tableToIndex == 0 ) {
|
||||||
// try to create it
|
// try to create it
|
||||||
string err;
|
string err;
|
||||||
if( !userCreateNS(tabletoidxns.c_str(), emptyObj, err) ) {
|
if( !userCreateNS(tabletoidxns.c_str(), emptyObj, err, false) ) {
|
||||||
problem() << "ERROR: failed to create collection while adding its index. " << tabletoidxns << endl;
|
problem() << "ERROR: failed to create collection while adding its index. " << tabletoidxns << endl;
|
||||||
return DiskLoc();
|
return DiskLoc();
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,8 @@ class Record;
|
|||||||
class Cursor;
|
class Cursor;
|
||||||
|
|
||||||
void dropDatabase(const char *ns);
|
void dropDatabase(const char *ns);
|
||||||
void dropNS(string& dropNs);
|
void dropNS(string& dropNs);;
|
||||||
|
bool userCreateNS(const char *ns, BSONObj j, string& err, bool logForReplication);
|
||||||
|
|
||||||
/*---------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@
|
|||||||
|
|
||||||
extern boost::mutex dbMutex;
|
extern boost::mutex dbMutex;
|
||||||
auto_ptr<Cursor> findTableScan(const char *ns, BSONObj& order, bool *isSorted=0);
|
auto_ptr<Cursor> findTableScan(const char *ns, BSONObj& order, bool *isSorted=0);
|
||||||
bool userCreateNS(const char *ns, BSONObj& j, string& err);
|
|
||||||
int _updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upsert, stringstream& ss, bool logOp=false);
|
int _updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upsert, stringstream& ss, bool logOp=false);
|
||||||
bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &b, BSONObjBuilder& anObjBuilder);
|
bool _runCommands(const char *ns, BSONObj& jsobj, stringstream& ss, BufBuilder &b, BSONObjBuilder& anObjBuilder);
|
||||||
void ensureHaveIdIndex(const char *ns);
|
void ensureHaveIdIndex(const char *ns);
|
||||||
@ -393,10 +392,8 @@ bool ReplSource::resync(string db) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
log() << "resync: cloning database " << db << endl;
|
log() << "resync: cloning database " << db << endl;
|
||||||
//Cloner c;
|
|
||||||
string errmsg;
|
string errmsg;
|
||||||
bool ok = cloneFrom(hostName.c_str(), errmsg, database->name);
|
bool ok = cloneFrom(hostName.c_str(), errmsg, database->name, false);
|
||||||
//bool ok = c.go(hostName.c_str(), errmsg);
|
|
||||||
if( !ok ) {
|
if( !ok ) {
|
||||||
problem() << "resync of " << db << " from " << hostName << " failed " << errmsg << endl;
|
problem() << "resync of " << db << " from " << hostName << " failed " << errmsg << endl;
|
||||||
throw SyncException();
|
throw SyncException();
|
||||||
@ -929,7 +926,7 @@ void startReplication() {
|
|||||||
setClientTempNs("local.oplog.$main");
|
setClientTempNs("local.oplog.$main");
|
||||||
string err;
|
string err;
|
||||||
BSONObj o = b.done();
|
BSONObj o = b.done();
|
||||||
userCreateNS("local.oplog.$main", o, err);
|
userCreateNS("local.oplog.$main", o, err, false);
|
||||||
database = 0;
|
database = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class DBClientCursor;
|
|||||||
extern bool slave;
|
extern bool slave;
|
||||||
extern bool master;
|
extern bool master;
|
||||||
|
|
||||||
bool cloneFrom(const char *masterHost, string& errmsg, const string& fromdb);
|
bool cloneFrom(const char *masterHost, string& errmsg, const string& fromdb, bool logForReplication);
|
||||||
|
|
||||||
#pragma pack(push,4)
|
#pragma pack(push,4)
|
||||||
class OpTime {
|
class OpTime {
|
||||||
|
Loading…
Reference in New Issue
Block a user