示例#1
0
文件: slave.cpp 项目: chenld/ssdb
int Slave::proc(const std::vector<Bytes> &req){
	Binlog log;
	if(log.load(req[0].Slice()) == -1){
		log_error("invalid binlog!");
		return 0;
	}
	if(log.type() != BinlogType::NOOP){
		if(this->is_mirror){
			log_debug("[mirror] %s", log.dumps().c_str());
		}else{
			log_debug("[sync] %s", log.dumps().c_str());
		}
	}
	switch(log.type()){
		case BinlogType::NOOP:
			return this->proc_noop(log, req);
			break;
		case BinlogType::COPY:
			return this->proc_copy(log, req);
			break;
		case BinlogType::SYNC:
		case BinlogType::MIRROR:
			return this->proc_sync(log, req);
			break;
		default:
			break;
	}
	return 0;
}
示例#2
0
文件: slave.cpp 项目: 1514louluo/ssdb
int Slave::proc(const std::vector<Bytes> &req){
	Binlog log;
	if(log.load(req[0].Slice()) == -1){
		log_error("invalid binlog!");
		return 0;
	}
	const char *sync_type = this->is_mirror? "mirror" : "sync";
	switch(log.type()){
		case BinlogType::NOOP:
			return this->proc_noop(log, req);
			break;
		case BinlogType::COPY:{
			if(++copy_count % 1000 == 1){
				log_info("copy_count: %" PRIu64 ", last_seq: %" PRIu64 ", seq: %" PRIu64 "",
					copy_count, this->last_seq, log.seq());
			}
			if(req.size() >= 2){
				log_debug("[%s] %s [%d]", sync_type, log.dumps().c_str(), req[1].size());
			}else{
				log_debug("[%s] %s", sync_type, log.dumps().c_str());
			}
			this->proc_copy(log, req);
			break;
		}
		case BinlogType::SYNC:
		case BinlogType::MIRROR:{
			if(++sync_count % 1000 == 1){
				log_info("sync_count: %" PRIu64 ", last_seq: %" PRIu64 ", seq: %" PRIu64 "",
					sync_count, this->last_seq, log.seq());
			}
			if(req.size() >= 2){
				log_debug("[%s] %s [%d]", sync_type, log.dumps().c_str(), req[1].size());
			}else{
				log_debug("[%s] %s", sync_type, log.dumps().c_str());
			}
			this->proc_sync(log, req);
			break;
		}
		default:
			break;
	}
	return 0;
}