baidu / braft

An industrial-grade C++ implementation of RAFT consensus algorithm based on brpc, widely used inside Baidu to build highly-available distributed systems.
Apache License 2.0
3.86k stars 865 forks source link

handle error in ProtoBufFile::load #403

Open CkTD opened 1 year ago

CkTD commented 1 year ago

https://github.com/baidu/braft/blob/e32b78a1f4973534aaa047dc2ead9167ec091b56/src/braft/protobuf_file.cpp#L87-L120

  1. 117 行没有检查返回值
  2. 如果执行到了112行, 且原因是实际文件长度比预期的短,返回了 -1。但读文件是成功的,errno 不会被更新。加载 log_meta时,如果发生了上述问题,且原来的 errno 正好是 ENOENT,后续逻辑会认为日志是空的,直接把 log 删光。

https://github.com/baidu/braft/blob/e32b78a1f4973534aaa047dc2ead9167ec091b56/src/braft/log.cpp#L1155-L1175