mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-19 16:15:07 +00:00
cql3: Move restrict_future_timestamp to cql_config
Move restrict_future_timestamp option from db::config to cql_config. This improves separation of concerns as timestamp validation is part of CQL query execution behavior. Update validate_timestamp() function signature to take cql_config reference instead of db::config, and update all callsites in modification_statement and batch_statement to pass cql_config. Signed-off-by: Pavel Emelyanov <xemul@scylladb.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -29,6 +29,7 @@ struct cql_config {
|
||||
utils::updateable_value<bool> enable_parallelized_aggregation;
|
||||
utils::updateable_value<uint32_t> batch_size_warn_threshold_in_kb;
|
||||
utils::updateable_value<uint32_t> batch_size_fail_threshold_in_kb;
|
||||
utils::updateable_value<bool> restrict_future_timestamp;
|
||||
|
||||
explicit cql_config(const db::config& cfg)
|
||||
: restrictions(cfg)
|
||||
@@ -39,6 +40,7 @@ struct cql_config {
|
||||
, enable_parallelized_aggregation(cfg.enable_parallelized_aggregation)
|
||||
, batch_size_warn_threshold_in_kb(cfg.batch_size_warn_threshold_in_kb)
|
||||
, batch_size_fail_threshold_in_kb(cfg.batch_size_fail_threshold_in_kb)
|
||||
, restrict_future_timestamp(cfg.restrict_future_timestamp)
|
||||
{}
|
||||
struct default_tag{};
|
||||
cql_config(default_tag)
|
||||
@@ -50,6 +52,7 @@ struct cql_config {
|
||||
, enable_parallelized_aggregation(true)
|
||||
, batch_size_warn_threshold_in_kb(128)
|
||||
, batch_size_fail_threshold_in_kb(1024)
|
||||
, restrict_future_timestamp(true)
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "batch_statement.hh"
|
||||
#include "cql3/util.hh"
|
||||
#include "raw/batch_statement.hh"
|
||||
#include "db/config.hh"
|
||||
#include "cql3/cql_config.hh"
|
||||
#include "db/consistency_level_validations.hh"
|
||||
#include "data_dictionary/data_dictionary.hh"
|
||||
@@ -243,7 +242,7 @@ future<shared_ptr<cql_transport::messages::result_message>> batch_statement::exe
|
||||
|
||||
future<shared_ptr<cql_transport::messages::result_message>> batch_statement::execute_without_checking_exception_message(
|
||||
query_processor& qp, service::query_state& state, const query_options& options, std::optional<service::group0_guard> guard) const {
|
||||
cql3::util::validate_timestamp(qp.db().get_config(), options, _attrs);
|
||||
cql3::util::validate_timestamp(qp.get_cql_config(), options, _attrs);
|
||||
return batch_stage(this, seastar::ref(qp), seastar::ref(state),
|
||||
seastar::cref(options), false, options.get_timestamp(state));
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ modification_statement::execute(query_processor& qp, service::query_state& qs, c
|
||||
|
||||
future<::shared_ptr<cql_transport::messages::result_message>>
|
||||
modification_statement::execute_without_checking_exception_message(query_processor& qp, service::query_state& qs, const query_options& options, std::optional<service::group0_guard> guard) const {
|
||||
cql3::util::validate_timestamp(qp.db().get_config(), options, attrs);
|
||||
cql3::util::validate_timestamp(qp.get_cql_config(), options, attrs);
|
||||
return modify_stage(this, seastar::ref(qp), seastar::ref(qs), seastar::cref(options));
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
|
||||
#include "utils/assert.hh"
|
||||
#include "util.hh"
|
||||
#include "cql_config.hh"
|
||||
#include "cql3/expr/expr-utils.hh"
|
||||
#include "db/config.hh"
|
||||
#include "db_clock.hh"
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
@@ -117,8 +118,8 @@ void do_with_parser_impl(const std::string_view& cql, dialect d, noncopyable_fun
|
||||
|
||||
#endif
|
||||
|
||||
void validate_timestamp(const db::config& config, const query_options& options, const std::unique_ptr<attributes>& attrs) {
|
||||
if (attrs->is_timestamp_set() && config.restrict_future_timestamp()) {
|
||||
void validate_timestamp(const cql_config& cql_cfg, const query_options& options, const std::unique_ptr<attributes>& attrs) {
|
||||
if (attrs->is_timestamp_set() && cql_cfg.restrict_future_timestamp()) {
|
||||
static constexpr int64_t MAX_DIFFERENCE = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::days(3)).count();
|
||||
auto now = std::chrono::duration_cast<std::chrono::microseconds>(db_clock::now().time_since_epoch()).count();
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ sstring single_quote(const std::string_view s);
|
||||
|
||||
// Check whether timestamp is not too far in the future as this probably
|
||||
// indicates its incorrectness (for example using other units than microseconds).
|
||||
void validate_timestamp(const db::config& config, const query_options& options, const std::unique_ptr<attributes>& attrs);
|
||||
void validate_timestamp(const cql_config& cql_cfg, const query_options& options, const std::unique_ptr<attributes>& attrs);
|
||||
|
||||
template<typename T>
|
||||
std::vector<T> to_vector(const std::vector<data_value>& values) {
|
||||
|
||||
Reference in New Issue
Block a user