orientdb the database for the web 1.1

104
The database for the Web www.orientechnologies.com

Upload: luca-garulli

Post on 10-May-2015

11.612 views

Category:

Technology


1 download

DESCRIPTION

Rich description about OrientDB features

TRANSCRIPT

Page 1: OrientDB the database for the web 1.1

The database for the Web

www.orientechnologies.com

Page 2: OrientDB the database for the web 1.1

Why do I need anotherDBMS?

www.orientechnologies.com

Page 3: OrientDB the database for the web 1.1

But the question is:are DBMSs ready for

the Web age?

www.orientechnologies.com

Page 4: OrientDB the database for the web 1.1

Web means:Hundreds of users today,

thousands ormillions tomorrow

www.orientechnologies.com

Page 5: OrientDB the database for the web 1.1

Web means:Idea → Demo in few weeks

www.orientechnologies.com

Page 6: OrientDB the database for the web 1.1

Web means:Fast and frequent

changes of requirements anddata structures

www.orientechnologies.com

Page 7: OrientDB the database for the web 1.1

Web means:+ social + relationships

+ interconnections= graph

www.orientechnologies.com

Page 8: OrientDB the database for the web 1.1

Web means:Low usage of resourcesrun on cheap hardware

www.orientechnologies.com

Page 9: OrientDB the database for the web 1.1

Web means:Speak HTTP, REST and JSON

please

www.orientechnologies.com

Page 10: OrientDB the database for the web 1.1

Why is the databaseso important

in modern applications?

www.orientechnologies.com

Page 11: OrientDB the database for the web 1.1

Becausemodern applicationsare mostly I/O Bound

notCPU bound

www.orientechnologies.com

Page 12: OrientDB the database for the web 1.1

www.orientechnologies.com

NoSQL= “Not Only SQL”

= make the best choice for youruse case

Page 13: OrientDB the database for the web 1.1

Can I trustnew DBMSs?

www.orientechnologies.com

Page 14: OrientDB the database for the web 1.1

www.orientechnologies.com

Page 15: OrientDB the database for the web 1.1

www.orientechnologies.com

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

Page 16: OrientDB the database for the web 1.1

www.orientechnologies.com

“NoSQL container” groups sovery-very-verydifferent products,

no standard,difficult to choice,

difficult to learn them

Page 17: OrientDB the database for the web 1.1

www.orientechnologies.com

Can I have aFast, scalable, flexible

storagewith ACID Tx, SQL, Securityeasy to use and maintain?

Page 18: OrientDB the database for the web 1.1

www.orientechnologies.com

The fastest NoSQL document-graph dbms

Page 19: OrientDB the database for the web 1.1

+12 yearsof research

www.orientechnologies.com

Page 20: OrientDB the database for the web 1.1

+1 yearof design and develop

www.orientechnologies.com

Page 21: OrientDB the database for the web 1.1

=best features of newest NoSQL solutions

+best features of Relational DBMS

+new ideas and concepts

www.orientechnologies.com

Page 22: OrientDB the database for the web 1.1

Ø configdownload, unzip, run!

cut & paste the db

www.orientechnologies.com

Page 23: OrientDB the database for the web 1.1

No dependencieswith 3rd parties software

no conflicts with other softwarejust 1 Mb of run-time libraries

www.orientechnologies.com

Page 24: OrientDB the database for the web 1.1

150,000records per second

www.orientechnologies.com

Page 25: OrientDB the database for the web 1.1

Schema-lessschema is not mandatory, relaxed model,

collect heterogeneous documents all together

www.orientechnologies.com

Page 26: OrientDB the database for the web 1.1

Schema-fullschema with constraints on fields and validation rules

Customer.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

Page 27: OrientDB the database for the web 1.1

Schema-mixedschema with mandatory and optional fields + constraints

the best of schema-less and schema-full modes

www.orientechnologies.com

Page 28: OrientDB the database for the web 1.1

ACID Transactionsdb.begin();

try{ // your code ... db.commit();

} catch( Exception e ) { db.rollback();}

www.orientechnologies.com

Page 29: OrientDB the database for the web 1.1

