orientdb clusterselection,我如何平均分配每个节点中的记录

时间:2016-03-02 03:27:05

标签: orientdb

Orientdb verson 2.1.11。

我有3个节点,我想平均分配每个节点的记录,我的代码是:

ODatabase database = new DatabaseDocumentTx("remote:node1;node2;node3/mydb").open("root", "1234");

System.out.println("selection:" + database.get(ODatabase.ATTRIBUTES.CLUSTERSELECTION));

database.command(new OCommandSQL("alter class Person clusterSelection round-robin"));

System.out.println("selection:" + database.get(ODatabase.ATTRIBUTES.CLUSTERSELECTION));

for (int i = 0; i < 100; ++i) {
    ODocument document = new ODocument("Person");
    document.field("name", "pengtao.geng" + i);
    document.field("age", 28 + i);

    document.save();
    System.out.println("save " + i);
}
database.close();
然而,它确实无效。我尝试通过工作室修改类clusterelection,它也不起作用。

我怎么能这样做,你能举个例子,非常感谢

1 个答案:

答案 0 :(得分:0)

在v2.2中,OrientDB支持负载均衡:http://orientdb.com/docs/2.1/Distributed-Configuration.html#load-balancing。您可以对此代码使用ROUND_ROBIN_REQUEST策略(服务器必须位于群集中):

ODatabase database = new DatabaseDocumentTx("remote:node1;node2;node3/mydb").open("root", "1234");

db.setProperty(OStorageRemote.PARAM_CONNECTION_STRATEGY, OStorageRemote.CONNECTION_STRATEGY.ROUND_ROBIN_REQUEST);

for (int i = 0; i < 100; ++i) {
    ODocument document = new ODocument("Person");
    document.field("name", "pengtao.geng" + i);
    document.field("age", 28 + i);

    document.save();
    System.out.println("save " + i);
}
database.close();