- 快召唤伙伴们来围观吧
- 微博 QQ QQ空间 贴吧
- 文档嵌入链接
- 复制
- 微信扫一扫分享
- 已成功复制到剪贴板
What's New in MongoDB 4.0
MongoDB4.0将事务属性从SQL世界带到了NoSQL世界。现在支持快照隔离、提交和回滚是MongoDB4.0最令人兴奋的特性之一。此外,MongoDB4.0还提供了一些有趣的增强功能,如更改流、sha-2身份验证和安全增强,以使用身份验证限制创建用户。
在本课程中,我们将介绍MongoDB 4.0上提供的新功能:
交易
安全增强和SHA-2身份验证
更改流并读取关注点
4.2 MMAP折旧
MongoDB移动数据库
展开查看详情
1 .What’s new in Mongo 4.0 Vinicius Grippa Percona
2 .About me • Support Engineer at Percona since 2017 Working with MySQL for over 5 years - Started with SQL Server • Working with databases for 7 years 2
3 .Agenda • Transactions Support • Snapshot Read Concern • Security enhancements • Non-Blocking Secondary Reads • Extension to Change Streams • Data type conversions • Improved Sharding Operations • Hybrid Cursor Caching • Slow Query Logging on MongoS • The Future Features 3
4 .A brief history • MongoDB was developed in 2007 by organization called 10gen • MongoDB has grown from being a niche database solution to the Swiss army knife of the NoSQL technologies • It was developed as a PAAS (Platform as a service) • Currently there is MongoDB Atlas Database as a Service (DBaaS) 4
5 .MongoDB Roadmap 5
6 .Agenda • Transactions Support • Snapshot Read Concern • Security enhancements • Non-Blocking Secondary Reads • Extension to Change Streams • Data type conversions • Improved Sharding Operations • Hybrid Cursor Caching • Slow Query Logging on MongoS • The Future Features 6
7 .Transactions Support
8 .Transactions Support • Transactions feature has been in development since MongoDB version 3.0 (Two Phase Commit) • Logical sessions added on Mongo 3.6 • MongoDB 4.0 adds support for multi-document transactions 8
9 .Transactions - ACID • Atomicity • Consistency • Isolation • Durability 9
10 .Transactions - ACID • Atomicity • "all or nothing" guarantee for multi-document transaction operations • Data changes are only made visible outside the transaction if it is successful. • If a transaction fails, all of the data changes from the transaction is discarded. 10
11 .Transactions - ACID • Consistency • Handled by MongoDB • example: trying to change a value that fails schema validation, will cause inconsistent data • (permitted transactions should not corrupt data) 11
12 .Transactions - ACID • Isolation Snapshot isolation level • … creates a WiredTiger snapshot at the beginning of the transaction • … uses this snapshot to provide transactional reads throughout the transaction. 12
13 .Transactions - ACID • Durability • When a transactions use WriteConcern {j: true} (default), MongoDB will guarantee that it is returned after the transaction log is committed. • Even if a crash occurs, MongoDB can recover according to the transaction log. • If the {j: true} level is not specified, even after the transaction is successfully committed, the transaction may be rolled back (in case of crash recovery) – Needs journal enabled 13
14 .Transactions Support • Start Transaction 1 session = db.getMongo().startSession() 2 3 session.startTransaction() 4 session.getDatabase("percona").test.insert({today : new Date()}) session.getDatabase("percona").test.insert({some_value : "abc"}) 14
15 .Transactions Support • Commit/Rollback Transaction 1 session.commitTransaction() 2 session.abortTransaction() 15
16 .Transactions and Replica set In the replica set configuration, an oplog will be recorded on commit • … including all the operations in the transaction. The slave node pulls the oplog and replays the transaction operations locally (the document size limit is 16 MB, so whole transaction can not exceed 16MB) 16
17 .Transactions and Wired Tiger Unified Transaction Timing WiredTiger has supported transactions for a long time • (guarantee the modification atomicity of data, index, and oplog) The problem was with timing: • MongoDB used the oplog timestamps to identify the global order • WiredTiger used the internal transaction IDs to identify the global order MongoDB version 4.0 / WiredTiger 3.0 introduced transaction timestamps • MongoDB can now explicitly assign a commit timestamp to the WiredTiger transaction (read "as of" a timestamp) • When the oplog is replayed, the read on the slave node will no longer conflict with the replayed oplog, and the read request will not be blocked by replaying the oplog. 17
18 .Transactions - Conflict foo:PRIMARY> session = db.getMongo().startSession() session { "id" : UUID("b312c662-247c-47c5-b0c9-23d77f4e9f6d") } foo:PRIMARY> session.startTransaction() foo:PRIMARY> session.getDatabase("percona").test.update({trx : 0}, {trx: 2}) WriteCommandError({ "errorLabels" : [ "TransientTransactionError" ], "operationTime" : Timestamp(1529675754, 1), "ok" : 0, "errmsg" : "WriteConflict", "code" : 112, "codeName" : "WriteConflict", "$clusterTime" : { "clusterTime" : Timestamp(1529675754, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), 18 "keyId" : NumberLong(0)
19 .Transactions – Write Concern MongoDB is a distributed database- be aware of the different options for consistency. Write concern describes the level of acknowledgement requested from MongoDB for write operations For multi-document transactions, you set the write concern at the transaction level, not at the individual operation level. Session.startTransaction({ writeConcern: { w: <level>} }) // w: 1, majority If you commit using "w: 1" write concern, your transaction can be rolled back during the failover process. 19
20 .Transactions – Read Concern The readConcern option allows you to control the consistency and isolation properties of the data read from replica sets and replica set shards. For multi-document transactions, you set the read concern at the transaction level, not at the individual operation level. If unspecified at the transaction start, transactions use the session-level read concern or, if that is unset, the client-level read concern. Session.startTransaction({ readConcern: { level: <level>} }) 20
21 .Transactions – Read Concern Read concern "snapshot" is only available for multi-document transactions. Multi-document transactions support read concern "snapshot" as well as "local", and "majority". Session.startTransaction({ readConcern: { level: "snapshot"} }) 21
22 .Agenda • Transactions Support • Snapshot Read Concern • Security enhancements • Non-Blocking Secondary Reads • Extension to Change Streams • Data type conversions • Improved Sharding Operations • Hybrid Cursor Caching • Slow Query Logging on MongoS • The Future Features 22
23 .Snapshot Read Concern
24 .Snapshot Read Concern • readConcern option helps in achieving consistency, and isolation properties of the data. Snapshot Read Concern ensures that a consistent view of the data is returned to the client, irrespective of whether that data is being simultaneously modified by concurrent operations. 24
25 .Snapshot Read Concern • If the transaction is not part of a causally consistent session, upon transaction commit with write concern "majority", the transaction operations are guaranteed to have read from a snapshot of majority-committed data. • If the transaction is part of a causally consistent session, upon transaction commit with write concern "majority", the transaction operations are guaranteed to have read from a snapshot of majority-committed data that provides causal consistency with the operation immediately preceding the transaction start. 25
26 .Agenda • Transactions Support • Snapshot Read Concern • Security enhancements • Non-Blocking Secondary Reads • Extension to Change Streams • Data type conversions • Improved Sharding Operations • Hybrid Cursor Caching • Slow Query Logging on MongoS • The Future Features 26
27 .Security Enhancements
28 .Security Enhancements SHA-2 Authentication With MongoDB 4.0, authentication has been updated to the latest SHA-2 family (SHA-256), providing a stronger alternative to SHA-1 28
29 .Security Enhancements – Mongo 3.6 authenticationRestrictions: [ { clientSource: ["<IP>" | "<CIDR range>", ...] serverAddress: ["<IP>" | "<CIDR range>", ...] }, 29