Mongodb replica set questions

423 views Asked by At

I have a mongodb replica set configuration of one primary machine, one secondary machine and one arbiter machine. The primary and secondary machines have 2 collections (each in its own database)

I need to delete a few Gb from one collection and leave the other collection intact. I am brand new at this so I would like to get ideas/gotchas on this. I am thinking of following this procedure:

  1. Remove the secondary from the replica set.
  2. In the secondary, for the collection that I want to delete, do a mongodump of the data I want to keep.
  3. Do a mongo restore from that dump.
  4. Re-add the secondary back to the replica set. I think I will have to set priorities so that the primary does not become secondary?
  5. The secondary will sync/catch up with the primary I hope but what happens to the data that I deleted in the secondary? Does the primary removes it from itself? (which is what I want)

  6. Do I need to do anything with the Primary?

1

There are 1 answers

0
aldwinaldwin On

Rolling Maintenance:

  • To see how much time of oplog you have, to bring down a Secondary and to catchup : db.printReplicationInfo()
  • When working with Primary, Secondary and Arbiter ... then taking out the secondary can have a risk. The primary won't have a failover in case something happens during your maintenance period. Primary-Secondary-Secondary would be safer.
  • After shutdown your Secondary, restart it without the --replSet option AND on a different port otherwise the rest of the replicaSet will be confused.
  • Restart your Secondary with --replSet and the old port again will add it to the ReplicaSet. Don't worry, your Primary will stay Primary. A voting/election 'only' happens when a Primary has disappeared ... and that is not the case when adding a Secondary.
  • The Secondary will catch up from the oplog.
  • To work on the Primary. Do a rs.stepDown() on the Primary, let the Secondary take over, and repeat the process.

Cleanup during the Rolling Maintenance

Here I am not very sure and can only make some guesses for now because I didn't test this yet. What you can do during a Rolling maintenance is:

  • update binaries (apt-get update/yum update/...)
  • build indexes
  • compact and repair

Now about deleting data? That you need to test on a local small replica.

  • I'm afraid that dump/restore is a bad idea. But I'm not sure.
  • Execute a remove statement... i think there is a way to do that, and let that statement then execute on the Primary but i don't know how yet.
  • Most simple: Why not execute the remove statement on the primary and let that spread to the secondary? Because you want to decrease the database size? Well, after the remove you can do the Rolling Maintenance to do the Repair. Compact will not create extra space, only order data inside the pre-allocated files. And Repair, be careful, needs double space to build. A 100GB DB needs at least 100GB free space to do the repair.

https://dba.stackexchange.com/questions/28269/disk-space-recovery-on-mongodb-replicaset-secondaries

And have a look at https://university.mongodb.com => M202: MongoDB Advanced Deployment and Operations ... This issue is handled in those free lessons.