OrientDB the database for the web 1.1


Published on

Rich description about OrientDB features

Published in: Technology
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

OrientDB the database for the web 1.1

  1. 1. www.orientechnologies.comThe database for the Web
  2. 2. Why do I need another DBMS? www.orientechnologies.com
  3. 3. But the question is:are DBMSs ready for the Web age? www.orientechnologies.com
  4. 4. Web means: Hundreds of users today, thousands or millions tomorrow www.orientechnologies.com
  5. 5. Web means: Idea → Demo in few weeks www.orientechnologies.com
  6. 6. Web means: Fast and frequent changes of requirements and data structures www.orientechnologies.com
  7. 7. Web means: + social + relationships + interconnections = graph www.orientechnologies.com
  8. 8. Web means: Low usage of resources run on cheap hardware www.orientechnologies.com
  9. 9. Web means: Speak HTTP, REST and JSON please www.orientechnologies.com
  10. 10. Why is the database so importantin modern applications? www.orientechnologies.com
  11. 11. Becausemodern applicationsare mostly I/O Bound not CPU bound www.orientechnologies.com
  12. 12. NoSQL = “Not Only SQL”= make the best choice for your use case www.orientechnologies.com
  13. 13. Can I trustnew DBMSs? www.orientechnologies.com
  14. 14. www.orientechnologies.com
  15. 15. Non exhaustive list of NoSQL products: AllegroGraph, Amazon SimpleDB, Amazon Dynamo, Dynomite, BerkleyDB, Google BigTable, Cassandra, CouchDB, DB4O, Hbase, Hipertable, Hive, Jackrabbit, InfiniteGraph, InfoGrid, Memcached, MemcacheDB, Mnesia, M/DB/DT.M, MongoDB, Neo4J, OrientDB, Pig, Project Voldemort, RavenDB, Redis, Riak, Scalaris,Sesame, Sones, Terrastore, Tokyo Cabinet/Tyrant, Yahoo! Pnuts/Sherpa www.orientechnologies.com
  16. 16. “NoSQL container” groups so very-very-very different products, no standard, difficult to choice, difficult to learn them www.orientechnologies.com
  17. 17. Can I have aFast, scalable, flexible storagewith ACID Tx, SQL, Security easy to use and maintain? www.orientechnologies.com
  18. 18. The fastest NoSQL document-graph dbms www.orientechnologies.com
  19. 19. +12 years of research www.orientechnologies.com
  20. 20. +1 yearof design and develop www.orientechnologies.com
  21. 21. =best features of newest NoSQL solutions + best features of Relational DBMS + new ideas and concepts www.orientechnologies.com
  22. 22. Ø config download, unzip, run! cut & paste the db www.orientechnologies.com
  23. 23. No dependencies rd with 3 parties softwareno conflicts with other software just 1 Mb of run-time libraries www.orientechnologies.com
  24. 24. 150,000 records per second www.orientechnologies.com
  25. 25. Schema-less schema is not mandatory, relaxed model,collect heterogeneous documents all together www.orientechnologies.com
  26. 26. Schema-fullschema with constraints on fields and validation rulesCustomer.age > 17Customer.address not nullCustomer.surname is mandatoryCustomer.email matches b[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}b www.orientechnologies.com
  27. 27. Schema-mixedschema with mandatory and optional fields + constraints the best of schema-less and schema-full modes www.orientechnologies.com
  28. 28. ACID Transactionsdb.begin();try{ // your code ... db.commit();} catch( Exception e ) { db.rollback();} www.orientechnologies.com
  29. 29. Complex types collections, maps (key/value)native support for and embedded documents no more additional tables to handle them www.orientechnologies.com
  30. 30. Relationships are direct linksno Relational JOINS to connect multiple tables Load trees and graphs in few ms! www.orientechnologies.com
  31. 31. SQLselect * from employee where name like %Jay% and status=0 www.orientechnologies.com
  32. 32. For the most of the querieseveryday a programmer needs SQL is simpler, more readable and compact then Scripting (Map/Reduce) www.orientechnologies.com
  33. 33. SELECT SUM(price) as prices, SUM(cost) as costs, prices-costs, margin/price FROM Balance VSfunction (key, values) { var price = 0.0, cost = 0.0, margin = 0.0, marginPercent = 0.0; for (var i = 0; i < values.length; i++) { price += values[i].price; cost += values[i].cost; } margin = price - cost; marginPercent = margin / price; return { price: price, cost: cost, margin: margin, marginPercent: marginPercent };} www.orientechnologies.com
  34. 34. Asynchronous Queryinvoke callback when a record matches the condition doesnt collect the result set perfect for immediate results useful to compute aggregates www.orientechnologies.com
  35. 35. ®runs Java everywhere is available JRE1.5+ robust engine www.orientechnologies.com
  36. 36. Language bindings Java as nativeJRuby, Scala and Javascript readyC, C++, Ruby, Node.js in progress www.orientechnologies.com
  37. 37. Your language isnot supported (yet)? Write an adapter using the C, Java or HTTP binding www.orientechnologies.com
  38. 38. HTTP RESTful firewall friendlyuse it from the webbrowser use it from the ESB (SOA) www.orientechnologies.com
  39. 39. Native JSON{ @rid = 26:10, @class = Developer, name : Luca, surname : Garulli, company : 19:76} www.orientechnologies.com
  40. 40. Import/Export uses JSON formatonline operations (dont stop the database) www.orientechnologies.com
  41. 41. Binary protocolFast compressed JSON over tcp/ip available for Java and soon C, C++ and Ruby www.orientechnologies.com
  42. 42. RB+Tree index the best of B+Tree and RB-Treefast on browsing, low insertion cost Its a new algorithm (soon public) www.orientechnologies.com
  43. 43. OO Inheritance Definition of Classes of documents Classes can extend others classes Queries are polymorphics Contact name : string surname : string Customer Provider orders : List<Order> products : List<Product> www.orientechnologies.com
  44. 44. Hooks similar to triggerscatch events against records, database and transactions implement custom cascade deletion algorithm enforce constraints www.orientechnologies.com
  45. 45. Fetch plans Choose what to fetch on query and document loadingDocuments not fetched will be lazy-loaded on requestInvoice 3:100 | | customer +---------> Customer | 5:233 | city country +---------> City ---------> Country | 11:2 12:3 | orders +--------->* [OrderItem OrderItem OrderItem] [ 8:12 8:19 8:23 ] www.orientechnologies.com
  46. 46. Securityusers and roles, encrypted passwords fine grain privileges www.orientechnologies.com
  47. 47. 4 storage modes embedded client/server distributed in-memory www.orientechnologies.com
  48. 48. Embedded mode really fastruns in the same JVM of the application, less resources, no tcp/ip used www.orientechnologies.com
  49. 49. Client/server modeclient and server are separated JVMsthousands of clients concurrently remote tcp/ip binary transport www.orientechnologies.com
  50. 50. Distributed mode distribute database clusters onmultiple servers (in alpha status) www.orientechnologies.com
  51. 51. In-memory modeDatabase lives only in memory No disk is used Destroyed at shutdown www.orientechnologies.com
  52. 52. User API Document DatabaseKey/Value Database Graph Database Object Database www.orientechnologies.com
  53. 53. Document Database the base of all DB implementations documents have dynamic structuresomething like a smart Map<String,Object> www.orientechnologies.com
  54. 54. Open the databaseODatabaseDocumentTx db = new ODatabaseDocumentTx( "remote:localhost/demo" );db.open("admin", "admin");try{ …} finally { Open the database demo db.close(); from a remote server} www.orientechnologies.com
  55. 55. Create a documentODocument doc = new ODocument( db, "Person" );doc.field( "name", "Luke" ); Relationshipdoc.field( "surname", "Skywalker" );doc.field( "city", new ODocument("City" ).fields("name","Rome") );doc.save(); www.orientechnologies.com
  56. 56. SQL QueryList<ODocument> result = db.query( new OSQLSynchQuery( "select * from person where city.name = Rome" ) );for( ODocument d : result ) { System.out.println( "Person: " + d.field( "name" ) + d.field( "surname" ) );} www.orientechnologies.com
  57. 57. Native QueryList<ODocument> result = new ONativeSynchQuery<ODocument, OQueryContextNativeSchema<ODocument>>( db, "Profile", new OQueryContextNativeSchema<ODocument>()) { @Override public boolean filter(OQueryContextNativeSchema<ODocument> iRecord) { return iRecord.field("city").field("name").eq("Rome").and().field("name").like("G%").go(); };}.setLimit(20).execute(); www.orientechnologies.com
  58. 58. Update a documentList<ODocument> result = db.query( new OSQLSynchQuery( "select * from person where city.name = Rome"));for( ODocument d : result ) { d.field( "local", true ); d.save();}// ITS THE SAME OF:int changed = db.command( new OSQLCommand( "update person set local = true where city.name = Rome")) .execute(); www.orientechnologies.com
  59. 59. Delete a documentList<ODocument> result = db.query( new OSQLSynchQuery( "select * from person where city.name = Rome" ) );for( ODocument d : result ) { d.delete();// ITS THE SAME OF:int deleted = db.command( new OSQLCommand( "delete person where city.name = Rome")).execute(); www.orientechnologies.com
  60. 60. from/to JSON// EXPORT JSONSystem.out.println( document.toJSON() );// IMPORT JSONdocument.fromJSON( “{ @class = Developer, name : Luca, surname : Garulli }” );document.save(); www.orientechnologies.com
  61. 61. Use hooks (triggers)public class HookTest extends ORecordHookAbstract { public saveProfile(){ ODatabaseObjectTx database = new ODatabaseObjectTx("remote:localhost/demo"); database.open("writer", "writer"); database.registerHook(this); ... } @Override public void onRecordAfterCreate(ORecord<?> iRecord){ System.out.println("Record created successfully"); }} www.orientechnologies.com
  62. 62. Key/Value Database bucket / key / value HTTP RESTful protocolHazelcast plug-in to distribute database www.orientechnologies.com
  63. 63. Key/Value = RB+Treeworks mainly using RB+Tree custom indexes sort of Map<String,Map<String,Record>> www.orientechnologies.com
  64. 64. Object Databasewrapper on top of Document Database binds POJO from/to the database no OR-Mapping complexity no enhancement, no Java Proxies www.orientechnologies.com
  65. 65. POJO mappingUses the reflection to bind POJO fieldsat start-up caches reflection meta-data 1-to-1 binding configurable options by @annotations www.orientechnologies.com
  66. 66. Open the databaseODatabaseObjectTx db = new ODatabaseObjectTx( "remote:localhost/demo" );db.open("admin", "admin");try{ … Same usage of Document Database, but the class} finally { is different db.close();} www.orientechnologies.com
  67. 67. Create a persistent POJOPerson person = new Person();person.setName( "Luke" ); Relationshipperson.setSurname( "Skywalker" );person.setCity( new City( "Rome" ) );db.save( person ); www.orientechnologies.com
  68. 68. Polymorphics SQL QueryList<Person> result = database.query( new OSQLSynchQuery("select from person where city.name = Rome")); Queries are polymorphics and subclasses of Person can be part of result setfor( Person p : result ) { if( p instanceof Customer ) System.out.println("Customer: " + p.getName() + “ “ + p.getSurname() );} www.orientechnologies.com
  69. 69. Graph Database wrapper on top of Document DatabaseFew simple concepts: Vertex, Edge, Property and Index www.orientechnologies.com
  70. 70. Example of a Graph www.orientechnologies.com
  71. 71. TinkerPop technologies sort of “standard” for GraphDB a lot of free open-source projects http://tinkerpop.com www.orientechnologies.com
  72. 72. TinkerPop Blueprintsbasic API to interact with GraphDB implements transactional and indexable property graph model bidirectional edges www.orientechnologies.com
  73. 73. GraphDB & Blueprints APIOrientGraph graph = new OrientGraph("local:/tmp/db/graph”);Vertex actor = graph.addVertex(null);actor.setProperty("name", "Leonardo");actor.setProperty("surname", "Di Caprio");Vertex movie = graph.addVertex(null);movie.setProperty("name", "Inception");Edge edge = graph.addEdge(null, actor, movie, "StarredIn");graph.shutdown(); www.orientechnologies.com
  74. 74. TinkerPop scripting language easy to learn and understandUsed for operations against graphs www.orientechnologies.com
  75. 75. Graph example graph-example-1.xml www.orientechnologies.com
  76. 76. Load graphRun the console, open the database and load a graph in xml formatmarko:~/software/gremlin$ ./gremlin.sh ,,,/ (o o)-----oOOo-(_)-oOOo-----gremlin> $_g := orientdb:open(/tmp/graph/test)==>orientgraph[/tmp/graph/test]gremlin> g:load(data/graph-example-1.xml)==>truegremlin> $_g==>orientgraph[/tmp/graph/test] www.orientechnologies.com
  77. 77. SearchDisplays outgoing edges of vertices with name equals to marko, then the name of inbound verticesgremlin> g:key-v(name,marko)/outE==>e[6:0][5:2-knows->5:1]==>e[6:1][5:2-knows->5:4]==>e[6:4][5:2-created->5:0]gremlin> g:key-v(name,marko)/outE/inV/@name==>vadas==>josh==>lopgremlin> g:close()==>true www.orientechnologies.com
  78. 78. API resumeobject, key/value and graph elements all work on top of Document you can always access to the underlying document changes to the document are reflected to the object, key/value and graph elements and viceversa www.orientechnologies.com
  79. 79. High-AvailabilityCluster of distributed server nodes Synchronous, Asynchronous and Read-Only replicationLoad-balancing between client ↔ servers and Servers ↔ Servers www.orientechnologies.com
  80. 80. Synchronous scenario Server #1 owns all the data, used for reads/writes Server #2 is the backup replica, can be used for reads Clients receive ack only when both are updated Server #1 and #2 are Always ConsistentClient A Client B Client A Client B Server #1 Server #2 (Leader+Owner) (Synchronous) DB DB www.orientechnologies.com
  81. 81. Asynchronous scenario As for synchronous, but: Server #2 is Eventually Consistent Clients receive ack just when Server #1 is updatedClient A Client B Client A Client B Server #1 Server #2 (Leader+Owner) (Asynchronous) update-delay=x DB DB www.orientechnologies.com
  82. 82. Fail-over Server #1 logs changes while Server #2 is disconnected Transparent client switch to good servers (alpha status)Running transactions will be repeated transparently (v0.9.26)Client A Client B Client A Client B Server #1 Server #2 (Leader+Owner) (Asynchronous) Log changes DB DB www.orientechnologies.com
  83. 83. Mixed scenario Strict Consistency is acceptableUse Server #1 and #2 for cases whenUse Server #3 for cases when Eventually Consistency is acceptable Server #1 (Leader+Owner) Server #2 Server #3 (Synchronous) update-delay=0 (Asynchronous) DB DB DB www.orientechnologies.com
  84. 84. Partitioning Cluster level granularityPlace the “owner” close to the clients to reduce latencyServer main Server USA (Leader) Customers Customers Europe Asynchronous (update-delay=0) Europe (owner) Customers Customers Asynchronous (update-delay=0) USA USA (owner) www.orientechnologies.com
  85. 85. Real world scenario I Distribute data across multiple sites Play with sync/asynch+delay Keep synchronous copies close and propagate in asynch Customers Server Farm Europe USA Server China (Owner) CustomersCustomers Asia USA Server Main China Copy (Synchronous) Customers (Owner) Asynchronous EuropeCustomers Asia propagation Main CopyCustomers (Synchronous) Europe Customers Server USA USA (Owner) Customers Asia USA Copy (Synchronous) Customers Europe www.orientechnologies.com
  86. 86. Real world scenario II Put server nodes in chain Load-balance requests China EastServer Copy Read-only(Synchronous) China West Read-only Server China China North (Asynchronous) Read-onlyServer Main(Leader-Owner) Server USA USA South (Asynchronous) Read-only Canada Update European Customer: Read-only Propagate the change www.orientechnologies.com
  87. 87. Choose the best strategy for your use-caseServer Copy Client B (Synchronous) consistent reads, Client D delegated writes ev. consistent reads, no writes Server Main Server China China North(Leader-Owner) (Asynchronous) Read-only Client A Client Cconsistent reads, ev. consistent reads, direct writes delegates writes www.orientechnologies.com
  88. 88. Enhanced SQLSQL is not enough for collections, maps, trees and graphs need to enhance SQL syntax Easy syntax derived from JDO/JPA standards www.orientechnologies.com
  89. 89. SQL & relationshipsselect from Account where address.city.country.name = Italyselect from Account where addresses contains (city.country.name = Italy) www.orientechnologies.com
  90. 90. SQL & trees/graphsselect from Profile where friends traverse(0,7) ( sex = female ) (Soon new specific operators for trees and graphs) www.orientechnologies.com
  91. 91. SQL & stringsselect from Profile where name.toUpperCase() = LUCAselect from City where country.name.substring(1,3).toUpperCase() = TALselect from Agenda where phones contains ( number.indexOf( +39 ) > -1 )select from Agenda where email matches bA-Z0-9._%+-?+@A-Z0-9.-?+.A-Z?{2,4}b www.orientechnologies.com
  92. 92. SQL & conversionsselect from Shapes where area.toFloat() > 3.14select from Agenda where birthDate.toDateTime() > 1976-10-26 07:00:00select from Workflow where completed.toBoolean() = true www.orientechnologies.com
  93. 93. SQL & schema-lessselect from Profile where any() like %Jay%select from Stock where all() is not null www.orientechnologies.com
  94. 94. SQL & collectionsselect from Tree where children contains ( married = true )select from Tree where children containsAll ( married = true )select from User where roles containsKey shutdownselect from Graph where edges.size() > 0 www.orientechnologies.com
  95. 95. SQL & documentsselect from Vehicle where @class = Carselect from Friend where @version > 100select from File where @size > 1000000 www.orientechnologies.com
  96. 96. ConsoleORIENT database v.0.9.23 www.orientechnologies.comType help to display all the commands supported.> connect remote:localhost/demo admin adminConnecting to database [remote:localhost/demo] with user admin...OK> select from profile where nick.startsWith(L)---+--------+--------------------+--------------------+--------------------+ #| REC ID |NICK |SEX |AGE |---+--------+--------------------+--------------------+--------------------+ 0| 10:0|Lvca |male |34 1| 10:3|Leo |male |22 2| 10:7|Luisa |female |273 item(s) found. Query executed in 0.013 sec(s).> closeDisconnecting from the database [demo]...OK> quit www.orientechnologies.com
  97. 97. OrientDB Studio/SQL query Resultset is editable and changes are immediately persistent! www.orientechnologies.com
  98. 98. OrientDB Studio/db structure Physical structure of database www.orientechnologies.com
  99. 99. OrientDB Studio/server profiler Statistics and timing are collected in real-time www.orientechnologies.com
  100. 100. Always FreeOpen Source Apache 2 license free for any purposes, even commercials www.orientechnologies.com
  101. 101. Prof€$$ional $€rvic€$ by a network of companies through Orient Technologiessupport, training, consulting, mentoring www.orientechnologies.com
  102. 102. OrientDB OrientDBfor Java developers Master Development 8 hours 14 hours OrientDB OrientDB for SOA and the power of graphs 6 hours 6 hours OrientDB OrientPlanet for DBA for Web Developers 6 hours 6 hours www.orientechnologies.com
  103. 103. Certification Program to be part of the network do courses share revenues for support work as consultant Contactcommercial@orientechnologies.com www.orientechnologies.com
  104. 104. Luca Garulli Author of OrientDB and Roma <Meta> Framework Open Source projects, Member of JSR#12 (jdo 1.0) and JSR#243 (jdo 2.0) CTO at Asset Data and Orientwww.twitter.com/lgarulli Technologies @Rome, Italy Technical Manager at Romulus consortium www.orientechnologies.com