Mongodb write concern: all replica members dynamically?

Is it possible to set WriteConcern to something like everything, which means that the insert / update will be returned only when all members of the replica “are currently functioning” (at the time of the operation) confirm the operation?

As

  • the majority option leaves some unaccounted members.
  • if we specify a numerical value, the insert / update may pause indefinitely if we set WriteConcern as the "total number of participants" and any members of the replica will do for some reason.
  • if we use a set of tags, as indicated in the official docs, we still need to specify a numerical value for each tag, and if we specify a numerical value as the total number of members, and any member is omitted, the result will be the same as the Second point.

What do we mean if there is a parameter for WriteConcern , which is dynamically the total number of replica members during insert / update.

Thanks in advance!

+6
source share
1 answer

Is it possible to set WriteConcern to something like everything, which means that the insert / update will be returned only when all members of the replica are “currently operational” (at the time of the operation) confirm the operation?

There is a logical contradiction in the assumption that your use case requires strong consistency, unless it is not possible. The expected scenarios, such as lagging in replication, maintenance or failure (and subsequent recovery), when one or more of your replica sets can be online, but lag behind the current primary.

If your use case requires strong consistency, you should always read from the primary, not secondary, and use the mass / replica _safe issue for writing to ensure sufficient data replication to ensure high availability in the event of a failure.

By default, read preference is a direct reading of the primary information for consistency. Secondary copies of MongoDB replica sets are typically designed to support high availability rather than reading scaling (with a few exceptions, for example, for distribution across multiple data centers). For a more detailed explanation, see: Can I use more replica nodes to scale? .

the majority option leaves some unaccounted members.

Most of the recording concerts coincide with the majority needed to select the primary one in case of choosing a replica. The replica set of election mechanics includes ensuring that the new primary level is updated with the most recent operation available in the replica set (nodes that run in the election).

if we specify a numerical value, the insert / update can pause indefinitely if we set WriteConcern as the "total number of members" and any members of the replicas will do for some reason.

This is the expected default behavior, however there is a wtimeout option that sets a time limit (in milliseconds), so write will not block indefinitely waiting for confirmation to be confirmed.

Reservations regarding the use of timeouts are very important and provide even less confidence in the results:

wtimeout causes write operations to return an error after the specified limit, even if the requested write problem ultimately succeeds. When these write operations return, MongoDB does not roll back successful data changes made before the write problem exceeded the wtimeout limit.

The recording wait timeout is not directly related to the current health of the members of the replica set (that is, whether they are online or offline and may be able to confirm the problem with the recording) or the end result is just a hard stop on how long your application will wait response before return.

if we use a set of tags, as indicated in the official docs, we still need to specify a numerical value for each tag, and if we specify a numerical value as the total number of members and any member goes down, the result will be the same as the 2nd item.

Right.

+5
source

Source: https://habr.com/ru/post/986366/


All Articles