2016-03-02 48 views
1

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(); 
但是

,但這並沒有工作。我試圖通過工作室來修改類的選擇,它不起作用。

我如何能做到這一點,你可以給我一個例子,非常感謝你

回答

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();