0
#include "../grid/message.h"
0
+extern boost::mutex dbMutex;
0
+auto_ptr<Cursor> findTableScan(const char *ns, JSObj& order);
0
+bool userCreateNS(const char *ns, JSObj& j, string& err);
0
+OpTime last((unsigned) time(0), 1);
0
+ unsigned t = (unsigned) time(0);
0
+ return OpTime(last.secs, last.i+1);
0
+/* Cloner -----------------------------------------------------------
0
+ makes copy of existing database.
0
class Cloner: boost::noncopyable {
0
DBClientConnection conn;
0
@@ -69,6 +87,11 @@ bool Cloner::go(const char *masterHost, string& errmsg) {
0
const char *name = e.valuestr();
0
if( strstr(name, ".system.") || strchr(name, '$') )
0
+ JSObj options = collection.getObjectField("options");
0
+ if( !options.isEmpty() ) {
0
+ userCreateNS(name, options, err);
0
@@ -84,3 +107,116 @@ bool cloneFrom(const char *masterHost, string& errmsg)
0
return c.go(masterHost, errmsg);
0
+/* --------------------------------------------------------------*/
0
+Source::Source(JSObj o) {
0
+ hostName = o.getStringField("host");
0
+ sourceName = o.getStringField("source");
0
+ uassert( !hostName.empty() );
0
+ uassert( !sourceName.empty() );
0
+ Element e = o.getField("syncedTo");
0
+ uassert( e.type() == Number );
0
+ syncedTo.asDouble() = e.number();
0
+JSObj Source::jsobj() {
0
+ b.append("host", hostName);
0
+ b.append("source", sourceName);
0
+ b.append("syncedTo", syncedTo.asDouble());
0
+ return b.doneAndDecouple();
0
+void Source::updateOnDisk() {
0
+ b.append("host", hostName);
0
+ b.append("source", sourceName);
0
+ JSObj pattern = b.done();
0
+ setClient("local.sources");
0
+ updateObjects("local.sources", o, pattern, false, ss);
0
+void Source::cleanup(vector<Source*>& v) {
0
+ for( vector<Source*>::iterator i = v.begin(); i != v.end(); i++ )
0
+void Source::loadAll(vector<Source*>& v) {
0
+ setClient("local.sources");
0
+ auto_ptr<Cursor> c = findTableScan("local.sources", emptyObj);
0
+ v.push_back( new Source(c->current()) );
0
+JSObj opTimeQuery = fromjson("{getoptime:1}");
0
+/* note: not yet in mutex at this point. */
0
+ log() << "pull source " << sourceName << '@' << hostName << endl;
0
+// if( syncedTo.isNull() ) {
0
+ DBClientConnection conn;
0
+ if( !conn.connect(hostName.c_str(), errmsg) ) {
0
+ cout << " pull: cantconn " << errmsg << endl;
0
+ // get current mtime at the server.
0
+ JSObj o = conn.findOne("admin.$cmd", opTimeQuery);
0
+ Element e = o.findElement("optime");
0
+ cout << " pull: failed to get curtime from master" << endl;
0
+ cout << " " << o.toString() << endl;
0
+ uassert( e.type() == Number );
0
+ serverCurTime.asDouble() = e.number();
0
+/* --------------------------------------------------------------*/
0
+ vector<Source*> sources;
0
+ Source::loadAll(sources);
0
+ for( vector<Source*>::iterator i = sources.begin(); i != sources.end(); i++ ) {
0
+ Source::cleanup(sources);
0
+void replMainThread() {
0
+ catch( AssertionException ) {
0
+ problem() << "Assertion in replMainThread(): sleeping 5 minutes before retry" << endl;
0
+void startReplication() {
0
+// boost::thread repl_thread(replMainThread);
Comments
No one has commented yet.