Complex typesnative support for collections, maps (key/value)

and embedded documentsno more additional tables to handle them

www.orientechnologies.com

Page 30: OrientDB the database for the web 1.1

Relationshipsare direct links

no Relational JOINS to connect multiple tables

Load trees and graphs in few ms!

www.orientechnologies.com

Page 31: OrientDB the database for the web 1.1

SQLselect * from employee where name like '%Jay%' and status=0

www.orientechnologies.com

Page 32: OrientDB the database for the web 1.1

www.orientechnologies.com

For the most of the querieseveryday a programmer needs

SQL is simpler,more readable and

compact thenScripting (Map/Reduce)

Page 33: OrientDB the database for the web 1.1

www.orientechnologies.com

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 };}

Page 34: OrientDB the database for the web 1.1

Asynchronous Queryinvoke callback when a record matches the condition

doesn't collect the result setperfect for immediate results

useful to compute aggregates

www.orientechnologies.com

Page 35: OrientDB the database for the web 1.1

Java®

runs everywhere is available JRE1.5+robust engine

www.orientechnologies.com

Page 36: OrientDB the database for the web 1.1

Language bindingsJava as native

JRuby, Scala and Javascript readyC, C++, Ruby, Node.js in progress

www.orientechnologies.com

Page 37: OrientDB the database for the web 1.1

Your language isnot supported (yet)?

Write an adapter using theC, Java or HTTP binding

www.orientechnologies.com

Page 38: OrientDB the database for the web 1.1

HTTP RESTfulfirewall friendly

use it from the web browseruse it from the ESB (SOA)

www.orientechnologies.com

Page 39: OrientDB the database for the web 1.1

Native JSON{ '@rid' = '26:10', '@class' = 'Developer', 'name' : 'Luca', 'surname' : 'Garulli', 'company' : '19:76'}

www.orientechnologies.com

Page 40: OrientDB the database for the web 1.1

Import/Exportuses JSON format

online operations (don't stop the database)

www.orientechnologies.com

Page 41: OrientDB the database for the web 1.1

Binary protocolFast compressed JSON over tcp/ip

available for Javaand soon C, C++ and Ruby

www.orientechnologies.com

Page 42: OrientDB the database for the web 1.1

RB+Tree index

the best of B+Tree and RB-Treefast on browsing, low insertion costIt's a new algorithm (soon public)

www.orientechnologies.com

Page 43: OrientDB the database for the web 1.1

www.orientechnologies.com

Contactname : string

surname : string

OO InheritanceDefinition of Classes of documentsClasses can extend others classes

Queries are polymorphics

Customerorders : List<Order>

Providerproducts : List<Product>

Page 44: OrientDB the database for the web 1.1

Hookssimilar to triggers

catch events against records, database and transactionsimplement custom cascade deletion algorithm

enforce constraints

www.orientechnologies.com

Page 45: OrientDB the database for the web 1.1

Fetch plansChoose what to fetch on query and document loading

Documents not fetched will be lazy-loaded on request

Invoice 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

Page 46: OrientDB the database for the web 1.1

Securityusers and roles, encrypted passwords

fine grain privileges

www.orientechnologies.com

Page 47: OrientDB the database for the web 1.1

4 storage modesembedded

client/serverdistributedin-memory

www.orientechnologies.com

Page 48: OrientDB the database for the web 1.1

Embedded modereally fast

runs in the same JVM of the application,less resources, no tcp/ip used

www.orientechnologies.com

Page 49: OrientDB the database for the web 1.1

Client/server modeclient and server are separated JVMsthousands of clients concurrently

remote tcp/ip binary transport

www.orientechnologies.com

Page 50: OrientDB the database for the web 1.1

Distributed modedistribute database clusters on

multiple servers (in alpha status)

www.orientechnologies.com

Page 51: OrientDB the database for the web 1.1

In-memory modeDatabase lives only in memory

No disk is usedDestroyed at shutdown

www.orientechnologies.com

Page 52: OrientDB the database for the web 1.1

www.orientechnologies.com

Document Database

Key/Value Database Graph Database

Object Database

User API

Page 53: OrientDB the database for the web 1.1

Document Databasethe base of all DB implementationsdocuments have dynamic structure

something like a smart Map<String,Object>

www.orientechnologies.com

Page 54: OrientDB the database for the web 1.1

Open the databaseODatabaseDocumentTx db = new ODatabaseDocumentTx( "remote:localhost/demo" );

db.open("admin", "admin");

try{

} finally { db.close();}

www.orientechnologies.com

Open the database 'demo'from a remote server

Page 55: OrientDB the database for the web 1.1

Create a documentODocument doc = new ODocument( db, "Person" );

doc.field( "name", "Luke" );

doc.field( "surname", "Skywalker" );

doc.field( "city", new ODocument("City" ).fields("name","Rome") );

doc.save();

www.orientechnologies.com

Relationship

Page 56: OrientDB the database for the web 1.1

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

Page 57: OrientDB the database for the web 1.1

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

Page 58: OrientDB the database for the web 1.1

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();}

