Remove has_read_version_been_set_ from CommitRequest

This commit is contained in:
2025-08-17 14:09:55 -04:00
parent fa2a2e4427
commit 67ddcd0fc8
4 changed files with 22 additions and 21 deletions

View File

@@ -3,7 +3,6 @@
#include "arena_allocator.hpp"
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <vector>
@@ -43,7 +42,6 @@ private:
std::optional<std::string_view> request_id_;
std::string_view leader_id_;
uint64_t read_version_ = 0;
bool has_read_version_been_set_ = false;
std::vector<Precondition, ArenaStlAllocator<Precondition>> preconditions_;
std::vector<Operation, ArenaStlAllocator<Operation>> operations_;
@@ -59,7 +57,6 @@ public:
CommitRequest(CommitRequest &&other) noexcept
: arena_(std::move(other.arena_)), request_id_(other.request_id_),
leader_id_(other.leader_id_), read_version_(other.read_version_),
has_read_version_been_set_(other.has_read_version_been_set_),
preconditions_(std::move(other.preconditions_)),
operations_(std::move(other.operations_)) {}
@@ -70,7 +67,6 @@ public:
request_id_ = other.request_id_;
leader_id_ = other.leader_id_;
read_version_ = other.read_version_;
has_read_version_been_set_ = other.has_read_version_been_set_;
preconditions_ = std::move(other.preconditions_);
operations_ = std::move(other.operations_);
}
@@ -101,12 +97,6 @@ public:
*/
uint64_t read_version() const { return read_version_; }
/**
* @brief Check if read version has been explicitly set.
* @return true if read version was set during parsing
*/
bool has_read_version_been_set() const { return has_read_version_been_set_; }
/**
* @brief Get the preconditions.
* @return span of preconditions
@@ -151,7 +141,6 @@ public:
request_id_.reset();
leader_id_ = {};
read_version_ = 0;
has_read_version_been_set_ = false;
preconditions_.clear();
operations_.clear();
}
@@ -166,10 +155,7 @@ public:
leader_id_ = arena_allocated_leader_id;
}
void set_read_version(uint64_t read_version) {
read_version_ = read_version;
has_read_version_been_set_ = true;
}
void set_read_version(uint64_t read_version) { read_version_ = read_version; }
void add_precondition(Precondition::Type type, uint64_t version,
std::string_view arena_allocated_begin,
@@ -214,4 +200,4 @@ public:
}
}
}
};
};

View File

@@ -423,6 +423,7 @@ void JsonCommitRequestParser::handle_completed_number(std::string_view s) {
auto result = std::from_chars(s.data(), s.data() + s.size(), version);
if (result.ec == std::errc{}) {
current_request_->set_read_version(version);
ctx.has_read_version_been_set = true;
} else {
ctx.parse_error = "Invalid number format for read_version field";
}
@@ -456,7 +457,7 @@ bool JsonCommitRequestParser::parse(CommitRequest &request, char *data,
finish_streaming_parse(request);
return !has_parse_error() && !request.leader_id().empty() &&
request.has_read_version_been_set();
parser_context_->has_read_version_been_set;
}
bool JsonCommitRequestParser::begin_streaming_parse(CommitRequest &request) {
@@ -469,6 +470,7 @@ bool JsonCommitRequestParser::begin_streaming_parse(CommitRequest &request) {
parser_context_->reset_arena_memory(&request.arena());
parser_context_->parse_error = nullptr;
parser_context_->parse_complete = false;
parser_context_->has_read_version_been_set = false;
}
if (json_parser_) {
@@ -544,4 +546,8 @@ bool JsonCommitRequestParser::has_parse_error() const {
const char *JsonCommitRequestParser::get_parse_error() const {
return parser_context_ ? parser_context_->parse_error : nullptr;
}
bool JsonCommitRequestParser::has_read_version_been_set() const {
return parser_context_ && parser_context_->has_read_version_been_set;
}

View File

@@ -58,6 +58,7 @@ private:
bool in_key = false;
const char *parse_error = nullptr;
bool parse_complete = false;
bool has_read_version_been_set = false;
// Current objects being parsed
PreconditionParseState current_precondition{};
@@ -73,7 +74,9 @@ private:
current_string(ArenaStlAllocator<char>(arena)),
current_number(ArenaStlAllocator<char>(arena)),
precondition_type(ArenaStlAllocator<char>(arena)),
operation_type(ArenaStlAllocator<char>(arena)) {}
operation_type(ArenaStlAllocator<char>(arena)) {
has_read_version_been_set = false;
}
void reset_arena_memory(ArenaAllocator *arena) {
current_key = ArenaString{ArenaStlAllocator<char>(arena)};
@@ -119,6 +122,12 @@ public:
bool has_parse_error() const override;
const char *get_parse_error() const override;
/**
* @brief Check if read version has been explicitly set during parsing.
* @return true if read version was set during parsing
*/
bool has_read_version_been_set() const;
// Weaseljson callbacks (public for global callbacks)
static void on_begin_object(void *userdata);
static void on_end_object(void *userdata);