学习
eX
tremeDB之余,用Cluster API写了一段测试代码。对于Cluster中的每一个node都有一个唯一的node id,而node id的值通过cluster node IP与本机IP的比较来获得。代码如下:
-
const char* NodesAddr[NODES_NUM] = {"192.168.1.1",
-
"192.168.1.2",
-
"192.168.1.3",
-
"192.168.1.4"};
-
-
const char* NodesPort[NODES_NUM] = {"20000","20000","20000","20000"};
-
-
.......
-
-
/* according to ip address to set node id */
-
gethostname(host_name,sizeof(host_name));
-
ht = gethostbyname(host_name);
-
if(NULL != ht)
-
{
-
mco_memcpy(host_addr,inet_ntoa (*(struct in_addr *)*ht->h_addr_list),sizeof(host_addr));
-
}
-
-
for (i = 0; i < NODES_NUM; ++i) {
-
if (mco_memcmp(host_addr,NodesAddr[i],sizeof(NodesAddr[i]))) {
-
cl_params.node_id = i;
-
}
-
}
阅读(1193) | 评论(0) | 转发(0) |