- How can I compact my third server in this scenario?
Complete step by step on how to perform compact operation on Atlas cluster.
All Atlas deployments utilize the WiredTiger (WT) storage engine, which is a no-overwrite data engine that only releases disk space when blocks available for re-use are checked and used for the writing of new blocks before files are extended. More often than not, there is no need to forcibly compact your data, as WT should manage this for you.
However, if you would like to reclaim disk space regardless of the information provided above, you can use compact() to try to release unused space that has been allocated for re-use by WT.
Taking the above into account, please see the procedure outlined below (which applies to both replica sets and sharded clusters).
Procedure
-
Create a MongoDB user with the required privileges to run the
compact()command. -
Log into a
SECONDARYnode via themongoshell with the user that you just created. This can be done by specifying only theSECONDARYnode’s hostname in themongoshell command, similar to the following (where the02node is a currentSECONDARY):mongo "mongodb://test-shard-00-02-abc123.mongodb.net:27017/test" --ssl --authenticationDatabase admin --username USERNAME --password PASSWORD -
Run the
compact()command. See the documentation for required or optional fields.NOTE: Only run the command on one
SECONDARYnode at a time. Wait for it to complete before moving onto the next node! -
Confirm that you have completed the
compact()command by downloading and reviewing the member’smongodlog. The following message can be seen when thecompact()command is complete:2019-06-12T22:45:30.765+0000 I COMMAND [conn9382] compact <collection ns> end -
Perform steps 2-4 on all current
SECONDARYnodes in the cluster. -
Once you have completed running
compact()on allSECONDARYnodes in the cluster, use the cluster’s Test Failover functionality to step down the currentPRIMARYmember(s) and wait for the member(s) to transition toSECONDARYstatus. -
Perform the
compact()command again on the remaining member(s) that stepped down in step 5.
For more background on the compact() command in MongoDB, please see our compact() command documentation.
- What happens if the third node reaches its storage limit while the other two still have free space due to compaction?
Enable storage auto-sclaing and you can always reach out to MongoDB support via chats or support cases if you encounter any issues.