summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Hernandez <scotthernandez@gmail.com>2013-03-29 17:14:38 -0400
committerScott Hernandez <scotthernandez@gmail.com>2013-03-29 17:32:42 -0400
commit198c577fe4dc2d35a829fac99a97f9e9b03e4ffd (patch)
tree20c9a135f0030e22ec86f7fd25807e7c87444a78
parent85fc27444fa888d30cba56b31b6dfec8072a9116 (diff)
downloadmongo-198c577fe4dc2d35a829fac99a97f9e9b03e4ffd.tar.gz
SERVER-9053: ttl: don't delete on non-primaries
-rw-r--r--jstests/slowNightly/ttl_repl_secondary_disabled.js52
-rw-r--r--src/mongo/db/ttl.cpp5
2 files changed, 56 insertions, 1 deletions
diff --git a/jstests/slowNightly/ttl_repl_secondary_disabled.js b/jstests/slowNightly/ttl_repl_secondary_disabled.js
new file mode 100644
index 00000000000..47a447e048d
--- /dev/null
+++ b/jstests/slowNightly/ttl_repl_secondary_disabled.js
@@ -0,0 +1,52 @@
+/** Test TTL docs are not deleted from secondaries directly
+ */
+
+var rt = new ReplSetTest( { name : "ttl_repl" , nodes: 2 } );
+
+// setup set
+var nodes = rt.startSet();
+rt.initiate();
+var master = rt.getMaster();
+rt.awaitSecondaryNodes();
+var slave1 = rt.getSecondary();
+
+// shortcuts
+var masterdb = master.getDB( 'd' );
+var slave1db = slave1.getDB( 'd' );
+var mastercol = masterdb[ 'c' ];
+var slave1col = slave1db[ 'c' ];
+
+// create TTL index, wait for TTL monitor to kick in, then check things
+mastercol.ensureIndex( { x : 1 } , { expireAfterSeconds : 10 } );
+
+rt.awaitReplication();
+
+//increase logging
+slave1col.getDB().adminCommand({setParameter:1, logLevel:1});
+
+//insert old doc (10 minutes old) directly on secondary using godinsert
+slave1col.runCommand("godinsert",
+ {obj: {_id: new Date(), x: new Date( (new Date()).getTime() - 600000 ) } })
+assert.eq(1, slave1col.count(), "missing inserted doc" );
+
+sleep(70*1000) //wait for 70seconds
+assert.eq(1, slave1col.count(), "ttl deleted my doc!" );
+
+// looking for this error : "Assertion: 13312:replSet error : logOp() but not primary"
+// indicating that the secondary tried to delete the doc, but shouldn't be writing
+var errorString = "13312";
+var foundError = false;
+var globalLogLines = slave1col.getDB().adminCommand({getLog:"global"}).log
+for (i in globalLogLines) {
+ var line = globalLogLines[i];
+ if (line.match( errorString )) {
+ foundError = true;
+ errorString = line; // replace error string with what we found.
+ break;
+ }
+}
+
+assert.eq(false, foundError, "found error in this line: " + errorString);
+
+// finish up
+rt.stopSet(); \ No newline at end of file
diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp
index d94552cb5fc..584bc20a3bc 100644
--- a/src/mongo/db/ttl.cpp
+++ b/src/mongo/db/ttl.cpp
@@ -50,6 +50,9 @@ namespace mongo {
void doTTLForDB( const string& dbName ) {
+ //check isMaster before becoming god
+ bool isMaster = isMasterNs( dbName.c_str() );
+
Client::GodScope god;
vector<BSONObj> indexes;
@@ -100,7 +103,7 @@ namespace mongo {
nsd->syncUserFlags( ns );
}
// only do deletes if on master
- if ( ! isMasterNs( dbName.c_str() ) ) {
+ if ( ! isMaster ) {
continue;
}