Foreground indexing on primary blocks all databases on secondaries

It is expected behavior for all databases on a secondary to be blocked during an index build, as oplog updates are applied in batches and modifications made by each batch affect the overall state of the whole server. Thus, the operation cannot selectively target a specific database or collection and a global lock is required.
The replication steps are as follows:
  1. Get oplog batch
  2. Acquire global lock
  3. Apply batch in parallel
  4. Write to local oplog
  5. Release global lock
A foreground index build from the primary is applied during the apply batch step on a secondary.
Note
Before MongoDB version 2.6, background index creation operations become foreground indexing operations on secondary members of replica sets. After 2.6, background index builds replicate as background index builds on the secondaries.
For details on building indexes for replica sets, see Build Indexes on Replica Sets.
For more information on concurrency and locking in MongoDB, see the Concurrency FAQ.

Comments