Use signed in a bunch of places
This commit is contained in:
@@ -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<int>(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<int>((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<int>(blocks.size()); ++i) {
|
||||
Block *b = blocks[i];
|
||||
out << "Block #" << (blocks.size() - i) << " @ " << static_cast<void *>(b)
|
||||
<< " -> data @ " << static_cast<void *>(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<int>(blocks.size()); ++i) {
|
||||
Block *b = blocks[i];
|
||||
size_t block_num = blocks.size() - i;
|
||||
int block_num = static_cast<int>(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<int64_t>(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<int>(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<unsigned char>(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;
|
||||
|
||||
@@ -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<std::string_view> request_id_;
|
||||
std::string_view leader_id_;
|
||||
uint64_t read_version_ = 0;
|
||||
int64_t read_version_ = 0;
|
||||
std::vector<Precondition, ArenaStlAllocator<Precondition>> preconditions_;
|
||||
std::vector<Operation, ArenaStlAllocator<Operation>> 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,
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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};
|
||||
};
|
||||
|
||||
@@ -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<int>(max_fds_); ++fd) {
|
||||
delete connections_[fd].load(std::memory_order_relaxed);
|
||||
}
|
||||
if (munmap(connections_, aligned_size_) == -1) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
private:
|
||||
struct PreconditionParseState {
|
||||
Precondition::Type type;
|
||||
std::optional<uint64_t> version;
|
||||
std::optional<int64_t> version;
|
||||
// These are owned by CommitRequest::arena
|
||||
std::optional<std::string_view> key;
|
||||
std::optional<std::string_view> 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;
|
||||
|
||||
|
||||
@@ -512,14 +512,14 @@ void Server::process_connection_batch(
|
||||
std::span<const int> events) {
|
||||
|
||||
// First process writes for each connection
|
||||
for (size_t i = 0; i < batch.size(); ++i) {
|
||||
for (int i = 0; i < static_cast<int>(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<int>(batch.size()); ++i) {
|
||||
if (batch[i]) {
|
||||
process_connection_reads(batch[i], events[i]);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user