1

We are planning to shard a collection that contains few hundred gigs of data. I am going to use sh.shardCollection api for this. This is supposed to take hours to complete. I couldn't find any reference in the docs explaining whether the command acquires lock on the collection or not.

In short, all I want to know is whether collection is going to be available for read and write during while shardCollection is executing or not.

  • @azi, Yes, "sh.shardCollection()" acuire the lock. It depends on your mongos. – Md Haidar Ali Khan May 1 '18 at 8:25
  • @azi, what is MongoDB version (x,y,z)? – Md Haidar Ali Khan May 1 '18 at 8:41
0

Yes, the collection is available during the process. Actually, that command sh.shardCollection will take only milliseconds to execute, but actual balancing work will take hours or days to be ready. Balancing will not lock collection, it's just moving chunks from one shard to other one.

Just be careful when selecting sharding key, you should have good knowledge of basics of sharding and how it works.

0

Yes, Be sure about MongoDB version because related to sh.shardCollection there is bug in some version of MongoDB, as per MongoDB jira blog there is Bug mongos blocks db during shardCollection While shardCollection is running, accesses to the same database (via the same mongos) will block until shardCollection finishes, at which point they run. However, accessing the database is possible via other mongos. On the affected mongos, accesses to other databases are fine.

The affects Version/s : 2.4.14, 2.6.12, 2.8.0-rc4, 3.0.14

As Google group blog documentation here Choosing the correct shard key is extremely important for a sharded cluster deployment. If the shard key you are using involves a date element, the key will be monotonically increasing. This may result in a “hot shard”, i.e. there will be a shard that is more active compared to others. This could limit your insert rate, and the cluster will constantly need to split chunks and rebalance, since all inserts could go into a single chunk.

For further your ref here, here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy