Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions source/core/replica-set-oplog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,12 @@ without becoming too stale to continue replicating. However, most
replica sets have much lower operation volumes, and their oplogs can
hold much higher numbers of operations.

Before :program:`mongod` creates an oplog, you can specify its size
with the :setting:`~replication.oplogSizeMB` option. Once you have started
a replica set member for the first time, use the :dbcommand:`replSetResizeOplog`
to dynamically change the oplog size. If you are using the MMAPv1 storage
engine, follow the :doc:`/tutorial/change-oplog-size` procedure to change
the oplog size.

Before :program:`mongod` creates an oplog, you can specify its size with
the :setting:`~replication.oplogSizeMB` option. Once you have started a
replica set member for the first time, use the
:dbcommand:`replSetResizeOplog` to change the oplog size.
:dbcommand:`replSetResizeOplog` enables you to resize the oplog
dynamically without restarting the :program:`mongod` process.

Workloads that Might Require a Larger Oplog Size
------------------------------------------------
Expand Down
27 changes: 18 additions & 9 deletions source/reference/command/replSetResizeOplog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ Definition

.. versionadded:: 3.6

The :dbcommand:`replSetResizeOplog` dynamically resizes a replica
set member's oplog to satisfy the operational needs in a replica
set. It bypasses the need to perform a maintenance
operation to resize the oplog. The command may only be run against the
``admin`` database.
Use the :dbcommand:`replSetResizeOplog` administrative command to
change the size of a replica set member's oplog.
:dbcommand:`replSetResizeOplog` enables you to resize the oplog
dynamically without restarting the :program:`mongod` process.

This feature is only available for nodes running on the WiredTiger
storage engine. If you are using the MMAPv1 storage engine, see
:doc:`/tutorial/change-oplog-size` to follow the maintenance
procedure.
You must run this command against the ``admin`` database.

The command has the following form:

Expand All @@ -40,6 +36,19 @@ Definition
in megabytes, while the oplog size is stored in bytes. The size
parameter must also be over 990 megabytes.

Behavior
--------

You can only use :dbcommand:`replSetResizeOplog` on
:program:`mongod` instances running with the
:ref:`Wired Tiger storage engine <storage-wiredtiger>`.

Changing the oplog size of a given replica set member with
:dbcommand:`replSetResizeOplog` does not change the oplog size of any
other member in the replica set. You must run
:dbcommand:`replSetResizeOplog` on each replica set member in your
cluster to change the oplog size for all members.

Example
--------

Expand Down
221 changes: 39 additions & 182 deletions source/tutorial/change-oplog-size.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,208 +10,65 @@ Change the Size of the Oplog
:depth: 1
:class: singlecol

The :term:`oplog` exists internally as a :term:`capped collection`, so
you cannot modify its size in the course of normal operations. In most
cases the :ref:`default oplog size <replica-set-oplog-sizing>` is an
acceptable size; however, in some situations you may need a larger or
smaller oplog. For example, you might need to change the oplog size
if your applications perform large numbers of multi-updates or
deletes in short periods of time.
.. versionadded:: 3.6

This tutorial describes how to resize the oplog when using the MMAPv1
storage engine. If you are using WiredTiger, see
:doc:`/reference/command/replSetResizeOplog` to dynamically change the oplog size.
This procedure changes the size of the oplog on each member of a
replica set using the :dbcommand:`replSetResizeOplog` command, starting
with the :term:`secondary` members before proceeding to the
:term:`primary`.

For a detailed explanation of oplog sizing, see :ref:`replica-set-oplog-sizing`.
For details of how oplog size affects :term:`delayed members <delayed
member>` and affects :term:`replication lag`, see
:ref:`replica-set-delayed-members`.
.. important::

Overview
--------
You can only run :dbcommand:`replSetResizeOplog` on
replica set member's running with the
:ref:`Wired Tiger storage engine <storage-wiredtiger>`.

To change the size of the oplog, you must perform maintenance on each
member of the replica set in turn. The procedure requires: stopping
the :program:`mongod` instance and starting as a standalone instance,
modifying the oplog size, and restarting the member.
Perform these steps on each :term:`secondary` replica set member
*first*. Once you have changed the oplog size for all secondary
members, perform these steps on the :term:`primary`.

.. important:: Always start rolling replica set maintenance with the
secondaries, and finish with the maintenance on primary member.
A. Connect to the replica set member
------------------------------------

Procedure
---------
Connect to the replica set member using the :program:`mongo` shell:

- Restart the member in standalone mode.
.. code-block:: shell

.. tip:: Always use :method:`rs.stepDown()` to force the primary to
become a secondary, before stopping the server. This facilitates
a more efficient election process.
mongo --host <hostname>:<port>

- Recreate the oplog with the new size and with an old oplog entry as
a seed.
.. note::

- Restart the :program:`mongod` instance as a member of the replica
set.
If the replica set enforces :ref:`authentication <authentication>`,
you must authenticate as a user with privileges to modify the
``local`` database, such as the :authrole:`clusterManager` or
:authrole:`clusterAdmin` role.

