-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
replica-set-oplog.txt
152 lines (112 loc) · 4.85 KB
/
replica-set-oplog.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
.. _replica-set-oplog:
=================
Replica Set Oplog
=================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
The :term:`oplog` (operations log) is a special :term:`capped
collection` that keeps a rolling record of all operations that modify
the data stored in your databases. MongoDB applies database operations
on the :term:`primary` and then records the operations on the
primary's oplog. The :term:`secondary` members then copy and apply
these operations in an asynchronous process. All replica set members
contain a copy of the oplog, in the :data:`local.oplog.rs` collection,
which allows them to maintain the current state of the database.
To facilitate replication, all replica set members send heartbeats
(pings) to all other members. Any member can import oplog entries from
any other member.
Each operation in the oplog is :term:`idempotent`. That is, oplog
operations produce the same results whether applied once or multiple
times to the target dataset.
.. _replica-set-oplog-sizing:
Oplog Size
----------
When you start a replica set member for the first time, MongoDB creates
an oplog of a default size.
For Unix and Windows systems
The default oplog size depends on the storage engine:
.. list-table::
:widths: 30 30 20 20
:header-rows: 1
* - Storage Engine
- Default Oplog Size
- Lower Bound
- Upper Bound
* - :doc:`/core/inmemory`
- 5% of physical memory
- 50 MB
- 50 GB
* - :doc:`/core/wiredtiger`
- 5% of free disk space
- 990 MB
- 50 GB
* - :doc:`/core/mmapv1`
- 5% of free disk space
- 990 MB
- 50 GB
For 64-bit macOS systems
The default oplog size is 192 MB of either physical memory or free
disk space depending on the storage engine:
.. list-table::
:widths: 50 50
:header-rows: 1
* - Storage Engine
- Default Oplog Size
* - :doc:`/core/inmemory`
- 192 MB of physical memory
* - :doc:`/core/wiredtiger`
- 192 MB of free disk space
* - :doc:`/core/mmapv1`
- 192 MB of free disk space
In most cases, the default oplog size is sufficient. For example, if an
oplog is 5% of free disk space and fills up in 24 hours of operations, then
secondaries can stop copying entries from the oplog for up to 24 hours
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 :binary:`~bin.mongod` creates an oplog, you can specify its size
with the :setting:`~replication.oplogSizeMB` option. However, after you have started
a replica set member for the first time, you can only change the size
of the oplog using the :doc:`/tutorial/change-oplog-size` procedure.
Workloads that Might Require a Larger Oplog Size
------------------------------------------------
If you can predict your replica set's workload to resemble one of the
following patterns, then you might want to create an oplog that is
larger than the default. Conversely, if your application predominantly
performs reads with a minimal amount of write operations, a smaller oplog
may be sufficient.
The following workloads might require a larger oplog size.
Updates to Multiple Documents at Once
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The oplog must translate multi-updates into individual operations in
order to maintain :term:`idempotency <idempotent>`. This can use a great
deal of oplog space without a corresponding increase in data size or disk
use.
Deletions Equal the Same Amount of Data as Inserts
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you delete roughly the same amount of data as you insert, the
database will not grow significantly in disk use, but the size
of the operation log can be quite large.
Significant Number of In-Place Updates
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If a significant portion of the workload is updates that do not
increase the size of the documents, the database records a large number
of operations but does not change the quantity of data on disk.
Oplog Status
------------
To view oplog status, including the size and the time range of
operations, issue the :method:`rs.printReplicationInfo()` method. For
more information on oplog status, see
:ref:`replica-set-troubleshooting-check-oplog-size`.
Under various exceptional situations, updates to a :term:`secondary's
<secondary>` oplog might lag behind the desired performance time. Use
:method:`db.getReplicationInfo()` from a secondary member and the
:doc:`replication status </reference/method/db.getReplicationInfo>`
output to assess the current state of replication and determine if
there is any unintended replication delay.
See :ref:`Replication Lag <replica-set-replication-lag>` for more
information.