本文整理汇总了C++中LogEntry::Decode方法的典型用法代码示例。如果您正苦于以下问题:C++ LogEntry::Decode方法的具体用法?C++ LogEntry::Decode怎么用?C++ LogEntry::Decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogEntry
的用法示例。
在下文中一共展示了LogEntry::Decode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}