36 {
37 if (!reader_.
Open(input_file_)) {
38 AERROR <<
"open input file failed, file: " << input_file_;
39 return false;
40 }
41
42
44 if (!writer_.
Open(output_file_)) {
45 AERROR <<
"open output file failed. file: " << output_file_;
46 return false;
47 }
49 AERROR <<
"write header to output file failed. file: " << output_file_;
50 return false;
51 }
52
53
55 proto::Index index = reader_.
GetIndex();
56 FOR_EACH(i, 0, index.indexes_size()) {
57 proto::SingleIndex* single_index = index.mutable_indexes(i);
58 if (single_index->type() != SectionType::SECTION_CHANNEL) {
59 continue;
60 }
61 ChannelCache* chan_cache = single_index->mutable_channel_cache();
62 if (std::find(channel_vec_.begin(), channel_vec_.end(),
63 chan_cache->name()) == channel_vec_.end()) {
64 channel_vec_.push_back(chan_cache->name());
65 Channel chan;
66 chan.set_name(chan_cache->name());
67 chan.set_message_type(chan_cache->message_type());
68 chan.set_proto_desc(chan_cache->proto_desc());
70 }
71 }
72 }
73
74
77 Section section;
79 AINFO <<
"read section failed, try next.";
80 continue;
81 }
82 if (section.type == SectionType::SECTION_INDEX) {
83 break;
84 }
85 switch (section.type) {
86 case SectionType::SECTION_CHANNEL: {
87 Channel chan;
88 if (!reader_.
ReadSection<Channel>(section.size, &chan)) {
89 AINFO <<
"one channel section broken, skip it.";
90 break;
91 }
92 if (std::find(channel_vec_.begin(), channel_vec_.end(), chan.name()) ==
93 channel_vec_.end()) {
94 channel_vec_.push_back(chan.name());
96 }
97 break;
98 }
99 case SectionType::SECTION_CHUNK_HEADER: {
100 ChunkHeader chdr;
101 if (!reader_.
ReadSection<ChunkHeader>(section.size, &chdr)) {
102 AINFO <<
"one chunk header section broken, skip it.";
103 }
104 break;
105 }
106 case SectionType::SECTION_CHUNK_BODY: {
107 ChunkBody cbd;
108 if (!reader_.
ReadSection<ChunkBody>(section.size, &cbd)) {
109 AINFO <<
"one chunk body section broken, skip it";
110 break;
111 }
112 for (int idx = 0; idx < cbd.messages_size(); ++idx) {
114 AERROR <<
"add new message failed.";
115 return false;
116 }
117 }
118 break;
119 }
120 default: {
121 AERROR <<
"this section should not be here, section type: "
122 << section.type;
123 return false;
124 }
125 }
126 }
127 AINFO <<
"recover record file done.";
128 return true;
129}
const proto::Index & GetIndex() const
bool ReadSection(Section *section)
bool Open(const std::string &path) override
bool Open(const std::string &path) override
bool WriteHeader(const proto::Header &header)
bool WriteChannel(const proto::Channel &channel)
bool WriteMessage(const proto::SingleMessage &message)
#define FOR_EACH(i, begin, end)