summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2008-08-25 16:46:39 -0400
committerDwight <dmerriman@gmail.com>2008-08-25 16:46:39 -0400
commitca08e48791b87cfb248ed3cf10c1852d788ae029 (patch)
treec1b75803c486f6b28524a04c2e95f50f15b0fb06
parent94f9bdee473f53837e5ec052526f40d857eb9d1e (diff)
downloadmongo-ca08e48791b87cfb248ed3cf10c1852d788ae029.tar.gz
repl tweaks
-rw-r--r--db/namespace.h6
-rw-r--r--db/pdfile.cpp3
-rw-r--r--db/repl.cpp29
-rw-r--r--db/repl.h1
-rw-r--r--db/scanandorder.h4
-rw-r--r--stdafx.cpp4
-rw-r--r--stdafx.h5
7 files changed, 35 insertions, 17 deletions
diff --git a/db/namespace.h b/db/namespace.h
index 8229808eed8..ef23cb56c13 100644
--- a/db/namespace.h
+++ b/db/namespace.h
@@ -273,6 +273,7 @@ extern NamespaceIndexMgr namespaceIndexMgr;
*/
// "client.a.b.c" -> "client"
+const int MaxClientLen = 256;
inline void nsToClient(const char *ns, char *client) {
const char *p = ns;
char *q = client;
@@ -285,7 +286,10 @@ inline void nsToClient(const char *ns, char *client) {
*q++ = *p++;
}
*q = 0;
- assert(q-client<256);
+ if(q-client>=MaxClientLen) {
+ problem() << "nsToClient: ns too long. terminating, buf overrun condition" << endl;
+ dbexit(60);
+ }
}
/*
diff --git a/db/pdfile.cpp b/db/pdfile.cpp
index 8603faeb29d..d2fb10b4140 100644
--- a/db/pdfile.cpp
+++ b/db/pdfile.cpp
@@ -47,6 +47,9 @@ int callDepth = 0;
extern int otherTraceLevel;
+/* this is a good place to set a breakpoint when debugging, as lots of warning things
+ (assert, wassert) call it.
+*/
void sayDbContext(const char *errmsg) {
if( errmsg ) {
problem() << errmsg << endl;
diff --git a/db/repl.cpp b/db/repl.cpp
index c5a2caa3a68..13789376b1f 100644
--- a/db/repl.cpp
+++ b/db/repl.cpp
@@ -69,13 +69,14 @@ int test2() {
/* --------------------------------------------------------------*/
Source::Source(JSObj o) {
+ only = o.getStringField("only");
hostName = o.getStringField("host");
sourceName = o.getStringField("source");
- uassert( !hostName.empty() );
- uassert( !sourceName.empty() );
+ uassert( "'host' field not set in sources collection object", !hostName.empty() );
+ uassert( "'source' field not set in sources collection object", !sourceName.empty() );
Element e = o.getField("syncedTo");
if( !e.eoo() ) {
- uassert( e.type() == Date );
+ uassert( "bad sources 'syncedTo' field value", e.type() == Date );
OpTime tmp( e.date() );
syncedTo = tmp;
//syncedTo.asDate() = e.date();
@@ -98,6 +99,8 @@ JSObj Source::jsobj() {
JSObjBuilder b;
b.append("host", hostName);
b.append("source", sourceName);
+ if( !only.empty() )
+ b.append("only", only);
b.appendDate("syncedTo", syncedTo.asDate());
JSObjBuilder dbs_builder;
@@ -198,11 +201,17 @@ bool Source::resync(string db) {
}
/* { ts: ..., op: <optype>, ns: ..., o: <obj> , o2: <extraobj>, b: <boolflag> }
- You must lock dbMutex before calling.
*/
-void Source::applyOperation(JSObj& op) {
- stringstream ss;
+void Source::applyOperation(JSObj& op) {
+ char clientName[MaxClientLen];
const char *ns = op.getStringField("ns");
+ nsToClient(ns, clientName);
+
+ if( !only.empty() && only != clientName )
+ return;
+
+ dblock lk;
+
setClientTempNs(ns);
if( client->justCreated || /* datafiles were missing. so we need everything, no matter what sources object says */
@@ -212,6 +221,7 @@ void Source::applyOperation(JSObj& op) {
client->justCreated = false;
}
+ stringstream ss;
const char *opType = op.getStringField("op");
JSObj o = op.getObjectField("o");
if( *opType == 'i' ) {
@@ -303,7 +313,6 @@ void Source::pullOpLog() {
log() << "pull: initial run\n";
}
{
- dblock lk;
applyOperation(op);
n++;
}
@@ -320,11 +329,11 @@ void Source::pullOpLog() {
// apply operations
{
- dblock lk;
while( 1 ) {
if( !c->more() ) {
log() << "pull: applied " << n << " operations" << endl;
syncedTo = t;
+ dblock lk;
save(); // note how far we are synced up to now
break;
}
@@ -337,7 +346,7 @@ void Source::pullOpLog() {
t = tmp;
if( !( last < t ) ) {
problem() << "sync error: last " << last.toString() << " >= t " << t.toString() << endl;
- uassert(false);
+ uassert("bad 'ts' value in sources", false);
}
applyOperation(op);
@@ -489,7 +498,7 @@ void replMain() {
int debug_stop_repl = 0;
void replSlaveThread() {
- sleepsecs(3);
+ sleepsecs(30);
while( 1 ) {
try {
replMain();
diff --git a/db/repl.h b/db/repl.h
index e73359fd52a..e6db4baaf9c 100644
--- a/db/repl.h
+++ b/db/repl.h
@@ -95,6 +95,7 @@ class Source {
public:
string hostName; // ip addr or hostname
string sourceName; // a logical source name.
+ string only; // only a certain db. note that in the sources collection, this may not be changed once you start replicating.
/* the last time point we have already synced up to. */
OpTime syncedTo;
diff --git a/db/scanandorder.h b/db/scanandorder.h
index a4489b00b1e..07c38fafe74 100644
--- a/db/scanandorder.h
+++ b/db/scanandorder.h
@@ -84,7 +84,7 @@ public:
JSObj k = order.getKeyFromObject(o);
if( (int) best.size() < limit ) {
approxSize += k.objsize();
- uassert( approxSize < 1 * 1024 * 1024 );
+ uassert( "too much key data for sort() with no index", approxSize < 1 * 1024 * 1024 );
_add(k, o);
return;
}
@@ -111,7 +111,7 @@ public:
nFilled++;
if( nFilled >= limit )
goto done;
- uassert( b.len() < 4000000 ); // appserver limit
+ uassert( "too much data for sort() with no index", b.len() < 4000000 ); // appserver limit
}
}
done:
diff --git a/stdafx.cpp b/stdafx.cpp
index f499f8b9bc0..89c5194be32 100644
--- a/stdafx.cpp
+++ b/stdafx.cpp
@@ -46,8 +46,8 @@ void asserted(const char *msg, const char *file, unsigned line) {
throw AssertionException();
}
-void uasserted(const char *msg, const char *file, unsigned line) {
- problem() << "User Assertion failure " << msg << ' ' << file << ' ' << line << endl;
+void uasserted(const char *msg) {
+ problem() << "User Assertion " << msg << endl;
throw AssertionException();
}
diff --git a/stdafx.h b/stdafx.h
index 23257e08a44..0612fa9f506 100644
--- a/stdafx.h
+++ b/stdafx.h
@@ -58,7 +58,7 @@ public:
void asserted(const char *msg, const char *file, unsigned line);
void wasserted(const char *msg, const char *file, unsigned line);
-void uasserted(const char *msg, const char *file, unsigned line);
+void uasserted(const char *msg);
void msgasserted(const char *msg);
#ifdef assert
@@ -68,7 +68,8 @@ void msgasserted(const char *msg);
#define assert(_Expression) (void)( (!!(_Expression)) || (asserted(#_Expression, __FILE__, __LINE__), 0) )
/* "user assert". if asserts, user did something wrong, not our code */
-#define uassert(_Expression) (void)( (!!(_Expression)) || (uasserted(#_Expression, __FILE__, __LINE__), 0) )
+//#define uassert(_Expression) (void)( (!!(_Expression)) || (uasserted(#_Expression, __FILE__, __LINE__), 0) )
+#define uassert(msg,_Expression) (void)( (!!(_Expression)) || (uasserted(msg), 0) )
#define xassert(_Expression) (void)( (!!(_Expression)) || (asserted(#_Expression, __FILE__, __LINE__), 0) )