writing datomic in clojure
play

Writing Datomic in Clojure Rich Hickey Overview What is Datomic? - PowerPoint PPT Presentation

Writing Datomic in Clojure Rich Hickey Overview What is Datomic? Architecture Implementation - Clojure Applied Summary What is Datomic? A database A sound model of information, with time Provides database as a value


  1. Writing Datomic in Clojure Rich Hickey

  2. Overview • What is Datomic? • Architecture • Implementation - Clojure Applied • Summary

  3. What is Datomic? • A database • A sound model of information, with time • Provides database as a value to applications • Bring declarative programming to applications • Focus on reducing complexity

  4. Why Datomic? • Architecture • Data Model

  5. Architectures App App App App App App App App App App App App App App App App Server Server Queries Transactions Client-Server Client-Server Consistency Storage

  6. Architectures App App App App App App App App App App App App App App App App Server Server Server Server Queries Transactions Clustered Client-Server Clustered Client-Server Consistency Storage

  7. Architectures App App App App App App App App App App App App App App App App Server Server Server Server Server Server Queries Transactions Sharded Client-Server Sharded Client-Server Consistency Storage

  8. Architectures App App App App App App App App App App App App App App App App Server Server Server Server Server Server Queries Queries Transactions Transactions Sharded Client-Server Sharded Client-Server Consistency Consistency Storage Storage

  9. Architectures App App App App App App App App App App App App App App App App Server Server Server Server Server Server Queries Queries Transactions Transactions K/V Store K/V Store Consistency Consistency Storage Storage

  10. Architectures App App App App App App App App App App App App App App App App Server Server Server Server Server Server Queries Queries Queries Transactions Transactions Transactions K/V Store K/V Store Consistency Consistency Consistency Storage Storage Storage

  11. Architectures App App App App App App App App App App App App App App App App Distributed Distributed Storage Storage Service Service Queries Queries Queries Transactions Transactions Transactions K/V Store K/V Store Consistency Consistency Consistency Storage Storage Storage

  12. Datomic Architecture App App App App App App App App App App App App App App App App Distributed Distributed Storage Storage Service Service

  13. Datomic Architecture App App App App App App App App App App App App App App App App Queries Distributed Distributed Storage Storage Service Service Transactions Consistency Storage

  14. Datomic Architecture App App App App App App App App App App App App App App App App Queries Distributed Distributed Storage Storage Service Service Transactions Consistency Storage

  15. Datomic Architecture App App App App App App App App App App App App App App App App Transactor Queries Distributed Distributed Storage Storage Service Service Transactions Consistency Storage

  16. Datomic Architecture App App App App App App App App App App App App App App App App Transactor Queries Queries Distributed Distributed Storage Storage Service Service Transactions Transactions Consistency Consistency Storage Storage

  17. Datomic Architecture App App App App App App App App App App App App App App App App Transactor Queries Queries Distributed Distributed Storage Storage Service Service Transactions Transactions Consistency Consistency Storage Storage

  18. Datomic Architecture App App App App App App App App App App App App App App App App Transactor Queries Queries Distributed Distributed Storage Storage Service Service Transactions Transactions Consistency Consistency Storage Storage

  19. Datomic Architecture App App App App App App App App App App App App App App App App Transactor Queries Queries Distributed Distributed Storage Storage Service Service Transactions Transactions Consistency Consistency Storage Storage

  20. Datomic Architecture App App App App App App App App App App App App App App App App Transactor Queries Queries Distributed Distributed Storage Storage Service Service Transactions Transactions Consistency Consistency Storage Storage

  21. The Database, Deconstructed App Process App Process D Peer Lib App Data Query App Live Cache Data Index D Transactor Strings Result Sets Trans- DDL + DML Indexing actions cache Server Data Data Segments Trans- segments actions Indexing Storage Service I/O a,d,e b,c,e a,b,d Query Data Segments Storage T raditional DB Datomic

  22. Designed for the Cloud • Ephemeral instances, unreliable disks • Redundancy in storage service • Leverages reliable storage services • e.g. DynamoDB, Riak

  23. Elastic Scaling • More peers, more power • Fewer peers, less power, lower cost • Demand - driven • No configuration

  24. Get Y our Own Brain • Query, communication and memory engine • Goes into your app, making it a peer • The db is e ff ectively local • Ad hoc, long running queries - ok

  25. Logic • Declarative search and business logic • The query language is Datalog • Simple rules and data patterns • Joins are implicit, meaning is evident • db and non - db sources

  26. Perception • Obtain a queue of transactions • not just your own • Query transactions for filtering/triggering

  27. Consistency • ACID transactions add new facts • Database presented to app as a value • Data in storage service is immutable

  28. Programmability • T ransactions/Rules/Queries/Results are data • Extensible types, predicates, etc • Queries can invoke your code

  29. A Database of Facts • A single storage construct, the datom • Entity/Attribute/V alue/T ransaction • Attribute definition is the only 'schema'

  30. Adaptability • Sparse, irregular, hierarchical data • Single and multi - valued attributes • No structural rigidity

  31. Time Built - in • Every datom retains its transaction • T ransactions are totally ordered • T ransactions are first - class entities • Get the db as - of, or since, a point in time

  32. Clojure Time Model Process events (pure functions) F F F v1 v2 v3 v4 States Identity (immutable values) (succession of states) Observers/perception/memory

  33. Datomic Time Model Process events Transactions (pure functions) F F F v1 v2 v3 v4 States DB Values Identity (immutable values) DB (succession of Connection states) Observers/perception/memory Queries

  34. Implementation

  35. Datomic Architecture App Server Process App Server Process App Server Process Peer Lib Peer Lib Peer Lib App App Query App Query Query Live Comm Cache Live Index Comm Cache Live Index Comm Cache Index Data Segments memcached cluster (optional) Storage Service Transactor Transactor Trans- Data Segments Indexing Trans- actions Segment storage Redundant Indexing actions segment storage standby

  36. State • Immutable, expanding value • Must be organized to support query

  37. Index • Sorted set of facts • Maintaining sort live in storage - bad • BigTable - mem + storage merge • occasional merge into storage • persistent trees

  38. Memory Index • New persistent sorted set • Large internal nodes • Pluggable comparators • 2 sorts always maintained • EAVT, AEVT • plus AVET, VAET

  39. Storage • Log of tx asserts/retracts ( in tree ) • V arious covering indexes ( trees ) • Storage requirements • Data segment values ( K - >V ) • atoms ( consistent read ) • pods ( conditional put )

  40. Index in Storage Identity Index ref T EAVT AEVT VeAET AVET Lucene 42 Index Root of key->dir Value dirs Sorted segs Datoms

  41. What’s in a DB V alue? Identity Memory index (live window) db atom db value live Storage index history nextT asOfT sinceT Lucene index Storage-backed index live Lucene Roots EAVT AEVT VeAET t Value Hierarchical Cache

  42. DB V alues • Time travel and more • db.asOf - past, db.since - windowed • db.with(tx) - speculative • db.filter(pred) - slice • dbs are arguments to query, not implicit • mock with datom - shaped data: [[:fred :likes "Pizza"] [:sally :likes "Ice cream"]]

  43. Process • Assert/retract can’t express transformation • T ransaction function: (f db & args) - > tx - data • tx - data: assert|retract|(tx-fn args...) • Expand/splice until all assert/retracts

  44. Process Expansion + + - foo - + + + + - bar baz - + + + + - + + + - + - + + ...

  45. T ransactor • Accepts transactions • Expands, applies, logs, broadcasts • Periodic indexing, in background • Indexing creates garbage • Storage GC

  46. T ransactor Implementation • HornetQ for transaction communication • Extensive internal pipelining - j.u.c. queues • Async message decompression • transaction expansion/application • encoding for, communication with storage • Java interop to storage APIs

  47. Indexing • Extensive use of laziness • Parallel processing • Parallel I/O • Async, rejoins via queue

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend