MongoDB: The collections metadata lock is taken

mongodbsharding

Running a mongodb 2.6 cluster on localhost with four shards and four replication sets.

Using a for loop with 100 iterations that pre-splits chunks among the existing shards. I am getting the error The collections metadata lock is taken after a couple of minutes

mongos> for( var i=0; i < 100; i++) { sh.splitAt("test_cluster.presplit_demo", { x:1000000 * i / 100 } ); }
{
    "cause" : {
        "who" : {
            "_id" : "test_cluster.presplit_demo",
            "state" : 2,
            "who" : "localhost.localdomain:27000:1402761131:1123537020:conn19:1622303703",
            "process" : "localhost.localdomain:27000:1402761131:1123537020",
            mongos&gt; for( var i=0; i &lt; 100; i++) { sh.splitAt("test_cluster.presplit_demo", { x:1000000 * i / 100 } ); }
{
    "cause" : {
        "who" : {
            "_id" : "test_cluster.presplit_demo",
            "state" : 2,
            "who" : "localhost.localdomain:27000:1402761131:1123537020:conn19:1622303703",
            "process" : "localhost.localdomain:27000:1402761131:1123537020",
            "when" : ISODate("2014-06-14T15:56:16.439Z"),
            "why" : "migrate-{ x: 360000.0 }",
            "ts" : ObjectId("539c70a07b296ac1c721eca4")
        },
        "ok" : 0,
        "errmsg" : "the collection's metadata lock is taken"
    },
    "ok" : 0,
    "errmsg" : "split failed"
}

I see the lock in config: db.locks.find(), removed the lock but it just comes back. If I reduce the number of iterations to 50, the for loop completes successfully. There is more than enough disk space.

Question

Anyone else run into this issue with pre-splitting and what did you do to resolve it?

Best Answer

Turn off the balancer first, you are likely seeing it trying to balance the collections while you are attempting to split it. You can do this with the sh.stopBalancer() command. If you take a look at this answer I go into the necessary steps for pre-splitting in more detail.