diff --git a/src/arena_allocator.cpp b/src/arena_allocator.cpp index ddac348..16ce262 100644 --- a/src/arena_allocator.cpp +++ b/src/arena_allocator.cpp @@ -163,7 +163,7 @@ void ArenaAllocator::debug_dump(std::ostream &out, bool show_memory_map, out << "Block Chain (newest to oldest):" << std::endl; // Display blocks in reverse order (current first) - for (size_t i = 0; i < blocks.size(); ++i) { + for (int i = 0; i < static_cast(blocks.size()); ++i) { Block *b = blocks[i]; // Calculate used bytes in this specific block @@ -182,12 +182,12 @@ void ArenaAllocator::debug_dump(std::ostream &out, bool show_memory_map, // Show memory map if requested if (show_memory_map && b->size > 0) { - const size_t map_width = 60; - size_t used_chars = (map_width * block_used) / b->size; + const int map_width = 60; + int used_chars = static_cast((map_width * block_used) / b->size); used_chars = std::min(used_chars, map_width); out << " ["; - for (size_t j = 0; j < map_width; ++j) { + for (int j = 0; j < map_width; ++j) { if (j < used_chars) { out << "#"; } else { @@ -200,7 +200,7 @@ void ArenaAllocator::debug_dump(std::ostream &out, bool show_memory_map, out << std::endl; out << "Block addresses and relationships:" << std::endl; - for (size_t i = 0; i < blocks.size(); ++i) { + for (int i = 0; i < static_cast(blocks.size()); ++i) { Block *b = blocks[i]; out << "Block #" << (blocks.size() - i) << " @ " << static_cast(b) << " -> data @ " << static_cast(b->data()); @@ -217,9 +217,9 @@ void ArenaAllocator::debug_dump(std::ostream &out, bool show_memory_map, out << std::endl; out << "Memory Contents:" << std::endl; - for (size_t i = 0; i < blocks.size(); ++i) { + for (int i = 0; i < static_cast(blocks.size()); ++i) { Block *b = blocks[i]; - size_t block_num = blocks.size() - i; + int block_num = static_cast(blocks.size()) - i; // Calculate used bytes in this specific block size_t block_used = b->offset; @@ -259,17 +259,19 @@ size_t ArenaAllocator::calculate_next_block_size(size_t required_size) const { void ArenaAllocator::dump_memory_contents(std::ostream &out, const char *data, size_t size) { - const size_t bytes_per_line = 16; + const int bytes_per_line = 16; - for (size_t offset = 0; offset < size; offset += bytes_per_line) { + for (int64_t offset = 0; offset < static_cast(size); + offset += bytes_per_line) { // Print offset out << " 0x" << std::setfill('0') << std::setw(4) << std::hex << offset << ": "; - size_t bytes_in_line = std::min(bytes_per_line, size - offset); + int bytes_in_line = + std::min(bytes_per_line, static_cast(size - offset)); // Print hex bytes - for (size_t i = 0; i < bytes_per_line; ++i) { + for (int i = 0; i < bytes_per_line; ++i) { if (i < bytes_in_line) { unsigned char byte = static_cast(data[offset + i]); out << std::setfill('0') << std::setw(2) << std::hex @@ -286,7 +288,7 @@ void ArenaAllocator::dump_memory_contents(std::ostream &out, const char *data, // Print ASCII representation out << " |"; - for (size_t i = 0; i < bytes_in_line; ++i) { + for (int i = 0; i < bytes_in_line; ++i) { char c = data[offset + i]; if (c >= 32 && c <= 126) { // Printable ASCII out << c; diff --git a/src/commit_request.hpp b/src/commit_request.hpp index 8caa6b1..c5ac4c0 100644 --- a/src/commit_request.hpp +++ b/src/commit_request.hpp @@ -25,7 +25,7 @@ struct Precondition { }; Type type; ///< Type of precondition check - uint64_t + int64_t version; ///< Expected version number (0 uses read_version from request) std::string_view begin; ///< Begin key (or single key for PointRead) std::string_view end; ///< End key for RangeRead (unused for PointRead) @@ -66,7 +66,7 @@ private: ArenaAllocator arena_; std::optional request_id_; std::string_view leader_id_; - uint64_t read_version_ = 0; + int64_t read_version_ = 0; std::vector> preconditions_; std::vector> operations_; @@ -120,7 +120,7 @@ public: * @brief Get the read version. * @return Read version number */ - uint64_t read_version() const { return read_version_; } + int64_t read_version() const { return read_version_; } /** * @brief Get the preconditions. @@ -205,7 +205,7 @@ public: * @brief Set the read version for precondition validation. * @param read_version The snapshot version number */ - void set_read_version(uint64_t read_version) { read_version_ = read_version; } + void set_read_version(int64_t read_version) { read_version_ = read_version; } /** * @brief Add a precondition to the commit request. @@ -215,7 +215,7 @@ public: * @param arena_allocated_end End key for RangeRead (optional, empty for * PointRead) */ - void add_precondition(Precondition::Type type, uint64_t version, + void add_precondition(Precondition::Type type, int64_t version, std::string_view arena_allocated_begin, std::string_view arena_allocated_end = {}) { preconditions_.push_back(Precondition{type, version, arena_allocated_begin, diff --git a/src/commit_request_parser.hpp b/src/commit_request_parser.hpp index c0d36f9..fcc8249 100644 --- a/src/commit_request_parser.hpp +++ b/src/commit_request_parser.hpp @@ -44,7 +44,8 @@ public: * @param len Length of the data in bytes * @return ParseResult indicating success or specific error type */ - virtual ParseResult parse(CommitRequest &request, char *data, size_t len) = 0; + virtual ParseResult parse(CommitRequest &request, char *data, + int64_t len) = 0; /** * @brief Initialize streaming parsing. @@ -59,7 +60,7 @@ public: * @param len Length of the data. Must be non-zero. * @return ParseStatus indicating current parse state */ - virtual ParseStatus parse_chunk(char *data, size_t len) = 0; + virtual ParseStatus parse_chunk(char *data, int64_t len) = 0; /** * @brief Finish streaming parse (call when no more data is available). diff --git a/src/config.hpp b/src/config.hpp index 5a71946..b22e7d2 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -17,7 +17,7 @@ struct ServerConfig { /// Unix socket path (if specified, takes precedence over TCP) std::string unix_socket_path; /// Maximum size in bytes for incoming HTTP requests (default: 1MB) - size_t max_request_size_bytes = 1024 * 1024; + int64_t max_request_size_bytes = 1024 * 1024; /// Number of I/O threads for handling connections and network events int io_threads = 1; /// Number of epoll instances to reduce epoll_ctl contention (default: @@ -28,7 +28,7 @@ struct ServerConfig { /// Maximum number of concurrent connections (0 = unlimited) int max_connections = 50000; /// Buffer size for reading from socket connections (default: 16KB) - size_t read_buffer_size = 16 * 1024; + int read_buffer_size = 16 * 1024; }; /** @@ -36,11 +36,11 @@ struct ServerConfig { */ struct CommitConfig { /// Minimum required length for request_id to ensure sufficient entropy - size_t min_request_id_length = 20; + int min_request_id_length = 20; /// How long to retain request IDs for duplicate detection std::chrono::hours request_id_retention_hours{24}; /// Minimum number of commit versions to retain request IDs for - size_t request_id_retention_versions = 100000000; + int64_t request_id_retention_versions = 100000000; }; /** @@ -48,7 +48,7 @@ struct CommitConfig { */ struct SubscriptionConfig { /// Maximum buffer size for unconsumed subscription data before backpressure - size_t max_buffer_size_bytes = 10 * 1024 * 1024; + int64_t max_buffer_size_bytes = 10 * 1024 * 1024; /// Interval between keepalive comments in subscription streams std::chrono::seconds keepalive_interval{30}; }; diff --git a/src/connection_registry.cpp b/src/connection_registry.cpp index 545fda0..3a7bd82 100644 --- a/src/connection_registry.cpp +++ b/src/connection_registry.cpp @@ -36,7 +36,7 @@ ConnectionRegistry::ConnectionRegistry() : connections_(nullptr), max_fds_(0) { ConnectionRegistry::~ConnectionRegistry() { if (connections_ != nullptr) { - for (size_t fd = 0; fd < max_fds_; ++fd) { + for (int fd = 0; fd < static_cast(max_fds_); ++fd) { delete connections_[fd].load(std::memory_order_relaxed); } if (munmap(connections_, aligned_size_) == -1) { diff --git a/src/http_handler.cpp b/src/http_handler.cpp index ea8c61e..cb6d811 100644 --- a/src/http_handler.cpp +++ b/src/http_handler.cpp @@ -374,7 +374,7 @@ int HttpHandler::onHeaderValueComplete(llhttp_t *parser) { // Check for X-Request-Id header if (field.size() == 12 && strncasecmp(field.data(), "x-request-id", 12) == 0) { - uint64_t id = 0; + int64_t id = 0; for (char c : value) { if (c >= '0' && c <= '9') { id = id * 10 + (c - '0'); diff --git a/src/http_handler.hpp b/src/http_handler.hpp index be3b4b6..3651201 100644 --- a/src/http_handler.hpp +++ b/src/http_handler.hpp @@ -53,7 +53,7 @@ struct HttpConnectionState { ArenaString current_header_field_buf; ArenaString current_header_value_buf; bool header_field_complete = false; - uint64_t request_id = 0; // X-Request-Id header value + int64_t request_id = 0; // X-Request-Id header value explicit HttpConnectionState(ArenaAllocator &arena); }; diff --git a/src/json_commit_request_parser.cpp b/src/json_commit_request_parser.cpp index c8dc960..bdf510a 100644 --- a/src/json_commit_request_parser.cpp +++ b/src/json_commit_request_parser.cpp @@ -420,7 +420,7 @@ void JsonCommitRequestParser::handle_completed_number(std::string_view s) { switch (current_state) { case ParseState::Root: { if (ctx.current_key_token == JsonTokenType::ReadVersion) { - uint64_t version; + int64_t version; auto result = std::from_chars(s.data(), s.data() + s.size(), version); if (result.ec == std::errc{}) { current_request_->set_read_version(version); @@ -433,7 +433,7 @@ void JsonCommitRequestParser::handle_completed_number(std::string_view s) { } case ParseState::PreconditionObject: { if (ctx.current_key_token == JsonTokenType::Version) { - uint64_t version; + int64_t version; auto result = std::from_chars(s.data(), s.data() + s.size(), version); if (result.ec == std::errc{}) { ctx.current_precondition.version = version; @@ -450,7 +450,8 @@ void JsonCommitRequestParser::handle_completed_number(std::string_view s) { } CommitRequestParser::ParseResult -JsonCommitRequestParser::parse(CommitRequest &request, char *data, size_t len) { +JsonCommitRequestParser::parse(CommitRequest &request, char *data, + int64_t len) { if (!begin_streaming_parse(request)) { return ParseResult::OutOfMemory; } @@ -501,7 +502,7 @@ bool JsonCommitRequestParser::begin_streaming_parse(CommitRequest &request) { } JsonCommitRequestParser::ParseStatus -JsonCommitRequestParser::parse_chunk(char *data, size_t len) { +JsonCommitRequestParser::parse_chunk(char *data, int64_t len) { assert(len != 0); if (!json_parser_ || !parser_context_) { return ParseStatus::Error; diff --git a/src/json_commit_request_parser.hpp b/src/json_commit_request_parser.hpp index fff8103..6277539 100644 --- a/src/json_commit_request_parser.hpp +++ b/src/json_commit_request_parser.hpp @@ -28,7 +28,7 @@ public: private: struct PreconditionParseState { Precondition::Type type; - std::optional version; + std::optional version; // These are owned by CommitRequest::arena std::optional key; std::optional begin; @@ -114,9 +114,9 @@ public: JsonCommitRequestParser &operator=(JsonCommitRequestParser &&other) noexcept; // CommitRequestParser interface implementation - ParseResult parse(CommitRequest &request, char *data, size_t len) override; + ParseResult parse(CommitRequest &request, char *data, int64_t len) override; bool begin_streaming_parse(CommitRequest &request) override; - ParseStatus parse_chunk(char *data, size_t len) override; + ParseStatus parse_chunk(char *data, int64_t len) override; ParseStatus finish_streaming_parse() override; const char *get_parse_error() const override; diff --git a/src/server.cpp b/src/server.cpp index 1f53f42..ad19757 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -512,14 +512,14 @@ void Server::process_connection_batch( std::span events) { // First process writes for each connection - for (size_t i = 0; i < batch.size(); ++i) { + for (int i = 0; i < static_cast(batch.size()); ++i) { if (batch[i]) { process_connection_writes(batch[i], events[i]); } } // Then process reads for each connection - for (size_t i = 0; i < batch.size(); ++i) { + for (int i = 0; i < static_cast(batch.size()); ++i) { if (batch[i]) { process_connection_reads(batch[i], events[i]); } diff --git a/tests/test_commit_request.cpp b/tests/test_commit_request.cpp index 45623a9..b1d73ad 100644 --- a/tests/test_commit_request.cpp +++ b/tests/test_commit_request.cpp @@ -335,7 +335,7 @@ TEST_CASE("Parser Comparison - Edge Cases") { SUBCASE("Large read_version") { test_parser_comparison(R"({ "leader_id": "leader456", - "read_version": 18446744073709551615 + "read_version": 9223372036854775807 })", "Large read_version"); }