Production Considerations (Sharded Clusters)生产注意事项(分片集群)
On this page本页内容
Starting in version 4.2, MongoDB provides the ability to perform multi-document transactions for sharded clusters.从4.2版本开始,MongoDB提供了为分片集群执行多文档事务的能力。
The following page lists concerns specific to running transactions on a sharded cluster. 下一页列出了特定于在分片集群上运行事务的关注。These concerns are in addition to those listed in Production Considerations.这些关注是生产注意事项中列出的关注之外的关注。
Sharded Transactions and MongoDB Drivers分片事务和MongoDB驱动程序
For transactions on MongoDB 4.2 deployments (replica sets and sharded clusters)对于MongoDB 4.2部署上的事务(副本集和分片集群), clients must use MongoDB drivers updated for MongoDB 4.2.,客户端必须使用为MongoDB 4.2更新的MongoDB驱动程序。
On sharded clusters with multiple 在具有多个mongos
instances, performing transactions with drivers updated for MongoDB 4.0 (instead of MongoDB 4.2) will fail and can result in errors, including:mongos
实例的分片集群上,使用为MongoDB 4.0(而不是MongoDB 4.2)更新的驱动程序执行事务将失败,并可能导致错误,包括:
Your driver may return a different error. Refer to your driver's documentation for details.您的驱动程序可能会返回不同的错误。有关详细信息,请参阅您的驾驶员文档。
251 | cannot continue txnId -1 for session ... with txnId 1 |
50940 | cannot commit with no participants |
Performance性能
Single Shard单个分片
Transactions that target a single shard should have the same performance as replica-set transactions.以单个分片为目标的事务应该具有与副本集事务相同的性能。
Multiple Shards多个分片
Transactions that affect multiple shards incur a greater performance cost.影响多个分片的事务会产生更大的性能成本。
On a sharded cluster, transactions that span multiple shards will error and abort if any involved shard contains an arbiter.在分片集群上,如果任何涉及的分片包含仲裁器,则跨多个分片的事务将出错并中止。
Time Limit时间限制
To specify a time limit, specify a 要指定时间限制,请在maxTimeMS
limit on commitTransaction
.commitTransaction
上指定maxTimeMS
限制。
If 如果未指定maxTimeMS
is unspecified, MongoDB will use the transactionLifetimeLimitSeconds
.maxTimeMS
,MongoDB将使用transactionLifetimeLimitSeconds
。
If 如果指定了maxTimeMS
is specified but would result in transaction that exceeds transactionLifetimeLimitSeconds
, MongoDB will use the transactionLifetimeLimitSeconds
.maxTimeMS
,但会导致事务超过transactionLifetimeLimitSeconds
,MongoDB将使用transactionLifetimeLimitSeconds
。
To modify 要修改分片集群的transactionLifetimeLimitSeconds
for a sharded cluster, the parameter must be modified for all shard replica set members.transactionLifetimeLimitSeconds
,必须修改所有分片副本集成员的参数。
Read Concerns读取关注
Multi-document transactions support 多文档事务支持"local"
, "majority"
, and "snapshot"
read concern levels."local"
、"majority"
和"snapshot"
读取关注级别。
For transactions on a sharded cluster, only the 对于分片集群上的事务,只有"snapshot"
read concern provides a consistent snapshot across multiple shards."snapshot"
读取关注点在多个分片之间提供一致的快照。
For more information on read concern and transactions, see Transactions and Read Concern.有关读取问题和事务的更多信息,请参阅事务和读取问题。
Write Concerns写入关注
You cannot run transactions on a sharded cluster that has a shard with 您不能在具有writeConcernMajorityJournalDefault
set to false
(such as a shard with a voting member that uses the in-memory storage engine).writeConcernMajorityJournalDefault
设置为false
的分片(例如具有使用内存存储引擎的投票成员的分片)的分片集群上运行事务。
Regardless of the write concern specified for the transaction, the commit operation for a sharded cluster transaction includes some parts that use 不管为事务指定的写入关注是什么,分片集群事务的提交操作都包括一些使用{w: "majority", j: true}
write concern.{w: "majority", j: true}
写入关注的部分。
Arbiters仲裁器
Transactions whose write operations span multiple shards will error and abort if any transaction operation reads from or writes to a shard that contains an arbiter.如果任何事务操作从包含仲裁器的分片中读取或写入,则写入操作跨多个分片的事务将出错并中止。
Backups and Restores备份和恢复
mongodump
and 和mongorestore
cannot be part of a backup strategy for 4.2+ sharded clusters that have sharded transactions in progress, as backups created with 对于正在进行分片事务的4.2+分片集群,不能作为备份策略的一部分,因为使用mongodump
do not maintain the atomicity guarantees of transactions across shards.mongodump
创建的备份不能维护跨分片的事务的原子性保证。
For 4.2+ sharded clusters with in-progress sharded transactions, use one of the following coordinated backup and restore processes which do maintain the atomicity guarantees of transactions across shards:对于具有正在进行的分片事务的4.2多个分片集群,请使用以下协调的备份和恢复过程之一,这些过程确实维护了跨分片的事务的原子性保证:
Chunk Migrations区块迁移
Chunk migration区块迁移 acquires exclusive collection locks during certain stages.在某些阶段获取独占集合锁。
If an ongoing transaction has a lock on a collection and a chunk migration that involves that collection starts, these migration stages must wait for the transaction to release the locks on the collection, thereby impacting the performance of chunk migrations.如果正在进行的事务对集合具有锁定,并且涉及该集合的块迁移开始,则这些迁移阶段必须等待事务释放对集合的锁定,从而影响块迁移的性能。
If a chunk migration interleaves with a transaction (for instance, if a transaction starts while a chunk migration is already in progress and the migration completes before the transaction takes a lock on the collection), the transaction errors during the commit and aborts.如果区块迁移与事务交错(例如,如果事务在区块迁移已经进行时开始,并且迁移在事务锁定集合之前完成),则事务在提交期间出错并中止。
Depending on how the two operations interleave, some sample errors include (the error messages have been abbreviated):根据两个操作的交错方式,一些示例错误包括(错误消息已缩写):
an error from cluster data placement change ... migration commit in progress for <namespace>
Cannot find shardId the chunk belonged to at cluster time ...
See also: 另请参阅:
Outside Reads During Commit提交期间的外部读取
During the commit for a transaction, outside read operations may try to read the same documents that will be modified by the transaction. 在事务的提交过程中,外部读取操作可能会尝试读取将由事务修改的相同文档。If the transaction writes to multiple shards, then during the commit attempt across the shards如果事务写入多个分片,那么在跨分片的提交尝试期间
Outside reads that use read concern使用读问题"snapshot"
or"linearizable"
, or are part of causally consistent sessions (i.e. include afterClusterTime) wait for all writes of a transaction to be visible."snapshot"
或"linearizable"
的外部读取,或者是因果一致会话的一部分(即,包括afterClusterTime
),等待事务的所有写入可见。Outside reads using other read concerns do not wait for all writes of a transaction to be visible but instead read the before-transaction version of the documents available.使用其他读取关注点的外部读取不会等待事务的所有写入都可见,而是读取可用文档的事务前版本。
See also: 另请参阅:
Additional Information附加信息
See also Production Considerations.另请参阅生产注意事项。