// IT'S THE SAME OF:int changed = db.command( new OSQLCommand( "update person set local = true where city.name = 'Rome'")) .execute();

www.orientechnologies.com

Page 59: OrientDB the database for the web 1.1

Delete a documentList<ODocument> result = db.query( new OSQLSynchQuery( "select * from person where city.name = 'Rome'" ) );

for( ODocument d : result ) { d.delete();

// IT'S THE SAME OF:int deleted = db.command( new OSQLCommand( "delete person where city.name = 'Rome'")).execute();

www.orientechnologies.com

Page 60: OrientDB the database for the web 1.1

from/to JSON // EXPORT JSONSystem.out.println( document.toJSON() );

// IMPORT JSONdocument.fromJSON( “{ '@class' = 'Developer', 'name' : 'Luca', 'surname' : 'Garulli' }” );document.save();

www.orientechnologies.com

Page 61: OrientDB the database for the web 1.1

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

Page 62: OrientDB the database for the web 1.1

Key/Value Databasebucket / key / value

HTTP RESTful protocolHazelcast plug-in to distribute database

www.orientechnologies.com

Page 63: OrientDB the database for the web 1.1

Key/Value = RB+Treeworks mainly using RB+Tree custom indexessort of Map<String,Map<String,Record>>

www.orientechnologies.com

Page 64: OrientDB the database for the web 1.1

Object Databasewrapper on top of Document Database

binds POJO from/to the databaseno OR-Mapping complexity

no enhancement, no Java Proxies

www.orientechnologies.com

Page 65: OrientDB the database for the web 1.1

POJO mappingUses the reflection to bind POJO fieldsat start-up caches reflection meta-data

1-to-1 bindingconfigurable options by @annotations

www.orientechnologies.com

Page 66: OrientDB the database for the web 1.1

Open the databaseODatabaseObjectTx db = new ODatabaseObjectTx( "remote:localhost/demo" );

db.open("admin", "admin");

try{

} finally { db.close();}

www.orientechnologies.com

Same usage of DocumentDatabase, but the class

is different

Page 67: OrientDB the database for the web 1.1

Create a persistent POJOPerson person = new Person();

person.setName( "Luke" );

person.setSurname( "Skywalker" );

person.setCity( new City( "Rome" ) ); db.save( person );

www.orientechnologies.com

Relationship

Page 68: OrientDB the database for the web 1.1

Polymorphics SQL QueryList<Person> result = database.query( new OSQLSynchQuery("select from person where city.name = 'Rome'"));

for( Person p : result ) { if( p instanceof Customer ) System.out.println("Customer: " + p.getName() + “ “ + p.getSurname() );}

www.orientechnologies.com

Queries are polymorphicsand subclasses of Person can be

part of result set

Page 69: OrientDB the database for the web 1.1

Graph Databasewrapper on top of Document Database

Few simple concepts: Vertex, Edge,Property and Index

www.orientechnologies.com

Page 70: OrientDB the database for the web 1.1

Example of a Graph

www.orientechnologies.com

Page 71: OrientDB the database for the web 1.1

TinkerPop technologiessort of “standard” for GraphDB

a lot of free open-source projects

http://tinkerpop.com

www.orientechnologies.com

Page 72: OrientDB the database for the web 1.1

TinkerPop Blueprintsbasic API to interact with GraphDB

implements transactional andindexable property graph model

bidirectional edges

www.orientechnologies.com

Page 73: OrientDB the database for the web 1.1

GraphDB & Blueprints API

OrientGraph 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

Page 74: OrientDB the database for the web 1.1

TinkerPop scripting language

easy to learn and understandUsed for operations against graphs

www.orientechnologies.com

Page 75: OrientDB the database for the web 1.1

www.orientechnologies.com

Graph examplegraph-example-1.xml

Page 76: OrientDB the database for the web 1.1

Load graph Run the console, open the database and load a graph in xml format

marko:~/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

Page 77: OrientDB the database for the web 1.1

SearchDisplays outgoing edges of vertices with name equals to 'marko',

then the name of inbound vertices

gremlin> 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

Page 78: OrientDB the database for the web 1.1

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 theobject, key/value and graph elements

and viceversa

www.orientechnologies.com

Page 79: OrientDB the database for the web 1.1

High-AvailabilityCluster of distributed server nodesSynchronous, Asynchronous and Read-Only

replicationLoad-balancing between client servers and↔

Servers Servers↔

www.orientechnologies.com

Page 80: OrientDB the database for the web 1.1

www.orientechnologies.com

Server #1(Leader+Owner)

Client A

Server #2(Synchronous)

DB DB

Client B Client A Client B

Synchronous scenarioServer #1 owns all the data, used for reads/writes

Server #2 is the backup replica, can be used for readsClients receive ack only when both are updated

Server #1 and #2 are Always Consistent

Page 81: OrientDB the database for the web 1.1

www.orientechnologies.com

Server #1(Leader+Owner)

Client A

Server #2(Asynchronous)

DB DB

Client B Client A Client B

Asynchronous scenarioAs for synchronous, but:

Server #2 is Eventually ConsistentClients receive ack just when Server #1 is updated

update-delay=x

Page 82: OrientDB the database for the web 1.1

www.orientechnologies.com

Server #1(Leader+Owner)

Client A

Server #2(Asynchronous)

DB DB

Client B Client A Client B

Fail-overServer #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)

Logchanges

Page 83: OrientDB the database for the web 1.1

www.orientechnologies.com

Server #2(Synchronous)

DB

DB

Mixed scenarioUse Server #1 and #2 for cases when Strict Consistency is acceptable

Use Server #3 for cases when Eventually Consistency is acceptable

Server #3(Asynchronous)

DB

update-delay=0

Server #1(Leader+Owner)

Page 84: OrientDB the database for the web 1.1

www.orientechnologies.com

CustomersUSA

(owner)

CustomersEurope

CustomersUSA

CustomersEurope(owner)

PartitioningCluster level granularity

Place the “owner” close to the clients to reduce latency

Asynchronous (update-delay=0)

Asynchronous (update-delay=0)

Server main(Leader)

Server USA

Page 85: OrientDB the database for the web 1.1

www.orientechnologies.com

Main Copy(Synchronous)

Real world scenario IDistribute data across multiple sites

Play with sync/asynch+delayKeep synchronous copies close and propagate in asynch

China Copy(Synchronous)

Server Main(Owner)

Server Farm Europe

USA Copy(Synchronous)

CustomersUSA

CustomersAsia

CustomersEurope

CustomersUSA

CustomersAsia

CustomersEurope

CustomersUSA

CustomersAsia

CustomersEurope

Server China(Owner)

Server USA(Owner)

Asynchronouspropagation

Page 86: OrientDB the database for the web 1.1

www.orientechnologies.com

Server Copy(Synchronous)

Real world scenario IIPut server nodes in chainLoad-balance requests

Server China(Asynchronous)

Server Main(Leader-Owner)

Server USA(Asynchronous)

China EastRead-only

China WestRead-only

China NorthRead-only

USA SouthRead-only

CanadaRead-onlyUpdate European Customer:

Propagate the change

Page 87: OrientDB the database for the web 1.1

www.orientechnologies.com

Server Copy(Synchronous)

Choose the best strategyfor your use-case

Server China(Asynchronous)

China NorthRead-only

Client Aconsistent reads,

direct writes

Client Bconsistent reads,delegated writes

Server Main(Leader-Owner)

Client Dev. consistent reads,

no writes

Client Cev. consistent reads,

delegates writes

Page 88: OrientDB the database for the web 1.1

Enhanced SQLSQL is not enough for collections, maps, trees and graphs

need to enhance SQL syntaxEasy syntax derived from JDO/JPA standards

www.orientechnologies.com

Page 89: OrientDB the database for the web 1.1

SQL & relationshipsselect from Account where address.city.country.name = 'Italy'

select from Account where addresses contains (city.country.name = 'Italy')

www.orientechnologies.com

Page 90: OrientDB the database for the web 1.1

SQL & trees/graphsselect from Profile where friends traverse(0,7) ( sex = 'female' )

(Soon new specific operators for trees and graphs)

www.orientechnologies.com

Page 91: OrientDB the database for the web 1.1

SQL & stringsselect from Profile where name.toUpperCase() = 'LUCA'

select from City where country.name.substring(1,3).toUpperCase() = 'TAL'

select from Agenda where phones contains ( number.indexOf( '+39' ) > -1 )

select from Agenda where email matches '\bA-Z0-9._%[email protected]?+\.A-Z?{2,4}\b'

www.orientechnologies.com

Page 92: OrientDB the database for the web 1.1

SQL & conversionsselect from Shapes where area.toFloat() > 3.14

select from Agenda where birthDate.toDateTime() > '1976-10-26 07:00:00'

select from Workflow where completed.toBoolean() = true

www.orientechnologies.com

Page 93: OrientDB the database for the web 1.1

SQL & schema-lessselect from Profile where any() like '%Jay%'

select from Stock where all() is not null

www.orientechnologies.com

Page 94: OrientDB the database for the web 1.1

SQL & collectionsselect from Tree where children contains ( married = true )

select from Tree where children containsAll ( married = true )

select from User where roles containsKey 'shutdown'

select from Graph where edges.size() > 0

www.orientechnologies.com

Page 95: OrientDB the database for the web 1.1

SQL & documentsselect from Vehicle where @class = 'Car'

select from Friend where @version > 100

select from File where @size > 1000000

www.orientechnologies.com

Page 96: OrientDB the database for the web 1.1

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

> quitwww.orientechnologies.com

Page 97: OrientDB the database for the web 1.1

OrientDB Studio/SQL query

www.orientechnologies.com

Resultset is editable andchanges are immediately

persistent!

Page 98: OrientDB the database for the web 1.1

OrientDB Studio/db structure

www.orientechnologies.com

Physical structureof database

Page 99: OrientDB the database for the web 1.1

OrientDB Studio/server profiler

www.orientechnologies.com

Statistics and timing arecollected in real-time

Page 100: OrientDB the database for the web 1.1

Always FreeOpen Source Apache 2 license

free for any purposes,even commercials

www.orientechnologies.com

Page 101: OrientDB the database for the web 1.1

Prof€$$ional$€rvic€$

by a network of companies throughOrient Technologies

support, training, consulting, mentoring

www.orientechnologies.com

Page 102: OrientDB the database for the web 1.1

www.orientechnologies.com

OrientDBfor Java developers

8 hours

OrientDBMaster Development

14 hours

OrientDBfor SOA

6 hours

OrientDBand the power of graphs

6 hours

OrientDBfor DBA

6 hours

OrientPlanetfor Web Developers

6 hours

Page 103: OrientDB the database for the web 1.1

Certification Programto be part of the network

do coursesshare revenues for support

work as consultant

www.orientechnologies.com

[email protected]

Page 104: OrientDB the database for the web 1.1

Luca GarulliAuthor of OrientDB and

Roma <Meta> FrameworkOpen Source projects,

Member of JSR#12 (jdo 1.0) and JSR#243 (jdo 2.0)

CTO at Asset Data and Orient Technologies

Technical Manager atRomulus consortium

www.orientechnologies.com

www.twitter.com/lgarulli@Rome, Italy