Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

MongoDB World 2019: Distributed Transactions: With Great Power Comes Great Responsibility

419 Aufrufe

Veröffentlicht am

A year ago we launched replica-set transactions in MongoDB 4.0. We've now expanded transactions to span across shards, making development against MongoDB even easier. Snapshot isolation, write atomicity, distributed commit – we'll touch on it all. You'll learn all you need to know about distributed transactions before you push to prod.

Veröffentlicht in: Technologie
  • Als Erste(r) kommentieren

  • Gehören Sie zu den Ersten, denen das gefällt!

MongoDB World 2019: Distributed Transactions: With Great Power Comes Great Responsibility

  1. 1. Alyson Cabral, Product Manager Distributed Transactions: with Great Power Comes Great Responsibility aly_cabral
  2. 2. I know what you’re thinking…
  3. 3. But, Really… MongoDB Transactions are ACID Compliant (yes, even across shards)
  4. 4. Transactions make application development easier • Don’t need to worry about interim states • Either a customer is signed-up or they are not • Rollback/Abort is handled automatically if any single statement fails • Point-in-time consistency across reads/writes
  5. 5. def insertDocuments(s): s.client.db.col.insert_one({'abc': 1}, session=s) s.client.db.col.insert_one({'xyz': 999}, session=s) with client.start_session() as s: s.with_transaction(insertDocuments); New API in MongoDB 4.2! New in MongoDB 4.2 -- Cross Shard Transactions
  6. 6. Transactions Guarantees
  7. 7. Multi- Collection Database Statement Document Shard
  8. 8. All or Nothing Execution TXN Application MongoDB Uncommitted Writes { Document 1 } { Document 2 } { Document 3 } Committed Writes
  9. 9. Snapshot Isolation 100 101 102 103 104 105 106 107 108 109 110 111 Snapshot 102 Snapshot 108
  10. 10. Read Your Own Writes Operation Read TXN {_id: “OWNER12345”, name: { first: “Aly”, last: “Cabral”}, accountType: “Paid”, pets: [ { type: “Dog”, name: “Lady”}], contact: { phoneNumber: 8008675309}, Address: { city: “New York”, street: “94th”, zipecode: 10025}} Uncommitted Writes street: “92nd” Address.street = 94th Address.street = 92nd
  11. 11. Transactions Guidelines
  12. 12. 1) All data modeling rules still apply 2) Transactions should not be the most common operation (sanity check for rule 1) 3) Pass in the session to all statements 4) Implement retry logic, transactions can always abort 5) Don’t unnecessarily leave snapshots open 6) To trigger write conflicts, make sure you’re doing writes 7) Plan for DDL Operations
  13. 13. Distributed Transactions Workflow
  14. 14. Majority Writes ------------ What promises do majority writes give you? No Arbiters!
  15. 15. Participant any shard that executes operations on behalf of a given transaction Coordinator A single shard that is responsible for coordinating the commit across shards for a given transaction
  16. 16. P S S S P S Query Router Insert {_id : “abc”}Insert {_id : “xyz”} Coordinator! Commit transaction Show that the commit happens across all replicas
  17. 17. “ We see at least 2x performance improvement when running MongoDB transactions vs logic on our own, in- app” Imagine a world without transactions
  18. 18. Even better perf results Collocate your data
  19. 19. Even better perf results Write to a single shard
  20. 20. READ CONCERN = READ ISOLATION Options: LOCAL, MAJORITY, SNAPSHOT, LINEARIZABLE Fun Fact: ReadConcern: Majority does not need to coordinate across nodes to return results!
  21. 21. Read Concern: Snapshot P S S P S S P S S time: 102 Majority or Local time: 102 time: 110 time: 104
  22. 22. Snapshot Isolation is expensive All shards need to coordinate the time The same snapshot is used throughout the duration of the transaction Even once a snapshot time is selected, some shards may not have that time
  23. 23. … … keys K K K KVV V V txn time data next Update Structure txn time data next WiredTiger Cache
  24. 24. More New Functionality in 4.2
  25. 25. Transactions Larger than 16MB { <statement 1>, <statement 2>, <statement 3>, <statement 4>} Prior to MongoDB 4.2:
  26. 26. This does not mean you can have infinitely large transactions -- WT still has to maintain the history since the snapshot time Transactions automatically abort after 60 seconds – TUNABLE. transactionLifetimeLimitSeconds
  27. 27. Mutable Shard Key Values Tiered storage: Aging out older documents to low cost storage shard Global-redistribution: Rehoming documents to a new region
  28. 28. Use MongoDB 4.2 drivers Transactions targeting a single shard will be faster than those spanning multiple shards Best practice: No more than 1,000 documents modified in a single transaction No arbiters Chunk migrations will block behind running transactions
  29. 29. MONGODB4DOT2
  30. 30. • Free ▪ Online ▪ 9 Chapters • Register Now! - https://university.mongodb.com/courses/M042/about

×