Your SlideShare is downloading. ×

OrientDB the database for the web 1.1


Published on

Rich description about OrientDB features

Rich description about OrientDB features

Published in: Technology
No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. www.orientechnologies.comThe database for the Web
  • 2. Why do I need another DBMS?
  • 3. But the question is:are DBMSs ready for the Web age?
  • 4. Web means: Hundreds of users today, thousands or millions tomorrow
  • 5. Web means: Idea → Demo in few weeks
  • 6. Web means: Fast and frequent changes of requirements and data structures
  • 7. Web means: + social + relationships + interconnections = graph
  • 8. Web means: Low usage of resources run on cheap hardware
  • 9. Web means: Speak HTTP, REST and JSON please
  • 10. Why is the database so importantin modern applications?
  • 11. Becausemodern applicationsare mostly I/O Bound not CPU bound
  • 12. NoSQL = “Not Only SQL”= make the best choice for your use case
  • 13. Can I trustnew DBMSs?
  • 14.
  • 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
  • 16. “NoSQL container” groups so very-very-very different products, no standard, difficult to choice, difficult to learn them
  • 17. Can I have aFast, scalable, flexible storagewith ACID Tx, SQL, Security easy to use and maintain?
  • 18. The fastest NoSQL document-graph dbms
  • 19. +12 years of research
  • 20. +1 yearof design and develop
  • 21. =best features of newest NoSQL solutions + best features of Relational DBMS + new ideas and concepts
  • 22. Ø config download, unzip, run! cut & paste the db
  • 23. No dependencies rd with 3 parties softwareno conflicts with other software just 1 Mb of run-time libraries
  • 24. 150,000 records per second
  • 25. Schema-less schema is not mandatory, relaxed model,collect heterogeneous documents all together
  • 26. Schema-fullschema with constraints on fields and validation rulesCustomer.age > 17Customer.address not nullCustomer.surname is matches b[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}b
  • 27. Schema-mixedschema with mandatory and optional fields + constraints the best of schema-less and schema-full modes
  • 28. ACID Transactionsdb.begin();try{ // your code ... db.commit();} catch( Exception e ) { db.rollback();}
  • 29. Complex types collections, maps (key/value)native support for and embedded documents no more additional tables to handle them
  • 30. Relationships are direct linksno Relational JOINS to connect multiple tables Load trees and graphs in few ms!
  • 31. SQLselect * from employee where name like %Jay% and status=0
  • 32. For the most of the querieseveryday a programmer needs SQL is simpler, more readable and compact then Scripting (Map/Reduce)
  • 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 };}
  • 34. Asynchronous Queryinvoke callback when a record matches the condition doesnt collect the result set perfect for immediate results useful to compute aggregates
  • 35. ®runs Java everywhere is available JRE1.5+ robust engine
  • 36. Language bindings Java as nativeJRuby, Scala and Javascript readyC, C++, Ruby, Node.js in progress
  • 37. Your language isnot supported (yet)? Write an adapter using the C, Java or HTTP binding
  • 38. HTTP RESTful firewall friendlyuse it from the webbrowser use it from the ESB (SOA)
  • 39. Native JSON{ @rid = 26:10, @class = Developer, name : Luca, surname : Garulli, company : 19:76}
  • 40. Import/Export uses JSON formatonline operations (dont stop the database)
  • 41. Binary protocolFast compressed JSON over tcp/ip available for Java and soon C, C++ and Ruby
  • 42. RB+Tree index the best of B+Tree and RB-Treefast on browsing, low insertion cost Its a new algorithm (soon public)
  • 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>
  • 44. Hooks similar to triggerscatch events against records, database and transactions implement custom cascade deletion algorithm enforce constraints
  • 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 ]
  • 46. Securityusers and roles, encrypted passwords fine grain privileges
  • 47. 4 storage modes embedded client/server distributed in-memory
  • 48. Embedded mode really fastruns in the same JVM of the application, less resources, no tcp/ip used
  • 49. Client/server modeclient and server are separated JVMsthousands of clients concurrently remote tcp/ip binary transport
  • 50. Distributed mode distribute database clusters onmultiple servers (in alpha status)
  • 51. In-memory modeDatabase lives only in memory No disk is used Destroyed at shutdown
  • 52. User API Document DatabaseKey/Value Database Graph Database Object Database
  • 53. Document Database the base of all DB implementations documents have dynamic structuresomething like a smart Map<String,Object>
  • 54. Open the databaseODatabaseDocumentTx db = new ODatabaseDocumentTx( "remote:localhost/demo" );"admin", "admin");try{ …} finally { Open the database demo db.close(); from a remote server}
  • 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") );;
  • 56. SQL QueryList<ODocument> result = db.query( new OSQLSynchQuery( "select * from person where = Rome" ) );for( ODocument d : result ) { System.out.println( "Person: " + d.field( "name" ) + d.field( "surname" ) );}
  • 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();
  • 58. Update a documentList<ODocument> result = db.query( new OSQLSynchQuery( "select * from person where = Rome"));for( ODocument d : result ) { d.field( "local", true );;}// ITS THE SAME OF:int changed = db.command( new OSQLCommand( "update person set local = true where = Rome")) .execute();
  • 59. Delete a documentList<ODocument> result = db.query( new OSQLSynchQuery( "select * from person where = Rome" ) );for( ODocument d : result ) { d.delete();// ITS THE SAME OF:int deleted = db.command( new OSQLCommand( "delete person where = Rome")).execute();
  • 60. from/to JSON// EXPORT JSONSystem.out.println( document.toJSON() );// IMPORT JSONdocument.fromJSON( “{ @class = Developer, name : Luca, surname : Garulli }” );;
  • 61. Use hooks (triggers)public class HookTest extends ORecordHookAbstract { public saveProfile(){ ODatabaseObjectTx database = new ODatabaseObjectTx("remote:localhost/demo");"writer", "writer"); database.registerHook(this); ... } @Override public void onRecordAfterCreate(ORecord<?> iRecord){ System.out.println("Record created successfully"); }}
  • 62. Key/Value Database bucket / key / value HTTP RESTful protocolHazelcast plug-in to distribute database
  • 63. Key/Value = RB+Treeworks mainly using RB+Tree custom indexes sort of Map<String,Map<String,Record>>
  • 64. Object Databasewrapper on top of Document Database binds POJO from/to the database no OR-Mapping complexity no enhancement, no Java Proxies
  • 65. POJO mappingUses the reflection to bind POJO fieldsat start-up caches reflection meta-data 1-to-1 binding configurable options by @annotations
  • 66. Open the databaseODatabaseObjectTx db = new ODatabaseObjectTx( "remote:localhost/demo" );"admin", "admin");try{ … Same usage of Document Database, but the class} finally { is different db.close();}
  • 67. Create a persistent POJOPerson person = new Person();person.setName( "Luke" ); Relationshipperson.setSurname( "Skywalker" );person.setCity( new City( "Rome" ) ); person );
  • 68. Polymorphics SQL QueryList<Person> result = database.query( new OSQLSynchQuery("select from person where = 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() );}
  • 69. Graph Database wrapper on top of Document DatabaseFew simple concepts: Vertex, Edge, Property and Index
  • 70. Example of a Graph
  • 71. TinkerPop technologies sort of “standard” for GraphDB a lot of free open-source projects
  • 72. TinkerPop Blueprintsbasic API to interact with GraphDB implements transactional and indexable property graph model bidirectional edges
  • 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();
  • 74. TinkerPop scripting language easy to learn and understandUsed for operations against graphs
  • 75. Graph example graph-example-1.xml
  • 76. Load graphRun the console, open the database and load a graph in xml formatmarko:~/software/gremlin$ ./ ,,,/ (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]
  • 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
  • 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
  • 79. High-AvailabilityCluster of distributed server nodes Synchronous, Asynchronous and Read-Only replicationLoad-balancing between client ↔ servers and Servers ↔ Servers
  • 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
  • 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
  • 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
  • 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
  • 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)
  • 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
  • 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
  • 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
  • 88. Enhanced SQLSQL is not enough for collections, maps, trees and graphs need to enhance SQL syntax Easy syntax derived from JDO/JPA standards
  • 89. SQL & relationshipsselect from Account where = Italyselect from Account where addresses contains ( = Italy)
  • 90. SQL & trees/graphsselect from Profile where friends traverse(0,7) ( sex = female ) (Soon new specific operators for trees and graphs)
  • 91. SQL & stringsselect from Profile where name.toUpperCase() = LUCAselect from City where,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
  • 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
  • 93. SQL & schema-lessselect from Profile where any() like %Jay%select from Stock where all() is not null
  • 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
  • 95. SQL & documentsselect from Vehicle where @class = Carselect from Friend where @version > 100select from File where @size > 1000000
  • 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
  • 97. OrientDB Studio/SQL query Resultset is editable and changes are immediately persistent!
  • 98. OrientDB Studio/db structure Physical structure of database
  • 99. OrientDB Studio/server profiler Statistics and timing are collected in real-time
  • 100. Always FreeOpen Source Apache 2 license free for any purposes, even commercials
  • 101. Prof€$$ional $€rvic€$ by a network of companies through Orient Technologiessupport, training, consulting, mentoring
  • 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
  • 103. Certification Program to be part of the network do courses share revenues for support work as consultant
  • 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 Technologies @Rome, Italy Technical Manager at Romulus consortium