Skip to content
lvca edited this page Dec 30, 2012 · 15 revisions

Previous : Tutorial: Classes - Next: Tutorial: RecordID

Even though we talked about classes, this is a logical concept in OrientDB. The records are stored in cluster.

What is a cluster?

The cluster is a place where are stored a group of records. The equivalent of the relational world would be a Table, but a cluster can also record heterogeneous records, for example Customers and Providers all together. Or again the "new Orders received today". But by default we have one cluster per class. All the records of a class go in the same cluster with the same name of the class.

Understanding the concepts of class and clusters at the very beginning allows you to use the power of clusters at first stage while you're designing your new database.

Even though by default one class = one cluster, a class can relies on multiple clusters. Why? This is because you can spawn records physically in multiple places. Example:

Class-Custer

The class "Customer" relies on 2 clusters:

  • USA_customers, containing all USA customers. This is the default one (look at the red star *)
  • China_customers, containing all USA customers

The default cluster, in this case USA_customers, is used by default when the generic class "Customer" is used. Example:

Class-Custer

When query the "Customer" class, all the involved clusters are scanned:

Class-Custer

But if you know the type of customer you're looking for you can query directly the target cluster avoiding to scan all the others:

Class-Custer

The pros of using different physical places to store records are:

  • faster queries against clusters because are a sub-set of all the class's clusters
  • good partitioning allow to reduce/remove usage of indexes
  • parallel queries if on multiple disks

There are three types of clusters:

  • Physical cluster (or local), which is persistent because writes directly to the file system,
  • Memory Cluster where everything is volatile, and therefore will be lost to the termination of the process or the server if the database is remote

For the most cases the physical clusters are preferred because a database must be persistent. The good news is that by default OrientDB creates physical clusters, so for now don't worry too much about it.

To view all clusters from clusters console run the cluster command:

orientdb> clusters

CLUSTERS:
----------------------------------------------+------+---------------------+-----------+
 NAME                                         |  ID  | TYPE                | RECORDS   |
----------------------------------------------+------+---------------------+-----------+
 account                                      |    11| PHYSICAL            |      1107 |
 actor                                        |    91| PHYSICAL            |         3 |
 address                                      |    19| PHYSICAL            |       166 |
 animal                                       |    17| PHYSICAL            |         0 |
 animalrace                                   |    16| PHYSICAL            |         2 |
 ....                                         |  ....| ....                |      .... |
----------------------------------------------+------+---------------------+-----------+
 TOTAL                                                                           23481 |
---------------------------------------------------------------------------------------+

Since by default each class has own cluster we can query database's users by class or by cluster:

orientdb> browse cluster OUser

---+---------+--------------------+--------------------+--------------------+--------------------
  #| RID     |name                |password            |status              |roles               
---+---------+--------------------+--------------------+--------------------+--------------------
  0|     #5:0|admin               |{SHA-256}8C6976E5B5410415BDE908BD4DEE15DFB167A9C873FC4BB8A81F6F2AB448A918|ACTIVE              |[1]                 
  1|     #5:1|reader              |{SHA-256}3D0941964AA3EBDCB00CCEF58B1BB399F9F898465E9886D5AEC7F31090A0FB30|ACTIVE              |[1]                 
  2|     #5:2|writer              |{SHA-256}B93006774CBDD4B299389A03AC3D88C3A76B460D538795BC12718011A909FBA5|ACTIVE              |[1]                 
---+---------+--------------------+--------------------+--------------------+--------------------

The result is identical to "browse class ouser" executed before.

Previous : Tutorial: Classes - Next: Tutorial: RecordID

Clone this wiki locally