Restart a Secondary in Standalone Mode on a Different Port
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
B. (Optional) Verify the current size of the oplog
--------------------------------------------------

Shut down the :program:`mongod` instance for one of the non-primary
members of your replica set. For example, to shut down, use the
:method:`db.shutdownServer()` method:

.. code-block:: sh

use admin
db.shutdownServer()

Restart this :program:`mongod` as a standalone instance
running on a different port and *without*
the :option:`--replSet <mongod --replSet>` parameter. Use a command
similar to the following:

.. include:: /includes/warning-bind-ip-security-considerations.rst

.. code-block:: sh

mongod --port 37017 --dbpath /srv/mongodb --bind_ip localhost,<ip address of the mongod host>

Create a Backup of the Oplog (Optional)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Optionally, backup the existing oplog on the standalone instance, as
in the following example:

.. code-block:: sh

mongodump --db local --collection 'oplog.rs' --port 37017

Recreate the Oplog with a New Size and a Seed Entry
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Save the last entry from the oplog. For example, connect to the instance
using the :program:`mongo` shell, and enter the following command to
switch to the ``local`` database:
To view the current size of the oplog, switch to the ``local``
database and run :method:`db.collection.stats()` against the
``oplog.rs`` collection. :method:`~db.collection.stats()` displays the
oplog size as :data:`~collStats.maxSize`.

.. class:: copyable-code
.. code-block:: javascript

use local
db.oplog.rs.stats().maxSize

In :program:`mongo` shell scripts you can use the following operation
to set the ``db`` object:

.. code-block:: javascript

db = db.getSiblingDB('local')

Ensure that the ``temp`` temporary collection is empty by dropping the
collection:

.. code-block:: javascript

db.temp.drop()

Retrieve the latest oplog entry by sorting on reverse :term:`natural order`.
Modify the entry to set ``op`` to "n" (representing a no-op) and clear the
``o`` and ``o2`` fields. Then insert the modified oplog entry into a temporary
collection.

.. _last-oplog-entry:

.. code-block:: javascript

var oplogEntry = db.oplog.rs.find().sort({$natural: -1}).limit(1).next();
oplogEntry.op = 'n'; // Change the entry to a no-op.
oplogEntry.o = {}; // Remove any update modifiers that would prevent saving the oplog entry to a normal collection.
oplogEntry.o2 = {};
db.temp.insert(oplogEntry);

To see this oplog entry, use the following operation:

.. code-block:: javascript

db.temp.find()

Remove the Existing Oplog Collection
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Drop the old ``oplog.rs`` collection in the ``local`` database. Use
the following command:
The ``maxSize`` field displays the collection size in bytes.

.. code-block:: javascript

db = db.getSiblingDB('local')
db.oplog.rs.drop()

This returns ``true`` in the shell.

Create a New Oplog
~~~~~~~~~~~~~~~~~~

Use the :dbcommand:`create` command to create a new oplog of a
different size. Specify the ``size`` argument in bytes. A value of
``2 * 1024 * 1024 * 1024`` will create a new oplog that's 2 gigabytes:

.. code-block:: javascript

db.runCommand( { create: "oplog.rs", capped: true, size: (2 * 1024 * 1024 * 1024) } )

Upon success, this command returns the following status:

.. code-block:: javascript

{ "ok" : 1 }

Insert the Last Entry of the Old Oplog into the New Oplog
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Insert the previously inserted latest entry from the old oplog into the new
oplog. For example:

.. code-block:: javascript

db.oplog.rs.insert( db.temp.findOne() )

To confirm the entry is in the new oplog, use the following operation:

.. code-block:: javascript

db.oplog.rs.find()
C. Change the oplog size of the replica set member
--------------------------------------------------

Restart the Member
~~~~~~~~~~~~~~~~~~
To change the size, run the :dbcommand:`replSetResizeOplog` passing
the desired size in megabytes as the ``size`` parameter. The
specified size must be greater than ``990``, or 990 megabytes.

Stop the server. For example, from the :program:`mongo` shell, you can
issue the following:
The following operation changes the oplog size of the replica set
member to 16 gigabytes, or 16000 megabytes.

.. code-block:: javascript

use admin
db.shutdownServer()

Restart the :program:`mongod` as a member of the replica set on its
usual port. From the system prompt (**not** the :program:`mongo`
shell):

.. code-block:: sh

mongod --replSet rs0 --dbpath /srv/mongodb --bind_ip localhost,<ip address of the mongod host>

.. include:: /includes/warning-bind-ip-security-considerations.rst

The replica set member will recover and "catch up" before it is
eligible for election to primary.

Repeat Process for all Members that may become Primary
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Repeat this procedure for all members you want to change the size of
the oplog. Repeat the procedure for the primary as part of the
following step.

Change the Size of the Oplog on the Primary
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To finish the rolling maintenance operation, step down the primary with the
:method:`rs.stepDown()` method and repeat the oplog resizing procedure
above.
db.adminCommand({replSetResizeOplog: 1, size: 16000})