Skip to content

Commit 442dad9

Browse files
committed
DOCSP-3449: Compact Oplog after Reducing Size
1 parent 274fcfb commit 442dad9

File tree

4 files changed

+119
-8
lines changed

4 files changed

+119
-8
lines changed

source/reference/command/compact.txt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,70 @@ Definition
4141
.. warning:: Always have an up-to-date backup before performing server
4242
maintenance such as the :dbcommand:`compact` operation.
4343

44+
.. _compact-authentication:
45+
46+
``compact`` Required Privileges
47+
-------------------------------
48+
49+
For clusters enforcing :ref:`authentication <authentication>`,
50+
you must authenticate as a user with the :authrole:`compact` privilege
51+
action on the target collection. The :authrole:`dbAdmin` role provides
52+
the required privileges for running :dbcommand:`compact` against
53+
non-system collections.
54+
55+
For :ref:`system collections <metadata-system-collections>`, create a
56+
custom role that grants the :authrole:`compact` action on the system
57+
collection. You can then grant that role to a new or existing user and
58+
authenticate as that user to perform the :dbcommand:`compact` command.
59+
For example, the following operations create a custom role that grants
60+
the :authrole:`compact` action against specified database and
61+
collection:
62+
63+
.. code-block:: javascript
64+
65+
use admin
66+
db.createRole(
67+
{
68+
role: "myCustomCompactRole",
69+
privileges: [
70+
{
71+
resource: { "db" : "<database>" , "collection" : "<collection>" },
72+
actions: [ "compact" ]
73+
}
74+
],
75+
roles: []
76+
}
77+
)
78+
79+
For more information on configuring the ``resource`` document, see
80+
:ref:`resource-document`.
81+
82+
To add the :authrole:`dbAdmin` or the custom role to an existing
83+
user, use :method:`db.grantRoleToUser` or :method:`db.updateUser()`.
84+
The following operation grants the custom ``compact`` role to the
85+
``myCompactUser`` on the ``admin`` database:
86+
87+
.. code-block:: javascript
88+
89+
use admin
90+
db.grantRoleToUser("myCompactUser", [ "dbAdmin" | "myCustomCompactRole" ] )
91+
92+
To add the :authrole:`dbAdmin` or the custom role to a new user,
93+
specify the role to the ``roles`` array of the
94+
:method:`db.createUser()` method when creating the user.
95+
96+
.. code-block:: javascript
97+
98+
use admin
99+
db.createUser(
100+
{
101+
user: "myCompactUser",
102+
pwd: "myCompactUserPassword"
103+
roles: [
104+
{ role: "dbAdmin", db: "<database>" } | "myCustomCompactRole"
105+
]
106+
}
107+
)
44108

45109
Behavior
46110
--------

source/reference/command/replSetResizeOplog.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ other member in the replica set. You must run
5252
:dbcommand:`replSetResizeOplog` on each replica set member in your
5353
cluster to change the oplog size for all members.
5454

55+
Reducing the oplog size does *not* reclaim that disk space
56+
automatically. You must run :dbcommand:`compact` against the
57+
``oplog.rs`` collection in the ``local`` database. ``compact``
58+
blocks all operations on the database it runs against.
59+
Running ``compact`` against ``oplog.rs`` therefore prevents oplog
60+
synchronization. For a procedure on resizing the oplog and compacting
61+
``oplog.rs``, see :doc:`/tutorial/change-oplog-size`.
62+
5563
Example
5664
--------
5765

source/tutorial/change-oplog-size.txt

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,11 @@ Change the Size of the Oplog
1010
:depth: 1
1111
:class: singlecol
1212

13-
.. versionadded:: 3.6
14-
1513
This procedure changes the size of the oplog [#oplog]_ on each member of a
1614
replica set using the :dbcommand:`replSetResizeOplog` command, starting
1715
with the :term:`secondary` members before proceeding to the
1816
:term:`primary`.
1917

20-
.. important::
21-
22-
You can only run :dbcommand:`replSetResizeOplog` on
23-
replica set members running with the
24-
:ref:`WiredTiger storage engine <storage-wiredtiger>`.
25-
2618
Perform these steps on each :term:`secondary` replica set member
2719
*first*. Once you have changed the oplog size for all secondary
2820
members, perform these steps on the :term:`primary`.
@@ -76,3 +68,48 @@ member to 16 gigabytes, or 16000 megabytes.
7668
.. [#oplog]
7769

7870
.. include:: /includes/fact-oplog-size.rst
71+
72+
.. compact-oplog-rs:
73+
74+
D. (Optional) Compact ``oplog.rs`` to reclaim disk space
75+
--------------------------------------------------------
76+
77+
Reducing the size of the oplog does *not* automatically reclaim
78+
the disk space allocated to the original oplog size. You must run
79+
:dbcommand:`compact` against the ``oplog.rs`` collection in the
80+
``local`` database to reclaim disk space. There are no benefits to
81+
running ``compact`` on the ``oplog.rs`` collection after increasing the
82+
oplog size.
83+
84+
.. important::
85+
86+
The replica set member cannot replicate oplog entries while the
87+
``compact`` operation is ongoing. While ``compact`` runs, the
88+
member may fall so far behind the primary that it cannot resume
89+
replication. The likelihood of a member becoming "stale" during
90+
the ``compact`` procedure increases with cluster write throughput,
91+
and may be further exacerbated by the reduced oplog size.
92+
93+
Consider scheduling a maintenance window during which writes are
94+
throttled or stopped to mitigate the risk of the member becoming
95+
"stale" and requiring a :ref:`full resync <resync-replica-member>`.
96+
97+
Do **not** run ``compact`` against the primary replica set member.
98+
Connect a :binary:`mongo <bin.mongo>` shell to the primary and run
99+
:method:`rs.stepDown()`. If successful, the primary steps down and
100+
closes all open connections. Reconnect the :binary:`mongo <bin.mongo>`
101+
shell to the member and run the ``compact`` command on the member.
102+
103+
The following operation runs the ``compact`` command against the
104+
``oplog.rs`` collection:
105+
106+
.. code-block:: javascript
107+
108+
use local
109+
db.runCommand({ "compact" : "oplog.rs" } )
110+
111+
For clusters enforcing :ref:`authentication <authentication>`,
112+
authenticate as a user with the :authaction:`compact` privilege
113+
action on the ``local`` database and the ``oplog.rs`` collection.
114+
For complete documentation on :dbcommand:`compact` authentication
115+
requirements, see :ref:`compact-authentication`.

source/tutorial/resync-replica-set-member.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _resync-replica-member:
2+
13
================================
24
Resync a Member of a Replica Set
35
================================

0 commit comments

Comments
 (0)