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 ...
随机推荐
- spoj687(后缀数组)
http://www.spoj.com/problems/REPEATS/ 题意:给一串字符,需要你求这一串字符中有连续重复的字符的重复次数....... 思路:这是和poj3693一种类型的题目.. ...
- ADO.NET数据库应用开发_ExtendedProperties属性
7.5.5 ExtendedProperties属性 ExtendedProperties属性用来获取存储自定义属性的集合.可以在该属性中增加附加的存储信息.它的扩展属性必须是字符串类型.当以XML的 ...
- 数据库事务隔离级别<转>
数据库事务的隔离级别有4个,由低到高依次为Read uncommitted.Read committed.Repeatable read.Serializable,这四个级别可以逐个解决脏读.不可重复 ...
- Sys未定义处理方法
网上很多方法都试过,但是我发现,如果我把iis的端口号换一下,然后重新部署,就正常了,然后你可以再换回原来的端口号,也不会再报错了,应该是微软的一个bug,不知道大伙有什么更好的办法么
- Virtual Box下安装Oracle Linux 6.3
Oracle Linux 6.3已经公布快2年了,其功能有非常大的提升,增强了KVM,文件卷的在线resizing,LVM支持 raid4, 5, 6.支持很多其它的虚拟CPU数以及更大内存,详细能够 ...
- wifi的web 认证。
wifi的web 认证.wifidog+authpuppy+php 或者Wiwiz Auth API
- json 转 T
T test = JsonConvert.DeserializeObject<T>(json);(json.net)
- js后台常用树形菜单
来源:http://www.sucaihuo.com/js/1093.html demo: http://www.sucaihuo.com/jquery/10/1093/demo/
- 3D分子构型该怎么优化
很多的化学领域的专业人士都知道,分子的性质往往是有分子的结构所决定的,但是在实验室研究的过程中很难观察到稳定分子的结构,这往往是因为中间体寿命过短或者是混合物难以分离造成的,这个时候就需要通过计算化学 ...
- 1-1、superset开发环境搭建
在对superset进行二次开发的过程中,往往需要搭建本地开发环境,修改后立即看到效果,下面我们就讲下开发环境的搭建. 1.打开PyCharm,在菜单栏上执行VCS-->Checkout fro ...