From d073097ebfa5fa04dddad9898a5fc6d4c8bac684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Jadwiszczak?= Date: Tue, 12 May 2026 23:13:29 +0200 Subject: [PATCH] strong_consistency: allow QUORUM/LOCAL_QUORUM and ONE/LOCAL_ONE for reads We can execute strong consistent read queries in 2 ways: - with QUORUM/LOCAL_QUORUM CL - this path executes `read_barrier()` before reading the data, which synchronizes Raft log with the leader. But to execute it, we need quorum of replicas - with ONE/LOCAL_ONE CL - this path just reads data from one replica without any synchronization (not implemented yet) --- cql3/statements/strong_consistency/select_statement.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cql3/statements/strong_consistency/select_statement.cc b/cql3/statements/strong_consistency/select_statement.cc index 98bfb22c5c..213f89948a 100644 --- a/cql3/statements/strong_consistency/select_statement.cc +++ b/cql3/statements/strong_consistency/select_statement.cc @@ -8,6 +8,7 @@ #include "select_statement.hh" +#include "db/consistency_level_type.hh" #include "query/query-request.hh" #include "cql3/query_processor.hh" #include "service/strong_consistency/coordinator.hh" @@ -17,10 +18,19 @@ namespace cql3::statements::strong_consistency { using result_message = cql_transport::messages::result_message; +static void validate_consistency_level(const db::consistency_level& cl) { + if (cl != db::consistency_level::QUORUM && cl != db::consistency_level::LOCAL_QUORUM && + cl != db::consistency_level::ONE && cl != db::consistency_level::LOCAL_ONE) { + throw exceptions::invalid_request_exception("Strongly consistent reads must use QUORUM/LOCAL_QUORUM or ONE/LOCAL_ONE consistency level"); + } +} + future<::shared_ptr> select_statement::do_execute(query_processor& qp, service::query_state& state, const query_options& options) const { + validate_consistency_level(options.get_consistency()); + const auto key_ranges = _restrictions->get_partition_key_ranges(options); if (key_ranges.size() != 1 || !query::is_single_partition(key_ranges[0])) { throw exceptions::invalid_request_exception("Strongly consistent queries can only target a single partition");