Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different indexes on different replica set members

Tags:

mongodb

As part of our mongo cluster, we have a hidden node that the analytics people use for reporting. Their queries are quite a bit different than the ones that our main application is optimized for.

We can improve the performance of their queries quite dramatically by adding certain indexes, which are relatively expensive to compute, and take a fair amount of memory. Those indexes should not be used by any of the queries running on our primary and secondary members, so it seems a bit silly to spend time and memory on the main replica set members to compute and keep the reporting indexes in memory.

Is there a way to create an index so that it only exists on a single replica set member? Is there a way to tell my primary and secondary nodes to not compute or store the indexes I know they will not use?

like image 763
captncraig Avatar asked May 09 '13 22:05

captncraig


People also ask

What is the maximum number of nodes in a replica set?

MongoDB supports replica sets, which can have up to 50 nodes.

Does Sharding require a replica set?

When one shard of the cluster goes down, any data on it is inaccessible. For that reason each member of the cluster should also be a replica-set. This is not required. When you don't care about high-availability, a shard can also be a single mongod instance without replication.

What are primary and secondary replica sets?

[1] The primary records all changes to its data sets in its operation log, i.e. oplog. For more information on primary node operation, see Replica Set Primary. The secondaries replicate the primary's oplog and apply the operations to their data sets such that the secondaries' data sets reflect the primary's data set.


1 Answers

Yes - you can use a variation on the strategy used for creating a new index in a replica set without down time. This will require that the hidden member be taken off-line while the index(es) are created.

Here is the link for the strategy: http://docs.mongodb.org/manual/tutorial/build-indexes-on-replica-sets/#procedure

In your case you will take the hidden member off-line and restart in a standalone mode (remove the --replSet option and use a different port number). Once the member is isolated you can adjust the indexes (remove un-needed ones and add new ones). Once the indexes are done being created restart the member with the old port and --replSet option.

The hidden member will resync to the replica set and you are all set.

like image 112
Rob Moore Avatar answered Sep 20 '22 09:09

Rob Moore