Binlog: defragmentation of BinlogEvents buffers during reindex

GitOrigin-RevId: 89f61031d27d8aa20963a46566876a461ea3e338
This commit is contained in:
Arseny Smirnov 2020-08-07 20:30:05 +03:00
parent 80d98def74
commit 037bfb3776
3 changed files with 20 additions and 3 deletions

View File

@ -647,6 +647,7 @@ void Binlog::do_reindex() {
fd_events_ = 0;
reset_encryption();
processor_->for_each([&](BinlogEvent &event) {
event.realloc();
do_event(std::move(event)); // NB: no move is actually happens
});
need_sync_ = true; // must sync creation of the file
@ -667,9 +668,16 @@ void Binlog::do_reindex() {
<< fd_size_ << ' ' << detail::file_size(path_) << ' ' << fd_events_ << ' ' << path_;
double ratio = static_cast<double>(start_size) / static_cast<double>(finish_size + 1);
LOG(INFO) << "Regenerate index " << tag("name", path_) << tag("time", format::as_time(finish_time - start_time))
<< tag("before_size", format::as_size(start_size)) << tag("after_size", format::as_size(finish_size))
<< tag("ratio", ratio) << tag("before_events", start_events) << tag("after_events", finish_events);
[&](Slice msg) {
if (start_size > (10 << 20) || finish_time - start_time > 1) {
LOG(WARNING) << "Slow " << msg;
} else {
LOG(INFO) << msg;
}
}(PSLICE() << "Regenerate index " << tag("name", path_) << tag("time", format::as_time(finish_time - start_time))
<< tag("before_size", format::as_size(start_size)) << tag("after_size", format::as_size(finish_size))
<< tag("ratio", ratio) << tag("before_events", start_events) << tag("after_events", finish_events));
buffer_writer_ = ChainBufferWriter();
buffer_reader_ = buffer_writer_.extract_reader();

View File

@ -70,4 +70,11 @@ BufferSlice BinlogEvent::create_raw(uint64 id, int32 type, int32 flags, const St
return raw_event;
}
void BinlogEvent::realloc() {
auto data_offset = data_.begin() - raw_event_.as_slice().begin();
auto data_size = data_.size();
raw_event_ = raw_event_.copy();
data_ = raw_event_.as_slice().substr(data_offset, data_size);
}
} // namespace td

View File

@ -108,6 +108,8 @@ struct BinlogEvent {
}
Status validate() const;
void realloc();
};
inline StringBuilder &operator<<(StringBuilder &sb, const BinlogEvent &event) {