orientdb clusterselection,我如何在每个节点平均分配我的记录
问题描述:
Orientdb verson 2.1.11。orientdb clusterselection,我如何在每个节点平均分配我的记录
我有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();
但是
,但这并没有工作。我试图通过工作室来修改类的选择,它不起作用。
我如何能做到这一点,你可以给我一个例子,非常感谢你
答
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();