Create an index on a replica set slave?

485 views
Skip to first unread message

Michael Conigliaro

unread,
Apr 7, 2011, 3:11:24 PM4/7/11
to mongodb-user
So I just had MongoDB segfault on me while it was building an index.
Replica set failover worked properly, but the index did not exist yet
on the slave (which is now the master), so I decided to recreate the
index on that machine manually.

Next I looked at the old master (now the slave) and found that the
index actually did exist, despite the fact that it never finished
getting built. So I attempted to drop and recreate that index
manually. Of course, this didn't work, because setSlaveOk never works
for anything useful I want to do on a slave...

db.getMongo().setSlaveOk();
db.userEventsJournal.dropIndex({"adId":1, "eventId":1, "variationId":
1});
{ "errmsg" : "not master", "ok" : 0 }

OK, so then I decided to try the reindex command on the collection:

3:SECONDARY> db.runCommand( { reIndex :
'userEventsJournal' } )
{
"nIndexesWas" : 2,
"msg" : "indexes dropped for collection",
"errmsg" : "exception: no index name specified",
"code" : 12523,
"ok" : 0
}
3:SECONDARY>
db.userEventsJournal.getIndexes()
[ ]

Oops! So apparently, MongoDB will allow you to drop indexes on a
slave, but it won't actually let you create them. Wonderful. Anyone
have any tips for me? Or do I definitely have to promote this machine
to a master before recreating the indexes?

Michael Conigliaro

unread,
Apr 7, 2011, 4:21:13 PM4/7/11
to mongodb-user
Hmm, it looks like once the master finished building that newest
index, the slave noticed its missing indexes and started recreating
them. So things are looking good so far. I was worried I might have to
promote the slave and recreate all those indexes manually.
Reply all
Reply to author
Forward
0 new messages