当前位置: 首页>>代码示例>>C++>>正文


C++ LogEntry::Ref方法代码示例

本文整理汇总了C++中LogEntry::Ref方法的典型用法代码示例。如果您正苦于以下问题:C++ LogEntry::Ref方法的具体用法?C++ LogEntry::Ref怎么用?C++ LogEntry::Ref使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LogEntry的用法示例。


在下文中一共展示了LogEntry::Ref方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Open

bool LogManager::Open(const std::string& path){
	path_ = path;
	abb::Mutex::Locker l(mtx_);
	fd_ = open(path.c_str(),O_RDWR,0600);
	if(fd_ < 0){
		LOG(WARN)<< "raft.open.file.failed:"<<path<< " err:" <<errno<<" errstr:" << strerror(errno);
		fd_ = open(path.c_str(),O_RDWR|O_CREAT,0600);
		if(fd_ < 0){
			LOG(WARN)<< "raft.create.file.failed:"<<path<< " err:" <<errno<<" errstr:" << strerror(errno);
			return false;
		}
		LOG(DEBUG)<< "log.open.create " << path;
		return true;
	}
	fcntl(fd_, F_SETFD, FD_CLOEXEC);
	LOG(DEBUG)<< "log.open.exist " << path;
	lseek(fd_,0,SEEK_SET);
	abb::Buffer buf;
	while( buf.WriteFromeReader(StaticReader,this) > 0){
		;
	}
	int position = 0;
	int size = buf.ReadSize();
	while(size > 0){
		LogEntry* entry = new LogEntry();
		if( ! entry->Decode(buf) ) {
			entry->UnRef();
			return false;
		}

		entry->position = position;
		if(entry->index_ > this->start_index_){
			entry->Ref();
			this->log_entry_arr_.push_back(entry);
			if(entry->index_ <= this->commit_index_){
				entry->cmd_->Apply(this->svr_,NULL,NULL);
			}
		}
		position += size - buf.ReadSize();
		entry->UnRef();
		size = buf.ReadSize();
	}
	if(this->log_entry_arr_.size() > 0){
		LOG(DEBUG) << "open.log.append log index " << this->log_entry_arr_.front()->index_ << ":" <<this->log_entry_arr_.back()->index_ << "  " << this->commit_index_;
	}
	
	return true;
}
开发者ID:tempbottle,项目名称:libraft,代码行数:48,代码来源:log.cpp

示例2: CommitToIndex

bool LogManager::CommitToIndex(uint64_t index){
	LogEntryArray arr;
	{
		LOG(TRACE) << "CommitToIndex" << index;
		abb::Mutex::Locker l(mtx_);
		if(index > (log_entry_arr_.size() + start_index_)){
			LOG(DEBUG) << "raft.Log: Commit index" << index << "set back to " << ( log_entry_arr_.size() + start_index_);
			index = log_entry_arr_.size() + start_index_;
		}
		if (index < commit_index_) {
			LOG(DEBUG) << "raft.Log: Commit index earily :" << index << "commit_index_:" << commit_index_;
			return true;
		}
		for(unsigned i= this->commit_index_+1;i<=index;i++){
			int e_index = i - 1 - this->start_index_;
			LogEntry* entry = log_entry_arr_[e_index];
			this->commit_index_ = entry->index_;
			entry->Ref();
			arr.push_back(entry);
		}
	}
	for(unsigned i = 0;i< arr.size();i++){
		LogEntry* entry = arr[i];
		if(entry->ev_){
			IMessage* msg = NULL;
			std::string error ;
			entry->cmd_->Apply(this->svr_,&error,&msg);
			entry->ev_->Notify(msg,error);
			entry->ev_->UnRef();
			entry->ev_ = NULL;
		}else{
			entry->cmd_->Apply(this->svr_,NULL,NULL);
		}
		entry->UnRef();
	}
	return true;
}
开发者ID:tempbottle,项目名称:libraft,代码行数:37,代码来源:log.cpp

示例3: AppendEntries

bool LogManager::AppendEntries(LogEntryArray entries,std::string* save_err){
	abb::Mutex::Locker l(mtx_);
	for(unsigned i=0;i<entries.size();i++){
		LogEntry* entry = entries[i];
		if(this->log_entry_arr_.size() > 0){
			LogEntry* last_entry = this->log_entry_arr_.back();
			if(last_entry->term_ > entry->term_){
				LOG(DEBUG) << "Cannot Append entry with earlier term last:" << last_entry->term_ << "insert:" << entry->term_;
				if(save_err) *save_err = "Cannot Append entry with earlier term";
				return false;
			}else if(last_entry->term_ == entry->term_ && entry->index_ < last_entry->index_){
				LOG(DEBUG) << "Cannot Append entry with earlier index in same term last:" << last_entry->index_ << "insert:" << entry->index_;
				if(save_err) *save_err = "Cannot Append entry with earlier index";
				return false;
			}
		}
		entry->Ref();
		WriteEntry(fd_,entry);
		this->log_entry_arr_.push_back(entry);
	}
	if(entries.size() > 0)
		fsync(fd_);
	return true;
}
开发者ID:tempbottle,项目名称:libraft,代码行数:24,代码来源:log.cpp


注:本文中的LogEntry::Ref方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。