Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Switch Replication Messages to Message Pack #1572

Merged
merged 1 commit into from
May 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions src/include/replication/replication_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,6 @@ class MessageWrapper {
template <typename T>
T Get(const char *key) const;

/**
* Deserializes a given input to a string using the CBOR (Concise Binary Object Representation) serialization
* format.
*
* @param cbor cbor input
* @return parsed string
*
*/
static std::string FromCbor(const std::vector<uint8_t> &cbor);

/**
* Serializes a given input string to CBOR format
* @param str string to serialize
* @return CBOR format of string
*/
static std::vector<uint8_t> ToCbor(std::string_view str);

/**
* Serialize the message
*
Expand Down
15 changes: 7 additions & 8 deletions src/replication/replication_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const char *TxnAppliedMsg::key_applied_txn_id = "applied_txn_id";
MessageWrapper::MessageWrapper() : underlying_message_(std::make_unique<MessageFormat>()) {}

MessageWrapper::MessageWrapper(std::string_view str)
: underlying_message_(std::make_unique<MessageFormat>(common::json::parse(str))) {}
: underlying_message_(std::make_unique<MessageFormat>(common::json::from_msgpack(str))) {}

template <typename T>
void MessageWrapper::Put(const char *key, T value) {
Expand All @@ -45,11 +45,10 @@ template record_batch_id_t MessageWrapper::Get<record_batch_id_t>(const char *ke
template msg_id_t MessageWrapper::Get<msg_id_t>(const char *key) const;
template transaction::timestamp_t MessageWrapper::Get<transaction::timestamp_t>(const char *key) const;

std::string MessageWrapper::FromCbor(const std::vector<uint8_t> &cbor) { return common::json::from_cbor(cbor); }

std::vector<uint8_t> MessageWrapper::ToCbor(std::string_view str) { return common::json::to_cbor(str); }

std::string MessageWrapper::Serialize() const { return underlying_message_->dump(); }
std::string MessageWrapper::Serialize() const {
const auto msg_pack = common::json::to_msgpack(*underlying_message_);
return std::string(reinterpret_cast<const char *>(msg_pack.data()), msg_pack.size());
}

common::json MessageWrapper::ToJson() const { return *underlying_message_; }

Expand Down Expand Up @@ -115,14 +114,14 @@ NotifyOATMsg::NotifyOATMsg(ReplicationMessageMetadata metadata, record_batch_id_
MessageWrapper RecordsBatchMsg::ToMessageWrapper() const {
MessageWrapper message = BaseReplicationMessage::ToMessageWrapper();
message.Put(key_batch_id, batch_id_);
message.Put(key_contents, MessageWrapper::ToCbor(contents_));
message.Put(key_contents, contents_);
return message;
}

RecordsBatchMsg::RecordsBatchMsg(const MessageWrapper &message)
: BaseReplicationMessage(message),
batch_id_(message.Get<record_batch_id_t>(key_batch_id)),
contents_(MessageWrapper::FromCbor(message.Get<std::vector<uint8_t>>(key_contents))) {}
contents_(message.Get<std::string>(key_contents)) {}

RecordsBatchMsg::RecordsBatchMsg(ReplicationMessageMetadata metadata, record_batch_id_t batch_id,
storage::BufferedLogWriter *buffer)
Expand Down