@@ -105,24 +105,23 @@ configuration, which provides a component of "data center awareness."
105
105
Background
106
106
~~~~~~~~~~
107
107
108
- By default, applications direct queries (i.e. read operations) to the
108
+ By default, applications direct read operations to the
109
109
:term:`primary` member in a :term:`replica set`. When reading from the
110
- the primary, all read operations are :term:`strictly consistent
111
- <strict consistency>`. However, you can improve read performance and
110
+ the primary, all read operations reflect the latest version of the document.
111
+ However, you can improve read
112
112
throughput by distributing some or all reads to secondary members of
113
- the replica set as needed. While secondary reads are :term:`eventually
114
- consistent <eventual consistency>`, some applications may not require
115
- strict consistency.
113
+ the replica set as needed. While secondary reads may return stale data
114
+ this is acceptable for applications that do not require fully up to date data.
116
115
117
- Reads from secondaries are eventually consistent because MongoDB can
118
- not guarantee that secondary members will be consistent with the state
116
+ Reads from secondaries may be stale MongoDB can
117
+ not guarantee that secondary members will reflect the state
119
118
of the primary, which receives all incoming write operations. Do not
120
- allow secondary reads, unless you can accept eventual consistency for
121
- these operations .
119
+ allow secondary reads, unless your application can handle receiving
120
+ stale data .
122
121
123
- In many cases, your application will require the :term:`strict consistency`
124
- that primary reads provide. However, typically secondary reads are
125
- useful for:
122
+ In many cases, your application will require the most current document
123
+ that primary reads provide. However, the following use cases outline
124
+ several potetial use cases for other read preferences :
126
125
127
126
- running systems operations including backups and reports without
128
127
impacting the front-end application.
@@ -132,18 +131,14 @@ useful for:
132
131
than the primary or the rest of the set, you may see better
133
132
performance for that application if you use secondary reads.
134
133
135
- Secondary reads also provide graceful degradation in
136
- :ref:`failover <replica-set-failover>` situations. During failover, replica sets may take
137
- 10 seconds or more to elect a new primary. Because there is no primary,
138
- applications that can only read from primaries, with the
139
- :readmode:`primary` read preference mode, are unable to perform reads during this period.
140
- With read preference configured permit read from secondary
141
- members, as with the :readmode:`primaryPrefered` read preference mode, your
142
- application can continue read operations using the
143
- remaining secondary members.
134
+ - providing graceful degradation in :ref:`failover
135
+ <replica-set-failover>` situations, when a set can have *no* primary
136
+ for 10 seconds or more. If a set does not have a primary,
137
+ applications with :readmode:`primary` cannot perform reads. Use the
138
+ :readmode:`primaryPrefered` read preference in this situation.
144
139
145
140
MongoDB :term:`drivers <driver>` allow client applications to
146
- configure a :term:`read preference` on a per-connection or
141
+ configure a :term:`read preference` on a per-connection, per-collection or
147
142
per-operation basis. See the :func:`rs.slaveOk()` method for more
148
143
information about secondary read operations in the :program:`mongo`
149
144
shell, as well as the appropriate :ref:`driver` API documentation for
@@ -154,19 +149,19 @@ address read preference configuration and operations.
154
149
155
150
.. note::
156
151
157
- Read preference only affect which members of the set the application chooses
158
- to read from. Read preferences only affect the members of the replica
159
- set that the read operation uses, as well as the consistency of
160
- query results . Use appropriate :ref:`write concern
152
+ Read preferences affect how the application selects a member of the
153
+ replica set to use for read operations. As a result read
154
+ preferences dictate if the application will receive stale or
155
+ current data from MongoDB . Use appropriate :ref:`write concern
161
156
<replica-set-write-concern>` policies to ensure proper data
162
157
replication and constancy.
163
158
164
159
If read operations account for a large percentage of your
165
- application's traffic,distributing reads to secondary members may
166
- provide some performance improvement . However, in most cases
167
- :doc:`sharding </core/sharding>` will provide better support for
168
- larger scale operations, because shard clusters can distribute read
169
- and write operations across a group of machines.
160
+ application's traffic, distributing reads to secondary members may
161
+ improve read throughput . However, in most cases :doc:`sharding
162
+ </core/sharding>` will provide better support for larger scale
163
+ operations, because shard clusters can distribute read and write
164
+ operations across a group of machines.
170
165
171
166
.. index:: read preference; semantics
172
167
.. _replica-set-read-preference-semantics:
@@ -181,18 +176,18 @@ Read Preference Modes
181
176
All MongoDB drivers :doc:`drivers </applications/drivers>` support the
182
177
following read preference modes. These semantics make it possible to
183
178
specify read preference on a per-collection or per-operation
184
- basis. The member of the :term:`replica set` that the client read from
185
- can affect the consistency of the result set. See the :ref:`read
179
+ basis. The member of the :term:`replica set` that the client reads from
180
+ can affect how current or stale the result set is . See the :ref:`read
186
181
preference background <replica-set-read-preference-background>` and
187
182
:ref:`read preference behavior <replica-set-read-preference-behavior>`
188
183
for more information. Also see the :api:`documentation for your driver
189
184
<>` for specific read preference use. :program:`mongos` also supports
190
185
all read-preference modes in its connections to the replica sets that
191
186
provide each :term:`shard` in a :term:`shard cluster`.
192
187
193
- MongoDB drivers and :program:`mongos` all provide the five read
194
- preference modes, which are constants set in the driver itself. The
195
- exact name of the mode depends on driver implementation and the idioms
188
+ All MongoDB drivers provide five read
189
+ preference modes, which are constants set in the drivers
190
+ themselves. While the names are the same, the exact syntax depends the idioms
196
191
of the host language. In the :program:`mongo` shell, the
197
192
:func:`readPreference() <cursor.readPreference()>` cursor method
198
193
provides access to read preferences, which have the following names.
@@ -211,6 +206,9 @@ provides access to read preferences, which have the following names.
211
206
you specify a tag set with :readmode:`primary`, the driver will
212
207
produce an error.
213
208
209
+ The :readmode:`primary` mode sacrifices availability for
210
+ consistency, in terms of the :term:`CAP Theorm`.
211
+
214
212
.. readmode:: primaryPrefered
215
213
216
214
With the :readmode:`primaryPrefered` read preference mode,
@@ -225,6 +223,9 @@ provides access to read preferences, which have the following names.
225
223
tags. If there are no secondaries with tags that match the
226
224
specified tags, this read operation will produce an error.
227
225
226
+ The :readmode:`primaryPrefered` mode sacrifices consistency for
227
+ greater availability, in terms of the :term:`CAP Theorm`.
228
+
228
229
.. readmode:: secondary
229
230
230
231
With the :readmode:`secondary` read preference mode, operations
@@ -244,6 +245,9 @@ provides access to read preferences, which have the following names.
244
245
If there are no secondaries with tags that match the specified tag
245
246
set, this read operation will produce an error.
246
247
248
+ The :readmode:`secondary` mode sacrifices consistency for
249
+ greater availability, in terms of the :term:`CAP Theorm`.
250
+
247
251
.. readmode:: secondaryPrefered
248
252
249
253
With the :readmode:`secondaryPrefered`, operations will read from
@@ -259,6 +263,9 @@ provides access to read preferences, which have the following names.
259
263
If there are no secondaries with tags that match the specified tag
260
264
set, this read operation will produce an error.
261
265
266
+ The :readmode:`secondaryPrefered` mode sacrifices consistency for
267
+ greater availability, in terms of the :term:`CAP Theorm`.
268
+
262
269
.. readmode:: nearest
263
270
264
271
With the :readmode:`nearest`, the driver will read from the
@@ -270,7 +277,7 @@ provides access to read preferences, which have the following names.
270
277
secondaries.
271
278
272
279
Set this mode when you want minimize the effect of network latency
273
- on read operations.
280
+ on read operations without preference for current or stale data .
274
281
275
282
If you specify a :ref:`tag set <replica-set-read-preference-tag-sets>`,
276
283
the client will attempt to find a secondary members that match the
@@ -319,7 +326,9 @@ each of the following read preference modes:
319
326
- :readmode:`secondaryPrefered`
320
327
- :readmode:`nearest`
321
328
322
- See the documentation of each read preference mode for more
329
+ Tags only apply when :ref:`selecting <replica-set-read-preference-behavior-member-selection>`
330
+ a :term:`secondary` member of the set, *except* for the
331
+ :readmode:`nearest` mode. See the documentation of each read preference mode for more
323
332
information on the interaction of the read preference mode and tag
324
333
sets. All interfaces use the same :ref:`member selection logic
325
334
<replica-set-read-preference-behavior-member-selection>` to choose a
@@ -342,15 +351,15 @@ Auto-Retry
342
351
Connection between MongoDB drivers and :program:`mongod` instances in
343
352
a :term:`replica set` must balance two concerns:
344
353
345
- #. The client should attempt to maximize consistency and any
354
+ #. The client should attempt to prefer current results and any
346
355
connection should read from the same member of the replica set as
347
356
much as possible.
348
357
349
358
#. The client should minimize the amount of time that the database is
350
359
inaccessible as the result of a connection issue, networking
351
360
problem, or :term:`failover` in a replica set.
352
361
353
- As a result, MongoDB drivers, and :program:`mongos` will:
362
+ As a result, MongoDB drivers and :program:`mongos` will:
354
363
355
364
- reuse a connection to specific :program:`mongod` for as long as
356
365
possible after establishing a connection to that instance. This
@@ -443,8 +452,10 @@ For any operation that will target a member *other* than the
443
452
#. determine which of these suitable members is the closest to the
444
453
client in absolute terms.
445
454
446
- #. build a list of members that are, by default, within 15
447
- milliseconds of the "absolute nearest" member. [#acceptable-secondary-latency]_
455
+ .. defined fix
456
+
457
+ #. build a list of members that are within a defined ping distance (in
458
+ milliseconds) of the "absolute nearest" member. [#acceptable-secondary-latency]_
448
459
449
460
#. select a member to perform the read operation on from these hosts
450
461
at random.
@@ -461,7 +472,6 @@ for more information.
461
472
:option:`--localThreshold <mongos --localThreshold>` or
462
473
:setting:`localThreshold` runtime options to set this value.
463
474
464
-
465
475
.. index:: read preference; sharding
466
476
.. index:: read preference; mongos
467
477
.. _replica-set-read-preference-behavior-sharding:
@@ -475,12 +485,15 @@ Sharding and ``mongos``
475
485
:ref:`read preference mode semantics <replica-set-read-preference-modes>`.
476
486
477
487
In most :term:`shard clusters <shard cluster>`, a :term:`replica set`
478
- provides each shard, where read preferences are also
479
- applicable. Unlike simple replica sets, in shard clusters, all
480
- interactions with the shards pass from the clients to the
481
- :program:`mongos` instances that are actually connected to the set
482
- members. In these situations the :program:`mongos` is responsible for
483
- the actual application of the read preferences.
488
+ provides each shard, where read preferences are also applicable. Read
489
+ operations in a shard cluster, with regard to read preference, are
490
+ identical to unsharded replica sets.
491
+
492
+ Unlike simple replica sets, in shard clusters, all interactions with
493
+ the shards pass from the clients to the :program:`mongos` instances
494
+ that are actually connected to the set members. :program:`mongos` is
495
+ responsible for the application of the read preferences, which is
496
+ transparent to applications.
484
497
485
498
There are no configuration changes required for full support of read
486
499
preference modes in sharded environments, as long as the
0 commit comments