运行以上代码后的结果是:
The replica groups are SYSCatalogGroup, datagroup, testRG, There are 3 replica groups in total. Removing the old replica group... The replica groups are SYSCatalogGroup, datagroup, There are 2 replica groups in total. Adding the new replica group... The replica groups are SYSCatalogGroup, datagroup, testRG, There are 3 replica groups in total. Tere are 0 nodes in the group. starting the node 50000... starting the node 50010... starting the node 50020... Tere are 3 nodes in the group. The master node is 50000 The slave node is 50010 stoping the master node... re-selecting the master node... The master node is 50020可以看出,程序开始运行时,数据库内有三个复制组,其中testRG是上次运行遗留下来的无用复制组,另外两个是数据库默认的两个复制组。通过removeReplicaGroup()方法删除多余的testRG复制组,之后通过createReplicaGroup()添加新的testRG复制组,并且在新建的组内通过createNode()和start()添加并启动50000,50010,50020三个新的节点。通过getMaster()和getSlave()方法获取组内的主从节点,并利用stop()停止主节点50000,主节点完全停止后,组内将重新自动选举出新的主节点50020。
运行完成后,通过shell控制台查看数据库testRG复制组的详细情况:
>rg.getDetail()
{
"Group": [
{
"HostName": "sdbserver1",
"dbpath": "/opt/sequoiadb/database/test/50000",
"Service": [
{
"Type": 0,
"Name": "50000"
},
{
"Type": 1,
"Name": "50001"
},
{
"Type": 2,
"Name": "50002"
}
],
"NodeID": 1053
},
{
"HostName": "sdbserver1",
"dbpath": "/opt/sequoiadb/database/test/50010",
"Service": [
{
"Type": 0,
"Name": "50010"
},
{
"Type": 1,
"Name": "50011"
},
{
"Type": 2,
"Name": "50012"
}
],
"NodeID": 1054
},
{
"HostName": "sdbserver1",
"dbpath": "/opt/sequoiadb/database/test/50020",
"Service": [
{
"Type": 0,
"Name": "50020"
},
{
"Type": 1,
"Name": "50021"
},
{
"Type": 2,
"Name": "50022"
}
],
"NodeID": 1055
}
],
"GroupID": 1023,
"GroupName": "testRG",
"PrimaryNode": 1055,
"Role": 0,
"Status": 0,
"Version": 4,
"_id": {
"$oid": "53d9d38e14a63a88c621edd8"
}
}
Return 1 row(s).
Takes 0.4716s. 可以看出组内有三个节点,主节点(PrimaryNode)为1055,也就是50020。