150 likes | 399 Views
Persistent Data Structures. What is “persistent”?. A data structure capable of preserving the current version when modified A collection of immutable states. Why “persistent”?. The immutable states provide the basis for coordination around state in a distributed system.
E N D
What is “persistent”? • A data structure capable of preserving the current version when modified • A collection of immutable states
Why “persistent”? • The immutable states provide the basis for coordination around state in a distributed system
References Comparison • Clojure: 4 types of mutable references • Refs: shared/synchronous/coordinated • Agents: shared/asynchronous/autonomous • Atoms: shared/synchronous/autonomous • Vars: isolated changes within threads • ION R1: references • CASRefs shared/synchronous/coordinated • IDRefs shared/asynchronous/autonomous (writes), coordinated (reads) • Using git semantics: Push, Pull
Clojure-ION R1 • Clojure • Object structure is a hash map • Share strcutres in a single JVM (locks, shared resource) • Synchronous transactions, may fail if state has diverged • Mechanisms: Identity establishment, de-referencing (??) • ION R1 • Object structure is a graph data structure defined in proto meta object specifications • Distributed processes communicate by messages, • Eventually consistent backend (no locks, no sharing) • Asynchronous transactions, never fail (but may require merge on reads) • Working model for Commit and Checkouts
Achieving persistence • Simple copying • Inefficient in time and space • Reusing similar structures • Share structure between new and old versions • Using same subtree in a number of tree structures
Examples of persistent data structures (linked lists) zs = xs ++ ys • Copied: Nodes in list xs have been copied • Shared: Nodes in list ys are shared
Examples of persistent data structures (Trees) ys = insert ("e", xs) • Original tree (xs) persists • Many common nodes are shared
ION Persistence Performance • Metrics • Creating new version from previous version • Fetch, de-serialize, change, serialize, commit • Retrieving a previous version of data structures
Other References and Diagrams • http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey • https://docs.google.com/drawings/d/100bu4uC-TEH78dyBVmoIgT9DOpaAKEQLc8RqPt4nIjA/edit?hl=en_US&authkey=CO2M5dQD • https://docs2.google.com/drawings/d/1IPkIqsf5IWHHf9dRl9cEEOA45atjA5WCDoBnjXHtKCc/edit?hl=en_US • https://docs6.google.com/drawings/d/1Dgw2TF8ypRXmlCE5MdsjnkVISt4Cmx7rMvtJ7U5craM/edit?hl=en_US • https://docs3.google.com/drawings/d/1KtHHV5AgHppWfnBkyZGeORikjDT49OIbGiQa3c_6T3Q/edit?hl=en_US (Somewhat out of date)
Persistent data structures in Clojure • Composite values – immutable • ‘Change’ is merely a function, takes one value and returns another, ‘changed’ value • New versions are not full copies • Old version of the collection is still available after 'changes', with same performance • Structural sharing • Indirect references to immutable objects
Partially/Fully/Confluentlypersistent • Partially persistent • All versions can be accessed but only the newest version can be modified • Fully persistent • Every version can be both accessed and modified • Confluently persistent • A new version can be created from two previous versions (meld/merge operations)