aboutsummaryrefslogtreecommitdiffhomepage
path: root/tddb
diff options
context:
space:
mode:
authorArseny Smirnov <arseny30@gmail.com>2023-02-08 13:43:25 +0100
committerArseny Smirnov <arseny30@gmail.com>2023-02-09 22:53:02 +0100
commitcde74133a651e879c3d705262a30634765b565d2 (patch)
tree5588aa846fac616f389102bc1f7d27414316c052 /tddb
parentfb854c93a85a816913c3064d49541746c632db54 (diff)
Store std::string instead of BufferSlice in BinlogEvent
Diffstat (limited to 'tddb')
-rw-r--r--tddb/td/db/binlog/Binlog.cpp13
-rw-r--r--tddb/td/db/binlog/BinlogEvent.cpp6
-rw-r--r--tddb/td/db/binlog/BinlogEvent.h12
3 files changed, 9 insertions, 22 deletions
diff --git a/tddb/td/db/binlog/Binlog.cpp b/tddb/td/db/binlog/Binlog.cpp
index 01ca88170..70c2a4676 100644
--- a/tddb/td/db/binlog/Binlog.cpp
+++ b/tddb/td/db/binlog/Binlog.cpp
@@ -139,7 +139,8 @@ class BinlogReader {
}
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());
offset_ += size_;
event->offset_ = offset_;
@@ -333,14 +334,7 @@ void Binlog::do_event(BinlogEvent &&event) {
}
VLOG(binlog) << "Write binlog event: " << format::cond(state_ == State::Reindex, "[reindex] ")
<< 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_));
- break;
- }
+ buffer_writer_.append(as_slice(event.raw_event_));
}
if (event.type_ < 0) {
@@ -652,7 +646,6 @@ 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_ = start_size != 0; // must sync creation of the file if it is non-empty
diff --git a/tddb/td/db/binlog/BinlogEvent.cpp b/tddb/td/db/binlog/BinlogEvent.cpp
index b4fb4e57b..c74acd2b7 100644
--- a/tddb/td/db/binlog/BinlogEvent.cpp
+++ b/tddb/td/db/binlog/BinlogEvent.cpp
@@ -14,7 +14,7 @@
namespace td {
-void BinlogEvent::init(BufferSlice &&raw_event) {
+void BinlogEvent::init(string raw_event) {
TlParser parser(as_slice(raw_event));
size_ = static_cast<uint32>(parser.fetch_int());
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;
}
-void BinlogEvent::realloc() {
- raw_event_ = raw_event_.copy();
-}
-
} // namespace td
diff --git a/tddb/td/db/binlog/BinlogEvent.h b/tddb/td/db/binlog/BinlogEvent.h
index cc7807d79..ca93bb193 100644
--- a/tddb/td/db/binlog/BinlogEvent.h
+++ b/tddb/td/db/binlog/BinlogEvent.h
@@ -62,7 +62,7 @@ struct BinlogEvent {
uint64 extra_ = 0;
uint32 crc32_ = 0;
- BufferSlice raw_event_;
+ string raw_event_;
BinlogDebugInfo debug_info_;
@@ -78,20 +78,20 @@ struct BinlogEvent {
BinlogEvent clone() const {
BinlogEvent result;
result.debug_info_ = BinlogDebugInfo{__FILE__, __LINE__};
- result.init(raw_event_.clone());
+ result.init(raw_event_);
result.validate().ensure();
return result;
}
BufferSlice data_as_buffer_slice() const {
- return raw_event_.from_slice(get_data());
+ return BufferSlice(get_data());
}
BinlogEvent() = default;
BinlogEvent(BufferSlice &&raw_event, BinlogDebugInfo 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);
@@ -101,11 +101,9 @@ struct BinlogEvent {
<< tag("data", get_data().size()) << "]" << debug_info_;
}
- void init(BufferSlice &&raw_event);
+ void init(string raw_event);
Status validate() const TD_WARN_UNUSED_RESULT;
-
- void realloc();
};
inline StringBuilder &operator<<(StringBuilder &sb, const BinlogEvent &event) {