deconstructing the database
play

Deconstructing the Database Rich Hickey Most programs are outside - PowerPoint PPT Presentation

Deconstructing the Database Rich Hickey Most programs are outside the bounds of and single process we write in any single FP language What is Datomic? A new database A sound model of information, with time Provides database as a


  1. Deconstructing the Database Rich Hickey Most programs are outside the bounds of and single process we write in any single FP language

  2. What is Datomic? • A new database • A sound model of information, with time • Provides database as a value to applications • Bring declarative programming to applications • Focus on reducing complexity Not going to do a full rationalization or overview Focus on information important for Datomic, not necessarily for all use of dbs/stores

  3. DB Complexity • Stateful • Same query, different results • no basis • Over there • ‘Update’ poorly defined • Places Inherent complexity in state

  4. Update • What does update mean? • Does the new replace the old? • Granularity? new ___ replace the old ___ • Visibility? Granularity and replacement the big issues

  5. Manifestations • Wrong programs • Scaling problems • Round-trip fears • Fear of overloading server • Coupling, e.g. questions with reporting read committed vs repeatable, serializable

  6. Consistency and Scale • What’s possible? • Distributed redundancy and consistency? • Elasticity • Inconsistency huge source of complexity dynamo and bigtable

  7. Information and Time • Old-school memory and records • The kind you remember ... and keep • Auditing and more

  8. Perception and Reaction • No polling • Consistent

  9. Coming to Terms Value State • An immutable • Value of an identity at a magnitude, quantity, moment in time number... or immutable Time composite thereof • Relative before/after Identity ordering of causal values • A putative entity we associate with a series of causally related values (states) over time

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

  11. Implementing Values • Persistent data structures • Trees • Structural sharing

  12. Structural Sharing Next Past

  13. Place Model Process events Transactions (pure functions) F F F The Database Place Identity DB (succession of Connection states) Observers/perception/memory Queries We should recognize - same problems as OO Conflates identity and value, collapses time

  14. Epochal 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 This is what we want - transactions are functions of db values queries as well

  15. Traditional Database App Process ORM? App Caching policy? Strings Serialized DDL + DML Serialized Result Sets ??? ??? cache Server Trans- Indexing actions Query I/O Disk what’s makes up a database? cache over DB access, disk locality was important

  16. The Choices • Coordination • how much, and where? • process requires it • perception shouldn’t • Immutability • sine qua non coordinate up front or later immutability advantages with eventually consistent systems

  17. Approach • Move to information model • Split process and perception • Immutable basis in storage • Novelty in memory

  18. Information • Inform • ‘to convey knowledge via facts’ • ‘give shape to (the mind)’ • Information • the facts

  19. Facts • Fact - ‘an event or thing known to have happened or existed’ • From: factum - ‘something done’ • Must include time • Remove structure (a la RDF) • Atomic Datom • Entity/Attribute/Value/Transaction(time) don’t get more flexibility by trading tables for documents factum - “something done”

  20. Database State • The database as an expanding value • An accretion of facts • The past doesn’t change - immutable • Process requires new space • Fundamental move away from places What is the state - snapshot of a referential model?

  21. Accretion • Root per transaction doesn’t work • Latest values include past as well • The past is sub-range • Important for information model can we just do shared structure from before on disk?

  22. Process • Reified • Primitive representation of novelty • Assertions and retractions of facts • Minimal • Other transformations expand into those Important to accretion that novelty representation is minimal

  23. Deconstruction Server Trans- Indexing actions Query I/O Disk • Process • Perception/Reaction • Transactions • Query • Indexing • Indexes • O • I

  24. State • Must be organized to support query • Sorted set of facts • Maintaining sort live in storage - bad • BigTable - mem + storage merge • occasional merge into storage • persistent trees Databases are about leverage

  25. Indexing • Maintaining sort live in storage - bad • BigTable et al: • Accumulate novelty in memory • Current view: mem + storage merge • Occasional integrate mem into storage Releases memory

  26. Transactions and Indexing Trans- actions Log Data Segments Novelty Live Storage Index Index Data Segments Index Merging

  27. Perception Novelty Index Data Segments Live Storage Index Just a merge join. Any coordination required? Contention? How does live index get updated? Live vs periodic now separate decision

  28. Components • Transactor • Peers • Your app servers, analytics machines etc • Redundant storage service Physical architecture

  29. Datomic Architecture App Server Process App Server Process App Server Process Peer Lib Peer Lib App Peer Lib 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 But, storage now remote, slow? No - cache everywhere

  30. Transactor • Accepts transactions • Expands, applies, logs, broadcasts • Periodic indexing, in background • Indexing creates garbage • Storage GC

  31. Peer Servers • Peers directly access storage service • Have own query engine • Have live mem index and merging • Two-tier cache • Datoms w/object values (on heap) • Segments (memcached)

  32. Consistency and Scale • Process/writes go through transactor • traditional server scaling/availability • Immutability supports consistent reads • without transactions • Query scales with peers • Elastic/dynamic e.g. auto-scaling consistency as in db satisfies consistency predicate loopholes 7 and 10?

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

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

  35. Structural Sharing Next Past

  36. What’s in a DB Value? 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 Value can be lazily loaded, since source immutable

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

  38. Datomic on Riak + ZooKeeper • Riak redundant, distributed, highly available durable eventually consistent • ZooKeeper redundant, durable, consistent (ordered ops + CAS)

  39. Datomic on Riak Values Identities + ZooKeeper ZooKeeper Riak Index ref Log ref Coord ref Catalog ref pointer swap mentioned by Eric Brewer this morning

  40. Riak Usage • Everything put into Riak is immutable • N=3, W=2, DW=2 • R=1, not-found-ok = false ‘first found’ semantics • There or not no vector clocks, siblings etc • No speculative lookup What notion of consistency? Application-level predicate

  41. Client App Process (any language) App Process App Process Full Datomic App REST Client Stack HTTP + Server-Sent Events Peer REST Server Peer App Server Process Peer Service App Process Peer Service REST App Process Peer Lib Server App Query Query Live Comm Cache Index Live Comm Cache Index memcached cluster (optional) Transactor Transactor Data Segments Trans- Indexing Trans- actions Indexing actions Storage Server/Service Data Segments Standby Segment storage Redundant segment storage

  42. Stable Bases //Peer Database db = connection.db().asOf(1000); Peer.q(aQuery, db); basis //Client GET /data/mem/test/1000/datoms?index=aevt • Same query, same results • db permalinks! • communicable, recoverable • Multiple conversations about same value Value of values

  43. DB Values • Time travel • db.asOf - past • db.since - windowed • db.with(tx) - speculative • dbs are arguments to query, not implicit • mock with datom-shaped data: [[:fred :likes "Pizza"] [:sally :likes "Ice cream"]]

  44. DB Simplicity Benefits • Epochal state • Coordination only for process • Transactions well defined • Functional accretion • Freedom to relocate/scale storage, query • Extensive caching • Process events

Recommend


More recommend