From 2739ac66ed735b00650ec526594d703f64a37ba0 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Tue, 3 Jan 2023 13:20:54 +0200 Subject: [PATCH] treewide: drop cql_serialization_format Now that we don't accept cql protocol version 1 or 2, we can drop cql_serialization format everywhere, except when in the IDL (since it's part of the inter-node protocol). A few functions had duplicate versions, one with and one without a cql_serialization_format parameter. They are deduplicated. Care is taken that `partition_slice`, which communicates the cql_serialization_format across nodes, still presents a valid cql_serialization_format to other nodes when transmitting itself and rejects protocol 1 and 2 serialization\ format when receiving. The IDL is unchanged. One test checking the 16-bit serialization format is removed. --- alternator/auth.cc | 2 +- alternator/executor.cc | 8 +- alternator/serialization.cc | 2 +- alternator/streams.cc | 2 +- cdc/log.cc | 29 +- collection_mutation.hh | 4 +- compound.hh | 3 +- cql3/attributes.cc | 4 +- cql3/expr/expression.cc | 52 ++- cql3/expr/expression.hh | 1 - cql3/functions/aggregate_fcts.cc | 73 ++-- cql3/functions/as_json_function.hh | 3 +- cql3/functions/bytes_conversion_fcts.hh | 11 +- cql3/functions/castas_fcts.cc | 2 +- cql3/functions/error_injection_fcts.cc | 10 +- cql3/functions/functions.cc | 6 +- cql3/functions/native_scalar_function.hh | 5 +- cql3/functions/scalar_function.hh | 3 +- cql3/functions/time_uuid_fcts.hh | 32 +- cql3/functions/token_fct.hh | 2 +- cql3/functions/user_function.cc | 3 +- cql3/functions/user_function.hh | 4 +- cql3/functions/uuid_fcts.hh | 2 +- cql3/query_options.cc | 26 +- cql3/query_options.hh | 20 +- cql3/selection/aggregate_function_selector.hh | 13 +- cql3/selection/field_selector.hh | 9 +- cql3/selection/scalar_function_selector.hh | 11 +- cql3/selection/selection.cc | 21 +- cql3/selection/selection.hh | 7 +- cql3/selection/selector.hh | 6 +- cql3/selection/simple_selector.hh | 4 +- cql3/selection/writetime_or_ttl_selector.hh | 4 +- .../prune_materialized_view_statement.cc | 2 +- cql3/statements/select_statement.cc | 15 +- cql3/statements/update_statement.cc | 6 +- cql3/type_json.cc | 59 ++- cql3/type_json.hh | 2 +- cql3/values.hh | 18 +- cql_serialization_format.hh | 14 +- db/functions/aggregate_function.hh | 8 +- db/legacy_schema_migrator.cc | 2 +- db/system_keyspace.cc | 2 +- mutation_partition.cc | 2 +- partition_slice_builder.cc | 1 - query-request.hh | 7 +- query-result-set.cc | 2 +- query.cc | 10 +- replica/database.cc | 2 +- replica/table.cc | 2 +- service/forward_service.cc | 9 +- service/pager/query_pagers.cc | 3 +- service/raft/raft_sys_table_storage.cc | 4 +- test/boost/cql_query_large_test.cc | 9 - test/boost/cql_query_test.cc | 11 +- test/boost/restrictions_test.cc | 2 +- test/boost/types_test.cc | 34 +- test/lib/cql_test_env.cc | 2 +- test/lib/expr_test_utils.cc | 12 +- thrift/handler.cc | 10 +- thrift/thrift_validation.cc | 2 +- tools/scylla-types.cc | 2 +- tracing/trace_keyspace_helper.cc | 10 +- transport/request.hh | 9 +- transport/response.hh | 6 +- transport/server.cc | 24 +- transport/server.hh | 3 - types.cc | 397 +++++++----------- types.hh | 27 +- types/collection.hh | 48 +-- types/list.hh | 3 +- ...listlike_partial_deserializing_iterator.hh | 35 +- types/map.hh | 21 +- types/set.hh | 7 +- 74 files changed, 521 insertions(+), 707 deletions(-) diff --git a/alternator/auth.cc b/alternator/auth.cc index d2b6790329..cb460c98fc 100644 --- a/alternator/auth.cc +++ b/alternator/auth.cc @@ -141,7 +141,7 @@ future get_key_from_roles(service::storage_proxy& proxy, std::strin service::storage_proxy::coordinator_query_result qr = co_await proxy.query(schema, std::move(command), std::move(partition_ranges), cl, service::storage_proxy::coordinator_query_options(executor::default_timeout(), empty_service_permit(), client_state)); - cql3::selection::result_set_builder builder(*selection, gc_clock::now(), cql_serialization_format::latest()); + cql3::selection::result_set_builder builder(*selection, gc_clock::now()); query::result_view::consume(*qr.query_result, partition_slice, cql3::selection::result_set_builder::visitor(builder, *schema, *selection)); auto result_set = builder.build(); diff --git a/alternator/executor.cc b/alternator/executor.cc index 2e62c5b054..031855ae81 100644 --- a/alternator/executor.cc +++ b/alternator/executor.cc @@ -2305,7 +2305,7 @@ void executor::describe_single_item(const cql3::selection::selection& selection, rjson::add_with_string_name(field, type_to_string((*column_it)->type), json_key_column_value(*cell, **column_it)); } } else if (cell) { - auto deserialized = attrs_type()->deserialize(*cell, cql_serialization_format::latest()); + auto deserialized = attrs_type()->deserialize(*cell); auto keys_and_values = value_cast(deserialized); for (auto entry : keys_and_values) { std::string attr_name = value_cast(entry.first); @@ -2340,7 +2340,7 @@ std::optional executor::describe_single_item(schema_ptr schema, const std::optional& attrs_to_get) { rjson::value item = rjson::empty_object(); - cql3::selection::result_set_builder builder(selection, gc_clock::now(), cql_serialization_format::latest()); + cql3::selection::result_set_builder builder(selection, gc_clock::now()); query::result_view::consume(query_result, slice, cql3::selection::result_set_builder::visitor(builder, *schema, selection)); auto result_set = builder.build(); @@ -2363,7 +2363,7 @@ std::vector executor::describe_multi_item(schema_ptr schema, const cql3::selection::selection& selection, const query::result& query_result, const std::optional& attrs_to_get) { - cql3::selection::result_set_builder builder(selection, gc_clock::now(), cql_serialization_format::latest()); + cql3::selection::result_set_builder builder(selection, gc_clock::now()); query::result_view::consume(query_result, slice, cql3::selection::result_set_builder::visitor(builder, *schema, selection)); auto result_set = builder.build(); std::vector ret; @@ -3511,7 +3511,7 @@ public: rjson::add_with_string_name(field, type_to_string((*_column_it)->type), json_key_column_value(bv, **_column_it)); } } else { - auto deserialized = attrs_type()->deserialize(bv, cql_serialization_format::latest()); + auto deserialized = attrs_type()->deserialize(bv); auto keys_and_values = value_cast(deserialized); for (auto entry : keys_and_values) { std::string attr_name = value_cast(entry.first); diff --git a/alternator/serialization.cc b/alternator/serialization.cc index 6366b62e0d..1d4faf5c45 100644 --- a/alternator/serialization.cc +++ b/alternator/serialization.cc @@ -73,7 +73,7 @@ struct from_json_visitor { } // default void operator()(const abstract_type& t) const { - bo.write(from_json_object(t, v, cql_serialization_format::internal())); + bo.write(from_json_object(t, v)); } }; diff --git a/alternator/streams.cc b/alternator/streams.cc index 081052cb29..f8e52fb93f 100644 --- a/alternator/streams.cc +++ b/alternator/streams.cc @@ -883,7 +883,7 @@ future executor::get_records(client_state& client return _proxy.query(schema, std::move(command), std::move(partition_ranges), cl, service::storage_proxy::coordinator_query_options(default_timeout(), std::move(permit), client_state)).then( [this, schema, partition_slice = std::move(partition_slice), selection = std::move(selection), start_time = std::move(start_time), limit, key_names = std::move(key_names), attr_names = std::move(attr_names), type, iter, high_ts] (service::storage_proxy::coordinator_query_result qr) mutable { - cql3::selection::result_set_builder builder(*selection, gc_clock::now(), cql_serialization_format::latest()); + cql3::selection::result_set_builder builder(*selection, gc_clock::now()); query::result_view::consume(*qr.query_result, partition_slice, cql3::selection::result_set_builder::visitor(builder, *schema, *selection)); auto result_set = builder.build(); diff --git a/cdc/log.cc b/cdc/log.cc index 7935681de8..1d23705eab 100644 --- a/cdc/log.cc +++ b/cdc/log.cc @@ -605,7 +605,7 @@ private: public: collection_iterator(managed_bytes_view_opt v = {}) : _v(v.value_or(managed_bytes_view{})) - , _rem(_v.empty() ? 0 : read_collection_size(_v, cql_serialization_format::internal())) + , _rem(_v.empty() ? 0 : read_collection_size(_v)) { if (_rem != 0) { parse(); @@ -650,8 +650,8 @@ template<> void collection_iterator>::parse() { assert(_rem > 0); _next = _v; - auto k = read_collection_value(_next, cql_serialization_format::internal()); - auto v = read_collection_value(_next, cql_serialization_format::internal()); + auto k = read_collection_value(_next); + auto v = read_collection_value(_next); _current = std::make_pair(k, v); } @@ -659,7 +659,7 @@ template<> void collection_iterator::parse() { assert(_rem > 0); _next = _v; - auto k = read_collection_value(_next, cql_serialization_format::internal()); + auto k = read_collection_value(_next); _current = k; } @@ -728,7 +728,7 @@ auto make_maybe_back_inserter(Container& c, const abstract_type& type, collectio static size_t collection_size(const managed_bytes_opt& bo) { if (bo) { managed_bytes_view mbv(*bo); - return read_collection_size(mbv, cql_serialization_format::internal()); + return read_collection_size(mbv); } return 0; } @@ -750,7 +750,7 @@ static managed_bytes merge(const collection_type_impl& ctype, const managed_byte // note order: set_union, when finding doubles, use value from first1 (j here). So // since this is next, it has prio std::set_union(j, e, i, e, make_maybe_back_inserter(res, *type, collection_iterator(deleted)), cmp); - return map_type_impl::serialize_partially_deserialized_form_fragmented(res, cql_serialization_format::internal()); + return map_type_impl::serialize_partially_deserialized_form_fragmented(res); } static managed_bytes merge(const set_type_impl& ctype, const managed_bytes_opt& prev, const managed_bytes_opt& next, const managed_bytes_opt& deleted) { std::vector res; @@ -761,7 +761,7 @@ static managed_bytes merge(const set_type_impl& ctype, const managed_bytes_opt& }; collection_iterator e, i(prev), j(next), d(deleted); std::set_union(j, e, i, e, make_maybe_back_inserter(res, *type, d), cmp); - return set_type_impl::serialize_partially_deserialized_form_fragmented(res, cql_serialization_format::internal()); + return set_type_impl::serialize_partially_deserialized_form_fragmented(res); } static managed_bytes merge(const user_type_impl& type, const managed_bytes_opt& prev, const managed_bytes_opt& next, const managed_bytes_opt& deleted) { std::vector res(type.size()); @@ -812,15 +812,14 @@ static managed_bytes_opt get_preimage_col_value(const column_definition& cdef, c // flatten set [&] (const set_type_impl& type) { auto v = pirow->get_view(cdef.name_as_text()); - auto f = cql_serialization_format::internal(); - auto n = read_collection_size(v, f); + auto n = read_collection_size(v); std::vector tmp; tmp.reserve(n); while (n--) { - tmp.emplace_back(read_collection_value(v, f)); // key - read_collection_value(v, f); // value. ignore. + tmp.emplace_back(read_collection_value(v)); // key + read_collection_value(v); // value. ignore. } - return set_type_impl::serialize_partially_deserialized_form_fragmented({tmp.begin(), tmp.end()}, f); + return set_type_impl::serialize_partially_deserialized_form_fragmented({tmp.begin(), tmp.end()}); }, [&] (const abstract_type& o) -> managed_bytes { return pirow->get_blob_fragmented(cdef.name_as_text()); @@ -1122,7 +1121,7 @@ struct process_row_visitor { visit_collection(v); managed_bytes_opt added_keys = v._added_keys.empty() ? std::nullopt : - std::optional{set_type_impl::serialize_partially_deserialized_form_fragmented(v._added_keys, cql_serialization_format::internal())}; + std::optional{set_type_impl::serialize_partially_deserialized_form_fragmented(v._added_keys)}; return { v._is_column_delete, @@ -1178,7 +1177,7 @@ struct process_row_visitor { visit_collection(v); managed_bytes_opt added_cells = v._added_cells.empty() ? std::nullopt : - std::optional{map_type_impl::serialize_partially_deserialized_form_fragmented(v._added_cells, cql_serialization_format::internal())}; + std::optional{map_type_impl::serialize_partially_deserialized_form_fragmented(v._added_cells)}; return { v._is_column_delete, @@ -1198,7 +1197,7 @@ struct process_row_visitor { // then we deserialize again when merging images below managed_bytes_opt deleted_elements = std::nullopt; if (!deleted_keys.empty()) { - deleted_elements = set_type_impl::serialize_partially_deserialized_form_fragmented(deleted_keys, cql_serialization_format::internal()); + deleted_elements = set_type_impl::serialize_partially_deserialized_form_fragmented(deleted_keys); } // delta diff --git a/collection_mutation.hh b/collection_mutation.hh index b65ebb9dec..ffefd87fd2 100644 --- a/collection_mutation.hh +++ b/collection_mutation.hh @@ -21,8 +21,6 @@ class row_tombstone; class collection_mutation; -class cql_serialization_format; - // An auxiliary struct used to (de)construct collection_mutations. // Unlike collection_mutation which is a serialized blob, this struct allows to inspect logical units of information // (tombstone and cells) inside the mutation easily. @@ -131,4 +129,4 @@ collection_mutation merge(const abstract_type&, collection_mutation_view, collec collection_mutation difference(const abstract_type&, collection_mutation_view, collection_mutation_view); // Serializes the given collection of cells to a sequence of bytes ready to be sent over the CQL protocol. -bytes_ostream serialize_for_cql(const abstract_type&, collection_mutation_view, cql_serialization_format); +bytes_ostream serialize_for_cql(const abstract_type&, collection_mutation_view); diff --git a/compound.hh b/compound.hh index 86ff85a945..56e1752453 100644 --- a/compound.hh +++ b/compound.hh @@ -16,7 +16,6 @@ #include #include "utils/serialization.hh" #include -#include "cql_serialization_format.hh" enum class allow_prefixes { no, yes }; @@ -280,7 +279,7 @@ public: } for (size_t i = 0; i != values.size(); ++i) { //FIXME: is it safe to assume internal serialization-format format? - _types[i]->validate(values[i], cql_serialization_format::internal()); + _types[i]->validate(values[i]); } } bool equal(managed_bytes_view v1, managed_bytes_view v2) const { diff --git a/cql3/attributes.cc b/cql3/attributes.cc index 84e80eca67..622f1be1c7 100644 --- a/cql3/attributes.cc +++ b/cql3/attributes.cc @@ -50,7 +50,7 @@ int64_t attributes::get_timestamp(int64_t now, const query_options& options) { return now; } try { - return tval.view().validate_and_deserialize(*long_type, cql_serialization_format::internal()); + return tval.view().validate_and_deserialize(*long_type); } catch (marshal_exception& e) { throw exceptions::invalid_request_exception("Invalid timestamp value"); } @@ -70,7 +70,7 @@ int32_t attributes::get_time_to_live(const query_options& options) { int32_t ttl; try { - ttl = tval.view().validate_and_deserialize(*int32_type, cql_serialization_format::internal()); + ttl = tval.view().validate_and_deserialize(*int32_type); } catch (marshal_exception& e) { throw exceptions::invalid_request_exception("Invalid TTL value"); diff --git a/cql3/expr/expression.cc b/cql3/expr/expression.cc index 9326338e5e..f32f2635c7 100644 --- a/cql3/expr/expression.cc +++ b/cql3/expr/expression.cc @@ -1811,32 +1811,31 @@ cql3::raw_value evaluate(const expression& e, const query_options& options) { // Takes a value and reserializes it where needs_to_be_reserialized() says it's needed template static managed_bytes reserialize_value(View value_bytes, - const abstract_type& type, - const cql_serialization_format& sf) { + const abstract_type& type) { if (type.is_list()) { - utils::chunked_vector elements = partially_deserialize_listlike(value_bytes, sf); + utils::chunked_vector elements = partially_deserialize_listlike(value_bytes); const abstract_type& element_type = dynamic_cast(type).get_elements_type()->without_reversed(); - if (element_type.bound_value_needs_to_be_reserialized(sf)) { + if (element_type.bound_value_needs_to_be_reserialized()) { for (managed_bytes& element : elements) { - element = reserialize_value(managed_bytes_view(element), element_type, sf); + element = reserialize_value(managed_bytes_view(element), element_type); } } return collection_type_impl::pack_fragmented( elements.begin(), elements.end(), - elements.size(), cql_serialization_format::internal() + elements.size() ); } if (type.is_set()) { - utils::chunked_vector elements = partially_deserialize_listlike(value_bytes, sf); + utils::chunked_vector elements = partially_deserialize_listlike(value_bytes); const abstract_type& element_type = dynamic_cast(type).get_elements_type()->without_reversed(); - if (element_type.bound_value_needs_to_be_reserialized(sf)) { + if (element_type.bound_value_needs_to_be_reserialized()) { for (managed_bytes& element : elements) { - element = reserialize_value(managed_bytes_view(element), element_type, sf); + element = reserialize_value(managed_bytes_view(element), element_type); } } @@ -1848,26 +1847,26 @@ static managed_bytes reserialize_value(View value_bytes, return collection_type_impl::pack_fragmented( values_set.begin(), values_set.end(), - values_set.size(), cql_serialization_format::internal() + values_set.size() ); } if (type.is_map()) { - std::vector> elements = partially_deserialize_map(value_bytes, sf); + std::vector> elements = partially_deserialize_map(value_bytes); const map_type_impl mapt = dynamic_cast(type); const abstract_type& key_type = mapt.get_keys_type()->without_reversed(); const abstract_type& value_type = mapt.get_values_type()->without_reversed(); - if (key_type.bound_value_needs_to_be_reserialized(sf)) { + if (key_type.bound_value_needs_to_be_reserialized()) { for (std::pair& element : elements) { - element.first = reserialize_value(managed_bytes_view(element.first), key_type, sf); + element.first = reserialize_value(managed_bytes_view(element.first), key_type); } } - if (value_type.bound_value_needs_to_be_reserialized(sf)) { + if (value_type.bound_value_needs_to_be_reserialized()) { for (std::pair& element : elements) { - element.second = reserialize_value(managed_bytes_view(element.second), value_type, sf); + element.second = reserialize_value(managed_bytes_view(element.second), value_type); } } @@ -1885,8 +1884,8 @@ static managed_bytes reserialize_value(View value_bytes, for (std::size_t i = 0; i < elements.size(); i++) { const abstract_type& element_type = ttype.all_types().at(i)->without_reversed(); - if (elements[i].has_value() && element_type.bound_value_needs_to_be_reserialized(sf)) { - elements[i] = reserialize_value(managed_bytes_view(*elements[i]), element_type, sf); + if (elements[i].has_value() && element_type.bound_value_needs_to_be_reserialized()) { + elements[i] = reserialize_value(managed_bytes_view(*elements[i]), element_type); } } @@ -1915,15 +1914,15 @@ static cql3::raw_value evaluate(const bind_variable& bind_var, const evaluation_ const abstract_type& value_type = bind_var.receiver->type->without_reversed(); try { - value.validate(value_type, inputs.options->get_cql_serialization_format()); + value.validate(value_type); } catch (const marshal_exception& e) { throw exceptions::invalid_request_exception(format("Exception while binding column {:s}: {:s}", bind_var.receiver->name->to_cql_string(), e.what())); } - if (value_type.bound_value_needs_to_be_reserialized(inputs.options->get_cql_serialization_format())) { + if (value_type.bound_value_needs_to_be_reserialized()) { managed_bytes new_value = value.with_value([&] (const FragmentedView auto& value_bytes) { - return reserialize_value(value_bytes, value_type, inputs.options->get_cql_serialization_format()); + return reserialize_value(value_bytes, value_type); }); return raw_value::make_value(std::move(new_value)); @@ -1975,8 +1974,7 @@ static managed_bytes serialize_listlike(const Range& elements, const char* colle return collection_type_impl::pack_fragmented( elements.begin(), elements.end(), - elements.size(), - cql_serialization_format::internal() + elements.size() ); } @@ -2175,7 +2173,7 @@ static cql3::raw_value evaluate(const function_call& fun_call, const evaluation_ } } - bytes_opt result = scalar_fun->execute(cql_serialization_format::internal(), arguments); + bytes_opt result = scalar_fun->execute(arguments); if (has_cache_id) { inputs.options->cache_pk_function_call(**fun_call.lwt_cache_id, result); @@ -2186,7 +2184,7 @@ static cql3::raw_value evaluate(const function_call& fun_call, const evaluation_ } try { - scalar_fun->return_type()->validate(*result, cql_serialization_format::internal()); + scalar_fun->return_type()->validate(*result); } catch (marshal_exception&) { throw runtime_exception(format("Return of function {} ({}) is not a valid value for its declared return type {}", *scalar_fun, to_hex(result), @@ -2212,7 +2210,7 @@ utils::chunked_vector get_list_elements(const cql3::raw_value& va ensure_can_get_value_elements(val, "expr::get_list_elements"); return val.view().with_value([](const FragmentedView auto& value_bytes) { - return partially_deserialize_listlike(value_bytes, cql_serialization_format::internal()); + return partially_deserialize_listlike(value_bytes); }); } @@ -2220,7 +2218,7 @@ utils::chunked_vector get_set_elements(const cql3::raw_value& val ensure_can_get_value_elements(val, "expr::get_set_elements"); return val.view().with_value([](const FragmentedView auto& value_bytes) { - return partially_deserialize_listlike(value_bytes, cql_serialization_format::internal()); + return partially_deserialize_listlike(value_bytes); }); } @@ -2228,7 +2226,7 @@ std::vector> get_map_elements(const cql3 ensure_can_get_value_elements(val, "expr::get_map_elements"); return val.view().with_value([](const FragmentedView auto& value_bytes) { - return partially_deserialize_map(value_bytes, cql_serialization_format::internal()); + return partially_deserialize_map(value_bytes); }); } diff --git a/cql3/expr/expression.hh b/cql3/expr/expression.hh index 6a7af3990a..baf0303c99 100644 --- a/cql3/expr/expression.hh +++ b/cql3/expr/expression.hh @@ -365,7 +365,6 @@ untyped_constant make_untyped_null(); // Represents a constant value with known value and type // For null and unset the type can sometimes be set to empty_type struct constant { - // A value serialized using the internal (latest) cql_serialization_format cql3::raw_value value; // Never nullptr, for NULL and UNSET might be empty_type diff --git a/cql3/functions/aggregate_fcts.cc b/cql3/functions/aggregate_fcts.cc index f39fce9d01..592bff8da0 100644 --- a/cql3/functions/aggregate_fcts.cc +++ b/cql3/functions/aggregate_fcts.cc @@ -13,7 +13,6 @@ #include "types/tuple.hh" #include "cql3/functions/scalar_function.hh" #include "cql3/util.hh" -#include "cql_serialization_format.hh" #include "utils/big_decimal.hh" #include "aggregate_fcts.hh" #include "user_aggregate.hh" @@ -41,10 +40,10 @@ public: virtual void reset() override { _count = 0; } - virtual opt_bytes compute(cql_serialization_format sf) override { + virtual opt_bytes compute() override { return long_type->decompose(_count); } - virtual void add_input(cql_serialization_format sf, const std::vector& values) override { + virtual void add_input(const std::vector& values) override { ++_count; } virtual void set_accumulator(const opt_bytes& acc) override { @@ -57,7 +56,7 @@ public: virtual opt_bytes get_accumulator() const override { return long_type->decompose(_count); } - virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override { + virtual void reduce(const opt_bytes& acc) override { if (acc) { auto other = value_cast(long_type->deserialize(bytes_view(*acc))); _count += other; @@ -190,13 +189,13 @@ public: virtual void reset() override { _acc = _initcond; } - virtual opt_bytes compute(cql_serialization_format sf) override { - return _finalfunc ? _finalfunc->execute(sf, std::vector{_acc}) : _acc; + virtual opt_bytes compute() override { + return _finalfunc ? _finalfunc->execute(std::vector{_acc}) : _acc; } - virtual void add_input(cql_serialization_format sf, const std::vector& values) override { + virtual void add_input(const std::vector& values) override { std::vector args{_acc}; args.insert(args.end(), values.begin(), values.end()); - _acc = _sfunc->execute(sf, args); + _acc = _sfunc->execute(args); } virtual void set_accumulator(const opt_bytes& acc) override { _acc = acc; @@ -204,9 +203,9 @@ public: virtual opt_bytes get_accumulator() const override { return _acc; } - virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override { + virtual void reduce(const opt_bytes& acc) override { std::vector args{_acc, acc}; - _acc = _rfunc->execute(sf, args); + _acc = _rfunc->execute(args); } }; @@ -219,10 +218,10 @@ public: virtual void reset() override { _sum = {}; } - virtual opt_bytes compute(cql_serialization_format sf) override { + virtual opt_bytes compute() override { return data_type_for()->decompose(accumulator_for::narrow(_sum)); } - virtual void add_input(cql_serialization_format sf, const std::vector& values) override { + virtual void add_input(const std::vector& values) override { if (!values[0]) { return; } @@ -238,7 +237,7 @@ public: virtual opt_bytes get_accumulator() const override { return accumulator_for::decompose(_sum); } - virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override { + virtual void reduce(const opt_bytes& acc) override { if (acc) { auto other = accumulator_for::deserialize(acc); _sum += other; @@ -249,7 +248,7 @@ public: template class impl_reducible_sum_function final : public impl_sum_function_for { public: - virtual bytes_opt compute(cql_serialization_format sf) override { + virtual bytes_opt compute() override { return this->get_accumulator(); } }; @@ -317,14 +316,14 @@ public: _sum = {}; _count = 0; } - virtual opt_bytes compute(cql_serialization_format sf) override { + virtual opt_bytes compute() override { Type ret{}; if (_count) { ret = impl_div_for_avg::div(_sum, _count); } return data_type_for()->decompose(ret); } - virtual void add_input(cql_serialization_format sf, const std::vector& values) override { + virtual void add_input(const std::vector& values) override { if (!values[0]) { return; } @@ -349,7 +348,7 @@ public: ); return tuple_val.serialize(); } - virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override { + virtual void reduce(const opt_bytes& acc) override { if (acc) { data_type tuple_type = tuple_type_impl::get_instance({accumulator_for::data_type(), long_type}); auto tuple = value_cast(tuple_type->deserialize(bytes_view(*acc))); @@ -363,7 +362,7 @@ public: template class impl_reducible_avg_function : public impl_avg_function_for { public: - virtual bytes_opt compute(cql_serialization_format sf) override { + virtual bytes_opt compute() override { return this->get_accumulator(); } }; @@ -458,13 +457,13 @@ public: virtual void reset() override { _max = {}; } - virtual opt_bytes compute(cql_serialization_format sf) override { + virtual opt_bytes compute() override { if (!_max) { return {}; } return data_type_for()->decompose(data_value(Type{*_max})); } - virtual void add_input(cql_serialization_format sf, const std::vector& values) override { + virtual void add_input(const std::vector& values) override { if (!values[0]) { return; } @@ -488,8 +487,8 @@ public: } return {}; } - virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override { - return add_input(sf, {acc}); + virtual void reduce(const opt_bytes& acc) override { + return add_input({acc}); } }; @@ -503,10 +502,10 @@ public: virtual void reset() override { _max = {}; } - virtual opt_bytes compute(cql_serialization_format sf) override { + virtual opt_bytes compute() override { return _max.value_or(bytes{}); } - virtual void add_input(cql_serialization_format sf, const std::vector& values) override { + virtual void add_input(const std::vector& values) override { if (values.empty() || !values[0]) { return; } @@ -520,11 +519,11 @@ public: virtual opt_bytes get_accumulator() const override { return _max; } - virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override { + virtual void reduce(const opt_bytes& acc) override { if (acc && !acc->length()) { return; } - return add_input(sf, {acc}); + return add_input({acc}); } }; @@ -599,13 +598,13 @@ public: virtual void reset() override { _min = {}; } - virtual opt_bytes compute(cql_serialization_format sf) override { + virtual opt_bytes compute() override { if (!_min) { return {}; } return data_type_for()->decompose(data_value(Type{*_min})); } - virtual void add_input(cql_serialization_format sf, const std::vector& values) override { + virtual void add_input(const std::vector& values) override { if (!values[0]) { return; } @@ -629,8 +628,8 @@ public: } return {}; } - virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override { - return add_input(sf, {acc}); + virtual void reduce(const opt_bytes& acc) override { + return add_input({acc}); } }; @@ -644,10 +643,10 @@ public: virtual void reset() override { _min = {}; } - virtual opt_bytes compute(cql_serialization_format sf) override { + virtual opt_bytes compute() override { return _min.value_or(bytes{}); } - virtual void add_input(cql_serialization_format sf, const std::vector& values) override { + virtual void add_input(const std::vector& values) override { if (values.empty() || !values[0]) { return; } @@ -661,11 +660,11 @@ public: virtual opt_bytes get_accumulator() const override { return _min; } - virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override { + virtual void reduce(const opt_bytes& acc) override { if (acc && !acc->length()) { return; } - return add_input(sf, {acc}); + return add_input({acc}); } }; @@ -721,10 +720,10 @@ public: virtual void reset() override { _count = 0; } - virtual opt_bytes compute(cql_serialization_format sf) override { + virtual opt_bytes compute() override { return long_type->decompose(_count); } - virtual void add_input(cql_serialization_format sf, const std::vector& values) override { + virtual void add_input(const std::vector& values) override { if (!values[0]) { return; } @@ -740,7 +739,7 @@ public: virtual opt_bytes get_accumulator() const override { return long_type->decompose(_count); } - virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) override { + virtual void reduce(const opt_bytes& acc) override { if (acc) { auto other = value_cast(long_type->deserialize(bytes_view(*acc))); _count += other; diff --git a/cql3/functions/as_json_function.hh b/cql3/functions/as_json_function.hh index ebe8e1a98f..b908e55803 100644 --- a/cql3/functions/as_json_function.hh +++ b/cql3/functions/as_json_function.hh @@ -18,7 +18,6 @@ #include "bytes_ostream.hh" #include "types.hh" -#include "cql_serialization_format.hh" #include @@ -47,7 +46,7 @@ public: virtual bool requires_thread() const override; - virtual bytes_opt execute(cql_serialization_format sf, const std::vector& parameters) override { + virtual bytes_opt execute(const std::vector& parameters) override { bytes_ostream encoded_row; encoded_row.write("{", 1); for (size_t i = 0; i < _selector_names.size(); ++i) { diff --git a/cql3/functions/bytes_conversion_fcts.hh b/cql3/functions/bytes_conversion_fcts.hh index 41ba370ae4..519efbb151 100644 --- a/cql3/functions/bytes_conversion_fcts.hh +++ b/cql3/functions/bytes_conversion_fcts.hh @@ -14,7 +14,6 @@ #include "exceptions/exceptions.hh" #include #include "cql3/cql3_type.hh" -#include "cql_serialization_format.hh" namespace cql3 { @@ -28,7 +27,7 @@ shared_ptr make_to_blob_function(data_type from_type) { auto name = from_type->as_cql3_type().to_string() + "asblob"; return make_native_scalar_function(name, bytes_type, { from_type }, - [] (cql_serialization_format sf, const std::vector& parameters) { + [] (const std::vector& parameters) { return parameters[0]; }); } @@ -38,13 +37,13 @@ shared_ptr make_from_blob_function(data_type to_type) { sstring name = sstring("blobas") + to_type->as_cql3_type().to_string(); return make_native_scalar_function(name, to_type, { bytes_type }, - [name, to_type] (cql_serialization_format sf, const std::vector& parameters) -> bytes_opt { + [name, to_type] (const std::vector& parameters) -> bytes_opt { auto&& val = parameters[0]; if (!val) { return val; } try { - to_type->validate(*val, sf); + to_type->validate(*val); return val; } catch (marshal_exception& e) { using namespace exceptions; @@ -58,7 +57,7 @@ inline shared_ptr make_varchar_as_blob_fct() { return make_native_scalar_function("varcharasblob", bytes_type, { utf8_type }, - [] (cql_serialization_format sf, const std::vector& parameters) -> bytes_opt { + [] (const std::vector& parameters) -> bytes_opt { return parameters[0]; }); } @@ -67,7 +66,7 @@ inline shared_ptr make_blob_as_varchar_fct() { return make_native_scalar_function("blobasvarchar", utf8_type, { bytes_type }, - [] (cql_serialization_format sf, const std::vector& parameters) -> bytes_opt { + [] (const std::vector& parameters) -> bytes_opt { return parameters[0]; }); } diff --git a/cql3/functions/castas_fcts.cc b/cql3/functions/castas_fcts.cc index 143bc6e5cf..7bff59f717 100644 --- a/cql3/functions/castas_fcts.cc +++ b/cql3/functions/castas_fcts.cc @@ -35,7 +35,7 @@ public: virtual void print(std::ostream& os) const override { os << "cast(" << _arg_types[0]->name() << " as " << _return_type->name() << ")"; } - virtual bytes_opt execute(cql_serialization_format sf, const std::vector& parameters) override { + virtual bytes_opt execute(const std::vector& parameters) override { auto from_type = arg_types()[0]; auto to_type = return_type(); diff --git a/cql3/functions/error_injection_fcts.cc b/cql3/functions/error_injection_fcts.cc index 23683914f7..cc814992b5 100644 --- a/cql3/functions/error_injection_fcts.cc +++ b/cql3/functions/error_injection_fcts.cc @@ -40,8 +40,8 @@ public: return Pure; } - bytes_opt execute(cql_serialization_format sf, const std::vector& parameters) override { - return _func(sf, parameters); + bytes_opt execute(const std::vector& parameters) override { + return _func(parameters); } }; @@ -61,7 +61,7 @@ make_failure_injection_function(sstring name, shared_ptr make_enable_injection_function() { return make_failure_injection_function("enable_injection", empty_type, { ascii_type, ascii_type }, - [] (cql_serialization_format, const std::vector& parameters) { + [] (const std::vector& parameters) { sstring injection_name = ascii_type->get_string(parameters[0].value()); const bool one_shot = ascii_type->get_string(parameters[1].value()) == "true"; smp::invoke_on_all([injection_name, one_shot] () mutable { @@ -73,7 +73,7 @@ shared_ptr make_enable_injection_function() { shared_ptr make_disable_injection_function() { return make_failure_injection_function("disable_injection", empty_type, { ascii_type }, - [] (cql_serialization_format, const std::vector& parameters) { + [] (const std::vector& parameters) { sstring injection_name = ascii_type->get_string(parameters[0].value()); smp::invoke_on_all([injection_name] () mutable { utils::get_local_injector().disable(injection_name); @@ -85,7 +85,7 @@ shared_ptr make_disable_injection_function() { shared_ptr make_enabled_injections_function() { const auto list_type_inst = list_type_impl::get_instance(ascii_type, false); return make_failure_injection_function("enabled_injections", list_type_inst, {}, - [list_type_inst] (cql_serialization_format, const std::vector&) -> bytes { + [list_type_inst] (const std::vector&) -> bytes { return seastar::map_reduce(smp::all_cpus(), [] (unsigned) { return make_ready_future>(utils::get_local_injector().enabled_injections()); }, std::vector(), diff --git a/cql3/functions/functions.cc b/cql3/functions/functions.cc index 38db8ccca5..336d3a864b 100644 --- a/cql3/functions/functions.cc +++ b/cql3/functions/functions.cc @@ -174,7 +174,7 @@ inline shared_ptr make_to_json_function(data_type t) { return make_native_scalar_function("tojson", utf8_type, {t}, - [t](cql_serialization_format sf, const std::vector& parameters) -> bytes_opt { + [t](const std::vector& parameters) -> bytes_opt { return utf8_type->decompose(to_json_string(*t, parameters[0])); }); } @@ -183,12 +183,12 @@ inline shared_ptr make_from_json_function(data_dictionary::database db, const sstring& keyspace, data_type t) { return make_native_scalar_function("fromjson", t, {utf8_type}, - [&db, keyspace, t](cql_serialization_format sf, const std::vector& parameters) -> bytes_opt { + [&db, keyspace, t](const std::vector& parameters) -> bytes_opt { try { rjson::value json_value = rjson::parse(utf8_type->to_string(parameters[0].value())); bytes_opt parsed_json_value; if (!json_value.IsNull()) { - parsed_json_value.emplace(from_json_object(*t, json_value, sf)); + parsed_json_value.emplace(from_json_object(*t, json_value)); } return parsed_json_value; } catch(rjson::error& e) { diff --git a/cql3/functions/native_scalar_function.hh b/cql3/functions/native_scalar_function.hh index f8d4e917aa..3d89a3bbc4 100644 --- a/cql3/functions/native_scalar_function.hh +++ b/cql3/functions/native_scalar_function.hh @@ -12,7 +12,6 @@ #include "native_function.hh" #include "scalar_function.hh" -#include "cql_serialization_format.hh" #include "log.hh" #include @@ -48,9 +47,9 @@ public: virtual bool is_pure() const override { return Pure; } - virtual bytes_opt execute(cql_serialization_format sf, const std::vector& parameters) override { + virtual bytes_opt execute(const std::vector& parameters) override { try { - return _func(sf, parameters); + return _func(parameters); } catch(exceptions::cassandra_exception&) { // If the function's code took the time to produce an official // cassandra_exception, pass it through. Otherwise, below we will diff --git a/cql3/functions/scalar_function.hh b/cql3/functions/scalar_function.hh index 266be3e82e..98d6257757 100644 --- a/cql3/functions/scalar_function.hh +++ b/cql3/functions/scalar_function.hh @@ -23,12 +23,11 @@ public: /** * Applies this function to the specified parameter. * - * @param protocolVersion protocol version used for parameters and return value * @param parameters the input parameters * @return the result of applying this function to the parameter * @throws InvalidRequestException if this function cannot not be applied to the parameter */ - virtual bytes_opt execute(cql_serialization_format sf, const std::vector& parameters) = 0; + virtual bytes_opt execute(const std::vector& parameters) = 0; }; diff --git a/cql3/functions/time_uuid_fcts.hh b/cql3/functions/time_uuid_fcts.hh index b4fe6e1a69..693922b69b 100644 --- a/cql3/functions/time_uuid_fcts.hh +++ b/cql3/functions/time_uuid_fcts.hh @@ -24,7 +24,7 @@ inline shared_ptr make_now_fct() { return make_native_scalar_function("now", timeuuid_type, {}, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { return {to_bytes(utils::UUID_gen::get_time_UUID())}; }); } @@ -42,7 +42,7 @@ inline shared_ptr make_min_timeuuid_fct() { return make_native_scalar_function("mintimeuuid", timeuuid_type, { timestamp_type }, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { auto& bb = values[0]; if (!bb) { return {}; @@ -60,7 +60,7 @@ inline shared_ptr make_max_timeuuid_fct() { return make_native_scalar_function("maxtimeuuid", timeuuid_type, { timestamp_type }, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { auto& bb = values[0]; if (!bb) { return {}; @@ -89,7 +89,7 @@ inline shared_ptr make_date_of_fct() { return make_native_scalar_function("dateof", timestamp_type, { timeuuid_type }, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { using namespace utils; auto& bb = values[0]; if (!bb) { @@ -104,7 +104,7 @@ inline shared_ptr make_unix_timestamp_of_fct() { return make_native_scalar_function("unixtimestampof", long_type, { timeuuid_type }, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { using namespace utils; auto& bb = values[0]; if (!bb) { @@ -117,7 +117,7 @@ make_unix_timestamp_of_fct() { inline shared_ptr make_currenttimestamp_fct() { return make_native_scalar_function("currenttimestamp", timestamp_type, {}, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { return {timestamp_type->decompose(db_clock::now())}; }); } @@ -125,7 +125,7 @@ make_currenttimestamp_fct() { inline shared_ptr make_currenttime_fct() { return make_native_scalar_function("currenttime", time_type, {}, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { constexpr int64_t milliseconds_in_day = 3600 * 24 * 1000; int64_t milliseconds_since_epoch = std::chrono::duration_cast(db_clock::now().time_since_epoch()).count(); int64_t nanoseconds_today = (milliseconds_since_epoch % milliseconds_in_day) * 1000 * 1000; @@ -136,7 +136,7 @@ make_currenttime_fct() { inline shared_ptr make_currentdate_fct() { return make_native_scalar_function("currentdate", simple_date_type, {}, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { auto to_simple_date = get_castas_fctn(simple_date_type, timestamp_type); return {simple_date_type->decompose(to_simple_date(db_clock::now()))}; }); @@ -146,7 +146,7 @@ inline shared_ptr make_currenttimeuuid_fct() { return make_native_scalar_function("currenttimeuuid", timeuuid_type, {}, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { return {timeuuid_type->decompose(timeuuid_native_type{utils::UUID_gen::get_time_UUID()})}; }); } @@ -155,7 +155,7 @@ inline shared_ptr make_timeuuidtodate_fct() { return make_native_scalar_function("todate", simple_date_type, { timeuuid_type }, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { using namespace utils; auto& bb = values[0]; if (!bb) { @@ -171,7 +171,7 @@ inline shared_ptr make_timestamptodate_fct() { return make_native_scalar_function("todate", simple_date_type, { timestamp_type }, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { using namespace utils; auto& bb = values[0]; if (!bb) { @@ -190,7 +190,7 @@ inline shared_ptr make_timeuuidtotimestamp_fct() { return make_native_scalar_function("totimestamp", timestamp_type, { timeuuid_type }, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { using namespace utils; auto& bb = values[0]; if (!bb) { @@ -205,7 +205,7 @@ inline shared_ptr make_datetotimestamp_fct() { return make_native_scalar_function("totimestamp", timestamp_type, { simple_date_type }, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { using namespace utils; auto& bb = values[0]; if (!bb) { @@ -224,7 +224,7 @@ inline shared_ptr make_timeuuidtounixtimestamp_fct() { return make_native_scalar_function("tounixtimestamp", long_type, { timeuuid_type }, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { using namespace utils; auto& bb = values[0]; if (!bb) { @@ -242,7 +242,7 @@ inline shared_ptr make_timestamptounixtimestamp_fct() { return make_native_scalar_function("tounixtimestamp", long_type, { timestamp_type }, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { using namespace utils; auto& bb = values[0]; if (!bb) { @@ -260,7 +260,7 @@ inline shared_ptr make_datetounixtimestamp_fct() { return make_native_scalar_function("tounixtimestamp", long_type, { simple_date_type }, - [] (cql_serialization_format sf, const std::vector& values) -> bytes_opt { + [] (const std::vector& values) -> bytes_opt { using namespace utils; auto& bb = values[0]; if (!bb) { diff --git a/cql3/functions/token_fct.hh b/cql3/functions/token_fct.hh index 6cbd4bed8d..6f38b1fd0e 100644 --- a/cql3/functions/token_fct.hh +++ b/cql3/functions/token_fct.hh @@ -31,7 +31,7 @@ public: , _schema(s) { } - bytes_opt execute(cql_serialization_format sf, const std::vector& parameters) override { + bytes_opt execute(const std::vector& parameters) override { if (std::any_of(parameters.cbegin(), parameters.cend(), [](const auto& param){ return !param; })) { return std::nullopt; } diff --git a/cql3/functions/user_function.cc b/cql3/functions/user_function.cc index 8d943508a6..bc9cbbd2df 100644 --- a/cql3/functions/user_function.cc +++ b/cql3/functions/user_function.cc @@ -9,7 +9,6 @@ #include "user_function.hh" #include "cql3/util.hh" #include "log.hh" -#include "cql_serialization_format.hh" #include "lang/wasm.hh" #include @@ -33,7 +32,7 @@ bool user_function::is_aggregate() const { return false; } bool user_function::requires_thread() const { return true; } -bytes_opt user_function::execute(cql_serialization_format sf, const std::vector& parameters) { +bytes_opt user_function::execute(const std::vector& parameters) { const auto& types = arg_types(); if (parameters.size() != types.size()) { throw std::logic_error("Wrong number of parameters"); diff --git a/cql3/functions/user_function.hh b/cql3/functions/user_function.hh index 8fb9297cb1..312284f37d 100644 --- a/cql3/functions/user_function.hh +++ b/cql3/functions/user_function.hh @@ -26,7 +26,7 @@ public: sstring bitcode; // FIXME: We should not need a copy in each function. It is here // because user_function::execute is only passed the - // cql_serialization_format and the runtime arguments. We could + // the runtime arguments. We could // avoid it by having a runtime->execute(user_function) instead, // but that is a large refactoring. We could also store a // lua_runtime in a thread_local variable, but that is one extra @@ -59,7 +59,7 @@ public: virtual bool is_native() const override; virtual bool is_aggregate() const override; virtual bool requires_thread() const override; - virtual bytes_opt execute(cql_serialization_format sf, const std::vector& parameters) override; + virtual bytes_opt execute(const std::vector& parameters) override; virtual sstring keypace_name() const override { return name().keyspace; } virtual sstring element_name() const override { return name().name; } diff --git a/cql3/functions/uuid_fcts.hh b/cql3/functions/uuid_fcts.hh index 29fdab3d9a..f513112ba1 100644 --- a/cql3/functions/uuid_fcts.hh +++ b/cql3/functions/uuid_fcts.hh @@ -22,7 +22,7 @@ inline shared_ptr make_uuid_fct() { return make_native_scalar_function("uuid", uuid_type, {}, - [] (cql_serialization_format sf, const std::vector& parameters) -> bytes_opt { + [] (const std::vector& parameters) -> bytes_opt { return {uuid_type->decompose(utils::make_random_uuid())}; }); } diff --git a/cql3/query_options.cc b/cql3/query_options.cc index ce922e6c40..a2736e07a2 100644 --- a/cql3/query_options.cc +++ b/cql3/query_options.cc @@ -23,7 +23,7 @@ thread_local const query_options::specific_options query_options::specific_optio thread_local query_options query_options::DEFAULT{default_cql_config, db::consistency_level::ONE, std::nullopt, - std::vector(), false, query_options::specific_options::DEFAULT, cql_serialization_format::latest()}; + std::vector(), false, query_options::specific_options::DEFAULT}; query_options::query_options(const cql_config& cfg, db::consistency_level consistency, @@ -31,8 +31,8 @@ query_options::query_options(const cql_config& cfg, std::vector values, std::vector value_views, bool skip_metadata, - specific_options options, - cql_serialization_format sf) + specific_options options + ) : _cql_config(cfg) , _consistency(consistency) , _names(std::move(names)) @@ -40,7 +40,6 @@ query_options::query_options(const cql_config& cfg, , _value_views(value_views) , _skip_metadata(skip_metadata) , _options(std::move(options)) - , _cql_serialization_format(sf) { } @@ -49,8 +48,8 @@ query_options::query_options(const cql_config& cfg, std::optional> names, std::vector values, bool skip_metadata, - specific_options options, - cql_serialization_format sf) + specific_options options + ) : _cql_config(cfg) , _consistency(consistency) , _names(std::move(names)) @@ -58,7 +57,6 @@ query_options::query_options(const cql_config& cfg, , _value_views() , _skip_metadata(skip_metadata) , _options(std::move(options)) - , _cql_serialization_format(sf) { fill_value_views(); } @@ -68,8 +66,8 @@ query_options::query_options(const cql_config& cfg, std::optional> names, std::vector value_views, bool skip_metadata, - specific_options options, - cql_serialization_format sf) + specific_options options + ) : _cql_config(cfg) , _consistency(consistency) , _names(std::move(names)) @@ -77,7 +75,6 @@ query_options::query_options(const cql_config& cfg, , _value_views(std::move(value_views)) , _skip_metadata(skip_metadata) , _options(std::move(options)) - , _cql_serialization_format(sf) { } @@ -89,8 +86,7 @@ query_options::query_options(db::consistency_level cl, std::vector qo, lw_shared_ptr_values), std::move(qo->_value_views), qo->_skip_metadata, - query_options::specific_options{qo->_options.page_size, paging_state, qo->_options.serial_consistency, qo->_options.timestamp}, - qo->_cql_serialization_format) { + query_options::specific_options{qo->_options.page_size, paging_state, qo->_options.serial_consistency, qo->_options.timestamp}) { } @@ -114,8 +109,7 @@ query_options::query_options(std::unique_ptr qo, lw_shared_ptr_values), std::move(qo->_value_views), qo->_skip_metadata, - query_options::specific_options{page_size, paging_state, qo->_options.serial_consistency, qo->_options.timestamp}, - qo->_cql_serialization_format) { + query_options::specific_options{page_size, paging_state, qo->_options.serial_consistency, qo->_options.timestamp}) { } diff --git a/cql3/query_options.hh b/cql3/query_options.hh index ac9e2ae7e3..6b1e601c6b 100644 --- a/cql3/query_options.hh +++ b/cql3/query_options.hh @@ -17,7 +17,6 @@ #include "service/query_state.hh" #include "service/pager/paging_state.hh" #include "cql3/values.hh" -#include "cql_serialization_format.hh" namespace cql3 { @@ -50,7 +49,6 @@ private: std::vector _value_views; const bool _skip_metadata; const specific_options _options; - cql_serialization_format _cql_serialization_format; std::optional> _batch_options; // We must use the same microsecond-precision timestamp for // all cells created by an LWT statement or when a statement @@ -110,23 +108,23 @@ public: std::optional> names, std::vector values, bool skip_metadata, - specific_options options, - cql_serialization_format sf); + specific_options options + ); explicit query_options(const cql_config& cfg, db::consistency_level consistency, std::optional> names, std::vector values, std::vector value_views, bool skip_metadata, - specific_options options, - cql_serialization_format sf); + specific_options options + ); explicit query_options(const cql_config& cfg, db::consistency_level consistency, std::optional> names, std::vector value_views, bool skip_metadata, - specific_options options, - cql_serialization_format sf); + specific_options options + ); /** * @brief Batch query_options factory. @@ -195,10 +193,6 @@ public: return tstamp != api::missing_timestamp ? tstamp : state.get_timestamp(); } - cql_serialization_format get_cql_serialization_format() const { - return _cql_serialization_format; - } - const query_options::specific_options& get_specific_options() const { return _options; } @@ -282,7 +276,7 @@ query_options::query_options(query_options&& o, std::vector tmp; tmp.reserve(values_ranges.size()); std::transform(values_ranges.begin(), values_ranges.end(), std::back_inserter(tmp), [this](auto& values_range) { - return query_options(_cql_config, _consistency, {}, std::move(values_range), _skip_metadata, _options, _cql_serialization_format); + return query_options(_cql_config, _consistency, {}, std::move(values_range), _skip_metadata, _options); }); _batch_options = std::move(tmp); } diff --git a/cql3/selection/aggregate_function_selector.hh b/cql3/selection/aggregate_function_selector.hh index 509c441b3e..97427da068 100644 --- a/cql3/selection/aggregate_function_selector.hh +++ b/cql3/selection/aggregate_function_selector.hh @@ -9,7 +9,6 @@ #include "abstract_function_selector.hh" #include "cql3/functions/aggregate_function.hh" -#include "cql_serialization_format.hh" #pragma once @@ -24,20 +23,20 @@ public: return true; } - virtual void add_input(cql_serialization_format sf, result_set_builder& rs) override { + virtual void add_input(result_set_builder& rs) override { // Aggregation of aggregation is not supported size_t m = _arg_selectors.size(); for (size_t i = 0; i < m; ++i) { auto&& s = _arg_selectors[i]; - s->add_input(sf, rs); - _args[i] = s->get_output(sf); + s->add_input(rs); + _args[i] = s->get_output(); s->reset(); } - _aggregate->add_input(sf, _args); + _aggregate->add_input(_args); } - virtual bytes_opt get_output(cql_serialization_format sf) override { - return _aggregate->compute(sf); + virtual bytes_opt get_output() override { + return _aggregate->compute(); } virtual void reset() override { diff --git a/cql3/selection/field_selector.hh b/cql3/selection/field_selector.hh index f50b8c443f..7d431ca6a2 100644 --- a/cql3/selection/field_selector.hh +++ b/cql3/selection/field_selector.hh @@ -13,7 +13,6 @@ #include "selector.hh" #include "types.hh" #include "types/user.hh" -#include "cql_serialization_format.hh" namespace cql3 { @@ -59,12 +58,12 @@ public: return false; } - virtual void add_input(cql_serialization_format sf, result_set_builder& rs) override { - _selected->add_input(sf, rs); + virtual void add_input(result_set_builder& rs) override { + _selected->add_input(rs); } - virtual bytes_opt get_output(cql_serialization_format sf) override { - auto&& value = _selected->get_output(sf); + virtual bytes_opt get_output() override { + auto&& value = _selected->get_output(); if (!value) { return std::nullopt; } diff --git a/cql3/selection/scalar_function_selector.hh b/cql3/selection/scalar_function_selector.hh index 1a9b258f16..b75f49a99b 100644 --- a/cql3/selection/scalar_function_selector.hh +++ b/cql3/selection/scalar_function_selector.hh @@ -11,7 +11,6 @@ #include "abstract_function_selector.hh" #include "cql3/functions/scalar_function.hh" -#include "cql_serialization_format.hh" namespace cql3 { @@ -28,25 +27,25 @@ public: return _arg_selectors[0]->is_aggregate(); } - virtual void add_input(cql_serialization_format sf, result_set_builder& rs) override { + virtual void add_input(result_set_builder& rs) override { size_t m = _arg_selectors.size(); for (size_t i = 0; i < m; ++i) { auto&& s = _arg_selectors[i]; - s->add_input(sf, rs); + s->add_input(rs); } } virtual void reset() override { } - virtual bytes_opt get_output(cql_serialization_format sf) override { + virtual bytes_opt get_output() override { size_t m = _arg_selectors.size(); for (size_t i = 0; i < m; ++i) { auto&& s = _arg_selectors[i]; - _args[i] = s->get_output(sf); + _args[i] = s->get_output(); s->reset(); } - return fun()->execute(sf, _args); + return fun()->execute(_args); } virtual bool requires_thread() const override; diff --git a/cql3/selection/selection.cc b/cql3/selection/selection.cc index 8ccd078c60..755973881a 100644 --- a/cql3/selection/selection.cc +++ b/cql3/selection/selection.cc @@ -131,11 +131,11 @@ protected: virtual bool requires_thread() const override { return false; } - virtual std::vector get_output_row(cql_serialization_format sf) override { + virtual std::vector get_output_row() override { return std::move(_current); } - virtual void add_input_row(cql_serialization_format sf, result_set_builder& rs) override { + virtual void add_input_row(result_set_builder& rs) override { // GROUP BY calls add_input_row() repeatedly without reset() in between, and it expects // the output to be the first value encountered: // https://cassandra.apache.org/doc/latest/cql/dml.html#grouping-results @@ -216,18 +216,18 @@ protected: return _factories->does_aggregation(); } - virtual std::vector get_output_row(cql_serialization_format sf) override { + virtual std::vector get_output_row() override { std::vector output_row; output_row.reserve(_selectors.size()); for (auto&& s : _selectors) { - output_row.emplace_back(s->get_output(sf)); + output_row.emplace_back(s->get_output()); } return output_row; } - virtual void add_input_row(cql_serialization_format sf, result_set_builder& rs) override { + virtual void add_input_row(result_set_builder& rs) override { for (auto&& s : _selectors) { - s->add_input(sf, rs); + s->add_input(rs); } } }; @@ -292,7 +292,7 @@ selection::collect_metadata(const schema& schema, const std::vector<::shared_ptr return r; } -result_set_builder::result_set_builder(const selection& s, gc_clock::time_point now, cql_serialization_format sf, +result_set_builder::result_set_builder(const selection& s, gc_clock::time_point now, std::vector group_by_cell_indices) : _result_set(std::make_unique(::make_shared(*(s.get_result_metadata())))) , _selectors(s.new_selectors()) @@ -300,7 +300,6 @@ result_set_builder::result_set_builder(const selection& s, gc_clock::time_point , _last_group(_group_by_cell_indices.size()) , _group_began(false) , _now(now) - , _cql_serialization_format(sf) { if (s._collect_timestamps) { _timestamps.resize(s._columns.size(), 0); @@ -364,7 +363,7 @@ bool result_set_builder::last_group_ended() const { } void result_set_builder::flush_selectors() { - _result_set->add_row(_selectors->get_output_row(_cql_serialization_format)); + _result_set->add_row(_selectors->get_output_row()); _selectors->reset(); } @@ -376,7 +375,7 @@ void result_set_builder::process_current_row(bool more_rows_coming) { flush_selectors(); } update_last_group(); - _selectors->add_input_row(_cql_serialization_format, *this); + _selectors->add_input_row(*this); if (more_rows_coming) { current->clear(); } else { @@ -395,7 +394,7 @@ void result_set_builder::new_row() { std::unique_ptr result_set_builder::build() { process_current_row(/*more_rows_coming=*/false); if (_result_set->empty() && _selectors->is_aggregate()) { - _result_set->add_row(_selectors->get_output_row(_cql_serialization_format)); + _result_set->add_row(_selectors->get_output_row()); } return std::move(_result_set); } diff --git a/cql3/selection/selection.hh b/cql3/selection/selection.hh index 91691f1d02..d54823fe94 100644 --- a/cql3/selection/selection.hh +++ b/cql3/selection/selection.hh @@ -49,9 +49,9 @@ public: * @param rs the ResultSetBuilder * @throws InvalidRequestException */ - virtual void add_input_row(cql_serialization_format sf, result_set_builder& rs) = 0; + virtual void add_input_row(result_set_builder& rs) = 0; - virtual std::vector get_output_row(cql_serialization_format sf) = 0; + virtual std::vector get_output_row() = 0; virtual void reset() = 0; }; @@ -192,7 +192,6 @@ private: std::vector _timestamps; std::vector _ttls; const gc_clock::time_point _now; - cql_serialization_format _cql_serialization_format; public: template auto with_thread_if_needed(Func&& func) { @@ -246,7 +245,7 @@ public: bool do_filter(const selection& selection, const std::vector& pk, const std::vector& ck, const query::result_row_view& static_row, const query::result_row_view* row) const; }; - result_set_builder(const selection& s, gc_clock::time_point now, cql_serialization_format sf, + result_set_builder(const selection& s, gc_clock::time_point now, std::vector group_by_cell_indices = {}); void add_empty(); void add(bytes_opt value); diff --git a/cql3/selection/selector.hh b/cql3/selection/selector.hh index b4198dc257..768cb239df 100644 --- a/cql3/selection/selector.hh +++ b/cql3/selection/selector.hh @@ -38,20 +38,18 @@ public: /** * Add the current value from the specified result_set_builder. * - * @param protocol_version protocol version used for serialization * @param rs the result_set_builder * @throws InvalidRequestException if a problem occurs while add the input value */ - virtual void add_input(cql_serialization_format sf, result_set_builder& rs) = 0; + virtual void add_input(result_set_builder& rs) = 0; /** * Returns the selector output. * - * @param protocol_version protocol version used for serialization * @return the selector output * @throws InvalidRequestException if a problem occurs while computing the output value */ - virtual bytes_opt get_output(cql_serialization_format sf) = 0; + virtual bytes_opt get_output() = 0; /** * Returns the selector output type. diff --git a/cql3/selection/simple_selector.hh b/cql3/selection/simple_selector.hh index 34c4dbbcef..d49214220a 100644 --- a/cql3/selection/simple_selector.hh +++ b/cql3/selection/simple_selector.hh @@ -63,7 +63,7 @@ public: , _first(true) { } - virtual void add_input(cql_serialization_format sf, result_set_builder& rs) override { + virtual void add_input(result_set_builder& rs) override { // GROUP BY calls add_input() repeatedly without reset() in between, and it expects the // output to be the first value encountered: // https://cassandra.apache.org/doc/latest/cql/dml.html#grouping-results @@ -74,7 +74,7 @@ public: } } - virtual bytes_opt get_output(cql_serialization_format sf) override { + virtual bytes_opt get_output() override { return std::move(_current); } diff --git a/cql3/selection/writetime_or_ttl_selector.hh b/cql3/selection/writetime_or_ttl_selector.hh index f066a85710..cb9a76e7d0 100644 --- a/cql3/selection/writetime_or_ttl_selector.hh +++ b/cql3/selection/writetime_or_ttl_selector.hh @@ -56,7 +56,7 @@ public: return ::make_shared(std::move(column_name), idx, is_writetime); } - virtual void add_input(cql_serialization_format sf, result_set_builder& rs) override { + virtual void add_input(result_set_builder& rs) override { if (_is_writetime) { int64_t ts = rs.timestamp_of(_idx); if (ts != api::missing_timestamp) { @@ -78,7 +78,7 @@ public: } } - virtual bytes_opt get_output(cql_serialization_format sf) override { + virtual bytes_opt get_output() override { return _current; } diff --git a/cql3/statements/prune_materialized_view_statement.cc b/cql3/statements/prune_materialized_view_statement.cc index f705b54f4a..475fb2d6f5 100644 --- a/cql3/statements/prune_materialized_view_statement.cc +++ b/cql3/statements/prune_materialized_view_statement.cc @@ -46,7 +46,7 @@ static future<> delete_ghost_rows(dht::partition_range_vector partition_ranges, while (!p->is_exhausted()) { tracing::trace(state.get_trace_state(), "Fetching a page for ghost row deletion"); auto timeout = db::timeout_clock::now() + timeout_duration; - cql3::selection::result_set_builder builder(*selection, now, options.get_cql_serialization_format()); + cql3::selection::result_set_builder builder(*selection, now); co_await p->fetch_page(builder, page_size, now, timeout); } } diff --git a/cql3/statements/select_statement.cc b/cql3/statements/select_statement.cc index 08f7f86a86..b7a7142653 100644 --- a/cql3/statements/select_statement.cc +++ b/cql3/statements/select_statement.cc @@ -247,7 +247,7 @@ select_statement::make_partition_slice(const query_options& options) const if (_parameters->is_distinct()) { return query::partition_slice({ query::clustering_range::make_open_ended_both_sides() }, - std::move(static_columns), {}, _opts, nullptr, options.get_cql_serialization_format()); + std::move(static_columns), {}, _opts, nullptr); } auto bounds =_restrictions->get_clustering_bounds(options); @@ -263,7 +263,7 @@ select_statement::make_partition_slice(const query_options& options) const ++_stats.reverse_queries; } return query::partition_slice(std::move(bounds), - std::move(static_columns), std::move(regular_columns), _opts, nullptr, options.get_cql_serialization_format(), get_per_partition_limit(options)); + std::move(static_columns), std::move(regular_columns), _opts, nullptr, get_per_partition_limit(options)); } uint64_t select_statement::do_get_limit(const query_options& options, @@ -281,7 +281,7 @@ uint64_t select_statement::do_get_limit(const query_options& options, return default_limit; } try { - auto l = val.view().validate_and_deserialize(*int32_type, cql_serialization_format::internal()); + auto l = val.view().validate_and_deserialize(*int32_type); if (l <= 0) { throw exceptions::invalid_request_exception("LIMIT must be strictly positive"); } @@ -410,7 +410,7 @@ select_statement::do_execute(query_processor& qp, if (aggregate || nonpaged_filtering) { return do_with( cql3::selection::result_set_builder(*_selection, now, - options.get_cql_serialization_format(), *_group_by_cell_indices), std::move(p), + *_group_by_cell_indices), std::move(p), [this, page_size, now, timeout](auto& builder, std::unique_ptr& p) { return utils::result_do_until([&p] {return p->is_exhausted();}, [&p, &builder, page_size, now, timeout] { @@ -817,8 +817,7 @@ select_statement::process_results_complex(foreign_ptr cmd, const query_options& options, gc_clock::time_point now) const { - cql3::selection::result_set_builder builder(*_selection, now, - options.get_cql_serialization_format()); + cql3::selection::result_set_builder builder(*_selection, now); co_return co_await builder.with_thread_if_needed([&] { if (_restrictions_need_filtering) { results->ensure_counts(); @@ -1105,7 +1104,7 @@ indexed_table_select_statement::do_execute(query_processor& qp, // the paging state between requesting data from replicas. const bool aggregate = _selection->is_aggregate() || has_group_by(); if (aggregate) { - return do_with(cql3::selection::result_set_builder(*_selection, now, options.get_cql_serialization_format(), *_group_by_cell_indices), std::make_unique(cql3::query_options(options)), + return do_with(cql3::selection::result_set_builder(*_selection, now, *_group_by_cell_indices), std::make_unique(cql3::query_options(options)), [this, &options, &qp, &state, now, whole_partitions, partition_slices] (cql3::selection::result_set_builder& builder, std::unique_ptr& internal_options) { // page size is set to the internal count page size, regardless of the user-provided value internal_options.reset(new cql3::query_options(std::move(internal_options), options.get_paging_state(), internal_paging_size)); @@ -1270,7 +1269,7 @@ indexed_table_select_statement::read_posting_list(query_processor& qp, return qp.proxy().query_result(_view_schema, cmd, std::move(partition_ranges), options.get_consistency(), {timeout, state.get_permit(), state.get_client_state(), state.get_trace_state()}) .then(utils::result_wrap([this, now, &options, selection = std::move(selection), partition_slice = std::move(partition_slice)] (service::storage_proxy::coordinator_query_result qr) -> coordinator_result<::shared_ptr> { - cql3::selection::result_set_builder builder(*selection, now, options.get_cql_serialization_format()); + cql3::selection::result_set_builder builder(*selection, now); query::result_view::consume(*qr.query_result, std::move(partition_slice), cql3::selection::result_set_builder::visitor(builder, *_view_schema, *selection)); diff --git a/cql3/statements/update_statement.cc b/cql3/statements/update_statement.cc index a66574eb98..073dfd6c5b 100644 --- a/cql3/statements/update_statement.cc +++ b/cql3/statements/update_statement.cc @@ -51,7 +51,7 @@ static std::unordered_map handle_case_sensitivity(rjson:: } std::unordered_map -parse(const sstring& json_string, const std::vector& expected_receivers, cql_serialization_format sf) { +parse(const sstring& json_string, const std::vector& expected_receivers) { std::unordered_map json_map; auto prepared_map = handle_case_sensitivity(rjson::parse(json_string)); for (const auto& def : expected_receivers) { @@ -63,7 +63,7 @@ parse(const sstring& json_string, const std::vector& expected json_map.emplace(std::move(cql_name), bytes_opt{}); prepared_map.erase(value_it); } else { - json_map.emplace(std::move(cql_name), from_json_object(*def.type, std::move(value_it->second), sf)); + json_map.emplace(std::move(cql_name), from_json_object(*def.type, std::move(value_it->second))); prepared_map.erase(value_it); } } @@ -155,7 +155,7 @@ void update_statement::add_update_for_key(mutation& m, const query::clustering_r modification_statement::json_cache_opt insert_prepared_json_statement::maybe_prepare_json_cache(const query_options& options) const { cql3::raw_value c = expr::evaluate(_value, options); sstring json_string = utf8_type->to_string(to_bytes(c.view())); - return json_helpers::parse(std::move(json_string), s->all_columns(), cql_serialization_format::internal()); + return json_helpers::parse(std::move(json_string), s->all_columns()); } void diff --git a/cql3/type_json.cc b/cql3/type_json.cc index a39756d7b9..214a11b6d5 100644 --- a/cql3/type_json.cc +++ b/cql3/type_json.cc @@ -144,49 +144,49 @@ static std::string_view validated_to_string_view(const rjson::value& v, const ch return rjson::to_string_view(v); } -static bytes from_json_object_aux(const map_type_impl& t, const rjson::value& value, cql_serialization_format sf) { +static bytes from_json_object_aux(const map_type_impl& t, const rjson::value& value) { if (!value.IsObject()) { throw marshal_exception("map_type must be represented as JSON Object"); } std::map raw_map(t.get_keys_type()->as_less_comparator()); for (auto it = value.MemberBegin(); it != value.MemberEnd(); ++it) { - bytes value = from_json_object(*t.get_values_type(), it->value, sf); + bytes value = from_json_object(*t.get_values_type(), it->value); if (!t.get_keys_type()->is_compatible_with(*utf8_type)) { // Keys in maps can only be strings in JSON, but they can also be a string representation // of another JSON type, which needs to be reparsed. Example - map>, int> // will be represented like this: { "[1, 3, 6]": 3, "[]": 0, "[1, 2]": 2 } rjson::value map_key = rjson::parse(rjson::to_string_view(it->name)); - raw_map.emplace(from_json_object(*t.get_keys_type(), map_key, sf), std::move(value)); + raw_map.emplace(from_json_object(*t.get_keys_type(), map_key), std::move(value)); } else { - raw_map.emplace(from_json_object(*t.get_keys_type(), it->name, sf), std::move(value)); + raw_map.emplace(from_json_object(*t.get_keys_type(), it->name), std::move(value)); } } return map_type_impl::serialize_to_bytes(raw_map); } -static bytes from_json_object_aux(const set_type_impl& t, const rjson::value& value, cql_serialization_format sf) { +static bytes from_json_object_aux(const set_type_impl& t, const rjson::value& value) { if (!value.IsArray()) { throw marshal_exception("set_type must be represented as JSON Array"); } std::set raw_set(t.get_elements_type()->as_less_comparator()); for (const rjson::value& v : value.GetArray()) { - raw_set.emplace(from_json_object(*t.get_elements_type(), v, sf)); + raw_set.emplace(from_json_object(*t.get_elements_type(), v)); } - return collection_type_impl::pack(raw_set.begin(), raw_set.end(), raw_set.size(), sf); + return collection_type_impl::pack(raw_set.begin(), raw_set.end(), raw_set.size()); } -static bytes from_json_object_aux(const list_type_impl& t, const rjson::value& value, cql_serialization_format sf) { +static bytes from_json_object_aux(const list_type_impl& t, const rjson::value& value) { std::vector values; if (!value.IsArray()) { throw marshal_exception("list_type must be represented as JSON Array"); } for (const rjson::value& v : value.GetArray()) { - values.emplace_back(from_json_object(*t.get_elements_type(), v, sf)); + values.emplace_back(from_json_object(*t.get_elements_type(), v)); } - return collection_type_impl::pack(values.begin(), values.end(), values.size(), sf); + return collection_type_impl::pack(values.begin(), values.end(), values.size()); } -static bytes from_json_object_aux(const tuple_type_impl& t, const rjson::value& value, cql_serialization_format sf) { +static bytes from_json_object_aux(const tuple_type_impl& t, const rjson::value& value) { if (!value.IsArray()) { throw marshal_exception("tuple_type must be represented as JSON Array"); } @@ -198,12 +198,12 @@ static bytes from_json_object_aux(const tuple_type_impl& t, const rjson::value& raw_tuple.reserve(value.Size()); auto ti = t.all_types().begin(); for (auto vi = value.Begin(); vi != value.End(); ++vi, ++ti) { - raw_tuple.emplace_back(from_json_object(**ti, *vi, sf)); + raw_tuple.emplace_back(from_json_object(**ti, *vi)); } return t.build_value(std::move(raw_tuple)); } -static bytes from_json_object_aux(const user_type_impl& ut, const rjson::value& value, cql_serialization_format sf) { +static bytes from_json_object_aux(const user_type_impl& ut, const rjson::value& value) { if (!value.IsObject()) { throw marshal_exception("user_type must be represented as JSON Object"); } @@ -220,7 +220,7 @@ static bytes from_json_object_aux(const user_type_impl& ut, const rjson::value& if (!v || v->IsNull()) { raw_tuple.push_back(bytes_opt{}); } else { - raw_tuple.push_back(from_json_object(*t, *v, sf)); + raw_tuple.push_back(from_json_object(*t, *v)); } remaining_names.erase(std::string_view(ut.field_name_as_string(i))); } @@ -235,8 +235,8 @@ static bytes from_json_object_aux(const user_type_impl& ut, const rjson::value& namespace { struct from_json_object_visitor { const rjson::value& value; - cql_serialization_format sf; - bytes operator()(const reversed_type_impl& t) { return from_json_object(*t.underlying_type(), value, sf); } + ; + bytes operator()(const reversed_type_impl& t) { return from_json_object(*t.underlying_type(), value); } template bytes operator()(const integer_type_impl& t) { if (value.IsString()) { return t.from_string(rjson::to_string_view(value)); @@ -323,16 +323,16 @@ struct from_json_object_visitor { } bytes operator()(const duration_type_impl& t) { return t.from_string(validated_to_string_view(value, "duration_type")); } bytes operator()(const empty_type_impl& t) { return bytes(); } - bytes operator()(const map_type_impl& t) { return from_json_object_aux(t, value, sf); } - bytes operator()(const set_type_impl& t) { return from_json_object_aux(t, value, sf); } - bytes operator()(const list_type_impl& t) { return from_json_object_aux(t, value, sf); } - bytes operator()(const tuple_type_impl& t) { return from_json_object_aux(t, value, sf); } - bytes operator()(const user_type_impl& t) { return from_json_object_aux(t, value, sf); } + bytes operator()(const map_type_impl& t) { return from_json_object_aux(t, value); } + bytes operator()(const set_type_impl& t) { return from_json_object_aux(t, value); } + bytes operator()(const list_type_impl& t) { return from_json_object_aux(t, value); } + bytes operator()(const tuple_type_impl& t) { return from_json_object_aux(t, value); } + bytes operator()(const user_type_impl& t) { return from_json_object_aux(t, value); } }; } -bytes from_json_object(const abstract_type& t, const rjson::value& value, cql_serialization_format sf) { - return visit(t, from_json_object_visitor{value, sf}); +bytes from_json_object(const abstract_type& t, const rjson::value& value) { + return visit(t, from_json_object_visitor{value}); } template static T compose_value(const integer_type_impl& t, bytes_view bv) { @@ -344,13 +344,12 @@ template static T compose_value(const integer_type_impl& t, byte static sstring to_json_string_aux(const map_type_impl& t, bytes_view bv) { std::ostringstream out; - auto sf = cql_serialization_format::internal(); out << '{'; - auto size = read_collection_size(bv, sf); + auto size = read_collection_size(bv); for (int i = 0; i < size; ++i) { - auto kb = read_collection_value(bv, sf); - auto vb = read_collection_value(bv, sf); + auto kb = read_collection_value(bv); + auto vb = read_collection_value(bv); if (i > 0) { out << ", "; @@ -377,10 +376,9 @@ static sstring to_json_string_aux(const set_type_impl& t, bytes_view bv) { using llpdi = listlike_partial_deserializing_iterator; std::ostringstream out; bool first = true; - auto sf = cql_serialization_format::internal(); out << '['; managed_bytes_view mbv(bv); - std::for_each(llpdi::begin(mbv, sf), llpdi::end(mbv, sf), [&first, &out, &t] (const managed_bytes_view& e) { + std::for_each(llpdi::begin(mbv), llpdi::end(mbv), [&first, &out, &t] (const managed_bytes_view& e) { if (first) { first = false; } else { @@ -396,10 +394,9 @@ static sstring to_json_string_aux(const list_type_impl& t, bytes_view bv) { using llpdi = listlike_partial_deserializing_iterator; std::ostringstream out; bool first = true; - auto sf = cql_serialization_format::internal(); out << '['; managed_bytes_view mbv(bv); - std::for_each(llpdi::begin(mbv, sf), llpdi::end(mbv, sf), [&first, &out, &t] (const managed_bytes_view& e) { + std::for_each(llpdi::begin(mbv), llpdi::end(mbv), [&first, &out, &t] (const managed_bytes_view& e) { if (first) { first = false; } else { diff --git a/cql3/type_json.hh b/cql3/type_json.hh index 2797d320e0..084513e41f 100644 --- a/cql3/type_json.hh +++ b/cql3/type_json.hh @@ -11,7 +11,7 @@ #include "types.hh" #include "utils/rjson.hh" -bytes from_json_object(const abstract_type &t, const rjson::value& value, cql_serialization_format sf); +bytes from_json_object(const abstract_type &t, const rjson::value& value); sstring to_json_string(const abstract_type &t, bytes_view bv); sstring to_json_string(const abstract_type &t, const managed_bytes_view& bv); diff --git a/cql3/values.hh b/cql3/values.hh index 25dcc7c495..337d618d84 100644 --- a/cql3/values.hh +++ b/cql3/values.hh @@ -129,26 +129,26 @@ public: } template - ValueType deserialize(const collection_type_impl& t, cql_serialization_format sf) const { - return value_cast(with_value([&] (const FragmentedView auto& v) { return t.deserialize(v, sf); })); + ValueType deserialize(const collection_type_impl& t) const { + return value_cast(with_value([&] (const FragmentedView auto& v) { return t.deserialize(v); })); } - void validate(const abstract_type& t, cql_serialization_format sf) const { - return with_value([&] (const FragmentedView auto& v) { return t.validate(v, sf); }); + void validate(const abstract_type& t) const { + return with_value([&] (const FragmentedView auto& v) { return t.validate(v); }); } template - ValueType validate_and_deserialize(const collection_type_impl& t, cql_serialization_format sf) const { + ValueType validate_and_deserialize(const collection_type_impl& t) const { return with_value([&] (const FragmentedView auto& v) { - t.validate(v, sf); - return value_cast(t.deserialize(v, sf)); + t.validate(v); + return value_cast(t.deserialize(v)); }); } template - ValueType validate_and_deserialize(const abstract_type& t, cql_serialization_format sf) const { + ValueType validate_and_deserialize(const abstract_type& t) const { return with_value([&] (const FragmentedView auto& v) { - t.validate(v, sf); + t.validate(v); return value_cast(t.deserialize(v)); }); } diff --git a/cql_serialization_format.hh b/cql_serialization_format.hh index 9c2dd543d1..4ca87c3592 100644 --- a/cql_serialization_format.hh +++ b/cql_serialization_format.hh @@ -10,6 +10,7 @@ #include #include +#include using cql_protocol_version_type = uint8_t; @@ -26,15 +27,10 @@ public: static constexpr cql_protocol_version_type latest_version = 4; explicit cql_serialization_format(cql_protocol_version_type version) : _version(version) {} static cql_serialization_format latest() { return cql_serialization_format{latest_version}; } - static cql_serialization_format internal() { return latest(); } - bool using_32_bits_for_collections() const { return _version >= 3; } - bool operator==(cql_serialization_format x) const { return _version == x._version; } - bool operator!=(cql_serialization_format x) const { return !operator==(x); } cql_protocol_version_type protocol_version() const { return _version; } - friend std::ostream& operator<<(std::ostream& out, const cql_serialization_format& sf) { - return out << static_cast(sf._version); - } - bool collection_format_unchanged(cql_serialization_format other = cql_serialization_format::latest()) const { - return using_32_bits_for_collections() == other.using_32_bits_for_collections(); + void ensure_supported() const { + if (_version < 3) { + throw std::runtime_error("cql protocol version must be 3 or later"); + } } }; diff --git a/db/functions/aggregate_function.hh b/db/functions/aggregate_function.hh index 3540c010a8..dfd9a1aacd 100644 --- a/db/functions/aggregate_function.hh +++ b/db/functions/aggregate_function.hh @@ -63,24 +63,22 @@ public: /** * Adds the specified input to this aggregate. * - * @param protocol_version native protocol version * @param values the values to add to the aggregate. */ - virtual void add_input(cql_serialization_format sf, const std::vector& values) = 0; + virtual void add_input(const std::vector& values) = 0; /** * Computes and returns the aggregate current value. * - * @param protocol_version native protocol version * @return the aggregate current value. */ - virtual opt_bytes compute(cql_serialization_format sf) = 0; + virtual opt_bytes compute() = 0; virtual void set_accumulator(const opt_bytes& acc) = 0; virtual opt_bytes get_accumulator() const = 0; - virtual void reduce(cql_serialization_format sf, const opt_bytes& acc) = 0; + virtual void reduce(const opt_bytes& acc) = 0; /** * Reset this aggregate. diff --git a/db/legacy_schema_migrator.cc b/db/legacy_schema_migrator.cc index ca27ecf5de..444d55377b 100644 --- a/db/legacy_schema_migrator.cc +++ b/db/legacy_schema_migrator.cc @@ -346,7 +346,7 @@ public: return column_name_type->from_string(name); } catch (marshal_exception&) { // #2597: Scylla < 2.0 writes names in serialized form, try to recover - column_name_type->validate(to_bytes_view(name), cql_serialization_format::latest()); + column_name_type->validate(to_bytes_view(name)); return to_bytes(name); } }(); diff --git a/db/system_keyspace.cc b/db/system_keyspace.cc index 10bed9fb5d..2df119710a 100644 --- a/db/system_keyspace.cc +++ b/db/system_keyspace.cc @@ -1266,7 +1266,7 @@ future<> system_keyspace::setup_version(sharded& ms) { version::release(), cql3::query_processor::CQL_VERSION, ::cassandra::thrift_version, - to_sstring(cql_serialization_format::latest_version), + to_sstring(unsigned(cql_serialization_format::latest().protocol_version())), local_dc_rack().dc, local_dc_rack().rack, sstring(cfg.partitioner()), diff --git a/mutation_partition.cc b/mutation_partition.cc index 684ffb468a..0d431ea50e 100644 --- a/mutation_partition.cc +++ b/mutation_partition.cc @@ -822,7 +822,7 @@ void write_cell(RowWriter& w, const query::partition_slice& slice, data_type typ w.add().write().skip_timestamp() .skip_expiry() - .write_fragmented_value(serialize_for_cql(*type, std::move(v), slice.cql_format())) + .write_fragmented_value(serialize_for_cql(*type, std::move(v))) .skip_ttl() .end_qr_cell(); } diff --git a/partition_slice_builder.cc b/partition_slice_builder.cc index 275133e013..6fef65b10c 100644 --- a/partition_slice_builder.cc +++ b/partition_slice_builder.cc @@ -62,7 +62,6 @@ partition_slice_builder::build() { std::move(regular_columns), std::move(_options), std::move(_specific_ranges), - cql_serialization_format::internal(), _partition_row_limit, }; } diff --git a/query-request.hh b/query-request.hh index 8edd37bfdd..e06e255994 100644 --- a/query-request.hh +++ b/query-request.hh @@ -25,6 +25,7 @@ #include "db/per_partition_rate_limit_info.hh" #include "utils/UUID.hh" #include "bytes.hh" +#include "cql_serialization_format.hh" class position_in_partition_view; class position_in_partition; @@ -193,7 +194,6 @@ public: option_set options; private: std::unique_ptr _specific_ranges; - cql_serialization_format _cql_format; uint32_t _partition_row_limit_low_bits; uint32_t _partition_row_limit_high_bits; public: @@ -206,7 +206,6 @@ public: partition_slice(clustering_row_ranges row_ranges, column_id_vector static_columns, column_id_vector regular_columns, option_set options, std::unique_ptr specific_ranges = nullptr, - cql_serialization_format = cql_serialization_format::internal(), uint64_t partition_row_limit = partition_max_rows); partition_slice(clustering_row_ranges ranges, const schema& schema, const column_set& mask, option_set options); partition_slice(const partition_slice&); @@ -230,8 +229,8 @@ public: const std::unique_ptr& get_specific_ranges() const { return _specific_ranges; } - const cql_serialization_format& cql_format() const { - return _cql_format; + const cql_serialization_format cql_format() const { + return cql_serialization_format(4); // For IDL compatibility } const uint32_t partition_row_limit_low_bits() const { return _partition_row_limit_low_bits; diff --git a/query-result-set.cc b/query-result-set.cc index a985bf635a..b9009aa703 100644 --- a/query-result-set.cc +++ b/query-result-set.cc @@ -185,7 +185,7 @@ result_set_builder::deserialize(const result_row_view& row, bool is_static) ctype = map_type_impl::get_instance(ctype->name_comparator(), ctype->value_comparator(), true); } - cells.emplace(col.name_as_text(), ctype->deserialize_value(*cell, _slice.cql_format())); + cells.emplace(col.name_as_text(), ctype->deserialize_value(*cell)); } else { cells.emplace(col.name_as_text(), col.type->deserialize_value(*cell)); } diff --git a/query.cc b/query.cc index e331b2510d..1bcae03ea9 100644 --- a/query.cc +++ b/query.cc @@ -49,7 +49,6 @@ std::ostream& operator<<(std::ostream& out, const partition_slice& ps) { out << ", specific=[" << *ps._specific_ranges << "]"; } out << ", options=" << format("{:x}", ps.options.mask()); // FIXME: pretty print options - out << ", cql_format=" << ps.cql_format(); out << ", partition_row_limit=" << ps.partition_row_limit(); return out << "}"; } @@ -207,20 +206,20 @@ partition_slice::partition_slice(clustering_row_ranges row_ranges, , regular_columns(std::move(regular_columns)) , options(options) , _specific_ranges(std::move(specific_ranges)) - , _cql_format(std::move(cql_format)) , _partition_row_limit_low_bits(partition_row_limit_low_bits) , _partition_row_limit_high_bits(partition_row_limit_high_bits) -{} +{ + cql_format.ensure_supported(); +} partition_slice::partition_slice(clustering_row_ranges row_ranges, query::column_id_vector static_columns, query::column_id_vector regular_columns, option_set options, std::unique_ptr specific_ranges, - cql_serialization_format cql_format, uint64_t partition_row_limit) : partition_slice(std::move(row_ranges), std::move(static_columns), std::move(regular_columns), options, - std::move(specific_ranges), std::move(cql_format), static_cast(partition_row_limit), + std::move(specific_ranges), cql_serialization_format::latest(), static_cast(partition_row_limit), static_cast(partition_row_limit >> 32)) {} @@ -250,7 +249,6 @@ partition_slice::partition_slice(const partition_slice& s) , regular_columns(s.regular_columns) , options(s.options) , _specific_ranges(s._specific_ranges ? std::make_unique(*s._specific_ranges) : nullptr) - , _cql_format(s._cql_format) , _partition_row_limit_low_bits(s._partition_row_limit_low_bits) , _partition_row_limit_high_bits(s._partition_row_limit_high_bits) {} diff --git a/replica/database.cc b/replica/database.cc index 9d71cae943..752629cb60 100644 --- a/replica/database.cc +++ b/replica/database.cc @@ -1678,7 +1678,7 @@ future database::do_apply_counter_update(column_family& cf, const froz regular_columns.end()); auto slice = query::partition_slice(std::move(cr_ranges), std::move(static_columns), - std::move(regular_columns), { }, { }, cql_serialization_format::internal(), query::max_rows); + std::move(regular_columns), { }, { }, query::max_rows); return do_with(std::move(slice), std::move(m), std::vector(), [this, &cf, timeout, trace_state = std::move(trace_state), op = cf.write_in_progress()] (const query::partition_slice& slice, mutation& m, std::vector& locks) mutable { diff --git a/replica/table.cc b/replica/table.cc index bcdf6522fd..7f3e94163e 100644 --- a/replica/table.cc +++ b/replica/table.cc @@ -2558,7 +2558,7 @@ future table::do_push_view_replica_updates(schema_ptr s opts.set(query::partition_slice::option::send_ttl); opts.add(custom_opts); auto slice = query::partition_slice( - std::move(cr_ranges), std::move(static_columns), std::move(regular_columns), std::move(opts), { }, cql_serialization_format::internal(), query::max_rows); + std::move(cr_ranges), std::move(static_columns), std::move(regular_columns), std::move(opts), { }, query::max_rows); // Take the shard-local lock on the base-table row or partition as needed. // We'll return this lock to the caller, which will release it after // writing the base-table update. diff --git a/service/forward_service.cc b/service/forward_service.cc index 1a3fae35d4..8fa03d6e6e 100644 --- a/service/forward_service.cc +++ b/service/forward_service.cc @@ -14,7 +14,6 @@ #include #include -#include "cql_serialization_format.hh" #include "db/consistency_level.hh" #include "dht/i_partitioner.hh" #include "dht/sharder.hh" @@ -114,7 +113,7 @@ void forward_aggregates::merge(query::forward_result &result, query::forward_res for (size_t i = 0; i < _aggrs.size(); i++) { _aggrs[i]->set_accumulator(result.query_results[i]); - _aggrs[i]->reduce(cql_serialization_format::internal(), std::move(other.query_results[i])); + _aggrs[i]->reduce(std::move(other.query_results[i])); result.query_results[i] = _aggrs[i]->get_accumulator(); } } @@ -132,7 +131,7 @@ void forward_aggregates::finalize(query::forward_result &result) { for (size_t i = 0; i < _aggrs.size(); i++) { _aggrs[i]->set_accumulator(result.query_results[i]); - result.query_results[i] = _aggrs[i]->compute(cql_serialization_format::internal()); + result.query_results[i] = _aggrs[i]->compute(); } } @@ -398,14 +397,12 @@ future forward_service::execute_on_this_shard( std::optional>(), // Represents empty names. std::vector(), // Represents empty values. true, // Skip metadata. - cql3::query_options::specific_options::DEFAULT, - cql_serialization_format::latest() + cql3::query_options::specific_options::DEFAULT ); auto rs_builder = cql3::selection::result_set_builder( *selection, now, - cql_serialization_format::latest(), std::vector() // Represents empty GROUP BY indices. ); diff --git a/service/pager/query_pagers.cc b/service/pager/query_pagers.cc index 389756ab33..7d50603ad7 100644 --- a/service/pager/query_pagers.cc +++ b/service/pager/query_pagers.cc @@ -212,8 +212,7 @@ future> query_pager::fetch_page(uint32_t page_ future>> query_pager::fetch_page_result(uint32_t page_size, gc_clock::time_point now, db::timeout_clock::time_point timeout) { return do_with( - cql3::selection::result_set_builder(*_selection, now, - _options.get_cql_serialization_format()), + cql3::selection::result_set_builder(*_selection, now), [this, page_size, now, timeout](auto& builder) { return this->fetch_page_result(builder, page_size, now, timeout).then(utils::result_wrap([&builder] { return builder.with_thread_if_needed([&builder] () -> result> { diff --git a/service/raft/raft_sys_table_storage.cc b/service/raft/raft_sys_table_storage.cc index 374d2e46c9..6c9000f904 100644 --- a/service/raft/raft_sys_table_storage.cc +++ b/service/raft/raft_sys_table_storage.cc @@ -250,8 +250,8 @@ future<> raft_sys_table_storage::do_store_log_entries(const std::vector{}, false, - cql3::query_options::specific_options::DEFAULT, - cql_serialization_format::latest()), + cql3::query_options::specific_options::DEFAULT + ), std::move(stmt_value_views)); cql3::statements::batch_statement batch( diff --git a/test/boost/cql_query_large_test.cc b/test/boost/cql_query_large_test.cc index 83c9b34191..967fde1329 100644 --- a/test/boost/cql_query_large_test.cc +++ b/test/boost/cql_query_large_test.cc @@ -160,15 +160,6 @@ SEASTAR_TEST_CASE(test_insert_large_collection_values) { { make_map_value(map_type, map_type_impl::native_type({{sstring("key"), long_value}})).serialize() } }); BOOST_REQUIRE_THROW(e.execute_cql(format("INSERT INTO tbl (pk, m) VALUES ('Golding', {{'{}': 'value'}});", long_value)).get(), std::exception); - - auto make_query_options = [] (cql_protocol_version_type version) { - return std::make_unique(cql3::default_cql_config, db::consistency_level::ONE, std::nullopt, - std::vector(), false, - cql3::query_options::specific_options::DEFAULT, cql_serialization_format{version}); - }; - - BOOST_REQUIRE_THROW(e.execute_cql("SELECT l FROM tbl WHERE pk = 'Zamyatin';", make_query_options(2)).get(), std::exception); - BOOST_REQUIRE_THROW(e.execute_cql("SELECT m FROM tbl WHERE pk = 'Haksli';", make_query_options(2)).get(), std::exception); }); }); } diff --git a/test/boost/cql_query_test.cc b/test/boost/cql_query_test.cc index 31dcc28794..09e2d83a64 100644 --- a/test/boost/cql_query_test.cc +++ b/test/boost/cql_query_test.cc @@ -5431,12 +5431,10 @@ SEASTAR_TEST_CASE(test_not_parallelized_select_uda) { } cql3::raw_value make_collection_raw_value(size_t size_to_write, const std::vector& elements_to_write) { - cql_serialization_format sf = cql_serialization_format::latest(); - size_t serialized_len = 0; - serialized_len += collection_size_len(sf); + serialized_len += collection_size_len(); for (const cql3::raw_value& val : elements_to_write) { - serialized_len += collection_value_len(sf); + serialized_len += collection_value_len(); if (val.is_value()) { serialized_len += val.view().with_value([](const FragmentedView auto& view) { return view.size_bytes(); @@ -5447,7 +5445,7 @@ cql3::raw_value make_collection_raw_value(size_t size_to_write, const std::vecto bytes b(bytes::initialized_later(), serialized_len); bytes::iterator out = b.begin(); - write_collection_size(out, size_to_write, sf); + write_collection_size(out, size_to_write); for (const cql3::raw_value& val : elements_to_write) { if (val.is_null()) { write_int32(out, -1); @@ -5455,7 +5453,7 @@ cql3::raw_value make_collection_raw_value(size_t size_to_write, const std::vecto write_int32(out, -2); } else { val.view().with_value([&](const FragmentedView auto& val_view) { - write_collection_value(out, sf, linearized(val_view)); + write_collection_value(out, linearized(val_view)); }); } } @@ -5525,7 +5523,6 @@ SEASTAR_TEST_CASE(test_null_and_unset_in_collections) { return cql3::raw_value::make_value(int32_type->decompose(val)); }; - cql_serialization_format sf = cql_serialization_format::latest(); cql3::raw_value list_with_null = make_collection_raw_value(3, {make_int(1), null_value, make_int(2)}); cql3::raw_value set_with_null = make_collection_raw_value(3, {make_int(1), null_value, make_int(2)}); diff --git a/test/boost/restrictions_test.cc b/test/boost/restrictions_test.cc index 3f57d1ffd5..8889d0d191 100644 --- a/test/boost/restrictions_test.cc +++ b/test/boost/restrictions_test.cc @@ -35,7 +35,7 @@ std::unique_ptr to_options( return std::make_unique( cfg, d.get_consistency(), std::move(names), std::move(values), d.skip_metadata(), - d.get_specific_options(), d.get_cql_serialization_format()); + d.get_specific_options()); } /// Asserts that e.execute_prepared(id, values) contains expected rows, in any order. diff --git a/test/boost/types_test.cc b/test/boost/types_test.cc index 934ec30a00..45380ff4f2 100644 --- a/test/boost/types_test.cc +++ b/test/boost/types_test.cc @@ -575,7 +575,7 @@ BOOST_AUTO_TEST_CASE(test_tuple) { void test_validation_fails(const shared_ptr& type, bytes_view v) { try { - type->validate(v, cql_serialization_format::latest()); + type->validate(v); BOOST_FAIL("Validation should have failed"); } catch (const marshal_exception& e) { // expected @@ -583,28 +583,28 @@ void test_validation_fails(const shared_ptr& type, bytes_vi } BOOST_AUTO_TEST_CASE(test_ascii_type_validation) { - ascii_type->validate(bytes(), cql_serialization_format::latest()); - ascii_type->validate(bytes("foo"), cql_serialization_format::latest()); + ascii_type->validate(bytes()); + ascii_type->validate(bytes("foo")); test_validation_fails(ascii_type, bytes("fóo")); } BOOST_AUTO_TEST_CASE(test_utf8_type_validation) { - utf8_type->validate(bytes(), cql_serialization_format::latest()); - utf8_type->validate(bytes("foo"), cql_serialization_format::latest()); - utf8_type->validate(bytes("fóo"), cql_serialization_format::latest()); + utf8_type->validate(bytes()); + utf8_type->validate(bytes("foo")); + utf8_type->validate(bytes("fóo")); test_validation_fails(utf8_type, bytes("test") + from_hex("fe")); } BOOST_AUTO_TEST_CASE(test_int32_type_validation) { - int32_type->validate(bytes(), cql_serialization_format::latest()); - int32_type->validate(from_hex("deadbeef"), cql_serialization_format::latest()); + int32_type->validate(bytes()); + int32_type->validate(from_hex("deadbeef")); test_validation_fails(int32_type, from_hex("00")); test_validation_fails(int32_type, from_hex("0000000000")); } BOOST_AUTO_TEST_CASE(test_long_type_validation) { - long_type->validate(bytes(), cql_serialization_format::latest()); - long_type->validate(from_hex("deadbeefdeadbeef"), cql_serialization_format::latest()); + long_type->validate(bytes()); + long_type->validate(from_hex("deadbeefdeadbeef")); test_validation_fails(long_type, from_hex("00")); test_validation_fails(long_type, from_hex("00000000")); test_validation_fails(long_type, from_hex("000000000000000000")); @@ -612,7 +612,7 @@ BOOST_AUTO_TEST_CASE(test_long_type_validation) { BOOST_AUTO_TEST_CASE(test_timeuuid_type_validation) { auto now = utils::UUID_gen::get_time_UUID(); - timeuuid_type->validate(now.serialize(), cql_serialization_format::latest()); + timeuuid_type->validate(now.serialize()); auto random = utils::make_random_uuid(); test_validation_fails(timeuuid_type, random.serialize()); test_validation_fails(timeuuid_type, from_hex("00")); @@ -620,27 +620,27 @@ BOOST_AUTO_TEST_CASE(test_timeuuid_type_validation) { BOOST_AUTO_TEST_CASE(test_uuid_type_validation) { auto now = utils::UUID_gen::get_time_UUID(); - uuid_type->validate(now.serialize(), cql_serialization_format::latest()); + uuid_type->validate(now.serialize()); auto random = utils::make_random_uuid(); - uuid_type->validate(random.serialize(), cql_serialization_format::latest()); + uuid_type->validate(random.serialize()); test_validation_fails(uuid_type, from_hex("00")); } BOOST_AUTO_TEST_CASE(test_duration_type_validation) { - duration_type->validate(duration_type->from_string("1m23us"), cql_serialization_format::latest()); + duration_type->validate(duration_type->from_string("1m23us")); using exception_predicate::message_equals; BOOST_REQUIRE_EXCEPTION( - duration_type->validate(from_hex("ff"), cql_serialization_format::latest()), + duration_type->validate(from_hex("ff")), marshal_exception, message_equals("marshaling error: Expected at least 3 bytes for a duration, got 1")); BOOST_REQUIRE_EXCEPTION( - duration_type->validate(from_hex("fffffffffffffffffe0202"), cql_serialization_format::latest()), + duration_type->validate(from_hex("fffffffffffffffffe0202")), marshal_exception, message_equals("marshaling error: The duration months (9223372036854775807) must be a 32 bit integer")); BOOST_REQUIRE_EXCEPTION( - duration_type->validate(from_hex("010201"), cql_serialization_format::latest()), + duration_type->validate(from_hex("010201")), marshal_exception, message_equals("marshaling error: The duration months, days, and " "nanoseconds must be all of the same sign (-1, 1, -1)")); diff --git a/test/lib/cql_test_env.cc b/test/lib/cql_test_env.cc index 8c797b0174..8673e0957f 100644 --- a/test/lib/cql_test_env.cc +++ b/test/lib/cql_test_env.cc @@ -365,7 +365,7 @@ public: actual = c.value().linearize(); } else { actual = linearized(serialize_for_cql(*col_def->type, - cell->as_collection_mutation(), cql_serialization_format::internal())); + cell->as_collection_mutation())); } assert(col_def->type->equal(actual, exp)); }); diff --git a/test/lib/expr_test_utils.cc b/test/lib/expr_test_utils.cc index 1dc1e9b3d9..e3ee03dec5 100644 --- a/test/lib/expr_test_utils.cc +++ b/test/lib/expr_test_utils.cc @@ -84,12 +84,10 @@ constant make_text_const(const sstring_view& text) { // Some tests require the collection to contain unset_value or an empty value, // which is impossible to express using the existing code. cql3::raw_value make_collection_raw(size_t size_to_write, const std::vector& elements_to_write) { - cql_serialization_format sf = cql_serialization_format::latest(); - size_t serialized_len = 0; - serialized_len += collection_size_len(sf); + serialized_len += collection_size_len(); for (const cql3::raw_value& val : elements_to_write) { - serialized_len += collection_value_len(sf); + serialized_len += collection_value_len(); if (val.is_value()) { serialized_len += val.view().with_value([](const FragmentedView auto& view) { return view.size_bytes(); }); } @@ -98,7 +96,7 @@ cql3::raw_value make_collection_raw(size_t size_to_write, const std::vector> make_evalu } query_options options(default_cql_config, db::consistency_level::ONE, std::nullopt, bind_marker_values, true, - query_options::specific_options::DEFAULT, cql_serialization_format::internal()); + query_options::specific_options::DEFAULT); std::unique_ptr data = std::make_unique( evaluation_inputs_data{.partition_key = std::move(partition_key), diff --git a/thrift/handler.cc b/thrift/handler.cc index a3ace77077..3b96663c83 100644 --- a/thrift/handler.cc +++ b/thrift/handler.cc @@ -404,7 +404,7 @@ public: } clustering_ranges.emplace_back(query::clustering_range::make_open_ended_both_sides()); auto slice = query::partition_slice(std::move(clustering_ranges), { }, std::move(regular_columns), opts, - std::move(specific_ranges), cql_serialization_format::internal()); + std::move(specific_ranges)); auto cmd = make_lw_shared(s.id(), s.version(), std::move(slice), proxy.get_max_result_size(slice), query::tombstone_limit(proxy.get_tombstone_limit()), query::row_limit(row_limit), query::partition_limit(partition_limit)); cmd->allow_limit = db::allow_per_partition_rate_limit::yes; @@ -1053,7 +1053,7 @@ public: } auto& qp = _query_processor.local(); auto opts = std::make_unique(qp.get_cql_config(), cl_from_thrift(consistency), std::nullopt, std::vector(), - false, cql3::query_options::specific_options::DEFAULT, cql_serialization_format::latest()); + false, cql3::query_options::specific_options::DEFAULT); auto f = qp.execute_direct(query, _query_state, *opts); return f.then([cob = std::move(cob), opts = std::move(opts)](auto&& ret) { cql3_result_visitor visitor; @@ -1133,7 +1133,7 @@ public: }); auto& qp = _query_processor.local(); auto opts = std::make_unique(qp.get_cql_config(), cl_from_thrift(consistency), std::nullopt, std::move(bytes_values), - false, cql3::query_options::specific_options::DEFAULT, cql_serialization_format::latest()); + false, cql3::query_options::specific_options::DEFAULT); auto f = qp.execute_prepared(std::move(prepared), std::move(cache_key), _query_state, *opts, needs_authorization); return f.then([cob = std::move(cob), opts = std::move(opts)](auto&& ret) { cql3_result_visitor visitor; @@ -1348,7 +1348,7 @@ private: auto column_name_type = db::marshal::type_parser::parse(to_sstring(cf_def.comparator_type)); for (const ColumnDef& col_def : cf_def.column_metadata) { auto col_name = to_bytes(col_def.name); - column_name_type->validate(col_name, cql_serialization_format::latest()); + column_name_type->validate(col_name); builder.with_column(std::move(col_name), db::marshal::type_parser::parse(to_sstring(col_def.validation_class)), column_kind::regular_column); auto index = index_metadata_from_thrift(col_def); @@ -1613,7 +1613,7 @@ private: throw make_exception("SlicePredicate column_names and slice_range may not both be null"); } auto slice = query::partition_slice(std::move(clustering_ranges), {}, std::move(regular_columns), opts, - nullptr, cql_serialization_format::internal(), per_partition_row_limit); + nullptr, per_partition_row_limit); auto cmd = make_lw_shared(s.id(), s.version(), std::move(slice), proxy.get_max_result_size(slice), query::tombstone_limit(proxy.get_tombstone_limit())); cmd->allow_limit = db::allow_per_partition_rate_limit::yes; diff --git a/thrift/thrift_validation.cc b/thrift/thrift_validation.cc index 156b33d87b..7084536e4f 100644 --- a/thrift/thrift_validation.cc +++ b/thrift/thrift_validation.cc @@ -86,7 +86,7 @@ void validate_column(const Column& col, const column_definition& def) { if (!col.__isset.timestamp) { throw make_exception("Column timestamp is required"); } - def.type->validate(to_bytes_view(col.value), cql_serialization_format::latest()); + def.type->validate(to_bytes_view(col.value)); } } diff --git a/tools/scylla-types.cc b/tools/scylla-types.cc index 2035f7aff4..cb985c40df 100644 --- a/tools/scylla-types.cc +++ b/tools/scylla-types.cc @@ -142,7 +142,7 @@ void validate_handler(type_variant type, std::vector values, const bpo::v bytes_view value; void operator()(const data_type& type) { - type->validate(value, cql_serialization_format::internal()); + type->validate(value); } void operator()(const compound_type& type) { type.validate(value); diff --git a/tracing/trace_keyspace_helper.cc b/tracing/trace_keyspace_helper.cc index 4ae0762ec3..ad3bfd6898 100644 --- a/tracing/trace_keyspace_helper.cc +++ b/tracing/trace_keyspace_helper.cc @@ -280,7 +280,7 @@ cql3::query_options trace_keyspace_helper::make_session_mutation_data(const one_ }; return cql3::query_options(cql3::default_cql_config, - db::consistency_level::ANY, std::move(names), std::move(values), false, cql3::query_options::specific_options::DEFAULT, cql_serialization_format::latest()); + db::consistency_level::ANY, std::move(names), std::move(values), false, cql3::query_options::specific_options::DEFAULT); } cql3::query_options trace_keyspace_helper::make_session_time_idx_mutation_data(const one_session_records& session_records) { @@ -298,7 +298,7 @@ cql3::query_options trace_keyspace_helper::make_session_time_idx_mutation_data(c }; return cql3::query_options(cql3::default_cql_config, - db::consistency_level::ANY, std::nullopt, std::move(values), false, cql3::query_options::specific_options::DEFAULT, cql_serialization_format::latest()); + db::consistency_level::ANY, std::nullopt, std::move(values), false, cql3::query_options::specific_options::DEFAULT); } cql3::query_options trace_keyspace_helper::make_slow_query_mutation_data(const one_session_records& session_records, const utils::UUID& start_time_id) { @@ -341,7 +341,7 @@ cql3::query_options trace_keyspace_helper::make_slow_query_mutation_data(const o }); return cql3::query_options(cql3::default_cql_config, - db::consistency_level::ANY, std::nullopt, std::move(values), false, cql3::query_options::specific_options::DEFAULT, cql_serialization_format::latest()); + db::consistency_level::ANY, std::nullopt, std::move(values), false, cql3::query_options::specific_options::DEFAULT); } cql3::query_options trace_keyspace_helper::make_slow_query_time_idx_mutation_data(const one_session_records& session_records, const utils::UUID& start_time_id) { @@ -362,7 +362,7 @@ cql3::query_options trace_keyspace_helper::make_slow_query_time_idx_mutation_dat }); return cql3::query_options(cql3::default_cql_config, - db::consistency_level::ANY, std::nullopt, std::move(values), false, cql3::query_options::specific_options::DEFAULT, cql_serialization_format::latest()); + db::consistency_level::ANY, std::nullopt, std::move(values), false, cql3::query_options::specific_options::DEFAULT); } std::vector trace_keyspace_helper::make_event_mutation_data(one_session_records& session_records, const event_record& record) { @@ -398,7 +398,7 @@ future<> trace_keyspace_helper::apply_events_mutation(cql3::query_processor& qp, std::for_each(events_records.begin(), events_records.end(), [&values, all_records = records, this] (event_record& one_event_record) { values.emplace_back(make_event_mutation_data(*all_records, one_event_record)); }); return do_with( - cql3::query_options::make_batch_options(cql3::query_options(cql3::default_cql_config, db::consistency_level::ANY, std::nullopt, std::vector{}, false, cql3::query_options::specific_options::DEFAULT, cql_serialization_format::latest()), std::move(values)), + cql3::query_options::make_batch_options(cql3::query_options(cql3::default_cql_config, db::consistency_level::ANY, std::nullopt, std::vector{}, false, cql3::query_options::specific_options::DEFAULT), std::move(values)), cql3::statements::batch_statement(cql3::statements::batch_statement::type::UNLOGGED, std::move(modifications), cql3::attributes::none(), qp.get_cql_stats()), [this, &qp] (auto& batch_options, auto& batch) { return batch.execute(qp, _dummy_query_state, batch_options).then([] (shared_ptr res) { return now(); }); diff --git a/transport/request.hh b/transport/request.hh index 959636d5b6..a77a8798b2 100644 --- a/transport/request.hh +++ b/transport/request.hh @@ -204,11 +204,11 @@ private: options_flag::NAMES_FOR_VALUES >; public: - std::unique_ptr read_options(uint8_t version, cql_serialization_format cql_ser_format, const cql3::cql_config& cql_config) { + std::unique_ptr read_options(uint8_t version, const cql3::cql_config& cql_config) { auto consistency = read_consistency(); if (version == 1) { return std::make_unique(cql_config, consistency, std::nullopt, std::vector{}, - false, cql3::query_options::specific_options::DEFAULT, cql_ser_format); + false, cql3::query_options::specific_options::DEFAULT); } assert(version >= 2); @@ -256,11 +256,10 @@ public: onames = std::move(names); } options = std::make_unique(cql_config, consistency, std::move(onames), std::move(values), skip_metadata, - cql3::query_options::specific_options{page_size, std::move(paging_state), serial_consistency, ts}, - cql_ser_format); + cql3::query_options::specific_options{page_size, std::move(paging_state), serial_consistency, ts}); } else { options = std::make_unique(cql_config, consistency, std::nullopt, std::move(values), skip_metadata, - cql3::query_options::specific_options::DEFAULT, cql_ser_format); + cql3::query_options::specific_options::DEFAULT); } return options; diff --git a/transport/response.hh b/transport/response.hh index 70d7ae9682..7cbd2424ed 100644 --- a/transport/response.hh +++ b/transport/response.hh @@ -111,11 +111,7 @@ private: throw exceptions::protocol_exception(format("Invalid or unsupported protocol version: {:d}", version)); } - if (version > 0x02) { - return make_frame_one(version, length); - } else { - return make_frame_one(version, length); - } + return make_frame_one(version, length); } }; diff --git a/transport/server.cc b/transport/server.cc index 9f71b60258..067dbdc934 100644 --- a/transport/server.cc +++ b/transport/server.cc @@ -303,7 +303,6 @@ cql_server::connection::read_frame() { return make_ready_future(); } _version = buf[0]; - init_cql_serialization_format(); if (_version < 3 || _version > current_version) { auto client_version = _version; _version = current_version; @@ -830,11 +829,6 @@ future> cql_server::connection::process_op return make_ready_future>(make_supported(stream, std::move(trace_state))); } -void -cql_server::connection::init_cql_serialization_format() { - _cql_serialization_format = cql_serialization_format(_version); -} - std::unique_ptr make_result(int16_t stream, messages::result_message& msg, const tracing::trace_state_ptr& tr_state, cql_protocol_version_type version, bool skip_metadata = false); @@ -854,7 +848,7 @@ cql_server::connection::process_on_shard(::shared_ptr(std::move(msg)); @@ -878,7 +872,7 @@ cql_server::connection::process(uint16_t stream, request_reader in, service::cli fragmented_temporary_buffer::istream is = in.get_stream(); return process_fn(client_state, _server._query_processor, in, stream, - _version, _cql_serialization_format, permit, trace_state, true, {}) + _version, permit, trace_state, true, {}) .then([stream, &client_state, this, is, permit, process_fn, trace_state] (process_fn_return_type msg) mutable { auto* bounce_msg = std::get_if>(&msg); @@ -892,12 +886,12 @@ cql_server::connection::process(uint16_t stream, request_reader in, service::cli static future process_query_internal(service::client_state& client_state, distributed& qp, request_reader in, - uint16_t stream, cql_protocol_version_type version, cql_serialization_format serialization_format, + uint16_t stream, cql_protocol_version_type version, service_permit permit, tracing::trace_state_ptr trace_state, bool init_trace, cql3::computed_function_values cached_pk_fn_calls) { auto query = in.read_long_string_view(); auto q_state = std::make_unique(client_state, trace_state, std::move(permit)); auto& query_state = q_state->query_state; - q_state->options = in.read_options(version, serialization_format, qp.local().get_cql_config()); + q_state->options = in.read_options(version, qp.local().get_cql_config()); auto& options = *q_state->options; if (!cached_pk_fn_calls.empty()) { options.set_cached_pk_function_calls(std::move(cached_pk_fn_calls)); @@ -964,7 +958,7 @@ future> cql_server::connection::process_pr static future process_execute_internal(service::client_state& client_state, distributed& qp, request_reader in, - uint16_t stream, cql_protocol_version_type version, cql_serialization_format serialization_format, + uint16_t stream, cql_protocol_version_type version, service_permit permit, tracing::trace_state_ptr trace_state, bool init_trace, cql3::computed_function_values cached_pk_fn_calls) { cql3::prepared_cache_key_type cache_key(in.read_short_bytes()); auto& id = cql3::prepared_cache_key_type::cql_id(cache_key); @@ -989,9 +983,9 @@ process_execute_internal(service::client_state& client_state, distributedoptions = std::make_unique(qp.local().get_cql_config(), consistency, std::nullopt, values, false, - cql3::query_options::specific_options::DEFAULT, serialization_format); + cql3::query_options::specific_options::DEFAULT); } else { - q_state->options = in.read_options(version, serialization_format, qp.local().get_cql_config()); + q_state->options = in.read_options(version, qp.local().get_cql_config()); } auto& options = *q_state->options; if (!cached_pk_fn_calls.empty()) { @@ -1048,7 +1042,7 @@ future cql_server::connection::pro static future process_batch_internal(service::client_state& client_state, distributed& qp, request_reader in, - uint16_t stream, cql_protocol_version_type version, cql_serialization_format serialization_format, + uint16_t stream, cql_protocol_version_type version, service_permit permit, tracing::trace_state_ptr trace_state, bool init_trace, cql3::computed_function_values cached_pk_fn_calls) { if (version == 1) { throw exceptions::protocol_exception("BATCH messages are not support in version 1 of the protocol"); @@ -1137,7 +1131,7 @@ process_batch_internal(service::client_state& client_state, distributed(client_state, trace_state, std::move(permit)); auto& query_state = q_state->query_state; // #563. CQL v2 encodes query_options in v1 format for batch requests. - q_state->options = std::make_unique(cql3::query_options::make_batch_options(std::move(*in.read_options(version < 3 ? 1 : version, serialization_format, + q_state->options = std::make_unique(cql3::query_options::make_batch_options(std::move(*in.read_options(version < 3 ? 1 : version, qp.local().get_cql_config())), std::move(values))); auto& options = *q_state->options; if (!cached_pk_fn_calls.empty()) { diff --git a/transport/server.hh b/transport/server.hh index 0020359952..8b1db57ae2 100644 --- a/transport/server.hh +++ b/transport/server.hh @@ -176,7 +176,6 @@ private: fragmented_temporary_buffer::reader _buffer_reader; cql_protocol_version_type _version = 0; cql_compression _compression = cql_compression::none; - cql_serialization_format _cql_serialization_format = cql_serialization_format::latest(); service::client_state _client_state; timer _shedding_timer; bool _shed_incoming_requests = false; @@ -258,8 +257,6 @@ private: void write_response(foreign_ptr>&& response, service_permit permit = empty_service_permit(), cql_compression compression = cql_compression::none); - void init_cql_serialization_format(); - friend event_notifier; }; diff --git a/types.cc b/types.cc index b6922f8503..e9cfa6ecd7 100644 --- a/types.cc +++ b/types.cc @@ -533,10 +533,9 @@ std::strong_ordering listlike_collection_type_impl::compare_with_map(const map_t } const abstract_type& element_type = *_elements; - auto sf = cql_serialization_format::internal(); - size_t list_size = read_collection_size(list, sf); - size_t map_size = read_collection_size(map, sf); + size_t list_size = read_collection_size(list); + size_t map_size = read_collection_size(map); bytes_view list_value; bytes_view map_value[2]; @@ -547,9 +546,9 @@ std::strong_ordering listlike_collection_type_impl::compare_with_map(const map_t // List elements are stored in both vectors in list index order. for (size_t i = 0; i < std::min(list_size, map_size); ++i) { - list_value = read_collection_value(list, sf); - map_value[0] = read_collection_value(map, sf); - map_value[1] = read_collection_value(map, sf); + list_value = read_collection_value(list); + map_value[0] = read_collection_value(map); + map_value[1] = read_collection_value(map); auto cmp = element_type.compare(list_value, map_value[map_value_index]); if (cmp != 0) { return cmp; @@ -561,13 +560,12 @@ std::strong_ordering listlike_collection_type_impl::compare_with_map(const map_t bytes listlike_collection_type_impl::serialize_map(const map_type_impl& map_type, const data_value& value) const { assert((is_set() && map_type.get_keys_type() == _elements) || (!is_set() && map_type.get_values_type() == _elements)); - auto sf = cql_serialization_format::internal(); const std::vector>& map = map_type.from_value(value); // Lists are represented as vector>, sets are vector> bool first = is_set(); - size_t len = collection_size_len(sf); - size_t psz = collection_value_len(sf); + size_t len = collection_size_len(); + size_t psz = collection_value_len(); for (const std::pair& entry : map) { len += psz + (first ? entry.first : entry.second).serialized_size(); } @@ -575,9 +573,9 @@ bytes listlike_collection_type_impl::serialize_map(const map_type_impl& map_type bytes b(bytes::initialized_later(), len); bytes::iterator out = b.begin(); - write_collection_size(out, map.size(), sf); + write_collection_size(out, map.size()); for (const std::pair& entry : map) { - write_collection_value(out, sf, _elements, first ? entry.first : entry.second); + write_collection_value(out, _elements, first ? entry.first : entry.second); } return b; } @@ -616,39 +614,25 @@ static bool is_value_compatible_with_internal_aux(const collection_type_impl& t, return t.is_value_compatible_with_frozen(cprev); } -size_t collection_size_len(cql_serialization_format sf) { - if (sf.using_32_bits_for_collections()) { - return sizeof(int32_t); - } - return sizeof(uint16_t); +size_t collection_size_len() { + return sizeof(int32_t); } -size_t collection_value_len(cql_serialization_format sf) { - if (sf.using_32_bits_for_collections()) { - return sizeof(int32_t); - } - return sizeof(uint16_t); +size_t collection_value_len() { + return sizeof(int32_t); } -int read_collection_size(bytes_view& in, cql_serialization_format sf) { - if (sf.using_32_bits_for_collections()) { - return read_simple(in); - } else { - return read_simple(in); - } +int read_collection_size(bytes_view& in) { + return read_simple(in); } -void write_collection_size(bytes::iterator& out, int size, cql_serialization_format sf) { - if (sf.using_32_bits_for_collections()) { - serialize_int32(out, size); - } else { - serialize_int16(out, uint16_t(size)); - } +void write_collection_size(bytes::iterator& out, int size) { + serialize_int32(out, size); } -bytes_view read_collection_value(bytes_view& in, cql_serialization_format sf) { - int32_t size = sf.using_32_bits_for_collections() ? read_simple(in) : read_simple(in); +bytes_view read_collection_value(bytes_view& in) { + int32_t size = read_simple(in); if (size == -2) { throw exceptions::invalid_request_exception("unset value is not supported inside collections"); } @@ -658,17 +642,8 @@ bytes_view read_collection_value(bytes_view& in, cql_serialization_format sf) { return read_simple_bytes(in, size); } -void write_collection_value(bytes::iterator& out, cql_serialization_format sf, bytes_view val_bytes) { - if (sf.using_32_bits_for_collections()) { - serialize_int32(out, int32_t(val_bytes.size())); - } else { - if (val_bytes.size() > std::numeric_limits::max()) { - throw marshal_exception( - format("Collection value exceeds the length limit for protocol v{:d}. Collection values are limited to {:d} bytes but {:d} bytes value provided", - sf.protocol_version(), std::numeric_limits::max(), val_bytes.size())); - } - serialize_int16(out, uint16_t(val_bytes.size())); - } +void write_collection_value(bytes::iterator& out, bytes_view val_bytes) { + serialize_int32(out, int32_t(val_bytes.size())); out = std::copy_n(val_bytes.begin(), val_bytes.size(), out); } @@ -682,17 +657,8 @@ void write_simple(bytes_ostream& out, std::type_identity_t val) { out.write(bytes_view(val_ptr, sizeof(T))); } -void write_collection_value(bytes_ostream& out, cql_serialization_format sf, atomic_cell_value_view val) { - if (sf.using_32_bits_for_collections()) { - write_simple(out, int32_t(val.size_bytes())); - } else { - if (val.size_bytes() > std::numeric_limits::max()) { - throw marshal_exception( - format("Collection value exceeds the length limit for protocol v{:d}. Collection values are limited to {:d} bytes but {:d} bytes value provided", - sf.protocol_version(), std::numeric_limits::max(), val.size_bytes())); - } - write_simple(out, uint16_t(val.size_bytes())); - } +void write_collection_value(bytes_ostream& out, atomic_cell_value_view val) { + write_simple(out, int32_t(val.size_bytes())); for (auto&& frag : fragment_range(val)) { out.write(frag); } @@ -722,39 +688,17 @@ void write_simple(managed_bytes_mutable_view& out, std::type_identity_t val) } } -void write_collection_size(managed_bytes_mutable_view& out, int size, cql_serialization_format sf) { - if (sf.using_32_bits_for_collections()) { - write_simple(out, uint32_t(size)); - } else { - write_simple(out, uint16_t(size)); - } +void write_collection_size(managed_bytes_mutable_view& out, int size) { + write_simple(out, uint32_t(size)); } -void write_collection_value(managed_bytes_mutable_view& out, cql_serialization_format sf, bytes_view val) { - if (sf.using_32_bits_for_collections()) { - write_simple(out, int32_t(val.size())); - } else { - if (val.size() > std::numeric_limits::max()) { - throw marshal_exception( - format("Collection value exceeds the length limit for protocol v{:d}. Collection values are limited to {:d} bytes but {:d} bytes value provided", - sf.protocol_version(), std::numeric_limits::max(), val.size())); - } - write_simple(out, uint16_t(val.size())); - } +void write_collection_value(managed_bytes_mutable_view& out, bytes_view val) { + write_simple(out, int32_t(val.size())); write_fragmented(out, single_fragmented_view(val)); } -void write_collection_value(managed_bytes_mutable_view& out, cql_serialization_format sf, const managed_bytes_view& val) { - if (sf.using_32_bits_for_collections()) { - write_simple(out, int32_t(val.size_bytes())); - } else { - if (val.size_bytes() > std::numeric_limits::max()) { - throw marshal_exception( - format("Collection value exceeds the length limit for protocol v{:d}. Collection values are limited to {:d} bytes but {:d} bytes value provided", - sf.protocol_version(), std::numeric_limits::max(), val.size_bytes())); - } - write_simple(out, uint16_t(val.size_bytes())); - } +void write_collection_value(managed_bytes_mutable_view& out, const managed_bytes_view& val) { + write_simple(out, int32_t(val.size_bytes())); write_fragmented(out, val); } @@ -1032,14 +976,10 @@ const sstring& abstract_type::cql3_type_name() const { return _cql3_type_name; } -void write_collection_value(bytes::iterator& out, cql_serialization_format sf, data_type type, const data_value& value) { +void write_collection_value(bytes::iterator& out, data_type type, const data_value& value) { size_t val_len = value.serialized_size(); - if (sf.using_32_bits_for_collections()) { - serialize_int32(out, val_len); - } else { - serialize_int16(out, val_len); - } + serialize_int32(out, val_len); value.serialize(out); } @@ -1107,19 +1047,18 @@ map_type_impl::compare_maps(data_type keys, data_type values, managed_bytes_view } else if (o2.empty()) { return std::strong_ordering::greater; } - auto sf = cql_serialization_format::internal(); - int size1 = read_collection_size(o1, sf); - int size2 = read_collection_size(o2, sf); + int size1 = read_collection_size(o1); + int size2 = read_collection_size(o2); // FIXME: use std::lexicographical_compare() for (int i = 0; i < std::min(size1, size2); ++i) { - auto k1 = read_collection_value(o1, sf); - auto k2 = read_collection_value(o2, sf); + auto k1 = read_collection_value(o1); + auto k2 = read_collection_value(o2); auto cmp = keys->compare(k1, k2); if (cmp != 0) { return cmp; } - auto v1 = read_collection_value(o1, sf); - auto v2 = read_collection_value(o2, sf); + auto v1 = read_collection_value(o1); + auto v2 = read_collection_value(o2); cmp = values->compare(v1, v2); if (cmp != 0) { return cmp; @@ -1129,8 +1068,8 @@ map_type_impl::compare_maps(data_type keys, data_type values, managed_bytes_view } static size_t map_serialized_size(const map_type_impl::native_type* m) { - size_t len = collection_size_len(cql_serialization_format::internal()); - size_t psz = collection_value_len(cql_serialization_format::internal()); + size_t len = collection_size_len(); + size_t psz = collection_value_len(); for (auto&& kv : *m) { len += psz + kv.first.serialized_size(); len += psz + kv.second.serialized_size(); @@ -1139,34 +1078,34 @@ static size_t map_serialized_size(const map_type_impl::native_type* m) { } static void -serialize_map(const map_type_impl& t, const void* value, bytes::iterator& out, cql_serialization_format sf) { +serialize_map(const map_type_impl& t, const void* value, bytes::iterator& out) { auto& m = t.from_value(value); - write_collection_size(out, m.size(), sf); + write_collection_size(out, m.size()); for (auto&& kv : m) { - write_collection_value(out, sf, t.get_keys_type(), kv.first); - write_collection_value(out, sf, t.get_values_type(), kv.second); + write_collection_value(out, t.get_keys_type(), kv.first); + write_collection_value(out, t.get_values_type(), kv.second); } } template data_value -map_type_impl::deserialize(View in, cql_serialization_format sf) const { +map_type_impl::deserialize(View in) const { native_type m; - auto size = read_collection_size(in, sf); + auto size = read_collection_size(in); for (int i = 0; i < size; ++i) { - auto k = _keys->deserialize(read_collection_value(in, sf)); - auto v = _values->deserialize(read_collection_value(in, sf)); + auto k = _keys->deserialize(read_collection_value(in)); + auto v = _values->deserialize(read_collection_value(in)); m.insert(m.end(), std::make_pair(std::move(k), std::move(v))); } return make_value(std::move(m)); } template -static void validate_aux(const map_type_impl& t, View v, cql_serialization_format sf) { - auto size = read_collection_size(v, sf); +static void validate_aux(const map_type_impl& t, View v) { + auto size = read_collection_size(v); for (int i = 0; i < size; ++i) { - t.get_keys_type()->validate(read_collection_value(v, sf), sf); - t.get_values_type()->validate(read_collection_value(v, sf), sf); + t.get_keys_type()->validate(read_collection_value(v)); + t.get_values_type()->validate(read_collection_value(v)); } } @@ -1195,36 +1134,36 @@ static sstring map_to_string(const std::vector bytes map_type_impl::serialize_partially_deserialized_form( - const std::vector>& v, cql_serialization_format sf) { - size_t len = collection_value_len(sf) * v.size() * 2 + collection_size_len(sf); + const std::vector>& v) { + size_t len = collection_value_len() * v.size() * 2 + collection_size_len(); for (auto&& e : v) { len += e.first.size() + e.second.size(); } bytes b(bytes::initialized_later(), len); bytes::iterator out = b.begin(); - write_collection_size(out, v.size(), sf); + write_collection_size(out, v.size()); for (auto&& e : v) { - write_collection_value(out, sf, e.first); - write_collection_value(out, sf, e.second); + write_collection_value(out, e.first); + write_collection_value(out, e.second); } return b; } managed_bytes map_type_impl::serialize_partially_deserialized_form_fragmented( - const std::vector>& v, cql_serialization_format sf) { - size_t len = collection_value_len(sf) * v.size() * 2 + collection_size_len(sf); + const std::vector>& v) { + size_t len = collection_value_len() * v.size() * 2 + collection_size_len(); for (auto&& e : v) { len += e.first.size() + e.second.size(); } managed_bytes b(managed_bytes::initialized_later(), len); managed_bytes_mutable_view out = b; - write_collection_size(out, v.size(), sf); + write_collection_size(out, v.size()); for (auto&& e : v) { - write_collection_value(out, sf, e.first); - write_collection_value(out, sf, e.second); + write_collection_value(out, e.first); + write_collection_value(out, e.second); } return b; } @@ -1244,19 +1183,6 @@ static std::optional update_user_type_aux( static void serialize(const abstract_type& t, const void* value, bytes::iterator& out, cql_serialization_format sf); -managed_bytes_opt -collection_type_impl::reserialize(cql_serialization_format from, cql_serialization_format to, managed_bytes_view_opt v) const { - if (!v) { - return std::nullopt; - } - auto val = deserialize(*v, from); - bytes ret(bytes::initialized_later(), val.serialized_size()); // FIXME: serialized_size want @to - auto out = ret.begin(); - ::serialize(*this, get_value_ptr(val), out, to); - // FIXME: serialize directly to managed_bytes. - return managed_bytes(ret); -} - set_type set_type_impl::get_instance(data_type elements, bool is_multi_cell) { return intern::get_instance(elements, is_multi_cell); @@ -1311,16 +1237,16 @@ set_type_impl::is_value_compatible_with_frozen(const collection_type_impl& previ } template -static void validate_aux(const set_type_impl& t, View v, cql_serialization_format sf) { - auto nr = read_collection_size(v, sf); +static void validate_aux(const set_type_impl& t, View v) { + auto nr = read_collection_size(v); for (int i = 0; i != nr; ++i) { - t.get_elements_type()->validate(read_collection_value(v, sf), sf); + t.get_elements_type()->validate(read_collection_value(v)); } } static size_t listlike_serialized_size(const std::vector* s) { - size_t len = collection_size_len(cql_serialization_format::internal()); - size_t psz = collection_value_len(cql_serialization_format::internal()); + size_t len = collection_size_len(); + size_t psz = collection_value_len(); for (auto&& e : *s) { len += psz + e.serialized_size(); } @@ -1328,22 +1254,22 @@ static size_t listlike_serialized_size(const std::vector* s) { } static void -serialize_set(const set_type_impl& t, const void* value, bytes::iterator& out, cql_serialization_format sf) { +serialize_set(const set_type_impl& t, const void* value, bytes::iterator& out) { auto& s = t.from_value(value); - write_collection_size(out, s.size(), sf); + write_collection_size(out, s.size()); for (auto&& e : s) { - write_collection_value(out, sf, t.get_elements_type(), e); + write_collection_value(out, t.get_elements_type(), e); } } template data_value -set_type_impl::deserialize(View in, cql_serialization_format sf) const { - auto nr = read_collection_size(in, sf); +set_type_impl::deserialize(View in) const { + auto nr = read_collection_size(in); native_type s; s.reserve(nr); for (int i = 0; i != nr; ++i) { - auto e = _elements->deserialize(read_collection_value(in, sf)); + auto e = _elements->deserialize(read_collection_value(in)); if (e.is_null()) { throw marshal_exception("Cannot deserialize a set"); } @@ -1354,43 +1280,43 @@ set_type_impl::deserialize(View in, cql_serialization_format sf) const { bytes set_type_impl::serialize_partially_deserialized_form( - const std::vector& v, cql_serialization_format sf) { - return pack(v.begin(), v.end(), v.size(), sf); + const std::vector& v) { + return pack(v.begin(), v.end(), v.size()); } managed_bytes set_type_impl::serialize_partially_deserialized_form_fragmented( - const std::vector& v, cql_serialization_format sf) { - return pack_fragmented(v.begin(), v.end(), v.size(), sf); + const std::vector& v) { + return pack_fragmented(v.begin(), v.end(), v.size()); } template -utils::chunked_vector partially_deserialize_listlike(View in, cql_serialization_format sf) { - auto nr = read_collection_size(in, sf); +utils::chunked_vector partially_deserialize_listlike(View in) { + auto nr = read_collection_size(in); utils::chunked_vector elements; elements.reserve(nr); for (int i = 0; i != nr; ++i) { - elements.emplace_back(read_collection_value(in, sf)); + elements.emplace_back(read_collection_value(in)); } return elements; } -template utils::chunked_vector partially_deserialize_listlike(managed_bytes_view in, cql_serialization_format sf); -template utils::chunked_vector partially_deserialize_listlike(fragmented_temporary_buffer::view in, cql_serialization_format sf); +template utils::chunked_vector partially_deserialize_listlike(managed_bytes_view in); +template utils::chunked_vector partially_deserialize_listlike(fragmented_temporary_buffer::view in); template -std::vector> partially_deserialize_map(View in, cql_serialization_format sf) { - auto nr = read_collection_size(in, sf); +std::vector> partially_deserialize_map(View in) { + auto nr = read_collection_size(in); std::vector> elements; elements.reserve(nr); for (int i = 0; i != nr; ++i) { - auto key = managed_bytes(read_collection_value(in, sf)); - auto value = managed_bytes(read_collection_value(in, sf)); + auto key = managed_bytes(read_collection_value(in)); + auto value = managed_bytes(read_collection_value(in)); elements.emplace_back(std::move(key), std::move(value)); } return elements; } -template std::vector> partially_deserialize_map(managed_bytes_view in, cql_serialization_format sf); -template std::vector> partially_deserialize_map(fragmented_temporary_buffer::view in, cql_serialization_format sf); +template std::vector> partially_deserialize_map(managed_bytes_view in); +template std::vector> partially_deserialize_map(fragmented_temporary_buffer::view in); list_type list_type_impl::get_instance(data_type elements, bool is_multi_cell) { @@ -1454,10 +1380,10 @@ list_type_impl::is_value_compatible_with_frozen(const collection_type_impl& prev } template -static void validate_aux(const list_type_impl& t, View v, cql_serialization_format sf) { - auto nr = read_collection_size(v, sf); +static void validate_aux(const list_type_impl& t, View v) { + auto nr = read_collection_size(v); for (int i = 0; i != nr; ++i) { - t.get_elements_type()->validate(read_collection_value(v, sf), sf); + t.get_elements_type()->validate(read_collection_value(v)); } if (v.size_bytes()) { auto hex = with_linearized(v, [] (bytes_view bv) { return to_hex(bv); }); @@ -1468,22 +1394,22 @@ static void validate_aux(const list_type_impl& t, View v, cql_serialization_form } static void -serialize_list(const list_type_impl& t, const void* value, bytes::iterator& out, cql_serialization_format sf) { +serialize_list(const list_type_impl& t, const void* value, bytes::iterator& out) { auto& s = t.from_value(value); - write_collection_size(out, s.size(), sf); + write_collection_size(out, s.size()); for (auto&& e : s) { - write_collection_value(out, sf, t.get_elements_type(), e); + write_collection_value(out, t.get_elements_type(), e); } } template data_value -list_type_impl::deserialize(View in, cql_serialization_format sf) const { - auto nr = read_collection_size(in, sf); +list_type_impl::deserialize(View in) const { + auto nr = read_collection_size(in); native_type s; s.reserve(nr); for (int i = 0; i != nr; ++i) { - auto e = _elements->deserialize(read_collection_value(in, sf)); + auto e = _elements->deserialize(read_collection_value(in)); if (e.is_null()) { throw marshal_exception("Cannot deserialize a list"); } @@ -1554,12 +1480,12 @@ tuple_type_impl::get_instance(std::vector types) { } template -static void validate_aux(const tuple_type_impl& t, View v, cql_serialization_format sf) { +static void validate_aux(const tuple_type_impl& t, View v) { auto ti = t.all_types().begin(); while (ti != t.all_types().end() && v.size_bytes()) { std::optional e = read_tuple_element(v); if (e) { - (*ti)->validate(*e, sf); + (*ti)->validate(*e); } ++ti; } @@ -1581,10 +1507,10 @@ namespace { template struct validate_visitor { const View& v; - cql_serialization_format sf; + ; void operator()(const reversed_type_impl& t) { - visit(*t.underlying_type(), validate_visitor{v, sf}); + visit(*t.underlying_type(), validate_visitor{v}); } void operator()(const abstract_type&) {} template void operator()(const integer_type_impl& t) { @@ -1732,38 +1658,38 @@ struct validate_visitor { } void operator()(const map_type_impl& t) { with_simplified(v, [&] (FragmentedView auto v) { - validate_aux(t, v, sf); + validate_aux(t, v); }); } void operator()(const set_type_impl& t) { with_simplified(v, [&] (FragmentedView auto v) { - validate_aux(t, v, sf); + validate_aux(t, v); }); } void operator()(const list_type_impl& t) { with_simplified(v, [&] (FragmentedView auto v) { - validate_aux(t, v, sf); + validate_aux(t, v); }); } void operator()(const tuple_type_impl& t) { with_simplified(v, [&] (FragmentedView auto v) { - validate_aux(t, v, sf); + validate_aux(t, v); }); } }; } template -void abstract_type::validate(const View& view, cql_serialization_format sf) const { - visit(*this, validate_visitor{view, sf}); +void abstract_type::validate(const View& view) const { + visit(*this, validate_visitor{view}); } // Explicit instantiation. -template void abstract_type::validate<>(const single_fragmented_view&, cql_serialization_format) const; -template void abstract_type::validate<>(const fragmented_temporary_buffer::view&, cql_serialization_format) const; -template void abstract_type::validate<>(const managed_bytes_view&, cql_serialization_format) const; +template void abstract_type::validate<>(const single_fragmented_view&) const; +template void abstract_type::validate<>(const fragmented_temporary_buffer::view&) const; +template void abstract_type::validate<>(const managed_bytes_view&) const; -void abstract_type::validate(bytes_view v, cql_serialization_format sf) const { - visit(*this, validate_visitor{single_fragmented_view(v), sf}); +void abstract_type::validate(bytes_view v) const { + visit(*this, validate_visitor{single_fragmented_view(v)}); } static void serialize_aux(const tuple_type_impl& type, const tuple_type_impl::native_type* val, bytes::iterator& out) { @@ -1834,7 +1760,7 @@ static void serialize(const abstract_type& t, const void* value, bytes::iterator namespace { struct serialize_visitor { bytes::iterator& out; - cql_serialization_format sf; + ; void operator()(const reversed_type_impl& t, const void* v) { return serialize(*t.underlying_type(), v, out); } template void operator()(const integer_type_impl& t, const typename integer_type_impl::native_type* v1) { @@ -1957,13 +1883,13 @@ struct serialize_visitor { out += signed_vint::serialize(d.nanoseconds, out); } void operator()(const list_type_impl& t, const void* value) { - serialize_list(t, value, out, sf); + serialize_list(t, value, out); } void operator()(const map_type_impl& t, const void* value) { - serialize_map(t, value, out, sf); + serialize_map(t, value, out); } void operator()(const set_type_impl& t, const void* value) { - serialize_set(t, value, out, sf); + serialize_set(t, value, out); } void operator()(const tuple_type_impl& t, const tuple_type_impl::native_type* value) { return serialize_aux(t, value, out); @@ -1971,43 +1897,39 @@ struct serialize_visitor { }; } -static void serialize(const abstract_type& t, const void* value, bytes::iterator& out, cql_serialization_format sf) { - visit(t, value, serialize_visitor{out, sf}); -} - -static void serialize(const abstract_type& t, const void* value, bytes::iterator& out) { - return ::serialize(t, value, out, cql_serialization_format::internal()); +static void serialize(const abstract_type& t, const void* value, bytes::iterator& out) { + visit(t, value, serialize_visitor{out}); } template -data_value collection_type_impl::deserialize_impl(View v, cql_serialization_format sf) const { +data_value collection_type_impl::deserialize_impl(View v) const { struct visitor { View v; - cql_serialization_format sf; + ; data_value operator()(const abstract_type&) { on_internal_error(tlogger, "collection_type_impl::deserialize called on a non-collection type. This should be impossible."); } data_value operator()(const list_type_impl& t) { - return t.deserialize(v, sf); + return t.deserialize(v); } data_value operator()(const map_type_impl& t) { - return t.deserialize(v, sf); + return t.deserialize(v); } data_value operator()(const set_type_impl& t) { - return t.deserialize(v, sf); + return t.deserialize(v); } }; - return ::visit(*this, visitor{v, sf}); + return ::visit(*this, visitor{v}); } // Explicit instantiation. // This should be repeated for every View type passed to collection_type_impl::deserialize. -template data_value collection_type_impl::deserialize_impl<>(ser::buffer_view, cql_serialization_format) const; -template data_value collection_type_impl::deserialize_impl<>(fragmented_temporary_buffer::view, cql_serialization_format) const; -template data_value collection_type_impl::deserialize_impl<>(single_fragmented_view, cql_serialization_format) const; -template data_value collection_type_impl::deserialize_impl<>(managed_bytes_view, cql_serialization_format) const; +template data_value collection_type_impl::deserialize_impl<>(ser::buffer_view) const; +template data_value collection_type_impl::deserialize_impl<>(fragmented_temporary_buffer::view) const; +template data_value collection_type_impl::deserialize_impl<>(single_fragmented_view) const; +template data_value collection_type_impl::deserialize_impl<>(managed_bytes_view) const; -template int read_collection_size(ser::buffer_view& in, cql_serialization_format); -template ser::buffer_view read_collection_value(ser::buffer_view& in, cql_serialization_format); +template int read_collection_size(ser::buffer_view& in); +template ser::buffer_view read_collection_value(ser::buffer_view& in); template data_value deserialize_aux(const tuple_type_impl& t, View v) { @@ -2176,13 +2098,13 @@ struct deserialize_visitor { return static_cast(*long_type).make_value(read_simple_exactly(v)); } data_value operator()(const list_type_impl& t) { - return t.deserialize(v, cql_serialization_format::internal()); + return t.deserialize(v); } data_value operator()(const map_type_impl& t) { - return t.deserialize(v, cql_serialization_format::internal()); + return t.deserialize(v); } data_value operator()(const set_type_impl& t) { - return t.deserialize(v, cql_serialization_format::internal()); + return t.deserialize(v); } data_value operator()(const tuple_type_impl& t) { return deserialize_aux(t, v); } data_value operator()(const user_type_impl& t) { return deserialize_aux(t, v); } @@ -2297,10 +2219,9 @@ struct compare_visitor { } std::strong_ordering operator()(const listlike_collection_type_impl& l) { using llpdi = listlike_partial_deserializing_iterator; - auto sf = cql_serialization_format::internal(); return with_empty_checks([&] { - return lexicographical_tri_compare(llpdi::begin(v1, sf), llpdi::end(v1, sf), llpdi::begin(v2, sf), - llpdi::end(v2, sf), + return lexicographical_tri_compare(llpdi::begin(v1), llpdi::end(v1), llpdi::begin(v2), + llpdi::end(v2), [&] (const managed_bytes_view& o1, const managed_bytes_view& o2) { return l.get_elements_type()->compare(o1, o2); }); }); } @@ -2589,7 +2510,7 @@ template static bytes serialize_value(const T& t, const typename T::native_type& v) { bytes b(bytes::initialized_later(), serialized_size_visitor{}(t, &v)); auto i = b.begin(); - serialize_visitor{i, cql_serialization_format::internal()}(t, &v); + serialize_visitor{i}(t, &v); return b; } @@ -3107,7 +3028,7 @@ sstring abstract_type::get_string(const bytes& b) const { struct visitor { const bytes& b; sstring operator()(const abstract_type& t) { - t.validate(b, cql_serialization_format::latest()); + t.validate(b); return t.to_string(b); } sstring operator()(const reversed_type_impl& r) { return r.underlying_type()->get_string(b); } @@ -3206,50 +3127,50 @@ std::optional abstract_type::update_user_type(const shared_ptr bytes_ostream { throw std::runtime_error(format("attempted to serialize a collection of cells with type: {}", o.name())); } @@ -3641,19 +3562,13 @@ bool abstract_type::contains_collection() const { return _contains_collection; } -bool abstract_type::bound_value_needs_to_be_reserialized(const cql_serialization_format& sf) const { +bool abstract_type::bound_value_needs_to_be_reserialized() const { // If a value contains set or map, then this collection can be sent in the wrong order // or there could be duplicates inside. We need to reserialize it into proper set or map. if (contains_set_or_map()) { return true; } - // If a value contains a collection and it's serialized using the old serialization format, - // then we need to reserialize the collection to the current serialization format. - if (!sf.using_32_bits_for_collections() && contains_collection()) { - return true; - } - return false; } diff --git a/types.hh b/types.hh index d88fb1e3c0..eb8bff69df 100644 --- a/types.hh +++ b/types.hh @@ -37,7 +37,6 @@ class tuple_type_impl; class big_decimal; -class cql_serialization_format; namespace utils { @@ -517,8 +516,8 @@ public: return deserialize_impl(single_fragmented_view(v)); }; // Explicitly instantiated in .cc - template void validate(const View& v, cql_serialization_format sf) const; - void validate(bytes_view view, cql_serialization_format sf) const; + template void validate(const View& v) const; + void validate(bytes_view view) const; bool is_compatible_with(const abstract_type& previous) const; /* * Types which are wrappers over other types return the inner type. @@ -602,7 +601,7 @@ public: // Checks whether a bound value of this type has to be reserialized. // This can be for example because there is a set inside that needs to be sorted. - bool bound_value_needs_to_be_reserialized(const cql_serialization_format& sf) const; + bool bound_value_needs_to_be_reserialized() const; friend class list_type_impl; private: @@ -619,7 +618,7 @@ protected: static const void* get_value_ptr(const data_value& v) { return v._value; } - friend void write_collection_value(bytes::iterator& out, cql_serialization_format sf, data_type type, const data_value& value); + friend void write_collection_value(bytes::iterator& out, data_type type, const data_value& value); friend class tuple_type_impl; friend class data_value; friend class reversed_type_impl; @@ -1187,21 +1186,21 @@ inline sstring read_simple_short_string(bytes_view& v) { return ret; } -size_t collection_size_len(cql_serialization_format sf); -size_t collection_value_len(cql_serialization_format sf); -void write_collection_size(bytes::iterator& out, int size, cql_serialization_format sf); -void write_collection_size(managed_bytes_mutable_view&, int size, cql_serialization_format sf); -void write_collection_value(bytes::iterator& out, cql_serialization_format sf, bytes_view val_bytes); -void write_collection_value(managed_bytes_mutable_view&, cql_serialization_format sf, bytes_view val_bytes); -void write_collection_value(managed_bytes_mutable_view&, cql_serialization_format sf, const managed_bytes_view& val_bytes); +size_t collection_size_len(); +size_t collection_value_len(); +void write_collection_size(bytes::iterator& out, int size); +void write_collection_size(managed_bytes_mutable_view&, int size); +void write_collection_value(bytes::iterator& out, bytes_view val_bytes); +void write_collection_value(managed_bytes_mutable_view&, bytes_view val_bytes); +void write_collection_value(managed_bytes_mutable_view&, const managed_bytes_view& val_bytes); void write_int32(bytes::iterator& out, int32_t value); // Splits a serialized collection into a vector of elements, but does not recursively deserialize the elements. // Does not perform validation. template -utils::chunked_vector partially_deserialize_listlike(View in, cql_serialization_format sf); +utils::chunked_vector partially_deserialize_listlike(View in); template -std::vector> partially_deserialize_map(View in, cql_serialization_format sf); +std::vector> partially_deserialize_map(View in); using user_type = shared_ptr; using tuple_type = shared_ptr; diff --git a/types/collection.hh b/types/collection.hh index aa4c7b9499..a6a50ca4dd 100644 --- a/types/collection.hh +++ b/types/collection.hh @@ -11,13 +11,12 @@ #include #include #include - #include "types.hh" #include "collection_mutation.hh" #include "utils/chunked_vector.hh" #include "schema_fwd.hh" #include "log.hh" -#include "cql_serialization_format.hh" + #include "exceptions/exceptions.hh" namespace cql3 { @@ -47,33 +46,22 @@ public: template requires requires (Iterator it) { {*it} -> std::convertible_to; } - static bytes pack(Iterator start, Iterator finish, int elements, cql_serialization_format sf); + static bytes pack(Iterator start, Iterator finish, int elements); template requires requires (Iterator it) { {*it} -> std::convertible_to; } - static managed_bytes pack_fragmented(Iterator start, Iterator finish, int elements, cql_serialization_format sf); + static managed_bytes pack_fragmented(Iterator start, Iterator finish, int elements); private: // Explicitly instantiated in types.cc - template data_value deserialize_impl(View v, cql_serialization_format sf) const; + template data_value deserialize_impl(View v) const; public: - template data_value deserialize(View v, cql_serialization_format sf) const { - if (v.size_bytes() == v.current_fragment().size()) [[likely]] { - return deserialize_impl(single_fragmented_view(v.current_fragment()), sf); - } else { - return deserialize_impl(v, sf); - } + template data_value deserialize_value(View v) const { + return deserialize(v); } - template data_value deserialize_value(View v, cql_serialization_format sf) const { - return deserialize(v, sf); + data_value deserialize_value(bytes_view v) const { + return deserialize_impl(single_fragmented_view(v)); } - data_value deserialize(bytes_view v, cql_serialization_format sf) const { - return deserialize_impl(single_fragmented_view(v), sf); - } - data_value deserialize_value(bytes_view v, cql_serialization_format sf) const { - return deserialize_impl(single_fragmented_view(v), sf); - } - managed_bytes_opt reserialize(cql_serialization_format from, cql_serialization_format to, managed_bytes_view_opt v) const; }; // a list or a set @@ -105,17 +93,17 @@ public: template requires requires (Iterator it) { {*it} -> std::convertible_to; } bytes -collection_type_impl::pack(Iterator start, Iterator finish, int elements, cql_serialization_format sf) { - size_t len = collection_size_len(sf); - size_t psz = collection_value_len(sf); +collection_type_impl::pack(Iterator start, Iterator finish, int elements) { + size_t len = collection_size_len(); + size_t psz = collection_value_len(); for (auto j = start; j != finish; j++) { len += j->size() + psz; } bytes out(bytes::initialized_later(), len); bytes::iterator i = out.begin(); - write_collection_size(i, elements, sf); + write_collection_size(i, elements); while (start != finish) { - write_collection_value(i, sf, *start++); + write_collection_value(i, *start++); } return out; } @@ -123,17 +111,17 @@ collection_type_impl::pack(Iterator start, Iterator finish, int elements, cql_se template requires requires (Iterator it) { {*it} -> std::convertible_to; } managed_bytes -collection_type_impl::pack_fragmented(Iterator start, Iterator finish, int elements, cql_serialization_format sf) { - size_t len = collection_size_len(sf); - size_t psz = collection_value_len(sf); +collection_type_impl::pack_fragmented(Iterator start, Iterator finish, int elements) { + size_t len = collection_size_len(); + size_t psz = collection_value_len(); for (auto j = start; j != finish; j++) { len += j->size() + psz; } managed_bytes out(managed_bytes::initialized_later(), len); managed_bytes_mutable_view v(out); - write_collection_size(v, elements, sf); + write_collection_size(v, elements); while (start != finish) { - write_collection_value(v, sf, *start++); + write_collection_value(v, *start++); } return out; } diff --git a/types/list.hh b/types/list.hh index bc78bc7a8f..504c9bc60f 100644 --- a/types/list.hh +++ b/types/list.hh @@ -16,7 +16,6 @@ #include "types/collection.hh" class user_type_impl; -class cql_serialization_format; namespace Json { class Value; @@ -35,7 +34,7 @@ public: virtual bool is_value_compatible_with_frozen(const collection_type_impl& previous) const override; using abstract_type::deserialize; using collection_type_impl::deserialize; - template data_value deserialize(View v, cql_serialization_format sf) const; + template data_value deserialize(View v) const; }; data_value make_list_value(data_type type, list_type_impl::native_type value); diff --git a/types/listlike_partial_deserializing_iterator.hh b/types/listlike_partial_deserializing_iterator.hh index 4642673220..5844d1b1f7 100644 --- a/types/listlike_partial_deserializing_iterator.hh +++ b/types/listlike_partial_deserializing_iterator.hh @@ -9,27 +9,23 @@ #pragma once #include -#include "cql_serialization_format.hh" + #include "utils/fragment_range.hh" #include "utils/managed_bytes.hh" #include "exceptions/exceptions.hh" #include "types.hh" -int read_collection_size(bytes_view& in, cql_serialization_format sf); -bytes_view read_collection_value(bytes_view& in, cql_serialization_format sf); +int read_collection_size(bytes_view& in); +bytes_view read_collection_value(bytes_view& in); template -int read_collection_size(View& in, cql_serialization_format sf) { - if (sf.using_32_bits_for_collections()) { - return read_simple(in); - } else { - return read_simple(in); - } +int read_collection_size(View& in) { + return read_simple(in); } template -View read_collection_value(View& in, cql_serialization_format sf) { - auto size = sf.using_32_bits_for_collections() ? read_simple(in) : read_simple(in); +View read_collection_value(View& in) { + auto size = read_simple(in); if (size == -2) { throw exceptions::invalid_request_exception("unset value is not supported inside collections"); } @@ -52,16 +48,15 @@ private: managed_bytes_view* _in; int _remain; managed_bytes_view _cur; - cql_serialization_format _sf; private: struct end_tag {}; - listlike_partial_deserializing_iterator(managed_bytes_view& in, cql_serialization_format sf) - : _in(&in), _sf(sf) { - _remain = read_collection_size(*_in, _sf); + listlike_partial_deserializing_iterator(managed_bytes_view& in) + : _in(&in) { + _remain = read_collection_size(*_in); parse(); } listlike_partial_deserializing_iterator(end_tag) - : _remain(0), _sf(cql_serialization_format::internal()) { // _sf is bogus, but doesn't matter + : _remain(0) { } public: managed_bytes_view operator*() const { return _cur; } @@ -80,16 +75,16 @@ public: bool operator!=(const listlike_partial_deserializing_iterator& x) const { return _remain != x._remain; } - static listlike_partial_deserializing_iterator begin(managed_bytes_view& in, cql_serialization_format sf) { - return { in, sf }; + static listlike_partial_deserializing_iterator begin(managed_bytes_view& in) { + return { in }; } - static listlike_partial_deserializing_iterator end(managed_bytes_view in, cql_serialization_format sf) { + static listlike_partial_deserializing_iterator end(managed_bytes_view in) { return { end_tag() }; } private: void parse() { if (_remain) { - _cur = read_collection_value(*_in, _sf); + _cur = read_collection_value(*_in); } else { _cur = {}; } diff --git a/types/map.hh b/types/map.hh index cb2066c16a..9551d9dd85 100644 --- a/types/map.hh +++ b/types/map.hh @@ -17,7 +17,6 @@ #include "types/collection.hh" class user_type_impl; -class cql_serialization_format; namespace Json { class Value; @@ -43,11 +42,9 @@ public: managed_bytes_view o1, managed_bytes_view o2); using abstract_type::deserialize; using collection_type_impl::deserialize; - template data_value deserialize(View v, cql_serialization_format sf) const; - static bytes serialize_partially_deserialized_form(const std::vector>& v, - cql_serialization_format sf); - static managed_bytes serialize_partially_deserialized_form_fragmented(const std::vector>& v, - cql_serialization_format sf); + template data_value deserialize(View v) const; + static bytes serialize_partially_deserialized_form(const std::vector>& v); + static managed_bytes serialize_partially_deserialized_form_fragmented(const std::vector>& v); // Serializes a map using the internal cql serialization format // Takes a range of pair @@ -82,7 +79,7 @@ bytes map_type_impl::serialize_to_bytes(const Range& map_range) { bytes result(bytes::initialized_later(), serialized_len); bytes::iterator out = result.begin(); - write_collection_size(out, map_size, cql_serialization_format::internal()); + write_collection_size(out, map_size); for (const std::pair& elem : map_range) { if (elem.first.size() > std::numeric_limits::max()) { throw exceptions::invalid_request_exception( @@ -94,8 +91,8 @@ bytes map_type_impl::serialize_to_bytes(const Range& map_range) { fmt::format("Map value size too large: {} bytes > {}", map_size, std::numeric_limits::max())); } - write_collection_value(out, cql_serialization_format::internal(), elem.first); - write_collection_value(out, cql_serialization_format::internal(), elem.second); + write_collection_value(out, elem.first); + write_collection_value(out, elem.second); } return result; @@ -119,7 +116,7 @@ managed_bytes map_type_impl::serialize_to_managed_bytes(const Range& map_range) managed_bytes result(managed_bytes::initialized_later(), serialized_len); managed_bytes_mutable_view out(result); - write_collection_size(out, map_size, cql_serialization_format::internal()); + write_collection_size(out, map_size); for (const std::pair& elem : map_range) { if (elem.first.size() > std::numeric_limits::max()) { throw exceptions::invalid_request_exception( @@ -131,8 +128,8 @@ managed_bytes map_type_impl::serialize_to_managed_bytes(const Range& map_range) fmt::format("Map value size too large: {} bytes > {}", map_size, std::numeric_limits::max())); } - write_collection_value(out, cql_serialization_format::internal(), elem.first); - write_collection_value(out, cql_serialization_format::internal(), elem.second); + write_collection_value(out, elem.first); + write_collection_value(out, elem.second); } return result; diff --git a/types/set.hh b/types/set.hh index a006ed91b4..d8ff5133a8 100644 --- a/types/set.hh +++ b/types/set.hh @@ -16,7 +16,6 @@ #include "types/collection.hh" class user_type_impl; -class cql_serialization_format; namespace Json { class Value; @@ -35,11 +34,11 @@ public: virtual bool is_value_compatible_with_frozen(const collection_type_impl& previous) const override; using abstract_type::deserialize; using collection_type_impl::deserialize; - template data_value deserialize(View v, cql_serialization_format sf) const; + template data_value deserialize(View v) const; static bytes serialize_partially_deserialized_form( - const std::vector& v, cql_serialization_format sf); + const std::vector& v); static managed_bytes serialize_partially_deserialized_form_fragmented( - const std::vector& v, cql_serialization_format sf); + const std::vector& v); }; data_value make_set_value(data_type tuple_type, set_type_impl::native_type value);