Your SlideShare is downloading. ×
0
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Introduction to terrastore
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Introduction to terrastore

4,921

Published on

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

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,921
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
55
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

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: <ul><li>CouchDB (ERLANG)
  • 4. MongoDB (C++)
  • 5. RavenDB (C#)
  • 6. Terrastore (Java) </li></ul>
  • 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 <ul><li>One bucket for customer data
  • 16. One bucket for item data
  • 17. One bucket for orders </li></ul>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? <ul><li>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 </li></ul>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

×