Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Next Generation MongoDB with Spring: Sessions, ...

Next Generation MongoDB with Spring: Sessions, Streams, Transactions (WJax-2018)

Christoph Strobl

November 07, 2018
Tweet

More Decks by Christoph Strobl

Other Decks in Programming

Transcript

  1. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Next Generation MongoDB Christoph Strobl Software Engineer, Spring Data Sessions - Streams - Transactions
  2. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Christoph Strobl Fantasy Book Addict Workout Enthusiast Next Generation MongoDB Sessions - Streams - Transactions image: https://wall.alphacoders.com/
 License: PD
  3. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ image: https://wall.alphacoders.com/
 License: PD
  4. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD 10,30 € incl. VAT
 Shipping information 5 $ http GET :8080/book/f430cb49 HTTP/1.1 200 OK Content-Length: 177 Content-Type: application/json;charset=UTF-8 { "authors": [ "Peter V. Brett" ], "id": "f430cb49", "language": "English", "pages": 880, "publishDate": "2017-28-09", "publisherId": "Harper Collins Publishers", "stock": 3, "title": "The Core" }
  5. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD Cart Cart Register Shipping Payment Confirmation 3 copies available The Core 6 only 2 more copies available { _id: "f430cb49", title: "The Core", author: [ "Peter V. Brett" ], published_date: ISODate("2017-09-28"), pages: 880, language: "English", publisher_id: "Harper Collins", available: 2 checkout : [ {by : "cstrobl", date : "2018- ] } $ http POST :8080/book/f430cb49/order HTTP/1.1 200 OK Content-Length: 267 Content-Type: application/json;charset=UTF-8 { "books": [ { "authors": [ "Peter V. Brett" ], "id": "f430cb49", "language": "English", "pages": 880, "publishDate": "2017-28-09", "publisherId": "Harper Collins Publishers", "title": "The Core" } ], "customer": "cstrobl", "date": "2018-09-04" }
  6. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD Cart Cart Register Shipping Payment Confirmation 3 copies available The Core $ http POST :8080/book/f430cb49/order HTTP/1.1 200 OK Content-Length: 267 Content-Type: application/json;charset=UTF-8 { "books": [ { "authors": [ "Peter V. Brett" ], "id": "f430cb49", "language": "English", "pages": 880, "publishDate": "2017-28-09", "publisherId": "Harper Collins Publishers", "title": "The Core" } ], "customer": "cstrobl", "date": "2018-09-04" } 7 only 2 more copies available { "_id" : "5b8ee10e", "by" : "cstrobl", "date" : ISODate("2018-09-04"), "books" : [ { "$ref" : "books", "$id" : "f430cb49" } ] } { _id: "f430cb49", title: "The Core", author: [ "Peter V. Brett" ], published_date: ISODate("2017-09-28"), pages: 880, language: "English", publisher_id: "Harper Collins", available: 2 }
  7. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Multi Document Transactions image: http://www.intestasuimotori.it
 License: CC
  8. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD Requirements 9 // start transaction // update first collection // query second collection // update third collection // commit transaction • ACID • Conversational, multi-statement
  9. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD How To Get From There to Here 10 Wired Tiger MVCC 3.0 - 3.4
  10. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD How To Get From There to Here 11 Logical Sessions 3.6 Retryable Writes
  11. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD How To Get From There to Here 12 update : { lsid : 1, txnNum : 1}, updates: […] update : { lsid : 1, txnNum : 1}, updates: […] { ok : 1} Retryable Writes IO Exception
  12. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD How To Get From There to Here 13 Replica Set Transactions Sharded Cluster Transactions 4.0 4.2 (under development)
  13. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://github.com/christophstrobl/mongodb-bookstore image: https://wall.alphacoders.com/
 License: PD
  14. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD Known issues… 15 try(ClientSession session = client.startSession()) { session.startTransaction(); Long result = collection.count(session, Filters.gt("available", 0)); Bson nearSphereFilter = Filters.nearSphere("location", new Point(
 new Position(-73.99D, 40.73D)), 0.313D); Long result = collection.countDocuments(nearSphereFilter); Cannot run 'count' in a multi-document 
 transaction. Error 50851 '$geoNear, $near, and $nearSphere
 are not allowed in this context' Error 2 Long result = collection.countDocuments(session, Filters.gt("available", 0)); Bson nearSphereFilter = Filters.geoWithinCenterSphere("location", -73.99D, 40.73D, 0.313D); Long result = collection.countDocuments(nearSphereFilter);
  15. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD Reactive Multi Document Transactions 16 return mongoOperations.inTransaction().execute(action "-> { return action.save(order) .flatMap(order "-> { return action.update(Book.class) .matching(query( where("id").is(book.id) .and("available").gt(0))) .apply(new Update().inc("available", -1)).first() .flatMap(result "-> { if (result.getModifiedCount() "== 0) { throw new BookSoldOutException(book); } return Mono.just(order); }); }); }).next(); Flux.usingWhen(() "-> session, ClientSession"::commitTransaction, ClientSession"::abortTransaction, session "-> … ) @Transactional public Mono insertDocuments() @Deprecated public ReactiveSessionScoped inTransaction()
  16. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
 License: PD Summary & Outlook 17 Transactions are multi-document, multi-collection, conversational. They fit in well to existing Spring transaction paradigms.

  17. > Stay Connected. MongoDB 4.0 & SpringData Lovelace Releases are

    out now!
 Get started with Spring Boot 2.1.M4. https://www.mongodb.com/transactions http://projects.spring.io/spring-data-mongodb/
  18. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Safe Harbor Statement The following is intended to outline the general direction of Pivotal's offerings. It is intended for information purposes only and may not be incorporated into any contract. Any information regarding pre-release of Pivotal offerings, future updates or other planned modifications is subject to ongoing evaluation by Pivotal and is subject to change. This information is provided without warranty or any kind, express or implied, and is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions regarding Pivotal's offerings. These purchasing decisions should only be based on features currently available. The development, release, and timing of any features or functionality described for Pivotal's offerings in this presentation remain at the sole discretion of Pivotal. Pivotal has no obligation to update forward looking information in this presentation. 19