Coimbra, April 18th, 2012                                 Sanne Grinovero                            Hibernate Team, JBoss...
About me• Hibernate           in.relation.to/Bloggers/Sanne • Hibernate Search • Hibernate OGM                      Twitte...
Hibernate Object/Grid Mapper ?         JPA for NoSQL     • initially Key/Value store     • we started with Infinispan
Relational Databases           • Transactions           • Referential integrity           • Simple Types           • Well ...
Relational Databases  But scaling is hard!  -Replication  -Multiple instances w/ shared   disk  -Sharding
Relational Databases on a cloudMaster/replicas: which master?A single master? I was promised elasticityLess reliable “disk...
¬SQLmore meaning NotOnlySQL ¬SQL U SQL = anything
No-SQL goalsVery heterogeneus• Large datasets• High availability• Low latency / higher throughput• Specific data access pa...
NotOnlySQL• Document based stores• Column based• Graph oriented databases• Key / value stores• Full-Text Search
NotOnlySQLChoose one.          Before starting.                         Stick to it.
Flexibility at a cost• Programming model  • one per product :-(  • Often very thight code coupling  • No standard drivers ...
Where does Infinispan fit?Distributed Key/Value store      • (or Replicated, local only efficient cache,      invalidating...
But how to use it?map.put( “user-34”, userInstance );map.get( “user-34” );map.remove( “user-34” );
Its a ConcurrentMap !map.put( “user-34”, userInstance );map.get( “user-34” );map.remove( “user-34” );map.putIfAbsent( “use...
Other Hibernate/Infinispan      collaborations●    Second level cache for Hibernate ORM●    Hibernate Search indexing back...
Cloud-hack experimentsLets play with Infinispans integration forHibernates second level cache design: - usually configured...
Cloud-hack experimentsNow introduce Hibernate Search: - full-text queries should be handled byLucene, NOT by the database....
Whats the work left to the database?
These tools are very   appropriate for the job:Load by PK ->      second level cache ->           Key/Value storeFullText ...
These tools are very   appropriate for the job:Load by PK ->      second level cache ->           Key/Value storeFullText ...
Goals•   Encourage new data usage patterns•   Familiar environment•   Ease of use•   Easy to jump in•   Easy to jump out• ...
What it does• JPA front end to key/value stores  • Object CRUD (incl polymorphism and associations)  • OO queries (JP-QL)•...
Concepts
Schema or no schema?• Schema-less  • move to new schema very easy  • app deal with old and new structure or migrate all   ...
Entities as serialized blobs?• Serialize objects into the (key) value  • store the whole graph?• maintain consistency with...
OGM’s approach to schema• Keep what’s best from relational model  • as much as possible  • tables / columns / pks• Decorre...
OGM’s approach to schema• Store metadata for queries  • Lucene index• CRUD operations are key lookups
How does it work?• Entities are stored as tuples (Map<String,Object>)  • Or Documents?• The key is composed of  • table na...
Lets see some code...
Queries / Infinispan• Hibernate Search indexes entities• Store Lucene indexes in Infinispan• JP-QL to Lucene query transfo...
select a from Animal a where a.size > 20> animalQueryBuilder.range().onField(“size”).above(20).excludeLimit().createQuery(...
Why Infinispan?• We know it well• Supports transactions• Supports distribution of Lucene indexes• Designed for clouds• Its...
Why Infinispan?•Map/Reduce as an alternative to indexed queries •Might be chosen by a clever JP-QL  engine•Potential for a...
Why ?Nothing new to learn for most common operations:• JPA models• JP-QL queriesEverything else is performance tuning, inc...
Development state:  • Query via Hibernate Search    • Smart JP-QL parser is on github  • Available in master:    • EHCache...
Summary• Performance / scalability is different• Isolation is different
http://ogm.hibernate.org
http://www.jboss.org/jbw2011keynote.html   https://github.com/Sanne/tweets-ogm
Q+A
Using JPA applications in the era of NoSQL: Introducing Hibernate OGM
Using JPA applications in the era of NoSQL: Introducing Hibernate OGM
Using JPA applications in the era of NoSQL: Introducing Hibernate OGM
Upcoming SlideShare
Loading in …5
×

Using JPA applications in the era of NoSQL: Introducing Hibernate OGM

5,333 views
5,136 views

Published on

Apresentação de Sanne Grinovero - 8º encontro PT.JUG.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,333
On SlideShare
0
From Embeds
0
Number of Embeds
1,643
Actions
Shares
0
Downloads
36
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Using JPA applications in the era of NoSQL: Introducing Hibernate OGM

  1. 1. Coimbra, April 18th, 2012 Sanne Grinovero Hibernate Team, JBoss Red Hat, Inc
  2. 2. About me• Hibernate in.relation.to/Bloggers/Sanne • Hibernate Search • Hibernate OGM Twitter: @SanneGrinovero• Infinispan • Lucene Directory • Infinispan Query Studied at FEUP (Porto)!
  3. 3. Hibernate Object/Grid Mapper ? JPA for NoSQL • initially Key/Value store • we started with Infinispan
  4. 4. Relational Databases • Transactions • Referential integrity • Simple Types • Well understood - tuning, backup, resilience
  5. 5. Relational Databases But scaling is hard! -Replication -Multiple instances w/ shared disk -Sharding
  6. 6. Relational Databases on a cloudMaster/replicas: which master?A single master? I was promised elasticityLess reliable “disks”IP in configuration files? DNS update times?Who coordinates this? How does that failover?
  7. 7. ¬SQLmore meaning NotOnlySQL ¬SQL U SQL = anything
  8. 8. No-SQL goalsVery heterogeneus• Large datasets• High availability• Low latency / higher throughput• Specific data access pattern• Specific data structures• ...
  9. 9. NotOnlySQL• Document based stores• Column based• Graph oriented databases• Key / value stores• Full-Text Search
  10. 10. NotOnlySQLChoose one. Before starting. Stick to it.
  11. 11. Flexibility at a cost• Programming model • one per product :-( • Often very thight code coupling • No standard drivers / stable APIs• no schema => app driven schema• query (Map Reduce, specific DSL, ...)• data structure transpires• Transactions ?• durability / consistency puzzles
  12. 12. Where does Infinispan fit?Distributed Key/Value store • (or Replicated, local only efficient cache, invalidating cache) Each node is equal • Just start more nodes, or kill some No bottlenecks • by design Cloud-network friendly • JGroups • And “cloud storage” friendly too!
  13. 13. But how to use it?map.put( “user-34”, userInstance );map.get( “user-34” );map.remove( “user-34” );
  14. 14. Its a ConcurrentMap !map.put( “user-34”, userInstance );map.get( “user-34” );map.remove( “user-34” );map.putIfAbsent( “user-38”, another );
  15. 15. Other Hibernate/Infinispan collaborations● Second level cache for Hibernate ORM● Hibernate Search indexing backend● Infinispan Query
  16. 16. Cloud-hack experimentsLets play with Infinispans integration forHibernates second level cache design: - usually configured in clustering mode INVALIDATION. •Lets use DIST or REPL instead. - Disable expiry/timeouts. Whats the effect on your cloud-deployed database?
  17. 17. Cloud-hack experimentsNow introduce Hibernate Search: - full-text queries should be handled byLucene, NOT by the database.Hibernate Search identifies hits from theLucene index, but loads them by PK. *by default
  18. 18. Whats the work left to the database?
  19. 19. These tools are very appropriate for the job:Load by PK -> second level cache -> Key/Value storeFullText query -> Hibernate Search -> Lucene Indexes
  20. 20. These tools are very appropriate for the job:Load by PK -> second level cache -> Key/Value storeFullText query -> Hibernate Search -> Lucene Indexes What if we now shut down the database?
  21. 21. Goals• Encourage new data usage patterns• Familiar environment• Ease of use• Easy to jump in• Easy to jump out• Push NoSQL exploration in enterprises• “PaaS for existing API” initiative
  22. 22. What it does• JPA front end to key/value stores • Object CRUD (incl polymorphism and associations) • OO queries (JP-QL)• Reuses • Hibernate Core • Hibernate Search (and Lucene) • Infinispan• Is not a silver bullet • not for all NoSQL use cases
  23. 23. Concepts
  24. 24. Schema or no schema?• Schema-less • move to new schema very easy • app deal with old and new structure or migrate all data • need strict development guidelines• Schema • reduce likelihood of rogue developer corruption • share with other apps • “didn’t think about that” bugs reduced
  25. 25. Entities as serialized blobs?• Serialize objects into the (key) value • store the whole graph?• maintain consistency with duplicated objects • guaranteed identity a == b • concurrency / latency • structure change and (de)serialization, class definition changes
  26. 26. OGM’s approach to schema• Keep what’s best from relational model • as much as possible • tables / columns / pks• Decorrelate object structure from data structure• Data stored as (self-described) tuples• Core types limited • portability
  27. 27. OGM’s approach to schema• Store metadata for queries • Lucene index• CRUD operations are key lookups
  28. 28. How does it work?• Entities are stored as tuples (Map<String,Object>) • Or Documents?• The key is composed of • table name • entity id• Collections are represented as a list of tuples- The key is composed of: • table name hosting the collection information • column names representing the FK • column values representing the FK
  29. 29. Lets see some code...
  30. 30. Queries / Infinispan• Hibernate Search indexes entities• Store Lucene indexes in Infinispan• JP-QL to Lucene query transformation• Works for simple queries • Lucene is not a relational SQL engine
  31. 31. select a from Animal a where a.size > 20> animalQueryBuilder.range().onField(“size”).above(20).excludeLimit().createQuery();select u from Order o join o.user u where o.price > 100 and u.city =“Paris”> orderQB.bool() .must( orderQB.range() .onField(“price”).above(100).excludeLimit().createQuery() ) .must( orderQB.keyword(“user.city”).matching(“Paris”) .createQuery()).createQuery();
  32. 32. Why Infinispan?• We know it well• Supports transactions• Supports distribution of Lucene indexes• Designed for clouds• Its a key/value store with support for Map/Reduce • Simple • Likely a common point for many other “databases”
  33. 33. Why Infinispan?•Map/Reduce as an alternative to indexed queries •Might be chosen by a clever JP-QL engine•Potential for additional query types
  34. 34. Why ?Nothing new to learn for most common operations:• JPA models• JP-QL queriesEverything else is performance tuning, including:• Move to/from different NoSQL implementations• Move to/from a SQL implementation• Move to/from clouds/laptops• JPA is a well known standard: move to/from Hibernate :-)
  35. 35. Development state: • Query via Hibernate Search • Smart JP-QL parser is on github • Available in master: • EHCache • Infinispan • In development branches: • MongoDB • Voldemort
  36. 36. Summary• Performance / scalability is different• Isolation is different
  37. 37. http://ogm.hibernate.org
  38. 38. http://www.jboss.org/jbw2011keynote.html https://github.com/Sanne/tweets-ogm
  39. 39. Q+A

×