在分布式模式下通过Rest Call OrientDB保存到正确的集群

时间:2017-01-06 14:51:48

标签: rest orientdb

我将数据保存到OrientDB到特定群集。喜欢这个

CREATE VERTEX <Class> CLUSTER <Cluster> SET ect...

然后我通过REST调用查询特定的集群来获取数据。这在独立模式下工作正常,但在分布式模式下它不会,因为我可能正在尝试将数据保存到不是该集群所有者的节点。有没有办法自动将REST调用发送到正确的节点?

如果没有,我如何查询数据库以查看哪些节点拥有各个群集,以便我可以编写一些逻辑来向正确的节点发送请求?

我正在使用OrientDB 2.2.0

1 个答案:

答案 0 :(得分:0)

在具有2个节点的分布式2.2.13上,我已将类的集群选择策略更改为默认值;然后你可以创建顶点

    orientdb {db=GratefulDeadConcerts}> alter class written_by CLUSTERSELECTION default
    orientdb {db=GratefulDeadConcerts}> select name,defaultClusterId,clusterIds,clusterSelection from ( select expand(classes) from metadata:schema ) where clusterSelection="default"
    +----+----------+----------------+-------------------------+----------------+
    |#   |name      |defaultClusterId|clusterIds               |clusterSelection|
    +----+----------+----------------+-------------------------+----------------+
    |0   |written_by|33              |[33,34,35,36,37,38,39,40]|default         |
    +----+----------+----------------+-------------------------+----------------+
查询也适用于Postman

    localhost:2480/command/GratefulDeadConcerts/sql/select name,defaultClusterId,clusterIds,clusterSelection from ( select expand(classes) from metadata:schema ) where clusterSelection="default" 
    localhost:2481/command/GratefulDeadConcerts/sql/select name,defaultClusterId,clusterIds,clusterSelection from ( select expand(classes) from metadata:schema ) where clusterSelection="default" 

请查看有关课程集群策略的文档 http://orientdb.com/docs/2.2/SQL-Create-Class.html
http://orientdb.com/docs/2.2/SQL-Alter-Class.html
http://orientdb.com/docs/2.2/SQL-Create-Vertex.html

一个例子:

    orientdb {db=GratefulDeadConcerts}> CREATE CLASS V1 EXTENDS V 
    Class created successfully. Total classes in database now: 14.

    orientdb {db=GratefulDeadConcerts}> select name,defaultClusterId,clusterIds,clusterSelection from ( select expand(classes) from metadata:schema ) where name="V1"
    +----+----+----------------+-------------------------+----------------+
    |#   |name|defaultClusterId|clusterIds               |clusterSelection|
    +----+----+----------------+-------------------------+----------------+
    |0   |V1  |54              |[54,55,56,57,58,59,60,61]|round-robin     |
    +----+----+----------------+-------------------------+----------------+

    orientdb {db=GratefulDeadConcerts}> alter class V1 CLUSTERSELECTION default        
    Class updated successfully.

    orientdb {db=GratefulDeadConcerts}> info class V1
    CLASS 'V1'
    Records..............: 0
    Super classes........: [V]
    Default cluster......: v1 (id=54)
    Supported clusters...: v1(54), v1_1(55), v1_2(56), v1_3(57), v1_4(58), v1_5(59), v1_6(60), v1_7(61)
    Cluster selection....: default
    Oversize.............: 0.0

    orientdb {db=GratefulDeadConcerts}> CREATE VERTEX V1 CLUSTER V1  set name="me" , type="artist"
    Created vertex 'V1#54:0{name:me,type:artist} v1' in 0.017000 sec(s).

    orientdb {db=GratefulDeadConcerts}> select * from V1
    +----+-----+------+----+------+
    |#   |@RID |@CLASS|name|type  |
    +----+-----+------+----+------+
    |0   |#54:0|V1    |me  |artist|
    +----+-----+------+----+------+