liveBook · Manning

Initial sync

As explained in MongoDB 8.0 in Action, Third Edition

Initial sync is the process by which a new or empty replica-set member copies existing data and subsequent operations to reach the current replica-set state.

Initial sync brings a new or empty MongoDB replica-set member toward the set’s current data state by copying existing data and applying subsequent operations. While it runs, the member is in STARTUP2 and cannot vote; it has not yet become a functioning secondary. section 9.1.1

Check the member and the operations it needs to catch up:

  • In mongosh, run db.adminCommand("replSetGetStatus") or rs.status() and inspect the member’s state. STARTUP2 means initial sync is running. section 9.1.1
  • Check the oplog window with db.getReplicationInfo(). It must be long enough to retain operations generated during logical initial sync until the member can apply them; otherwise, needed entries may be removed. section 9.1.3
  • If retention needs adjustment, consider oplog size and minimum retention time. An existing member’s oplog can be resized with replSetResizeOplog without restarting mongod. section 9.1.3

MongoDB 6.0 and later offers logical initial sync and, in MongoDB Enterprise, file-based initial sync designed for data sets of 1 TB or more. After a failure such as losing access to needed oplog entries or a transient network problem, sync can resume within a default 24-hour window for logical sync or 10-minute window for file-based sync. mongod parameters can change those windows. section 9.1.3

Table 9.1 Possible state of each member of a replica set

Number

Name

Description

0

STARTUP

Initial state. Parses config document.

1

PRIMARY

Accepts writes. Eligible to vote.

2

SECONDARY

Replicates data. Eligible to vote.

3

RECOVERING

In self-checks, rollback, or resync. No reads. Votes.

4

STARTUP2

Running initial sync. Can’t vote.

5

UNKNOWN

State not known by others.

6

ARBITER

Only votes. Doesn’t replicate data.

7

DOWN

Unreachable by others.

8

ROLLBACK

Performing a rollback. No reads. Votes.

9

REMOVED

Was part of a set, now removed.

Compare STARTUP2 with SECONDARY, RECOVERING, and other member states when interpreting replica-set status. section 9.1.1

Listing 9.5 Output of the db.getReplicationInfo() command
db.getReplicationInfo()
{
  configuredLogSizeMB: 4096,
  logSizeMB: 4096,
  usedMB: 4074.63,
  timeDiff: 635133,
  timeDiffHours: 176.43,
  tFirst: 'Wed Mar 20 2024 10:44:15 GMT+0000 (Coordinated Universal Time)',
  tLast: 'Wed Mar 27 2024 19:09:48 GMT+0000 (Coordinated Universal Time)',
  now: 'Wed Mar 27 2024 19:09:49 GMT+0000 (Coordinated Universal Time)'
}

Use the reported oplog time span to assess whether operations are retained long enough for a syncing member. section 9.1.3

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains member state, oplog-window requirements, sync approaches, and recovery windows without detailing the full copying procedure.
Examples
Uses replica-set status output, a member-state table, and db.getReplicationInfo() output to make progress and retention inspectable.
What you can do after
Diagnose/debug with it by identifying STARTUP2 through replica-set status and checking oplog coverage with db.getReplicationInfo().
How it connects
Connects initial sync to replica-set member states, secondary replication, the oplog, and oplog retention.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.