Hello,
I have a 4-node MongoDB replica set:
- Node 1: Primary
- Node 2: Secondary
- Node 3: Secondary
- Node 4: Hidden
PBM agents run on all nodes.
MongoDB runs in Docker containers:
- percona/percona-server-mongodb:8.0.19-7
Additional details
- PBM 2.13.0, PITR enabled (the oplog slicer runs on the hidden node), daily logical backups.
- Default write concern is the implicit one (
getDefaultRWConcernreturnsw: "majority", sourceimplicit). - Containers are managed with Docker Compose,
restart: always. - Hosts are rebooted sequentially at night (hidden node first, then the other members, one at a time). No explicit
rs.stepDown()is performed before the reboot of the node that is currently primary.
What we observed
With Docker’s default stop timeout (10 seconds), when the host running the primary was rebooted, Docker sent SIGTERM to the mongod container and then SIGKILL after 10 seconds. In the mongod logs of the old primary we saw it entering quiesce mode (“The server is in quiesce mode and will shut down”), and at the next startup "Startup from clean shutdown?": false. Secondaries were never affected.
We then set stop_grace_period: 60s (120s for a second, smaller replica set on the same hosts) and systemd TimeoutStopSec=180 for the Docker service. After the following nightly reboot all members of both replica sets logged "Startup from clean shutdown?": true.
Questions
-
On SIGTERM, what is the exact shutdown sequence of a PRIMARY in 8.0 (stepdown / catch-up of a secondary, quiesce period via
shutdownTimeoutMillisForSignaledShutdown, final checkpoint), and what is the maximum time it can take? Is there an official recommendation for the stop grace period in containerized deployments (Dockerstop_grace_period, KubernetesterminationGracePeriodSeconds)? -
If mongod receives SIGKILL during the stepdown or the quiesce period, is the outcome equivalent to a crash of the primary? Specifically:
- Writes acknowledged with
w: "majority": can they be lost or rolled back in any case? - Writes acknowledged with
w: 1: is a rollback on the old primary the expected worst case (with documents saved under<dbpath>/rollback)? - Operations in progress: retryable writes are retried by the driver, multi-document operations (
updateMany/deleteMany) may be partially applied, and uncommitted transactions are aborted. Is that correct?
- Writes acknowledged with
-
Apart from the WiredTiger recovery at startup (last checkpoint + journal replay), is there any risk of data file inconsistency or corruption with a SIGKILL, given that journal and data files are on the same volume and the OS shuts down normally afterwards?
-
Is there any impact on PBM, for example gaps in PITR oplog chunks or a backup in progress, when the primary is killed instead of stepping down cleanly?
-
Is the election time different between the two cases: a clean stepdown on SIGTERM (a few seconds) vs. a killed primary (waiting for
electionTimeoutMillis, about 10-12 seconds)? -
For comparison, what changes if the primary is not killed by Docker but **powers off abruptly** (hardware or host failure, the VM simply disappears)?
* Our understanding is that the difference is mainly at node level: with SIGKILL, data already handed to the OS still reaches the disk, while with a power loss whatever is still in the OS page cache is lost too, so at most the last `commitIntervalMs` (100 ms) of journal for `w: 1` writes. Is that correct?
* At replica set level, is the behavior the same as in question 2 (`w: “majority”` writes safe, `w: 1` writes possibly rolled back or lost if the node never comes back, election after `electionTimeoutMillis`)?
* Assuming the storage honors `fsync` (enterprise VMware datastore), is WiredTiger recovery expected to be always successful, or are there known cases where an initial sync of the node is required?
Links to the relevant official documentation would be much appreciated, as we need to justify the configuration change internally.
Our goal is to confirm that a host reboot with a too short stop timeout effectively turns a planned maintenance into a simulated crash of the primary, which is avoidable, while a real hardware failure is handled by the replica set itself.
Thank you!
Francesco