Introduction to terrastore
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Introduction to terrastore

on

  • 5,322 views

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

Statistics

Views

Total Views
5,322
Views on SlideShare
4,108
Embed Views
1,214

Actions

Likes
3
Downloads
51
Comments
0

6 Embeds 1,214

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

Accessibility

Categories

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.

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

Introduction to terrastore Presentation Transcript

  • 1. Introduction to Terrastore Sven Johansson Mejsla @svjson Mats Henricson Crisp @matshenricson
  • 2. 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
  • 3. Document-oriented databases - Advanced Key/Value stores - Documents are nested data structures – JSON or JSON-variants - Examples of implementations:
    • CouchDB (ERLANG)
    • 4. MongoDB (C++)
    • 5. RavenDB (C#)
    • 6. Terrastore (Java)
  • 7. 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
  • 8. 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' }] }
  • 9. public class Person { private String name; private int age; private String[] titles; private Book currentlyReading; private List<Book> favouriteBooks; ... } ...and a corresponding Java Object
  • 10. Deployment architecture Single cluster - 1 Master - n Servers ( n hot standbys)
  • 11. Deployment architecture Multi-cluster (Ensemble) - Cluster of n Masters - n Servers each
  • 12. CRUD with Terrastore Mats Henricson Crisp AB Stockholm 2010-09-14, WTFPL license
  • 13. 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
  • 14. Annotations? Base classes? Nope. The POJO:s are plain vanilla vanilla POJO:s Stockholm 2010-09-14, WTFPL license
  • 15. 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
    • 16. One bucket for item data
    • 17. One bucket for orders
    Stockholm 2010-09-14, WTFPL license
  • 18. 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
  • 19. 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
  • 20. 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
  • 21. So, are we done?
    • It is safe to remove() non-existing documents
    • 22. Get for non-existing keys will throw KeyNotFoundException
    • 23. You can import and export whole buckets to file for backup
    • 24. You can get all documents in a bucket
    • 25. You can get n documents in a bucket
    • 26. You can get all documents within a key range
    • 27. You can read old documents into objects of updated classes
    No, there is a lot more cool stuff! Stockholm 2010-09-14, WTFPL license
  • 28. 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
  • 29. 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