summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2008-07-31 13:37:32 -0400
committerDwight <dmerriman@gmail.com>2008-07-31 13:37:32 -0400
commit234844724cfeb7635073d08e5229bcb521d961e2 (patch)
tree9e128b9e9ba58a1247efe8d0b7d24ea418c0b89e
parent74337a4d3c01b93623049a2766532bb0b5e29e79 (diff)
downloadmongo-234844724cfeb7635073d08e5229bcb521d961e2.tar.gz
checkpoitning work
-rw-r--r--db/pdfile.h7
-rw-r--r--db/repl.cpp15
-rw-r--r--util/goodies.h27
-rw-r--r--util/log.h8
4 files changed, 46 insertions, 11 deletions
diff --git a/db/pdfile.h b/db/pdfile.h
index 7827322b845..7f731a5b962 100644
--- a/db/pdfile.h
+++ b/db/pdfile.h
@@ -460,6 +460,13 @@ inline void setClient(const char *ns) {
clients[cl] = c;
client = c;
}
+/* we normally keep around a curNs ptr -- if this ns is temporary,
+ use this instead so we don't have a bad ptr. we could have made a copy,
+ but trying to be fast as we call setClient this for every single operation.
+*/
+inline void setClientTempNs(const char *ns) {
+ setClient(ns); curNs = "";
+}
inline void _deleteDataFiles(const char *client) {
string c = client;
diff --git a/db/repl.cpp b/db/repl.cpp
index 384252a910e..6ee1b8a7027 100644
--- a/db/repl.cpp
+++ b/db/repl.cpp
@@ -53,6 +53,9 @@ struct TestOpTime {
assert( s != t );
t = s;
}
+ OpTime q = t;
+ assert( q == t );
+ assert( !(q != t) );
}
} testoptime;
@@ -206,13 +209,12 @@ void Source::loadAll(vector<Source*>& v) {
JSObj opTimeQuery = fromjson("{getoptime:1}");
bool Source::resync(string db) {
- assert( client->name == db );
-
{
log() << "resync: dropping database " << db << endl;
string dummyns = db + ".";
+ assert( client->name == db );
dropDatabase(dummyns.c_str());
- setClient(dummyns.c_str());
+ setClientTempNs(dummyns.c_str());
}
{
@@ -237,7 +239,7 @@ bool Source::resync(string db) {
void Source::applyOperation(JSObj& op) {
stringstream ss;
const char *ns = op.getStringField("ns");
- setClient(ns);
+ setClientTempNs(ns);
if( client->justCreated || /* datafiles were missing. so we need everything, no matter what sources object says */
!dbs.count(client->name) ) /* if not in dbs, we've never synced this database before, so we need everything */
@@ -381,7 +383,7 @@ void _logOp(const char *opstr, const char *ns, JSObj& obj, JSObj *o2, bool *bb)
Client *oldClient = client;
if( localOplogMainDetails == 0 ) {
- setClient("local.");
+ setClientTempNs("local.");
localOplogClient = client;
localOplogMainDetails = nsdetails("local.oplog.$main");
}
@@ -471,11 +473,12 @@ void startReplication() {
if( master ) {
log() << "master=true" << endl;
+ lock lk(dbMutex);
/* create an oplog collection, if it doesn't yet exist. */
JSObjBuilder b;
b.append("size", 254.0 * 1000 * 1000);
b.appendBool("capped", 1);
- setClient("local.oplog.$main");
+ setClientTempNs("local.oplog.$main");
string err;
JSObj o = b.done();
userCreateNS("local.oplog.$main", o, err);
diff --git a/util/goodies.h b/util/goodies.h
index 43139d9c4a9..282f96694d0 100644
--- a/util/goodies.h
+++ b/util/goodies.h
@@ -162,7 +162,7 @@ inline unsigned curTimeMicros() {
return t;
}
using namespace boost;
-typedef boost::mutex::scoped_lock lock;
+typedef boost::mutex::scoped_lock boostlock;
// simple scoped timer
class Timer {
@@ -176,3 +176,28 @@ public:
private:
unsigned old;
};
+
+/*
+
+class DebugMutex : boost::noncopyable {
+ friend class lock;
+ boost::mutex m;
+ int locked;
+public:
+ DebugMutex() : locked(0); { }
+ bool isLocked() { return locked; }
+};
+
+*/
+/*
+struct lock {
+boostlock bl;
+ DebugMutex& m;
+ lock(DebugMutex& _m) : m(_m) {
+ do_lock();
+ }
+ ~lock() { do_unlock(); }
+}
+*/
+typedef boostlock lock;
+
diff --git a/util/log.h b/util/log.h
index 78be6e28b1b..61ac66a931b 100644
--- a/util/log.h
+++ b/util/log.h
@@ -35,7 +35,7 @@ public:
inline Nullstream& endl ( Nullstream& os ) { }
extern Nullstream nullstream;
-#define LOGIT { lock lk(mutex); cout << x; return *this; }
+#define LOGIT { boostlock lk(mutex); cout << x; return *this; }
class Logstream {
static boost::mutex mutex;
public:
@@ -49,10 +49,10 @@ public:
Logstream& operator<<(long long x) LOGIT
Logstream& operator<<(unsigned long long x) LOGIT
Logstream& operator<<(const string& x) LOGIT
- Logstream& operator<< (ostream& ( *_endl )(ostream&)) { lock lk(mutex); cout << _endl; return *this; }
- Logstream& operator<< (ios_base& (*_hex)(ios_base&)) { lock lk(mutex); cout << _hex; return *this; }
+ Logstream& operator<< (ostream& ( *_endl )(ostream&)) { boostlock lk(mutex); cout << _endl; return *this; }
+ Logstream& operator<< (ios_base& (*_hex)(ios_base&)) { boostlock lk(mutex); cout << _hex; return *this; }
Logstream& prolog(bool withNs = false) {
- lock lk(mutex);
+ boostlock lk(mutex);
time_t t;
time(&t);
string now(ctime(&t),0,20);