Skip to content

Commit 7b169e3

Browse files
committed
DOCSP-3449: Compact Oplog after Reducing Size
1 parent 60a066e commit 7b169e3

File tree

4 files changed

+122
-9
lines changed

4 files changed

+122
-9
lines changed

source/reference/command/compact.txt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,71 @@ to 100 bytes on the collection named by ``<collection>``:
108108

109109
db.runCommand ( { compact: '<collection>', paddingBytes: 100 } )
110110

111+
.. _compact-authentication:
112+
113+
``compact`` Required Privileges
114+
-------------------------------
115+
116+
For clusters enforcing :ref:`authentication <authentication>`,
117+
you must authenticate as a user with the :authrole:`compact` privilege
118+
action on the target collection. The :authrole:`dbAdmin` role provides
119+
the required privileges for running :dbcommand:`compact` against
120+
non-system collections.
121+
122+
For :ref:`system collections <metadata-system-collections>`, create a
123+
custom role that grants the :authrole:`compact` action on the system
124+
collection. You can then grant that role to a new or existing user and
125+
authenticate as that user to perform the :dbcommand:`compact` command.
126+
For example, the following operations create a custom role that grants
127+
the :authrole:`compact` action against specified database and
128+
collection:
129+
130+
.. code-block:: javascript
131+
132+
use admin
133+
db.createRole(
134+
{
135+
role: "myCustomCompactRole",
136+
privileges: [
137+
{
138+
resource: { "db" : "<database>" , "collection" : "<collection>" },
139+
actions: [ "compact" ]
140+
}
141+
],
142+
roles: []
143+
}
144+
)
145+
146+
For more information on configuring the ``resource`` document, see
147+
:ref:`resource-document`.
148+
149+
To add the :authrole:`dbAdmin` or the custom role to an existing
150+
user, use :method:`db.grantRoleToUser` or :method:`db.updateUser()`.
151+
The following operation grants the custom ``compact`` role to the
152+
``myCompactUser`` on the ``admin`` database:
153+
154+
.. code-block:: javascript
155+
156+
use admin
157+
db.grantRoleToUser("myCompactUser", [ "dbAdmin" | "myCustomCompactRole" ] )
158+
159+
To add the :authrole:`dbAdmin` or the custom role to a new user,
160+
specify the role to the ``roles`` array of the
161+
:method:`db.createUser()` method when creating the user.
162+
163+
.. code-block:: javascript
164+
165+
use admin
166+
db.createUser(
167+
{
168+
user: "myCompactUser",
169+
pwd: "myCompactUserPassword"
170+
roles: [
171+
{ role: "dbAdmin", db: "<database>" } | "myCustomCompactRole"
172+
]
173+
}
174+
)
175+
111176
Behavior
112177
--------
113178

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: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +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
18-
:term:`primary`.
19-
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>`.
16+
:term:`primary`. The :dbcommand:`replSetResizeOplog` command only
17+
supports the :ref:`storage-wiredtiger` storage engine.
2518

2619
Perform these steps on each :term:`secondary` replica set member
2720
*first*. Once you have changed the oplog size for all secondary
@@ -76,3 +69,48 @@ member to 16 gigabytes, or 16000 megabytes.
7669
.. [#oplog]
7770

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