Move BinlogEvent::create_raw implementation to cpp.
GitOrigin-RevId: 1e68c4d39044e6563c481d05a1bb1eb341b61c7c
This commit is contained in:
parent
e8f4c31586
commit
3afcad7a5e
@ -29,6 +29,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
template <class BinlogT>
|
template <class BinlogT>
|
||||||
class BinlogKeyValue : public KeyValueSyncInterface {
|
class BinlogKeyValue : public KeyValueSyncInterface {
|
||||||
public:
|
public:
|
||||||
@ -234,17 +235,21 @@ class BinlogKeyValue : public KeyValueSyncInterface {
|
|||||||
RwMutex rw_mutex_;
|
RwMutex rw_mutex_;
|
||||||
int32 magic_ = magic;
|
int32 magic_ = magic;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline void BinlogKeyValue<Binlog>::add_event(uint64 seq_no, BufferSlice &&event) {
|
inline void BinlogKeyValue<Binlog>::add_event(uint64 seq_no, BufferSlice &&event) {
|
||||||
binlog_->add_raw_event(std::move(event), BinlogDebugInfo{__FILE__, __LINE__});
|
binlog_->add_raw_event(std::move(event), BinlogDebugInfo{__FILE__, __LINE__});
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline void BinlogKeyValue<Binlog>::force_sync(Promise<> &&promise) {
|
inline void BinlogKeyValue<Binlog>::force_sync(Promise<> &&promise) {
|
||||||
binlog_->sync();
|
binlog_->sync();
|
||||||
promise.set_value(Unit());
|
promise.set_value(Unit());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline void BinlogKeyValue<Binlog>::lazy_sync(Promise<> &&promise) {
|
inline void BinlogKeyValue<Binlog>::lazy_sync(Promise<> &&promise) {
|
||||||
force_sync(std::move(promise));
|
force_sync(std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "td/utils/Slice.h"
|
#include "td/utils/Slice.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
class DbKey {
|
class DbKey {
|
||||||
public:
|
public:
|
||||||
enum Type { Empty, RawKey, Password };
|
enum Type { Empty, RawKey, Password };
|
||||||
@ -49,4 +50,5 @@ class DbKey {
|
|||||||
Type type_{Empty};
|
Type type_{Empty};
|
||||||
string data_;
|
string data_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -6,9 +6,13 @@
|
|||||||
//
|
//
|
||||||
#include "td/db/binlog/BinlogEvent.h"
|
#include "td/db/binlog/BinlogEvent.h"
|
||||||
|
|
||||||
|
#include "td/utils/crypto.h"
|
||||||
|
#include "td/utils/misc.h"
|
||||||
#include "td/utils/tl_parsers.h"
|
#include "td/utils/tl_parsers.h"
|
||||||
|
#include "td/utils/tl_storers.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
int32 VERBOSITY_NAME(binlog) = VERBOSITY_NAME(DEBUG) + 8;
|
int32 VERBOSITY_NAME(binlog) = VERBOSITY_NAME(DEBUG) + 8;
|
||||||
|
|
||||||
Status BinlogEvent::init(BufferSlice &&raw_event, bool check_crc) {
|
Status BinlogEvent::init(BufferSlice &&raw_event, bool check_crc) {
|
||||||
@ -47,4 +51,23 @@ Status BinlogEvent::validate() const {
|
|||||||
return event.init(raw_event_.clone(), true);
|
return event.init(raw_event_.clone(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BufferSlice BinlogEvent::create_raw(uint64 id, int32 type, int32 flags, const Storer &storer) {
|
||||||
|
auto raw_event = BufferSlice{storer.size() + MIN_EVENT_SIZE};
|
||||||
|
|
||||||
|
TlStorerUnsafe tl_storer(raw_event.as_slice().ubegin());
|
||||||
|
tl_storer.store_int(narrow_cast<int32>(raw_event.size()));
|
||||||
|
tl_storer.store_long(id);
|
||||||
|
tl_storer.store_int(type);
|
||||||
|
tl_storer.store_int(flags);
|
||||||
|
tl_storer.store_long(0);
|
||||||
|
|
||||||
|
CHECK(tl_storer.get_buf() == raw_event.as_slice().ubegin() + EVENT_HEADER_SIZE);
|
||||||
|
tl_storer.store_storer(storer);
|
||||||
|
|
||||||
|
CHECK(tl_storer.get_buf() == raw_event.as_slice().uend() - EVENT_TAIL_SIZE);
|
||||||
|
tl_storer.store_int(::td::crc32(raw_event.as_slice().truncate(raw_event.size() - EVENT_TAIL_SIZE)));
|
||||||
|
|
||||||
|
return raw_event;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -8,17 +8,15 @@
|
|||||||
|
|
||||||
#include "td/utils/buffer.h"
|
#include "td/utils/buffer.h"
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/crypto.h"
|
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
#include "td/utils/misc.h"
|
|
||||||
#include "td/utils/Slice.h"
|
#include "td/utils/Slice.h"
|
||||||
#include "td/utils/Status.h"
|
#include "td/utils/Status.h"
|
||||||
#include "td/utils/Storer.h"
|
#include "td/utils/Storer.h"
|
||||||
#include "td/utils/StringBuilder.h"
|
#include "td/utils/StringBuilder.h"
|
||||||
#include "td/utils/tl_storers.h"
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
struct EmptyStorerImpl {
|
struct EmptyStorerImpl {
|
||||||
EmptyStorerImpl() {
|
EmptyStorerImpl() {
|
||||||
}
|
}
|
||||||
@ -54,7 +52,6 @@ inline StringBuilder &operator<<(StringBuilder &sb, const BinlogDebugInfo &info)
|
|||||||
return sb << "[" << info.file << ":" << info.line << "]";
|
return sb << "[" << info.file << ":" << info.line << "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: smaller BinlogEvent
|
|
||||||
struct BinlogEvent {
|
struct BinlogEvent {
|
||||||
int64 offset_;
|
int64 offset_;
|
||||||
|
|
||||||
@ -102,6 +99,7 @@ struct BinlogEvent {
|
|||||||
Status init(BufferSlice &&raw_event, bool check_crc = true) TD_WARN_UNUSED_RESULT;
|
Status init(BufferSlice &&raw_event, bool check_crc = true) TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
std::string public_to_string() const {
|
std::string public_to_string() const {
|
||||||
return PSTRING() << "LogEvent[" << tag("id", format::as_hex(id_)) << tag("type", type_) << tag("flags", flags_)
|
return PSTRING() << "LogEvent[" << tag("id", format::as_hex(id_)) << tag("type", type_) << tag("flags", flags_)
|
||||||
<< tag("data", data_.size()) << "]" << debug_info_;
|
<< tag("data", data_.size()) << "]" << debug_info_;
|
||||||
@ -116,23 +114,4 @@ inline StringBuilder &operator<<(StringBuilder &sb, const BinlogEvent &event) {
|
|||||||
<< event.debug_info_;
|
<< event.debug_info_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementation
|
|
||||||
inline BufferSlice BinlogEvent::create_raw(uint64 id, int32 type, int32 flags, const Storer &storer) {
|
|
||||||
auto raw_event = BufferSlice{storer.size() + MIN_EVENT_SIZE};
|
|
||||||
|
|
||||||
TlStorerUnsafe tl_storer(raw_event.as_slice().ubegin());
|
|
||||||
tl_storer.store_int(narrow_cast<int32>(raw_event.size()));
|
|
||||||
tl_storer.store_long(id);
|
|
||||||
tl_storer.store_int(type);
|
|
||||||
tl_storer.store_int(flags);
|
|
||||||
tl_storer.store_long(0);
|
|
||||||
|
|
||||||
CHECK(tl_storer.get_buf() == raw_event.as_slice().ubegin() + EVENT_HEADER_SIZE);
|
|
||||||
tl_storer.store_storer(storer);
|
|
||||||
|
|
||||||
CHECK(tl_storer.get_buf() == raw_event.as_slice().uend() - EVENT_TAIL_SIZE);
|
|
||||||
tl_storer.store_int(::td::crc32(raw_event.as_slice().truncate(raw_event.size() - EVENT_TAIL_SIZE)));
|
|
||||||
|
|
||||||
return raw_event;
|
|
||||||
}
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
Loading…
Reference in New Issue
Block a user