summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordwight <dwight@Dwights-MacBook.local>2008-09-14 22:49:30 -0400
committerdwight <dwight@Dwights-MacBook.local>2008-09-14 22:49:30 -0400
commite783239b3f9284d0dfe0161b8f8effc41d33aa57 (patch)
treeb84ed0ab0a5954af8bd92f838e158d283b3c1523
parent3332989338a5815c30a039213bf2e4581759e8c8 (diff)
downloadmongo-e783239b3f9284d0dfe0161b8f8effc41d33aa57.tar.gz
copydb work
-rw-r--r--db/cloner.cpp49
-rw-r--r--db/db.cpp13
-rw-r--r--db/db.h33
-rw-r--r--db/namespace.cpp2
-rw-r--r--db/namespace.h7
-rw-r--r--db/pdfile.cpp2
6 files changed, 82 insertions, 24 deletions
diff --git a/db/cloner.cpp b/db/cloner.cpp
index cf2699a6295..cc1cd582dd0 100644
--- a/db/cloner.cpp
+++ b/db/cloner.cpp
@@ -23,6 +23,7 @@
#include "jsobj.h"
#include "query.h"
#include "commands.h"
+#include "db.h"
extern int port;
bool userCreateNS(const char *ns, JSObj& j, string& err);
@@ -36,9 +37,20 @@ public:
};
void Cloner::copy(const char *from_collection, const char *to_collection) {
- auto_ptr<DBClientCursor> c( conn.query(from_collection, emptyObj) );
+// cout << "COPY: " << from_collection << " -> " << to_collection << endl;
+// cout << " client: " << client->name << endl;
+ auto_ptr<DBClientCursor> c;
+ {
+ dbtemprelease r;
+ c = auto_ptr<DBClientCursor>( conn.query(from_collection, emptyObj) );
+ }
assert( c.get() );
- while( c->more() ) {
+ while( 1 ) {
+ {
+ dbtemprelease r;
+ if( !c->more() )
+ break;
+ }
JSObj js = c->next();
theDataFileMgr.insert(to_collection, (void*) js.objdata(), js.objsize());
}
@@ -54,32 +66,46 @@ bool Cloner::go(const char *masterHost, string& errmsg, const string& fromdb) {
return false;
}
}
- if( !conn.connect(masterHost, errmsg) )
- return false;
-
+ /* todo: we can put thesee releases inside dbclient or a dbclient specialization.
+ or just wait until we get rid of global lcok anyway.
+ */
string ns = fromdb + ".system.namespaces";
-
- auto_ptr<DBClientCursor> c( conn.query(ns.c_str(), emptyObj) );
+ auto_ptr<DBClientCursor> c;
+ {
+ dbtemprelease r;
+ if( !conn.connect(masterHost, errmsg) )
+ return false;
+ c = auto_ptr<DBClientCursor>( conn.query(ns.c_str(), emptyObj) );
+ }
if( c.get() == 0 ) {
errmsg = "query failed " + ns;
return false;
}
- while( c->more() ) {
+ while( 1 ) {
+ {
+ dbtemprelease r;
+ if( !c->more() )
+ break;
+ }
JSObj collection = c->next();
Element e = collection.findElement("name");
assert( !e.eoo() );
assert( e.type() == String );
const char *from_name = e.valuestr();
- if( strstr(from_name, ".system.") || strchr(from_name, '$') )
+ if( strstr(from_name, ".system.") || strchr(from_name, '$') ) {
+// cout << "TEMP: skip " << from_name << endl;
continue;
+ }
JSObj options = collection.getObjectField("options");
/* change name "<fromdb>.collection" -> <todb>.collection */
const char *p = strchr(from_name, '.');
assert(p);
string to_name = todb + p;
- if( !options.isEmpty() ) {
+ //if( !options.isEmpty() ) {
+ {
string err;
+// cout << "TEMP: usercreatens " << to_name << " client:" << client->name << endl;
userCreateNS(to_name.c_str(), options, err);
}
copy(from_name, to_name.c_str());
@@ -130,8 +156,7 @@ public:
errmsg = "parms missing - {copydb: 1, fromhost: <hostname>, fromdb: <db>, todb: <db>}";
return false;
}
- string temp = todb + ".";
- setClient(temp.c_str());
+ setClient(todb.c_str());
bool res = cloneFrom(fromhost.c_str(), errmsg, fromdb);
client = 0;
return res;
diff --git a/db/db.cpp b/db/db.cpp
index 1ef144abf73..517a44658ed 100644
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -970,14 +970,16 @@ int main(int argc, char* argv[], char *envp[] )
return 0;
}
-//#if !defined(_WIN32)
-//int main( int argc, char *argv[], char *envp[] ) {
-// return _tmain(argc, 0);
-//}
-//#endif
+void foo() {
+ boost::mutex z;
+ boost::detail::thread::lock_ops<boost::mutex>::lock(z);
+ cout << "inside lock" << endl;
+ boost::detail::thread::lock_ops<boost::mutex>::unlock(z);
+}
#undef exit
void dbexit(int rc, const char *why) {
+ foo();
log() << " dbexit: " << why << "; flushing op log and files" << endl;
flushOpLog();
@@ -988,3 +990,4 @@ void dbexit(int rc, const char *why) {
log() << " dbexit: really exiting now" << endl;
exit(rc);
}
+
diff --git a/db/db.h b/db/db.h
index 023b789fde0..896ec85d4db 100644
--- a/db/db.h
+++ b/db/db.h
@@ -34,3 +34,36 @@ struct dblock {
}
};
+/* a scoped release of a mutex temporarily -- like a scopedlock but reversed.
+*/
+struct temprelease {
+ boost::mutex& m;
+ temprelease(boost::mutex& _m) : m(_m) {
+ boost::detail::thread::lock_ops<boost::mutex>::unlock(m);
+ }
+ ~temprelease() {
+ boost::detail::thread::lock_ops<boost::mutex>::lock(m);
+ }
+};
+
+#include "pdfile.h"
+
+struct dbtemprelease {
+ string clientname;
+ dbtemprelease() {
+ if( client )
+ clientname = client->name;
+ dbLocked--;
+ assert( dbLocked == 0 );
+ boost::detail::thread::lock_ops<boost::mutex>::unlock(dbMutex);
+ }
+ ~dbtemprelease() {
+ boost::detail::thread::lock_ops<boost::mutex>::lock(dbMutex);
+ dbLocked++;
+ assert( dbLocked == 1 );
+ if( clientname.empty() )
+ client = 0;
+ else
+ setClient(clientname.c_str());
+ }
+};
diff --git a/db/namespace.cpp b/db/namespace.cpp
index eea9f1e66fe..327ebbee8a7 100644
--- a/db/namespace.cpp
+++ b/db/namespace.cpp
@@ -326,7 +326,7 @@ void NamespaceDetailsTransient::computeIndexKeys() {
options: { capped : ..., size : ... }
*/
void addNewNamespaceToCatalog(const char *ns, JSObj *options = 0) {
- log() << "New namespace: " << ns << endl;
+ OCCASIONALLY log() << "New namespace: " << ns << '\n';
if( strstr(ns, "system.namespaces") ) {
// system.namespaces holds all the others, so it is not explicitly listed in the catalog.
// TODO: fix above should not be strstr!
diff --git a/db/namespace.h b/db/namespace.h
index fc9de774c73..96cbf3c9aa8 100644
--- a/db/namespace.h
+++ b/db/namespace.h
@@ -305,11 +305,8 @@ inline void nsToClient(const char *ns, char *client) {
const char *p = ns;
char *q = client;
while( *p != '.' ) {
- if( *p == 0 ) {
- assert(false);
- *client = 0;
- return;
- }
+ if( *p == 0 )
+ break;
*q++ = *p++;
}
*q = 0;
diff --git a/db/pdfile.cpp b/db/pdfile.cpp
index 9180e6fabff..9b71b73baa0 100644
--- a/db/pdfile.cpp
+++ b/db/pdfile.cpp
@@ -106,7 +106,7 @@ bool userCreateNS(const char *ns, JSObj& j, string& err) {
/* todo: do this only when we have allocated space successfully? or we could insert with a { ok: 0 } field
and then go back and set to ok : 1 after we are done.
*/
- addNewNamespaceToCatalog(ns, &j);
+ addNewNamespaceToCatalog(ns, j.isEmpty() ? 0 : &j);
int ies = initialExtentSize(128);
Element e = j.findElement("size");