Fastest way to empty a graph database?

38 views
Skip to first unread message

Konrad

unread,
Dec 16, 2010, 4:32:24 AM12/16/10
to OrientDB
Hi,

I'm wondering what is the fastest way of emptying a ODatabaseGraphTx
of all vertexes and edges?
(would be nice if schema still stays).

Actually deleting the database and re-creating it takes quite some
time (like 10 sec) (OrientDB deleting and creating a bunch of files on
disk).



Kind regards,
Konrad Eriksson
InfraSight Labs AB - Insight Into IT Infrastructure
Web: http://www.infrasightlabs.com

Luca Garulli

unread,
Dec 16, 2010, 4:38:56 AM12/16/10
to orient-database
Hi,
you could truncate an entire class in this way:

OClass cls = currentDatabase.getMetadata().getSchema().getClass("Vehicle");
cls.truncate();

If you're not using polymorphism against vertexes and edges type just:

currentDatabase.getMetadata().getSchema().getClass("OGraphVertex").truncate();
currentDatabase.getMetadata().getSchema().getClass("OGraphEdge").truncate();

For the number of files probably you've a lot of classes. You could use LOGICAL cluster instead of PHYSICAL (default): http://code.google.com/p/orient/wiki/Concepts#Cluster

Lvc@

Konrad

unread,
Dec 16, 2010, 4:47:17 AM12/16/10
to OrientDB
Does 'truncate' on a Schema class means that I remove all instances of
that class on the database?

I do use polymorphism, and I guess the truncate() does not handle
that?
Could I then just traverse the whole schema tree and truncate() each
class to empty the database?

I get around 500 files since I do use quite some schema classes, but
that is not a problem and if keeping them physical speeds it up I'll
keep it like that.
Only time it seems to affect me is when opening/closing/creating/
deleting the whole database, then it takes a couple of seconds for
each action.

/Konrad

On Dec 16, 10:38 am, Luca Garulli <l.garu...@gmail.com> wrote:
> Hi,
> you could truncate an entire class in this way:
>
> OClass cls = currentDatabase.getMetadata().getSchema().getClass("Vehicle");
> cls.truncate();
>
> If you're not using polymorphism against vertexes and edges type just:
>
> currentDatabase.getMetadata().getSchema().getClass("OGraphVertex").truncate();
> currentDatabase.getMetadata().getSchema().getClass("OGraphEdge").truncate();
>
> For the number of files probably you've a lot of classes. You could use
> LOGICAL cluster instead of PHYSICAL (default):http://code.google.com/p/orient/wiki/Concepts#Cluster
>
> Lvc@
>

Luca Garulli

unread,
Dec 16, 2010, 4:52:34 AM12/16/10
to orient-database
On 16 December 2010 10:47, Konrad <konrad....@gmail.com> wrote:
Does 'truncate' on a Schema class means that I remove all instances of
that class on the database?

Yes 


I do use polymorphism, and I guess the truncate() does not handle
that?

You need to truncate each class to avoid unexpected behaviour when you trunk a sub-class.
 
Could I then just traverse the whole schema tree and truncate() each
class to empty the database?

Yes

I get around 500 files since I do use quite some schema classes, but
that is not a problem and if keeping them physical speeds it up I'll
keep it like that.
Only time it seems to affect me is when opening/closing/creating/
deleting the whole database, then it takes a couple of seconds for
each action.

Perfect. Let me know if it's fast enough.

Lvc@

Konrad

unread,
Dec 16, 2010, 6:49:05 AM12/16/10
to OrientDB
Thanks for the suggestion about truncate() it works fast even with the
schema traversal (or at least much faster than a delete+create on the
whole DB).

Just a hint for people trying this path, make sure you don't truncate
OUser and ORole because then you will have problem opening the DB next
time (because of missing user).
When wanting to clear a whole graph DB the easiest way to avoid
truncating OUser and ORole is to check the inheritance of the OClass
to truncate by doing isSubClassOf("OGraphVertex") ||
isSubClassOf("OGraphEdge") (simplified code)


Regards,
Konrad

On Dec 16, 10:52 am, Luca Garulli <l.garu...@gmail.com> wrote:

Luca Garulli

unread,
Dec 16, 2010, 6:54:01 AM12/16/10
to orient-database
Great,
probably could be implemented in this way the OrietnGraph.clear() of Blueprints...

Lvc@

Academia Learning Centro de inglés y de formación

unread,
Nov 22, 2016, 3:25:00 AM11/22/16
to OrientDB
And if there are many classes, is there any way to do it through a for? Getting all kinds of classes and truncating?
Reply all
Reply to author
Forward
0 new messages