28 std::lock_guard<std::mutex> lock(
mutex_);
37 <<
", errno: " << errno;
42 AERROR <<
"Read header section fail, file: " <<
path_;
64bool RecordFileReader::ReadHeader() {
67 AERROR <<
"Read header section fail, file is broken or it is not a record "
71 if (section.
type != SectionType::SECTION_HEADER) {
72 AERROR <<
"Check section type failed"
73 <<
", expect: " << SectionType::SECTION_HEADER
74 <<
", actual: " << section.
type;
77 if (!ReadSection<proto::Header>(section.
size, &
header_)) {
78 AERROR <<
"Read header section fail, file is broken or it is not a record "
83 AERROR <<
"Skip bytes for reaching the nex section failed.";
91 AERROR <<
"Record file is not complete.";
95 AERROR <<
"Skip bytes for reaching the index section failed.";
100 AERROR <<
"Read index section fail, maybe file is broken.";
103 if (section.
type != SectionType::SECTION_INDEX) {
104 AERROR <<
"Check section type failed"
105 <<
", expect: " << SectionType::SECTION_INDEX
106 <<
", actual: " << section.
type;
109 if (!ReadSection<proto::Index>(section.
size, &
index_)) {
110 AERROR <<
"Read index section fail.";
118 ssize_t count = read(
fd_, section,
sizeof(
struct Section));
120 AERROR <<
"Read fd failed, fd_: " <<
fd_ <<
", errno: " << errno;
122 }
else if (count == 0) {
124 AINFO <<
"Reach end of file.";
126 }
else if (count !=
sizeof(
struct Section)) {
128 <<
", expect count: " <<
sizeof(
struct Section)
129 <<
", actual count: " << count;
137 if (size > INT64_MAX - pos) {
138 AERROR <<
"Current position plus skip count is larger than INT64_MAX, "
139 << pos <<
" + " << size <<
" > " << INT64_MAX;
143 AERROR <<
"Skip failed, file: " <<
path_ <<
", current position: " << pos
144 <<
"skip count: " << size;
bool SetPosition(int64_t position)
int64_t CurrentPosition()
virtual ~RecordFileReader()
bool ReadSection(Section *section)
bool SkipSection(int64_t size)
bool Open(const std::string &path) override
bool PathExists(const std::string &path)
Check if the path exists.