In "mongodb distributed read/write operations (1)", we talked about distributed read operations. This section describes distributed write operations. 1. Distributed write operations 1.1 sharded cluster write operations for sharded cluster shard sets, mongos directly specifies the write operations of the application to the specified shard. Mongos from config? Server uses the cluster metadata to route write operations to the appropriate
In "mongodb distributed read/write operations (1)", we talked about distributed read operations. This section describes distributed write operations. 1. Distributed write operations 1.1 sharded cluster write operations for sharded cluster shard sets, mongos directly specifies the write operations of the application to the specified shard. Mongos from config? Server uses the cluster metadata to route write operations to the appropriate
In "mongodb distributed read/write operations (1)", we talked about distributed read operations. This section describes distributed write operations. 1. Distributed write operations 1.1 sharded cluster write operations for sharded cluster shard sets, mongos directly specifies the write operations of the application to the specified shard. Mongos from config? Server uses the cluster metadata to route write operations to appropriate shards. Partition data based on the partition key. Then, MongoDB will partition these blocks to the partition ,? The partition key determines the Partition Distribution. This may affect the cluster write operation performance. Note: updates that affect a single document must include the partition key or the _ id field. The update operation of multiple documents is affected ,?? In some cases, it is more effective. If a partition key exists, it can be broadcast to all shards. If the partition key value increases or each insert operation decreases, all the insert operations target a single partition. Therefore, a single shard capacity restricts the insertion capability of the shard cluster. 1.2 replica set write operations are performed under the replica set, and all write operations are performed on the primary node. All write operations are recorded in the oplog. Oplog is a reproducible sequence of a dataset. The secondary node constantly copies and applies the oplog. This process is asynchronous. A large number of write operations, especially batch operations, may create a problem. It is difficult for secondary nodes to copy and apply oplog from the primary node, resulting in secondary nodes falling behind the primary node. When secondary lags behind primary significantly, it is a problem for normal replica sets, especially in case of failover, data needs to be rolled back to achieve data consistency. To avoid this problem, you can customize the write concern to confirm writing to another node. This provides an opportunity for secondary to catch up with primary .? Write concern can slow down the overall progress of write operations, but it ensures that the current status of the secondary node is roughly the same as that of the primary node. Set the write concern level to w: 2 to ensure that the data is written to the primary node and at least one secondary node.
Original article address: mongodb distributed read/write operations (2). Thank you for sharing it.