mongodb4.0事務特性(解讀)
mongodb4.0即將推出,最大的亮點莫過於,開始支援‘真正的’事務了。為什麼說是真正的呢?之前的行級別原子性,兩階段提交,要麼應用場景有限,要麼實現成本太高,有點‘雞肋’。
大年三十的時候,mongodb的CTO兼聯合創始人Eliot Horowitz就發文給大家介紹了mongodb4.0的事務特性,讓我們一起看一下吧!
有興趣的可以去官網檢視英文版,https://www.mongodb.com/blog/post/multi-document-transactions-in-mongodb,這裡只是解讀,不是翻譯。
MongoDB 4.0 will add support for multi-documenttransactions, making it the only database to combine the speed, flexibility,and power of the document model with ACID data integrity guarantees. Throughsnapshot isolation, transactions provide a globally consistent view of data,and enforce all-or-nothing execution to maintain data integrity.
多文件事務:可以理解為多行,以前都是單行級別的原子性。
目標:高速、靈活、以及基於文件模型的事務支援
事務:通過快照實現、全域性一致性,由此可鑑,應該是全域性鎖,效能不會太高
Transactions in MongoDB will feel just liketransactions developers are familiar with from relational databases. They willbe multi-statement, with similar syntax (e.g. start_transaction andcommit_transaction), making them familiar to anyone with prior transactionexperience. The changes to MongoDB that enable multi-document transactions willnot impact performance for workloads that do not require them. In MongoDB 4.0,which will be released this summer*, transactions will work across a singlereplica set, and MongoDB 4.2* will support transactions across a shardeddeployment.
事務可執行範圍:4.0是副本集(難道可以跨庫嗎?really?),4.2是叢集
Because documents can bring together relateddata that would otherwise be modeled across separate parent-child tables in arelational schema, MongoDB’s atomic single-document operations already providetransaction semantics that meet the data integrity needs of the majority ofapplications. But multi-document transactions will make it easier than ever fordevelopers to address a complete range of use-cases, while for many, simplyknowing that they are available will provide critical peace of mind. WithMongoDB 4.0, you’ll be able to rely on transactional integrity, regardless ofhow you model your data.
之前的版本,若要實現事務,可以將事務關聯的資料放在一行,利用mongodb對每行操作的原子性來實現事務,當然這種實現應用場景有限。另外,可以通過程式碼中控制,使用mongodb所謂的‘兩階段提交’,來實現事務,但也夠麻煩的,且事務中邏輯若複雜些,就極其考驗開發者的技能了。mongodb4.0目標就是彌補上述的不足,讓你可以像操作sql型資料庫中事務一樣來操作mongodb的事務。
The imminent arrival of transactions is theculmination of a multi-year engineering effort, beginning over 3 years ago withthe integration of the WiredTiger storage engine. We’ve laid the groundwork inalmost every part of the server – from the storage layer itself, to thereplication consensus protocol, to the sharding architecture. We’ve built outfine-grained consistency and durability guarantees, introduced a global logicalclock, refactored cluster metadata management, and more. We’ve also exposed allof these enhancements through APIs that are fully consumable by our drivers.We’re now about 85% of the way through the backlog of features that enabletransactions, as this diagram summarizes:
介紹了事務的起源,為了事務功能所做的努力,團隊目標以及進展。看來當年收購WiredTiger是預謀已久(沒有任何偏見,我也希望mongodb越來越強大、好用),也足以見得,mongodb早已計劃在sql型資料庫的天下分一杯羹,且大有吞併之勢!走別人的路,讓別人無路可走,哈哈。
但是,mongodb既要實現事務,又要兼顧高效能、靈活的屬性,還有很長一段路要走。而且,當今的老大Oracle也並非資料庫界的諾基亞,也將支援json格式的資料。看來sql和nosql以後的界限就沒有那麼明顯了,兩者的合併將是大勢所趨。