Store std::string instead of BufferSlice in BinlogEvent
This commit is contained in:
parent
fb854c93a8
commit
cde74133a6
@ -139,7 +139,8 @@ class BinlogReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
event->debug_info_ = BinlogDebugInfo{__FILE__, __LINE__};
|
event->debug_info_ = BinlogDebugInfo{__FILE__, __LINE__};
|
||||||
event->init(input_->cut_head(size_).move_as_buffer_slice());
|
auto buffer_slice = input_->cut_head(size_).move_as_buffer_slice();
|
||||||
|
event->init(buffer_slice.as_slice().str());
|
||||||
TRY_STATUS(event->validate());
|
TRY_STATUS(event->validate());
|
||||||
offset_ += size_;
|
offset_ += size_;
|
||||||
event->offset_ = offset_;
|
event->offset_ = offset_;
|
||||||
@ -333,14 +334,7 @@ void Binlog::do_event(BinlogEvent &&event) {
|
|||||||
}
|
}
|
||||||
VLOG(binlog) << "Write binlog event: " << format::cond(state_ == State::Reindex, "[reindex] ")
|
VLOG(binlog) << "Write binlog event: " << format::cond(state_ == State::Reindex, "[reindex] ")
|
||||||
<< event.public_to_string();
|
<< event.public_to_string();
|
||||||
switch (encryption_type_) {
|
|
||||||
case EncryptionType::None:
|
|
||||||
buffer_writer_.append(event.raw_event_.clone());
|
|
||||||
break;
|
|
||||||
case EncryptionType::AesCtr:
|
|
||||||
buffer_writer_.append(as_slice(event.raw_event_));
|
buffer_writer_.append(as_slice(event.raw_event_));
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.type_ < 0) {
|
if (event.type_ < 0) {
|
||||||
@ -652,7 +646,6 @@ void Binlog::do_reindex() {
|
|||||||
fd_events_ = 0;
|
fd_events_ = 0;
|
||||||
reset_encryption();
|
reset_encryption();
|
||||||
processor_->for_each([&](BinlogEvent &event) {
|
processor_->for_each([&](BinlogEvent &event) {
|
||||||
event.realloc();
|
|
||||||
do_event(std::move(event)); // NB: no move is actually happens
|
do_event(std::move(event)); // NB: no move is actually happens
|
||||||
});
|
});
|
||||||
need_sync_ = start_size != 0; // must sync creation of the file if it is non-empty
|
need_sync_ = start_size != 0; // must sync creation of the file if it is non-empty
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
void BinlogEvent::init(BufferSlice &&raw_event) {
|
void BinlogEvent::init(string raw_event) {
|
||||||
TlParser parser(as_slice(raw_event));
|
TlParser parser(as_slice(raw_event));
|
||||||
size_ = static_cast<uint32>(parser.fetch_int());
|
size_ = static_cast<uint32>(parser.fetch_int());
|
||||||
LOG_CHECK(size_ == raw_event.size()) << size_ << ' ' << raw_event.size() << debug_info_;
|
LOG_CHECK(size_ == raw_event.size()) << size_ << ' ' << raw_event.size() << debug_info_;
|
||||||
@ -71,8 +71,4 @@ BufferSlice BinlogEvent::create_raw(uint64 id, int32 type, int32 flags, const St
|
|||||||
return raw_event;
|
return raw_event;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinlogEvent::realloc() {
|
|
||||||
raw_event_ = raw_event_.copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -62,7 +62,7 @@ struct BinlogEvent {
|
|||||||
uint64 extra_ = 0;
|
uint64 extra_ = 0;
|
||||||
uint32 crc32_ = 0;
|
uint32 crc32_ = 0;
|
||||||
|
|
||||||
BufferSlice raw_event_;
|
string raw_event_;
|
||||||
|
|
||||||
BinlogDebugInfo debug_info_;
|
BinlogDebugInfo debug_info_;
|
||||||
|
|
||||||
@ -78,20 +78,20 @@ struct BinlogEvent {
|
|||||||
BinlogEvent clone() const {
|
BinlogEvent clone() const {
|
||||||
BinlogEvent result;
|
BinlogEvent result;
|
||||||
result.debug_info_ = BinlogDebugInfo{__FILE__, __LINE__};
|
result.debug_info_ = BinlogDebugInfo{__FILE__, __LINE__};
|
||||||
result.init(raw_event_.clone());
|
result.init(raw_event_);
|
||||||
result.validate().ensure();
|
result.validate().ensure();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferSlice data_as_buffer_slice() const {
|
BufferSlice data_as_buffer_slice() const {
|
||||||
return raw_event_.from_slice(get_data());
|
return BufferSlice(get_data());
|
||||||
}
|
}
|
||||||
|
|
||||||
BinlogEvent() = default;
|
BinlogEvent() = default;
|
||||||
|
|
||||||
BinlogEvent(BufferSlice &&raw_event, BinlogDebugInfo info) {
|
BinlogEvent(BufferSlice &&raw_event, BinlogDebugInfo info) {
|
||||||
debug_info_ = info;
|
debug_info_ = info;
|
||||||
init(std::move(raw_event));
|
init(raw_event.as_slice().str());
|
||||||
}
|
}
|
||||||
|
|
||||||
static BufferSlice create_raw(uint64 id, int32 type, int32 flags, const Storer &storer);
|
static BufferSlice create_raw(uint64 id, int32 type, int32 flags, const Storer &storer);
|
||||||
@ -101,11 +101,9 @@ struct BinlogEvent {
|
|||||||
<< tag("data", get_data().size()) << "]" << debug_info_;
|
<< tag("data", get_data().size()) << "]" << debug_info_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(BufferSlice &&raw_event);
|
void init(string raw_event);
|
||||||
|
|
||||||
Status validate() const TD_WARN_UNUSED_RESULT;
|
Status validate() const TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
void realloc();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline StringBuilder &operator<<(StringBuilder &sb, const BinlogEvent &event) {
|
inline StringBuilder &operator<<(StringBuilder &sb, const BinlogEvent &event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user