• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Introduction to terrastore

Introduction to terrastore



Introduction to Terrastore, as presented at JavaForum 2010-09-14 by Sven Johansson and Mats Henricson

Introduction to Terrastore, as presented at JavaForum 2010-09-14 by Sven Johansson and Mats Henricson



Total Views
Views on SlideShare
Embed Views



6 Embeds 1,200

http://nosql.mypopescu.com 1193
http://translate.googleusercontent.com 3
http://static.slidesharecdn.com 1
http://feeds.feedburner.com 1
http://zendproxy.com 1
https://translate.googleusercontent.com 1



Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Introduction to terrastore Introduction to terrastore Presentation Transcript

    • Introduction to Terrastore Sven Johansson Mejsla @svjson Mats Henricson Crisp @matshenricson
    • NoSQL - A loosely defined movement - A complement to relational databases - Usually schema-less - Typically not concerned with transactions, locks or data integrity... - ...but more so with performance and scalability
    • Document-oriented databases - Advanced Key/Value stores - Documents are nested data structures – JSON or JSON-variants - Examples of implementations:
      • CouchDB (ERLANG)
      • MongoDB (C++)
      • RavenDB (C#)
      • Terrastore (Java)
    • Terrastore - Open source project founded in Sept-Oct 2009 - Written entirely in Java - Based on Terracotta - Offers per-document consistency - Distributed - Elastic - Scalable at the computational level - Extensible
    • A Terrastore document { 'name' : 'Sven Johansson', 'age' : '29', 'titles' : [ 'Developer', 'Consultant', 'Destroyer of worlds', ], 'currentlyReading : { title: 'The book of Dave' author: 'Will Self' } 'favouriteBooks' : [{ title: 'The naked and the dead', author: 'Norman Mailer' }, { title: 'On the road', author: 'Jack Kerouac' }] }
    • public class Person { private String name; private int age; private String[] titles; private Book currentlyReading; private List<Book> favouriteBooks; ... } ...and a corresponding Java Object
    • Deployment architecture Single cluster - 1 Master - n Servers ( n hot standbys)
    • Deployment architecture Multi-cluster (Ensemble) - Cluster of n Masters - n Servers each
    • CRUD with Terrastore Mats Henricson Crisp AB Stockholm 2010-09-14, WTFPL license
    • Example public class Customer { private String name; private Address address; private List<PhoneNumber> phoneNumbers = new LinkedList<PhoneNumber>(); // ... } public class Address { private String street; // ... } public class PhoneNumber { private String number; private String type; // … } } Stockholm 2010-09-14, WTFPL license
    • Annotations? Base classes? Nope. The POJO:s are plain vanilla vanilla POJO:s Stockholm 2010-09-14, WTFPL license
    • You store your domain objects into different buckets. Examples: Buckets are identified by string names, such as &quot;customers&quot;, &quot;items&quot;, &quot;orders&quot;. Buckets are comparable to RDBMS tables, but with no schema! If you need to link objects in different buckets, Then you have to use domain unique IDs. Buckets
      • One bucket for customer data
      • One bucket for item data
      • One bucket for orders
      Stockholm 2010-09-14, WTFPL license
    • First we need a terrastore client That localhost URL points to a terrastore server . If that server goes down, then your client is toast. Next version of the API have implemented fallbacks. Enough! I want an example, now! TerrastoreClient client = new TerrastoreClient(&quot;http://localhost:8080&quot;, new HTTPConnectionFactory()); Stockholm 2010-09-14, WTFPL license
    • Customer lindex = new Customer(&quot;Lindex&quot;); Address dg = new Address(&quot;Drottninggatan 77&quot;); PhoneNumber work = new PhoneNumber(&quot;1234567&quot;, &quot;work&quot;); PhoneNumber home = new PhoneNumber(&quot;2345678&quot;, &quot;home&quot;); // Set relationships lindex.setAddress(dg); lindex.addPhoneNumber(work); lindex.addPhoneNumber(home); Now lets create the POJO:s Stockholm 2010-09-14, WTFPL license
    • BucketOperation customers = client.bucket(&quot;customers&quot;); // Create: customers.key(&quot;lindex&quot;).put(lindex); // Read: Customer l = customers.key(&quot;lindex&quot;).get(Customer.class); // Important: l != lindex // Delete: customers.key(&quot;lindex&quot;).remove(); Create, Read and Delete You can update a document with another put() Stockholm 2010-09-14, WTFPL license
    • So, are we done?
      • It is safe to remove() non-existing documents
      • Get for non-existing keys will throw KeyNotFoundException
      • You can import and export whole buckets to file for backup
      • You can get all documents in a bucket
      • You can get n documents in a bucket
      • You can get all documents within a key range
      • You can read old documents into objects of updated classes
      No, there is a lot more cool stuff! Stockholm 2010-09-14, WTFPL license
    • Search example with ranges Map<String, Customer> customers = customersBucket.range(&quot;lexical-asc&quot;) .from(&quot;brothers&quot;).to(&quot;lindex&quot;) .limit(10).get(Customer.class); Stockholm 2010-09-14, WTFPL license
    • String xpath = &quot;jxpath:/address/street[.='Drottninggatan 77']&quot;; Map<String, Customer> dgCustomers = customersBucket.predicate(xpath).get(Customer.class); assertTrue(dgCustomers.containsValue(lindex)); XPath! Internally using JXPath. Stockholm 2010-09-14, WTFPL license