More validation of commit request

This commit is contained in:
2025-08-14 15:09:58 -04:00
parent ba1627ff10
commit 40fa403ec5
3 changed files with 104 additions and 2 deletions

View File

@@ -332,6 +332,7 @@ void CommitRequest::handle_completed_number() {
ctx.current_number.data() + ctx.current_number.size(), version);
if (result.ec == std::errc{}) {
read_version_ = version;
has_read_version_been_set_ = true;
} else {
ctx.parse_error = true;
}
@@ -379,7 +380,8 @@ bool CommitRequest::parse_json(std::string_view json_str) {
status = WeaselJsonParser_parse(parser, nullptr, 0);
}
bool success = (status == WeaselJson_OK) && !parser_context_.parse_error;
bool success =
(status == WeaselJson_OK) && !parser_context_.parse_error && is_valid();
WeaselJsonParser_destroy(parser);

View File

@@ -100,6 +100,7 @@ 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_;
ParserContext parser_context_;
@@ -131,6 +132,7 @@ 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_)),
parser_context_(std::move(other.parser_context_)),
@@ -149,6 +151,7 @@ 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_);
parser_context_ = std::move(other.parser_context_);
@@ -195,7 +198,16 @@ public:
* @return true if parsing is complete and successful
*/
bool is_parse_complete() const {
return parser_context_.parse_complete && !parser_context_.parse_error;
return parser_context_.parse_complete && !parser_context_.parse_error &&
is_valid();
}
/**
* @brief Validate that all required fields are present.
* @return true if all required fields are present
*/
bool is_valid() const {
return !leader_id_.empty() && has_read_version_been_set_;
}
/**
@@ -256,6 +268,7 @@ public:
request_id_.reset();
leader_id_ = {};
read_version_ = 0;
has_read_version_been_set_ = false;
preconditions_.clear();
operations_.clear();