Address a comment

20250318-000905-jzhou-f92206b417dfabb7
This commit is contained in:
Jingyu Zhou 2025-03-17 17:06:02 -07:00
parent a00f0c9b35
commit b56a0abaa6
3 changed files with 8 additions and 9 deletions

View File

@ -186,11 +186,11 @@ struct TagsAndMessage {
}
// Returns the size of the header, including: msg_length, version.sub, tag_count, tags.
int32_t getHeaderSize() const {
return sizeof(int32_t) + sizeof(uint32_t) + sizeof(uint16_t) + tags.size() * sizeof(Tag);
static int32_t getHeaderSize(int numTags) {
return sizeof(int32_t) + sizeof(uint32_t) + sizeof(uint16_t) + numTags * sizeof(Tag);
}
StringRef getMessageWithoutTags() const { return message.substr(getHeaderSize()); }
StringRef getMessageWithoutTags() const { return message.substr(getHeaderSize(tags.size())); }
// Returns the message with the header.
StringRef getRawMessage() const { return message; }

View File

@ -42,9 +42,6 @@
#define SevDebugMemory SevVerbose
// Based on TagsAndMessage::getHeaderSize(): assume 6 tags.
#define MessageOverheadBytes (sizeof(int32_t) + sizeof(uint32_t) + sizeof(uint16_t) + 6 * sizeof(Tag))
struct VersionedMessage {
LogMessageVersion version;
StringRef message;
@ -56,7 +53,8 @@ struct VersionedMessage {
: version(v), message(m), tags(t), arena(a) {}
Version getVersion() const { return version.version; }
uint32_t getSubVersion() const { return version.sub; }
size_t getEstimatedSize() const { return message.size() + MessageOverheadBytes; }
// Returns the estimated size of the message in bytes, assuming 6 tags.
size_t getEstimatedSize() const { return message.size() + TagsAndMessage::getHeaderSize(6); }
// Returns true if the message is a mutation that could be backed up (normal keys, system key backup ranges, or the
// metadata version key)

View File

@ -149,7 +149,7 @@ void ILogSystem::ServerPeekCursor::nextMessage() {
DEBUG_TAGS_AND_MESSAGE("ServerPeekCursor", messageVersion.version, messageAndTags.getRawMessage(), this->randomID);
// Rewind and consume the header so that reader() starts from the message.
rd.rewind();
rd.readBytes(messageAndTags.getHeaderSize());
rd.readBytes(TagsAndMessage::getHeaderSize(messageAndTags.tags.size()));
hasMsg = true;
DebugLogTraceEvent("SPC_NextMessageB", randomID)
.detail("Tag", tag.toString())
@ -165,7 +165,8 @@ StringRef ILogSystem::ServerPeekCursor::getMessage() {
StringRef ILogSystem::ServerPeekCursor::getMessageWithTags() {
StringRef rawMessage = messageAndTags.getRawMessage();
rd.readBytes(rawMessage.size() - messageAndTags.getHeaderSize()); // Consumes the message.
rd.readBytes(rawMessage.size() -
TagsAndMessage::getHeaderSize(messageAndTags.tags.size())); // Consumes the message.
return rawMessage;
}