aboutsummaryrefslogtreecommitdiffhomepage
path: root/tddb
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2023-02-02 03:08:26 +0300
committerlevlam <levlam@telegram.org>2023-02-02 03:08:26 +0300
commit882de6e8e851dc789cb28d810b36c292692e7228 (patch)
tree6a55f459b0a9738b9996abc5a0e873bc74a817f2 /tddb
parent2a5f6121ef4e622270f9f8f95c5f8f280960e7ef (diff)
Replace unsafe to maintain data_ field with get_data() method.
Diffstat (limited to 'tddb')
-rw-r--r--tddb/td/db/BinlogKeyValue.h4
-rw-r--r--tddb/td/db/TQueue.cpp2
-rw-r--r--tddb/td/db/binlog/Binlog.cpp2
-rw-r--r--tddb/td/db/binlog/BinlogEvent.cpp10
-rw-r--r--tddb/td/db/binlog/BinlogEvent.h9
-rw-r--r--tddb/td/db/binlog/binlog_dump.cpp8
-rw-r--r--tddb/td/db/binlog/detail/BinlogEventsBuffer.h2
7 files changed, 19 insertions, 18 deletions
diff --git a/tddb/td/db/BinlogKeyValue.h b/tddb/td/db/BinlogKeyValue.h
index 80500f839..ba3aa9d04 100644
--- a/tddb/td/db/BinlogKeyValue.h
+++ b/tddb/td/db/BinlogKeyValue.h
@@ -82,7 +82,7 @@ class BinlogKeyValue final : public KeyValueSyncInterface {
name,
[&](const BinlogEvent &binlog_event) {
Event event;
- event.parse(TlParser(binlog_event.data_));
+ event.parse(TlParser(binlog_event.get_data()));
map_.emplace(event.key.str(), std::make_pair(event.value.str(), binlog_event.id_));
},
std::move(db_key), DbKey::empty(), scheduler_id));
@@ -103,7 +103,7 @@ class BinlogKeyValue final : public KeyValueSyncInterface {
void external_init_handle(const BinlogEvent &binlog_event) {
Event event;
- event.parse(TlParser(binlog_event.data_));
+ event.parse(TlParser(binlog_event.get_data()));
map_.emplace(event.key.str(), std::make_pair(event.value.str(), binlog_event.id_));
}
diff --git a/tddb/td/db/TQueue.cpp b/tddb/td/db/TQueue.cpp
index 2e8802626..bcc9d3f22 100644
--- a/tddb/td/db/TQueue.cpp
+++ b/tddb/td/db/TQueue.cpp
@@ -550,7 +550,7 @@ void TQueueBinlog<BinlogT>::pop(uint64 log_event_id) {
template <class BinlogT>
Status TQueueBinlog<BinlogT>::replay(const BinlogEvent &binlog_event, TQueue &q) const {
TQueueLogEvent event;
- TlParser parser(binlog_event.data_);
+ TlParser parser(binlog_event.get_data());
int32 has_extra = binlog_event.type_ - BINLOG_EVENT_TYPE;
if (has_extra != 0 && has_extra != 1) {
return Status::Error("Wrong magic");
diff --git a/tddb/td/db/binlog/Binlog.cpp b/tddb/td/db/binlog/Binlog.cpp
index 04bc0a7a7..65ebf26b4 100644
--- a/tddb/td/db/binlog/Binlog.cpp
+++ b/tddb/td/db/binlog/Binlog.cpp
@@ -345,7 +345,7 @@ void Binlog::do_event(BinlogEvent &&event) {
if (event.type_ < 0) {
if (event.type_ == BinlogEvent::ServiceTypes::AesCtrEncryption) {
detail::AesCtrEncryptionEvent encryption_event;
- encryption_event.parse(TlParser(event.data_));
+ encryption_event.parse(TlParser(event.get_data()));
string key;
if (aes_ctr_key_salt_ == encryption_event.key_salt_) {
diff --git a/tddb/td/db/binlog/BinlogEvent.cpp b/tddb/td/db/binlog/BinlogEvent.cpp
index 213d2e4d8..ffb1a71a4 100644
--- a/tddb/td/db/binlog/BinlogEvent.cpp
+++ b/tddb/td/db/binlog/BinlogEvent.cpp
@@ -23,8 +23,7 @@ Status BinlogEvent::init(BufferSlice &&raw_event, bool check_crc) {
flags_ = parser.fetch_int();
extra_ = parser.fetch_long();
CHECK(size_ >= MIN_SIZE);
- auto slice_data = parser.fetch_string_raw<Slice>(size_ - MIN_SIZE);
- data_ = MutableSlice(const_cast<char *>(slice_data.begin()), slice_data.size());
+ parser.fetch_string_raw<Slice>(size_ - MIN_SIZE); // skip data
crc32_ = static_cast<uint32>(parser.fetch_int());
if (check_crc) {
auto calculated_crc = crc32(raw_event.as_slice().substr(0, size_ - TAIL_SIZE));
@@ -37,6 +36,10 @@ Status BinlogEvent::init(BufferSlice &&raw_event, bool check_crc) {
return Status::OK();
}
+Slice BinlogEvent::get_data() const {
+ return Slice(raw_event_.as_slice().data() + HEADER_SIZE, size_ - MIN_SIZE);
+}
+
Status BinlogEvent::validate() const {
BinlogEvent event;
if (raw_event_.size() < 4) {
@@ -69,10 +72,7 @@ BufferSlice BinlogEvent::create_raw(uint64 id, int32 type, int32 flags, const St
}
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
diff --git a/tddb/td/db/binlog/BinlogEvent.h b/tddb/td/db/binlog/BinlogEvent.h
index c86ab2d2e..9dd5499a4 100644
--- a/tddb/td/db/binlog/BinlogEvent.h
+++ b/tddb/td/db/binlog/BinlogEvent.h
@@ -60,7 +60,6 @@ struct BinlogEvent {
int32 type_; // type can be merged with flags
int32 flags_;
uint64 extra_;
- MutableSlice data_;
uint32 crc32_;
BufferSlice raw_event_;
@@ -70,6 +69,8 @@ struct BinlogEvent {
enum ServiceTypes { Header = -1, Empty = -2, AesCtrEncryption = -3, NoEncryption = -4 };
enum Flags { Rewrite = 1, Partial = 2 };
+ Slice get_data() const;
+
void clear() {
raw_event_ = BufferSlice();
}
@@ -84,7 +85,7 @@ struct BinlogEvent {
}
BufferSlice data_as_buffer_slice() const {
- return raw_event_.from_slice(data_);
+ return raw_event_.from_slice(get_data());
}
BinlogEvent() = default;
@@ -102,7 +103,7 @@ struct BinlogEvent {
std::string public_to_string() const {
return PSTRING() << "LogEvent[" << tag("id", format::as_hex(id_)) << tag("type", type_) << tag("flags", flags_)
- << tag("data", data_.size()) << "]" << debug_info_;
+ << tag("data", get_data().size()) << "]" << debug_info_;
}
Status validate() const;
@@ -112,7 +113,7 @@ struct BinlogEvent {
inline StringBuilder &operator<<(StringBuilder &sb, const BinlogEvent &event) {
return sb << "LogEvent[" << tag("id", format::as_hex(event.id_)) << tag("type", event.type_)
- << tag("flags", event.flags_) << tag("data", format::as_hex_dump<4>(event.data_)) << "]"
+ << tag("flags", event.flags_) << tag("data", format::as_hex_dump<4>(event.get_data())) << "]"
<< event.debug_info_;
}
diff --git a/tddb/td/db/binlog/binlog_dump.cpp b/tddb/td/db/binlog/binlog_dump.cpp
index 7e34b6a2f..fd2498f25 100644
--- a/tddb/td/db/binlog/binlog_dump.cpp
+++ b/tddb/td/db/binlog/binlog_dump.cpp
@@ -125,7 +125,7 @@ int main(int argc, char *argv[]) {
info[0].compressed_size += event.raw_event_.size();
info[event.type_].compressed_size += event.raw_event_.size();
if (event.type_ == ConfigPmcMagic || event.type_ == BinlogPmcMagic) {
- auto key = td::TlParser(event.data_).fetch_string<td::Slice>();
+ auto key = td::TlParser(event.get_data()).fetch_string<td::Slice>();
info[event.type_].compressed_trie.add(key);
}
},
@@ -134,13 +134,13 @@ int main(int argc, char *argv[]) {
info[0].full_size += event.raw_event_.size();
info[event.type_].full_size += event.raw_event_.size();
if (event.type_ == ConfigPmcMagic || event.type_ == BinlogPmcMagic) {
- auto key = td::TlParser(event.data_).fetch_string<td::Slice>();
+ auto key = td::TlParser(event.get_data()).fetch_string<td::Slice>();
info[event.type_].trie.add(key);
}
LOG(PLAIN) << "LogEvent[" << td::tag("event_id", td::format::as_hex(event.id_))
<< td::tag("type", event.type_) << td::tag("flags", event.flags_)
- << td::tag("size", event.data_.size()) << td::tag("data", td::format::escaped(event.data_))
- << "]\n";
+ << td::tag("size", event.get_data().size())
+ << td::tag("data", td::format::escaped(event.get_data())) << "]\n";
})
.ensure();
diff --git a/tddb/td/db/binlog/detail/BinlogEventsBuffer.h b/tddb/td/db/binlog/detail/BinlogEventsBuffer.h
index 32cc78e4b..37be436c0 100644
--- a/tddb/td/db/binlog/detail/BinlogEventsBuffer.h
+++ b/tddb/td/db/binlog/detail/BinlogEventsBuffer.h
@@ -25,7 +25,7 @@ class BinlogEventsBuffer {
auto &event = events_[i];
if (i + 1 != ids_.size() && (event.flags_ & BinlogEvent::Flags::Partial) == 0) {
callback(BinlogEvent(BinlogEvent::create_raw(event.id_, event.type_, event.flags_ | BinlogEvent::Flags::Partial,
- create_storer(event.data_)),
+ create_storer(event.get_data())),
BinlogDebugInfo{__FILE__, __LINE__}));
} else {
callback(std::move(event));