summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Pasette <dan@10gen.com>2013-10-30 17:14:22 -0400
committerDan Pasette <dan@mongodb.com>2013-10-30 17:14:22 -0400
commited7af1195c8364068118be90eb39996f8440fa47 (patch)
tree82322afb44951353df1254cc573683b58604dd27
parent94a9026ed0729997d8af6a79f56da4862ca1db6e (diff)
downloadmongo-ed7af1195c8364068118be90eb39996f8440fa47.tar.gz
SERVER-11421: make applyOps call logOpForDbHash
-rw-r--r--jstests/sharding/dbhash_cache.js38
-rw-r--r--src/mongo/db/oplog.cpp6
2 files changed, 43 insertions, 1 deletions
diff --git a/jstests/sharding/dbhash_cache.js b/jstests/sharding/dbhash_cache.js
new file mode 100644
index 00000000000..7ba95361cf2
--- /dev/null
+++ b/jstests/sharding/dbhash_cache.js
@@ -0,0 +1,38 @@
+/**
+* Test that split/move chunk update the dbhash on the config server
+*/
+
+st = new ShardingTest({ name: "dbhash", shards : 2, mongos : 2, verbose : 2, other: {separateConfig : 1 } });
+st.stopBalancer();
+
+var mongos = st.s0;
+var shards = mongos.getCollection( "config.shards" ).find().toArray();
+var admin = mongos.getDB( "admin" );
+var configs = st._configServers
+
+assert(admin.runCommand({ enablesharding : "test" }).ok);
+printjson(admin.runCommand({ movePrimary : "test", to : shards[0]._id }));
+assert(admin.runCommand({ shardcollection : "test.foo" , key : { x : 1 } }).ok);
+
+mongos.getCollection("test.foo").insert({x:1});
+assert.eq(1, st.config.chunks.count(), "there should only be 1 chunk")
+
+var dbhash1 = configs[0].getDB("config").runCommand( "dbhash");
+printjson("dbhash before split and move is " + dbhash1.collections.chunks);
+
+// split the chunk and move one chunk to the non-primary shard
+assert(admin.runCommand({ split : "test.foo", middle : { x : 0 } }).ok);
+assert( admin.runCommand({ moveChunk : "test.foo",
+ find : { x : 0 },
+ to : shards[1]._id,
+ _waitForDelete : true }).ok );
+
+st.printShardingStatus();
+assert.eq(2, st.config.chunks.count(), "there should be 2 chunks")
+
+var dbhash2 = configs[0].getDB("config").runCommand("dbhash");
+printjson("dbhash after split and move is " + dbhash2.collections.chunks);
+
+assert.neq(dbhash1.collections.chunks, dbhash2.collections.chunks, "The hash should be different after split and move." )
+
+st.stop();
diff --git a/src/mongo/db/oplog.cpp b/src/mongo/db/oplog.cpp
index 86a2dcba6d5..b88ad66ac03 100644
--- a/src/mongo/db/oplog.cpp
+++ b/src/mongo/db/oplog.cpp
@@ -979,13 +979,17 @@ namespace mongo {
BSONElement e = i.next();
const BSONObj& temp = e.Obj();
- Client::Context ctx(temp["ns"].String());
+ string ns = temp["ns"].String();
+ Client::Context ctx(ns);
+
bool failed = applyOperation_inlock(temp, false, alwaysUpsert);
ab.append(!failed);
if ( failed )
errors++;
num++;
+
+ logOpForDbHash( "u", ns.c_str(), BSONObj(), NULL );
}
result.append( "applied" , num );