22.Atomicity and Transactions-官方文档摘录
原子性和事务
1 在单个文档修改多个嵌入文档,写操作都在文档级别上都是原子的
2 在单个写操作修改多个文档时,每个文档的修改都具有原子性,但是,作为一个整体的操作,并不是原子的。其他操作可能有交互。使用$isolated操作符隔离单个写操作,可以影响多个文档
3 使用$isolated操作符,影响多个文档的写操作可以防止其他进程对其在修改操作过程中进行交互,在这样就确保了在写操作完成或者发生错误之前,没有客户端能看到这些更改
4 $isolated在分片集群中不支持
5 $isolated并不会有全有或者全无的概念,也就是说当你异常发生之时,之前的操作并不具有回滚的特性
6 $isolated会对集合有一个独占锁的操作,即使是像wiredTiger这种文档级锁定存储引擎也是一样,也就是说,在操作期间,$isolated使wiredTiger单线程化了
7 单个文档可以包含多个嵌入式文档,单文档的原子性在多个实际用例中已经足够,对于一个写操作序列则必须像在单个事务中那样操作的情况,你可以在用用程序中使用二阶段提交
In MongoDB, a write operation is atomic on the level of a single document, even if the operation modifies multiple embedded documents within a single document.
When a single write operation modifies multiple documents, the modification of each document is atomic, but the operation as a whole is not atomic and other operations may interleave. However, you can isolate a single write operation that affects multiple documents using the $isolated
operator.
$isolated
Operator
Using the $isolated
operator, a write operation that affects multiple documents can prevent other processes from interleaving once the write operation modifies the first document. This ensures that no client sees the changes until the write operation completes or errors out.
$isolated
does not work with sharded clusters.
An isolated write operation does not provide “all-or-nothing” atomicity. That is, an error during the write operation does not roll back all its changes that preceded the error.
NOTE
$isolated
operator causes write operations to acquire an exclusive lock on the collection, even for document-level locking storage engines such as WiredTiger. That is, $isolated
operator will make WiredTiger single-threaded for the duration of the operation.
For an example of an update operation that uses the $isolated
operator, see $isolated
. For an example of a remove operation that uses the $isolated
operator, see Isolate Remove Operations.
Transaction-Like Semantics
Since a single document can contain multiple embedded documents, single-document atomicity is sufficient for many practical use cases. For cases where a sequence of write operations must operate as if in a single transaction, you can implement a two-phase commit in your application.
However, two-phase commits can only offer transaction-like semantics. Using two-phase commit ensures data consistency, but it is possible for applications to return intermediate data during the two-phase commit or rollback.
For more information on two-phase commit and rollback, see Perform Two Phase Commits.
Concurrency Control
Concurrency control allows multiple applications to run concurrently without causing data inconsistency or conflicts.
One approach is to create a unique index on a field that can only have unique values. This prevents insertions or updates from creating duplicate data. Create a unique index on multiple fields to force uniqueness on that combination of field values. For examples of use cases, see update() and Unique Index and findAndModify() and Unique Index.
Another approach is to specify the expected current value of a field in the query predicate for the write operations. The two-phase commit pattern provides a variation where the query predicate includes theapplication identifier as well as the expected state of the data in the write operation.
22.Atomicity and Transactions-官方文档摘录的更多相关文章
- Cocos Creator 加载和切换场景(官方文档摘录)
Cocos Creator 加载和切换场景(官方文档摘录) 在 Cocos Creator 中,我们使用场景文件名( 可以不包含扩展名)来索引指代场景.并通过以下接口进行加载和切换操作: cc.dir ...
- ng的概念层次(官方文档摘录)
官方文档是这么说的: You write Angular applications by: composing HTML templates with Angularized markup, writ ...
- Cocos Creator 使用计时器(官方文档摘录)
在 Cocos Creator 中,我们为组件提供了方便的计时器,这个计时器源自于 Cocos2d-x 中的 cc.Scheduler,我们将它保留在了 Cocos Creator 中并适配了基于组件 ...
- Cocos Creator 生命周期回调(官方文档摘录)
Cocos Creator 为组件脚本提供了生命周期的回调函数.用户通过定义特定的函数回调在特定的时期编写相关 脚本.目前提供给用户的声明周期回调函数有: onLoad start update la ...
- angular 模板语法(官方文档摘录)
https://angular.cn/guide/template-syntax {{}} 和"" 如果嵌套,{{}}里面求完值,""就是原意 <h3&g ...
- Qt元类型(MetaType)注册入门(附一些官方文档的关键摘录)
昨天调试项目时,突然发现如下消息: QObject::connect: Cannot queue arguments of type 'ERROR_LEVEL' (Make sure 'ERROR_L ...
- Kotlin开发语言文档(官方文档)-- 目录
开始阅读Kotlin官方文档.先上文档目录.有些内容还未阅读,有些目录标目翻译还需琢磨琢磨.后续再将具体内容的链接逐步加上. 文档链接:https://kotlinlang.org/docs/kotl ...
- Spring 4 官方文档学习(十一)Web MVC 框架之配置Spring MVC
内容列表: 启用MVC Java config 或 MVC XML namespace 修改已提供的配置 类型转换和格式化 校验 拦截器 内容协商 View Controllers View Reso ...
- Spring 4 官方文档学习(十一)Web MVC 框架之HTTP caching support
一个良好的HTTP缓存策略可以显著地增进web应用的性能和其客户端的体验.主要使用"Cache-Control" HTTP response header来完成,配合conditi ...
- Google Android官方文档进程与线程(Processes and Threads)翻译
android的多线程在开发中已经有使用过了,想再系统地学习一下,找到了android的官方文档,介绍进程与线程的介绍,试着翻译一下. 原文地址:http://developer.android.co ...
随机推荐
- floyd算法&迪杰斯特拉算法
; k<=n; k++) ; i<=n; i++) ; j<=n; j++) { gra[i][j]=min(gra[i][j],gra[i][k]+gra[k][j]); } vo ...
- Bootstrap学习笔记(2)--栅格系统深入学习
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 卖座网一处SQL注射(Http Referer sqlinjection)
漏洞作者: 猪猪侠 漏洞详情 披露状态: 2015-01-13: 细节已通知厂商并且等待厂商处理中2015-01-14: 厂商已经确认,细节仅向厂商公开2015-01-24: 细节向核心白帽子及相关领 ...
- boost准模板库内存管理中pool和object_pool的使用
首先,在敲代码之前,必须改动一个问题.要不然,无法链接: boost安装文件夹:D:\boost. 找到D:\boost\boost_1_55_0\include\boost-1_55\b ...
- Extjs GridPanel 中放入 Combox显示问题
http://weijun8611-126-com.iteye.com/blog/566201 在项目中使用了extjs的editorgridpanel,但是其中的combobox在选择了相应的选项后 ...
- TCP协议格式
TCP协议 协议格式 0 16 31 |16位源端口 | 16位目标端口| | 32位序号 | | 32位确认序号 | |4位首部长度|保留(6位)|URG|ACK|PSH|RST|SYN|FIN|1 ...
- mysql数据库 详解
一.学习目录 1.认识数据库和mysql 2.mysql连接 3.入门语句 4.详解列类型 5.增删改查 INSERT INTO 表名(列1,…… 列n) VALUES(值 1,…… 值 n) ...
- LVM简介
3. 创建VG.. 7 4. 创建LV.. 9 5.LV格式化及挂载... 10 一.LVM简介 LVM是 Logical Volume Manager(逻辑卷管理)的简写,它由Heinz Mauel ...
- tomcat上
1. Tomcat简介 Tomcat是一个web服务器 web服务器:httpd,nginx web 处理静态文件:html css.js.jpg,png Tomcat 处理 html文件 php软件 ...
- 时钟.html
<!DOCTYPE html><html charset="utf-8"> <head> <title>时钟</title&g ...