You can perform multi-document transactions on sharded clusters.您可以在分片集群上执行多文档事务。
The following page lists concerns specific to running transactions on a sharded cluster. These concerns are in addition to those listed in Production Considerations.下一页列出了在分片集群上运行事务所特有的问题。这些问题是生产注意事项中列出的问题之外的问题。一>
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.影响多个分片的事务会产生更大的性能成本。
Note
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的分片的分片集群上运行事务(例如具有使用内存存储引擎的投票成员的分片)。
Note
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仲裁者
You cannot change a shard key using a transaction if the replica set has an arbiter. Arbiters cannot participate in the data operations required for multi-shard transactions.如果副本集有仲裁器,则无法使用事务更改分片键。仲裁员不能参与多分片事务所需的数据操作。
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备份和恢复
Warning
To use 要使用mongodump and mongorestore as a backup strategy for sharded clusters, see Back Up a Self-Managed Sharded Cluster with a Database Dump.mongodump和mongorestore作为分片集群的备份策略,请参阅使用数据库转储备份自管理分片集群。
Sharded clusters can also use one of the following coordinated backup and restore processes, which maintain the atomicity guarantees of transactions across shards:分片集群还可以使用以下协调的备份和恢复过程之一,以维护跨分片事务的原子性保证:
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 ...
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"wait until all writes of a transaction are visible."snapshot"或"linearizable"的外部读取会等到事务的所有写入都可见。Outside reads that are part of causally consistent sessions (those that include afterClusterTime) wait until all writes of a transaction are visible.作为因果一致会话一部分的外部读取(包括afterClusterTime)会等待事务的所有写入可见。Outside reads using other read concerns do not wait until all writes of a transaction are visible, but instead read the before-transaction version of the documents.使用其他读取关注的外部读取不会等到事务的所有写入都可见,而是读取文档的事务前版本。
Additional Information附加信息
See also 另请参阅Production Considerations.生产注意事项。