Upload
luca-garulli
View
11.607
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Rich description about OrientDB features
Citation preview
The database for the Web
www.orientechnologies.com
Why do I need anotherDBMS?
www.orientechnologies.com
But the question is:are DBMSs ready for
the Web age?
www.orientechnologies.com
Web means:Hundreds of users today,
thousands ormillions tomorrow
www.orientechnologies.com
Web means:Idea → Demo in few weeks
www.orientechnologies.com
Web means:Fast and frequent
changes of requirements anddata structures
www.orientechnologies.com
Web means:+ social + relationships
+ interconnections= graph
www.orientechnologies.com
Web means:Low usage of resourcesrun on cheap hardware
www.orientechnologies.com
Web means:Speak HTTP, REST and JSON
please
www.orientechnologies.com
Why is the databaseso important
in modern applications?
www.orientechnologies.com
Becausemodern applicationsare mostly I/O Bound
notCPU bound
www.orientechnologies.com
www.orientechnologies.com
NoSQL= “Not Only SQL”
= make the best choice for youruse case
Can I trustnew DBMSs?
www.orientechnologies.com
www.orientechnologies.com
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
www.orientechnologies.com
“NoSQL container” groups sovery-very-verydifferent products,
no standard,difficult to choice,
difficult to learn them
www.orientechnologies.com
Can I have aFast, scalable, flexible
storagewith ACID Tx, SQL, Securityeasy to use and maintain?
www.orientechnologies.com
The fastest NoSQL document-graph dbms
+12 yearsof research
www.orientechnologies.com
+1 yearof design and develop
www.orientechnologies.com
=best features of newest NoSQL solutions
+best features of Relational DBMS
+new ideas and concepts
www.orientechnologies.com
Ø configdownload, unzip, run!
cut & paste the db
www.orientechnologies.com
No dependencieswith 3rd parties software
no conflicts with other softwarejust 1 Mb of run-time libraries
www.orientechnologies.com
150,000records per second
www.orientechnologies.com
Schema-lessschema is not mandatory, relaxed model,
collect heterogeneous documents all together
www.orientechnologies.com
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
Schema-mixedschema with mandatory and optional fields + constraints
the best of schema-less and schema-full modes
www.orientechnologies.com
ACID Transactionsdb.begin();
try{ // your code ... db.commit();
} catch( Exception e ) { db.rollback();}
www.orientechnologies.com
Complex typesnative support for collections, maps (key/value)
and embedded documentsno more additional tables to handle them
www.orientechnologies.com
Relationshipsare direct links
no Relational JOINS to connect multiple tables
Load trees and graphs in few ms!
www.orientechnologies.com
SQLselect * from employee where name like '%Jay%' and status=0
www.orientechnologies.com
www.orientechnologies.com
For the most of the querieseveryday a programmer needs
SQL is simpler,more readable and
compact thenScripting (Map/Reduce)
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 };}
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
Java®
runs everywhere is available JRE1.5+robust engine
www.orientechnologies.com
Language bindingsJava as native
JRuby, Scala and Javascript readyC, C++, Ruby, Node.js in progress
www.orientechnologies.com
Your language isnot supported (yet)?
Write an adapter using theC, Java or HTTP binding
www.orientechnologies.com
HTTP RESTfulfirewall friendly
use it from the web browseruse it from the ESB (SOA)
www.orientechnologies.com
Native JSON{ '@rid' = '26:10', '@class' = 'Developer', 'name' : 'Luca', 'surname' : 'Garulli', 'company' : '19:76'}
www.orientechnologies.com
Import/Exportuses JSON format
online operations (don't stop the database)
www.orientechnologies.com
Binary protocolFast compressed JSON over tcp/ip
available for Javaand soon C, C++ and Ruby
www.orientechnologies.com
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
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>
Hookssimilar to triggers
catch events against records, database and transactionsimplement custom cascade deletion algorithm
enforce constraints
www.orientechnologies.com
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
Securityusers and roles, encrypted passwords
fine grain privileges
www.orientechnologies.com
4 storage modesembedded
client/serverdistributedin-memory
www.orientechnologies.com
Embedded modereally fast
runs in the same JVM of the application,less resources, no tcp/ip used
www.orientechnologies.com
Client/server modeclient and server are separated JVMsthousands of clients concurrently
remote tcp/ip binary transport
www.orientechnologies.com
Distributed modedistribute database clusters on
multiple servers (in alpha status)
www.orientechnologies.com
In-memory modeDatabase lives only in memory
No disk is usedDestroyed at shutdown
www.orientechnologies.com
www.orientechnologies.com
Document Database
Key/Value Database Graph Database
Object Database
User API
Document Databasethe base of all DB implementationsdocuments have dynamic structure
something like a smart Map<String,Object>
www.orientechnologies.com
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
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
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
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
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
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
from/to JSON // EXPORT JSONSystem.out.println( document.toJSON() );
// IMPORT JSONdocument.fromJSON( “{ '@class' = 'Developer', 'name' : 'Luca', 'surname' : 'Garulli' }” );document.save();
www.orientechnologies.com
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
Key/Value Databasebucket / key / value
HTTP RESTful protocolHazelcast plug-in to distribute database
www.orientechnologies.com
Key/Value = RB+Treeworks mainly using RB+Tree custom indexessort of Map<String,Map<String,Record>>
www.orientechnologies.com
Object Databasewrapper on top of Document Database
binds POJO from/to the databaseno OR-Mapping complexity
no enhancement, no Java Proxies
www.orientechnologies.com
POJO mappingUses the reflection to bind POJO fieldsat start-up caches reflection meta-data
1-to-1 bindingconfigurable options by @annotations
www.orientechnologies.com
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
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
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
Graph Databasewrapper on top of Document Database
Few simple concepts: Vertex, Edge,Property and Index
www.orientechnologies.com
Example of a Graph
www.orientechnologies.com
TinkerPop technologiessort of “standard” for GraphDB
a lot of free open-source projects
http://tinkerpop.com
www.orientechnologies.com
TinkerPop Blueprintsbasic API to interact with GraphDB
implements transactional andindexable property graph model
bidirectional edges
www.orientechnologies.com
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
TinkerPop scripting language
easy to learn and understandUsed for operations against graphs
www.orientechnologies.com
www.orientechnologies.com
Graph examplegraph-example-1.xml
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
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
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
High-AvailabilityCluster of distributed server nodesSynchronous, Asynchronous and Read-Only
replicationLoad-balancing between client servers and↔
Servers Servers↔
www.orientechnologies.com
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
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
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
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)
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
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
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
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
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
SQL & relationshipsselect from Account where address.city.country.name = 'Italy'
select from Account where addresses contains (city.country.name = 'Italy')
www.orientechnologies.com
SQL & trees/graphsselect from Profile where friends traverse(0,7) ( sex = 'female' )
(Soon new specific operators for trees and graphs)
www.orientechnologies.com
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
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
SQL & schema-lessselect from Profile where any() like '%Jay%'
select from Stock where all() is not null
www.orientechnologies.com
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
SQL & documentsselect from Vehicle where @class = 'Car'
select from Friend where @version > 100
select from File where @size > 1000000
www.orientechnologies.com
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
OrientDB Studio/SQL query
www.orientechnologies.com
Resultset is editable andchanges are immediately
persistent!
OrientDB Studio/db structure
www.orientechnologies.com
Physical structureof database
OrientDB Studio/server profiler
www.orientechnologies.com
Statistics and timing arecollected in real-time
Always FreeOpen Source Apache 2 license
free for any purposes,even commercials
www.orientechnologies.com
Prof€$$ional$€rvic€$
by a network of companies throughOrient Technologies
support, training, consulting, mentoring
www.orientechnologies.com
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
Certification Programto be part of the network
do coursesshare revenues for support
work as consultant
www.orientechnologies.com
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