Separate Connection and Request lifetimes

This commit is contained in:
2025-09-14 15:04:37 -04:00
parent cf0c1b7cc2
commit 16c7ee0408
14 changed files with 519 additions and 381 deletions

View File

@@ -1,21 +1,32 @@
#pragma once
#include "connection.hpp"
#include <memory>
#include <variant>
// Forward declarations
struct CommitRequest;
/**
* Pipeline entry for commit requests that need full 4-stage processing.
* Contains connection with parsed CommitRequest.
*/
struct CommitEntry {
Ref<Connection> connection;
WeakRef<MessageSender> connection;
int64_t assigned_version = 0; // Set by sequence stage
bool resolve_success = false; // Set by resolve stage
bool persist_success = false; // Set by persist stage
// Copied HTTP state (pipeline threads cannot access connection user_data)
int64_t http_request_id = 0;
bool connection_close = false;
const CommitRequest *commit_request =
nullptr; // Points to connection's arena data
CommitEntry() = default; // Default constructor for variant
explicit CommitEntry(Ref<Connection> conn) : connection(std::move(conn)) {}
explicit CommitEntry(WeakRef<MessageSender> conn, int64_t req_id,
bool close_conn, const CommitRequest *req)
: connection(std::move(conn)), http_request_id(req_id),
connection_close(close_conn), commit_request(req) {}
};
/**
@@ -23,11 +34,19 @@ struct CommitEntry {
* then transfer to status threadpool.
*/
struct StatusEntry {
Ref<Connection> connection;
WeakRef<MessageSender> connection;
int64_t version_upper_bound = 0; // Set by sequence stage
// Copied HTTP state
int64_t http_request_id = 0;
bool connection_close = false;
std::string_view status_request_id; // Points to connection's arena data
StatusEntry() = default; // Default constructor for variant
explicit StatusEntry(Ref<Connection> conn) : connection(std::move(conn)) {}
explicit StatusEntry(WeakRef<MessageSender> conn, int64_t req_id,
bool close_conn, std::string_view request_id)
: connection(std::move(conn)), http_request_id(req_id),
connection_close(close_conn), status_request_id(request_id) {}
};
/**
@@ -36,11 +55,17 @@ struct StatusEntry {
* Resolve stage can perform configurable CPU work for benchmarking.
*/
struct HealthCheckEntry {
Ref<Connection> connection;
WeakRef<MessageSender> connection;
// Copied HTTP state
int64_t http_request_id = 0;
bool connection_close = false;
HealthCheckEntry() = default; // Default constructor for variant
explicit HealthCheckEntry(Ref<Connection> conn)
: connection(std::move(conn)) {}
explicit HealthCheckEntry(WeakRef<MessageSender> conn, int64_t req_id,
bool close_conn)
: connection(std::move(conn)), http_request_id(req_id),
connection_close(close_conn) {}
};
/**