Remove has_read_version_been_set_ from CommitRequest
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
#include "arena_allocator.hpp"
|
#include "arena_allocator.hpp"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <span>
|
#include <span>
|
||||||
#include <string>
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -43,7 +42,6 @@ private:
|
|||||||
std::optional<std::string_view> request_id_;
|
std::optional<std::string_view> request_id_;
|
||||||
std::string_view leader_id_;
|
std::string_view leader_id_;
|
||||||
uint64_t read_version_ = 0;
|
uint64_t read_version_ = 0;
|
||||||
bool has_read_version_been_set_ = false;
|
|
||||||
std::vector<Precondition, ArenaStlAllocator<Precondition>> preconditions_;
|
std::vector<Precondition, ArenaStlAllocator<Precondition>> preconditions_;
|
||||||
std::vector<Operation, ArenaStlAllocator<Operation>> operations_;
|
std::vector<Operation, ArenaStlAllocator<Operation>> operations_;
|
||||||
|
|
||||||
@@ -59,7 +57,6 @@ public:
|
|||||||
CommitRequest(CommitRequest &&other) noexcept
|
CommitRequest(CommitRequest &&other) noexcept
|
||||||
: arena_(std::move(other.arena_)), request_id_(other.request_id_),
|
: arena_(std::move(other.arena_)), request_id_(other.request_id_),
|
||||||
leader_id_(other.leader_id_), read_version_(other.read_version_),
|
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_)),
|
preconditions_(std::move(other.preconditions_)),
|
||||||
operations_(std::move(other.operations_)) {}
|
operations_(std::move(other.operations_)) {}
|
||||||
|
|
||||||
@@ -70,7 +67,6 @@ public:
|
|||||||
request_id_ = other.request_id_;
|
request_id_ = other.request_id_;
|
||||||
leader_id_ = other.leader_id_;
|
leader_id_ = other.leader_id_;
|
||||||
read_version_ = other.read_version_;
|
read_version_ = other.read_version_;
|
||||||
has_read_version_been_set_ = other.has_read_version_been_set_;
|
|
||||||
preconditions_ = std::move(other.preconditions_);
|
preconditions_ = std::move(other.preconditions_);
|
||||||
operations_ = std::move(other.operations_);
|
operations_ = std::move(other.operations_);
|
||||||
}
|
}
|
||||||
@@ -101,12 +97,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
uint64_t read_version() const { return read_version_; }
|
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.
|
* @brief Get the preconditions.
|
||||||
* @return span of preconditions
|
* @return span of preconditions
|
||||||
@@ -151,7 +141,6 @@ public:
|
|||||||
request_id_.reset();
|
request_id_.reset();
|
||||||
leader_id_ = {};
|
leader_id_ = {};
|
||||||
read_version_ = 0;
|
read_version_ = 0;
|
||||||
has_read_version_been_set_ = false;
|
|
||||||
preconditions_.clear();
|
preconditions_.clear();
|
||||||
operations_.clear();
|
operations_.clear();
|
||||||
}
|
}
|
||||||
@@ -166,10 +155,7 @@ public:
|
|||||||
leader_id_ = arena_allocated_leader_id;
|
leader_id_ = arena_allocated_leader_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_read_version(uint64_t read_version) {
|
void set_read_version(uint64_t read_version) { read_version_ = read_version; }
|
||||||
read_version_ = read_version;
|
|
||||||
has_read_version_been_set_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_precondition(Precondition::Type type, uint64_t version,
|
void add_precondition(Precondition::Type type, uint64_t version,
|
||||||
std::string_view arena_allocated_begin,
|
std::string_view arena_allocated_begin,
|
||||||
|
|||||||
@@ -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);
|
auto result = std::from_chars(s.data(), s.data() + s.size(), version);
|
||||||
if (result.ec == std::errc{}) {
|
if (result.ec == std::errc{}) {
|
||||||
current_request_->set_read_version(version);
|
current_request_->set_read_version(version);
|
||||||
|
ctx.has_read_version_been_set = true;
|
||||||
} else {
|
} else {
|
||||||
ctx.parse_error = "Invalid number format for read_version field";
|
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);
|
finish_streaming_parse(request);
|
||||||
|
|
||||||
return !has_parse_error() && !request.leader_id().empty() &&
|
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) {
|
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_->reset_arena_memory(&request.arena());
|
||||||
parser_context_->parse_error = nullptr;
|
parser_context_->parse_error = nullptr;
|
||||||
parser_context_->parse_complete = false;
|
parser_context_->parse_complete = false;
|
||||||
|
parser_context_->has_read_version_been_set = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json_parser_) {
|
if (json_parser_) {
|
||||||
@@ -545,3 +547,7 @@ bool JsonCommitRequestParser::has_parse_error() const {
|
|||||||
const char *JsonCommitRequestParser::get_parse_error() const {
|
const char *JsonCommitRequestParser::get_parse_error() const {
|
||||||
return parser_context_ ? parser_context_->parse_error : nullptr;
|
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;
|
||||||
|
}
|
||||||
@@ -58,6 +58,7 @@ private:
|
|||||||
bool in_key = false;
|
bool in_key = false;
|
||||||
const char *parse_error = nullptr;
|
const char *parse_error = nullptr;
|
||||||
bool parse_complete = false;
|
bool parse_complete = false;
|
||||||
|
bool has_read_version_been_set = false;
|
||||||
|
|
||||||
// Current objects being parsed
|
// Current objects being parsed
|
||||||
PreconditionParseState current_precondition{};
|
PreconditionParseState current_precondition{};
|
||||||
@@ -73,7 +74,9 @@ private:
|
|||||||
current_string(ArenaStlAllocator<char>(arena)),
|
current_string(ArenaStlAllocator<char>(arena)),
|
||||||
current_number(ArenaStlAllocator<char>(arena)),
|
current_number(ArenaStlAllocator<char>(arena)),
|
||||||
precondition_type(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) {
|
void reset_arena_memory(ArenaAllocator *arena) {
|
||||||
current_key = ArenaString{ArenaStlAllocator<char>(arena)};
|
current_key = ArenaString{ArenaStlAllocator<char>(arena)};
|
||||||
@@ -119,6 +122,12 @@ public:
|
|||||||
bool has_parse_error() const override;
|
bool has_parse_error() const override;
|
||||||
const char *get_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)
|
// Weaseljson callbacks (public for global callbacks)
|
||||||
static void on_begin_object(void *userdata);
|
static void on_begin_object(void *userdata);
|
||||||
static void on_end_object(void *userdata);
|
static void on_end_object(void *userdata);
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ TEST_CASE("CommitRequest basic parsing") {
|
|||||||
REQUIRE_FALSE(
|
REQUIRE_FALSE(
|
||||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||||
// Check completion based on required fields
|
// Check completion based on required fields
|
||||||
REQUIRE(!request.has_read_version_been_set());
|
REQUIRE(!parser.has_read_version_been_set());
|
||||||
}
|
}
|
||||||
|
|
||||||
SUBCASE("Empty leader_id") {
|
SUBCASE("Empty leader_id") {
|
||||||
@@ -132,7 +132,7 @@ TEST_CASE("CommitRequest basic parsing") {
|
|||||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||||
// Check completion based on required fields
|
// Check completion based on required fields
|
||||||
bool missing_leader = request.leader_id().empty();
|
bool missing_leader = request.leader_id().empty();
|
||||||
bool missing_version = !request.has_read_version_been_set();
|
bool missing_version = !parser.has_read_version_been_set();
|
||||||
REQUIRE((missing_leader || missing_version));
|
REQUIRE((missing_leader || missing_version));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -656,7 +656,7 @@ TEST_CASE("CommitRequest streaming parsing") {
|
|||||||
|
|
||||||
REQUIRE(status == CommitRequestParser::ParseStatus::Complete);
|
REQUIRE(status == CommitRequestParser::ParseStatus::Complete);
|
||||||
// Check that required field is missing
|
// Check that required field is missing
|
||||||
REQUIRE(!request.has_read_version_been_set());
|
REQUIRE(!parser.has_read_version_been_set());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user