Exemplo n.º 1
0
int tapioca_init(const char* tconfig, const char* pconfig) {
	struct timeval now;

	tapioca_init_defaults();
	
	tapioca_config = tconfig;
	paxos_config = pconfig;
	
	lp_config = evpaxos_config_read(paxos_config);
	
	signal(SIGINT, sigint);
	signal(SIGSEGV, sigint);
	//signal(SIGKILL, sigint); // bad!! 
	signal(SIGTERM, sigint);
	signal(SIGPIPE, SIG_IGN);

	gettimeofday(&now, NULL);
    srandom(now.tv_usec);
	
	#ifndef linux
	setenv("EVENT_NOPOLL", "1", 1);
	setenv("EVENT_NOKQUEUE", "1", 1);
	#endif
	
	load_config_file(tapioca_config);
    
	base = event_init();
	// Set two possible priorities: 0 and 1.
	// event_base_priority_init(base, 2);
	
	return 0;
}
Exemplo n.º 2
0
/*建立一个proposer对象,并启动它*/
struct evproposer* evproposer_init(int id, const char* config, struct event_base* b)
{
	int port, acceptor_count;
	struct evproposer* p;

	/*读取配置文件*/
	struct evpaxos_config* conf = evpaxos_config_read(config);
	if(conf == NULL)
		return NULL;

	/*非法的proposer id*/
	if (id < 0 || id >= MAX_N_OF_PROPOSERS) {
		paxos_log_error("Invalid proposer id: %d", id);
		return NULL;
	}

	/*读取proposer的监听端口*/
	port = evpaxos_proposer_listen_port(conf, id);
	/*读取acceptor的数量*/
	acceptor_count = evpaxos_acceptor_count(conf);

	p = (struct evproposer *)malloc(sizeof(struct evproposer));
	p->id = id;
	p->base = b;

	/*获得同时提交的议案数量*/
	p->preexec_window = paxos_config.proposer_preexec_window;
	
	/*产生一个网络消息接收器*/
	p->receiver = tcp_receiver_new(b, port, handle_request, p);
	
	/*产生一个acceptor的管理器*/
	p->acceptors = peers_new(b);
	/*对每个acceptor发起连接*/
	peers_connect_to_acceptors(p->acceptors, conf, handle_request, p);
	
	/*设置定时器*/
	p->tv.tv_sec = paxos_config.proposer_timeout;
	p->tv.tv_usec = 0;
	/*产生一个libevent定时器事件对象,并设置一个定时器*/
	p->timeout_ev = evtimer_new(b, proposer_check_timeouts, p);
	event_add(p->timeout_ev, &p->tv);

	/*产生一个proposer 消息处理器*/
	p->state = proposer_new(p->id, acceptor_count);

	/*试探性执行prepare过程(提案第一阶段)*/
	proposer_preexecute(p);

	evpaxos_config_free(conf);

	return p;
}