Exemplo n.º 1
0
/* register and load cluster nodes */
cluster_t * register_and_load_cluster_nodes(char *addr, int port)
{
    int i;
    int DataNum = -1;
    char Buf[MAX_BUF_LEN] = "\0";
    int BufSize = MAX_BUF_LEN;
    char szMsg[MAX_BUF_LEN] = "\0";
    char ppData[MAX_DATA_NUM][MAX_DATA_LEN] = {0};
    ServiceHandler h = -1;
    // master server's addr and port
    h = open_remote_service(IP_ADDR,PORT);

    if(addr == NULL)
    {
        DataNum = 0;
    }
    else
    {
        DataNum = 1;
        sprintf(ppData[0],"%s %d\0",addr,port);
        debug("pasrer sprintf :%s\n",ppData[0]);     
    }

    format_ctl_data(Buf,&BufSize,CTL_REG_CMD,ppData,DataNum);
    send_data(h,Buf,BufSize);
    receive_data(h,Buf,&BufSize);
    int cmd = -1;
    parse_ctl_data(Buf,BufSize,&cmd,&DataNum,ppData);
    cluster_t *cluster = init_cluster();
    add_cluster_nodes(cluster, ppData, DataNum);
    close_remote_service(h);
    return cluster;
}
Exemplo n.º 2
0
/*
 * init_all
 *
 * Initialize modules.  Exit on failure.
 */
static void init_all(void)
{
	int r;

	if ((r = init_local()) ||
	    (r = init_cluster())) {
		exit(r);
	}
}
Exemplo n.º 3
0
int create_cluster(char *addr, int port)
{
    cluster_nodes_g = init_cluster();
    add_node(cluster_nodes_g, addr, port);
    return 0;
}