- Mastering MongoDB 3.x
- Alex Giamas
- 323字
- 2021-08-20 10:10:51
Read isolation and consistency
MongoDB read operations would be characterized as read uncommitted in a traditional RDBMS definition. What this means is that by default reads may get values that may not finally persist to the disk in the event, for example, of data loss or a replica set rollback operation.
In particular, when updating multiple documents with the default write behavior, lack of isolation may result in the following results:
- Reads may miss documents that were updated during the update operations
- Non-serializable operations
- Read operations are not point-in-time
These can be resolved by using the $isolated operator with a heavy performance penalty.
Queries with cursors that don't use .snapshot() may also in some cases get inconsistent results. This can happen if the query's result cursor fetches a document, this document receives an update while the query is still fetching results and because of insufficient padding, ends up in a different physical location on disk, ahead of the query's result cursor position. .snapshot() is a solution for this edge case, with the following limitations:
- It doesn't work with sharding
- It doesn't work with sort() or hint() to force an index to be used
- It still will not provide point-in-time read behavior
If our collection has mostly static data, we can use a unique index in the query field to simulate snapshot() and still be able to apply sort() to it.
All in all, we need to apply safeguards at the application level to make sure that we won't end up with unexpected results.
Starting from version 3.4, MongoDB offers a linearizable read concern. With linearizable read concern from a primary member of a replica set and a majority write concern, we can ensure that multiple threads can read and write a single document as if a single thread was performing these operations one after the other. This is considered a linearizable schedule in RDBMS and MongoDB calls it the real time order.
- Mastering VMware vSphere 6.5
- 腦動(dòng)力:PHP函數(shù)速查效率手冊(cè)
- Hands-On Data Science with SQL Server 2017
- 機(jī)器學(xué)習(xí)流水線實(shí)戰(zhàn)
- Java Web整合開發(fā)全程指南
- JavaScript典型應(yīng)用與最佳實(shí)踐
- 嵌入式操作系統(tǒng)
- 項(xiàng)目管理成功利器Project 2007全程解析
- Hadoop應(yīng)用開發(fā)基礎(chǔ)
- 智能生產(chǎn)線的重構(gòu)方法
- Godot Engine Game Development Projects
- Hands-On Data Warehousing with Azure Data Factory
- Learning Linux Shell Scripting
- 簡(jiǎn)明學(xué)中文版Photoshop
- 空間機(jī)器人智能感知技術(shù)