From 9e88b60ef5f7e1f2ea8078cf6069dcd8f19b1069 Mon Sep 17 00:00:00 2001 From: Duarte Nunes Date: Thu, 27 Apr 2017 00:38:49 +0200 Subject: [PATCH] mutation: Set cell using clustering_key_prefix Change the clustering key argument in mutation::set_cell from exploded_clustering_prefix to clustering_key_prefix, which allows for some overall code simplification and fewer copies. This mostly affects the cql3 layer. Signed-off-by: Duarte Nunes --- cql3/constants.cc | 2 +- cql3/constants.hh | 8 ++--- cql3/lists.cc | 41 ++++++----------------- cql3/lists.hh | 16 ++++----- cql3/maps.cc | 10 +++--- cql3/maps.hh | 10 +++--- cql3/operation.cc | 2 +- cql3/operation.hh | 2 +- cql3/sets.cc | 10 +++--- cql3/sets.hh | 10 +++--- cql3/statements/delete_statement.cc | 4 +-- cql3/statements/modification_statement.cc | 2 +- cql3/statements/update_statement.cc | 9 +++-- cql3/update_parameters.cc | 4 +-- cql3/update_parameters.hh | 22 ++++++++---- db/batchlog_manager.cc | 8 ++--- db/schema_tables.cc | 7 ++-- keys.hh | 3 ++ mutation.cc | 9 ++--- mutation.hh | 5 ++- mutation_partition.cc | 11 ------ mutation_partition.hh | 1 - service/storage_proxy.cc | 2 +- tests/sstable_datafile_test.cc | 17 ++++------ 24 files changed, 93 insertions(+), 122 deletions(-) diff --git a/cql3/constants.cc b/cql3/constants.cc index d0244f6240..42c2e9da32 100644 --- a/cql3/constants.cc +++ b/cql3/constants.cc @@ -159,7 +159,7 @@ constants::literal::prepare(database& db, const sstring& keyspace, ::shared_ptr< return ::make_shared(cql3::raw_value::make_value(parsed_value(receiver->type))); } -void constants::deleter::execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) { +void constants::deleter::execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) { if (column.type->is_multi_cell()) { collection_type_impl::mutation coll_m; coll_m.tomb = params.make_tombstone(); diff --git a/cql3/constants.hh b/cql3/constants.hh index 4ba98fbaa3..bf0d813bcd 100644 --- a/cql3/constants.hh +++ b/cql3/constants.hh @@ -197,7 +197,7 @@ public: public: using operation::operation; - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override { + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) override { auto value = _t->bind_and_get(params._options); if (value.is_null()) { m.set_cell(prefix, column, std::move(make_dead_cell(params))); @@ -210,7 +210,7 @@ public: struct adder final : operation { using operation::operation; - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override { + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) override { auto value = _t->bind_and_get(params._options); if (value.is_null()) { throw exceptions::invalid_request_exception("Invalid null value for counter increment"); @@ -225,7 +225,7 @@ public: struct subtracter final : operation { using operation::operation; - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override { + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) override { auto value = _t->bind_and_get(params._options); if (value.is_null()) { throw exceptions::invalid_request_exception("Invalid null value for counter increment"); @@ -246,7 +246,7 @@ public: : operation(column, {}) { } - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override; + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) override; }; }; diff --git a/cql3/lists.cc b/cql3/lists.cc index d90ca54a96..e9b8173b92 100644 --- a/cql3/lists.cc +++ b/cql3/lists.cc @@ -242,7 +242,7 @@ lists::precision_time::get_next(db_clock::time_point millis) { } void -lists::setter::execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) { +lists::setter::execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) { const auto& value = _t->bind(params._options); if (value == constants::UNSET_VALUE) { return; @@ -270,15 +270,10 @@ lists::setter_by_index::collect_marker_specification(shared_ptris_multi_cell()); // "Attempted to set an individual element on a frozen list"; - std::experimental::optional row_key; - if (!column.is_static()) { - row_key = clustering_key::from_clustering_prefix(*params._schema, prefix); - } - auto index = _idx->bind_and_get(params._options); if (index.is_null()) { throw exceptions::invalid_request_exception("Invalid null value for list index"); @@ -292,7 +287,7 @@ lists::setter_by_index::execute(mutation& m, const exploded_clustering_prefix& p } auto idx = net::ntoh(int32_t(*unaligned_cast(index->begin()))); - auto&& existing_list_opt = params.get_prefetched_list(m.key(), std::move(row_key), column); + auto&& existing_list_opt = params.get_prefetched_list(m.key().view(), prefix.view(), column); if (!existing_list_opt) { throw exceptions::invalid_request_exception("Attempted to set an element on a list which is null"); } @@ -327,15 +322,10 @@ lists::setter_by_uuid::requires_read() { } void -lists::setter_by_uuid::execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) { +lists::setter_by_uuid::execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) { // we should not get here for frozen lists assert(column.type->is_multi_cell()); // "Attempted to set an individual element on a frozen list"; - std::experimental::optional row_key; - if (!column.is_static()) { - row_key = clustering_key::from_clustering_prefix(*params._schema, prefix); - } - auto index = _idx->bind_and_get(params._options); auto value = _t->bind_and_get(params._options); @@ -355,7 +345,7 @@ lists::setter_by_uuid::execute(mutation& m, const exploded_clustering_prefix& pr } void -lists::appender::execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) { +lists::appender::execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) { const auto& value = _t->bind(params._options); if (value == constants::UNSET_VALUE) { return; @@ -367,7 +357,7 @@ lists::appender::execute(mutation& m, const exploded_clustering_prefix& prefix, void lists::do_append(shared_ptr value, mutation& m, - const exploded_clustering_prefix& prefix, + const clustering_key_prefix& prefix, const column_definition& column, const update_parameters& params) { auto&& list_value = dynamic_pointer_cast(value); @@ -401,7 +391,7 @@ lists::do_append(shared_ptr value, } void -lists::prepender::execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) { +lists::prepender::execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) { assert(column.type->is_multi_cell()); // "Attempted to prepend to a frozen list"; auto&& value = _t->bind(params._options); if (!value || value == constants::UNSET_VALUE) { @@ -433,15 +423,10 @@ lists::discarder::requires_read() { } void -lists::discarder::execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) { +lists::discarder::execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) { assert(column.type->is_multi_cell()); // "Attempted to delete from a frozen list"; - std::experimental::optional row_key; - if (!column.is_static()) { - row_key = clustering_key::from_clustering_prefix(*params._schema, prefix); - } - - auto&& existing_list = params.get_prefetched_list(m.key(), std::move(row_key), column); + auto&& existing_list = params.get_prefetched_list(m.key().view(), prefix.view(), column); // We want to call bind before possibly returning to reject queries where the value provided is not a list. auto&& value = _t->bind(params._options); @@ -490,7 +475,7 @@ lists::discarder_by_index::requires_read() { } void -lists::discarder_by_index::execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) { +lists::discarder_by_index::execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) { assert(column.type->is_multi_cell()); // "Attempted to delete an item by index from a frozen list"; auto&& index = _t->bind(params._options); if (!index) { @@ -504,11 +489,7 @@ lists::discarder_by_index::execute(mutation& m, const exploded_clustering_prefix auto cvalue = dynamic_pointer_cast(index); assert(cvalue); - std::experimental::optional row_key; - if (!column.is_static()) { - row_key = clustering_key::from_clustering_prefix(*params._schema, prefix); - } - auto&& existing_list_opt = params.get_prefetched_list(m.key(), std::move(row_key), column); + auto&& existing_list_opt = params.get_prefetched_list(m.key().view(), prefix.view(), column); int32_t idx = read_simple_exactly(*cvalue->_bytes); if (!existing_list_opt) { throw exceptions::invalid_request_exception("Attempted to delete an element from a list which is null"); diff --git a/cql3/lists.hh b/cql3/lists.hh index c2a37ea96e..ecdf1c19c8 100644 --- a/cql3/lists.hh +++ b/cql3/lists.hh @@ -146,7 +146,7 @@ public: setter(const column_definition& column, shared_ptr t) : operation(column, std::move(t)) { } - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override; + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) override; }; class setter_by_index : public operation { @@ -158,7 +158,7 @@ public: } virtual bool requires_read() override; virtual void collect_marker_specification(shared_ptr bound_names); - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override; + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) override; }; class setter_by_uuid : public setter_by_index { @@ -167,25 +167,25 @@ public: : setter_by_index(column, std::move(idx), std::move(t)) { } virtual bool requires_read() override; - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override; + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) override; }; class appender : public operation { public: using operation::operation; - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override; + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) override; }; static void do_append(shared_ptr value, mutation& m, - const exploded_clustering_prefix& prefix, + const clustering_key_prefix& prefix, const column_definition& column, const update_parameters& params); class prepender : public operation { public: using operation::operation; - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override; + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) override; }; class discarder : public operation { @@ -194,7 +194,7 @@ public: : operation(column, std::move(t)) { } virtual bool requires_read() override; - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override; + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) override; }; class discarder_by_index : public operation { @@ -203,7 +203,7 @@ public: : operation(column, std::move(idx)) { } virtual bool requires_read() override; - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params); + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params); }; }; diff --git a/cql3/maps.cc b/cql3/maps.cc index 3a6bd75f64..43c8a01d25 100644 --- a/cql3/maps.cc +++ b/cql3/maps.cc @@ -269,7 +269,7 @@ maps::marker::bind(const query_options& options) { } void -maps::setter::execute(mutation& m, const exploded_clustering_prefix& row_key, const update_parameters& params) { +maps::setter::execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params) { auto value = _t->bind(params._options); if (value == constants::UNSET_VALUE) { return; @@ -292,7 +292,7 @@ maps::setter_by_key::collect_marker_specification(shared_ptris_multi_cell()); // "Attempted to set a value for a single key on a frozen map"m auto key = _k->bind_and_get(params._options); @@ -315,7 +315,7 @@ maps::setter_by_key::execute(mutation& m, const exploded_clustering_prefix& pref } void -maps::putter::execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) { +maps::putter::execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) { assert(column.type->is_multi_cell()); // "Attempted to add items to a frozen map"; auto value = _t->bind(params._options); if (value != constants::UNSET_VALUE) { @@ -324,7 +324,7 @@ maps::putter::execute(mutation& m, const exploded_clustering_prefix& prefix, con } void -maps::do_put(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params, +maps::do_put(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params, shared_ptr value, const column_definition& column) { auto map_value = dynamic_pointer_cast(value); if (column.type->is_multi_cell()) { @@ -353,7 +353,7 @@ maps::do_put(mutation& m, const exploded_clustering_prefix& prefix, const update } void -maps::discarder_by_key::execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) { +maps::discarder_by_key::execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) { assert(column.type->is_multi_cell()); // "Attempted to delete a single key in a frozen map"; auto&& key = _t->bind(params._options); if (!key) { diff --git a/cql3/maps.hh b/cql3/maps.hh index 995ff8c919..ad9bc92b73 100644 --- a/cql3/maps.hh +++ b/cql3/maps.hh @@ -116,7 +116,7 @@ public: : operation(column, std::move(t)) { } - virtual void execute(mutation& m, const exploded_clustering_prefix& row_key, const update_parameters& params) override; + virtual void execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params) override; }; class setter_by_key : public operation { @@ -126,7 +126,7 @@ public: : operation(column, std::move(t)), _k(std::move(k)) { } virtual void collect_marker_specification(shared_ptr bound_names) override; - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override; + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) override; }; class putter : public operation { @@ -134,10 +134,10 @@ public: putter(const column_definition& column, shared_ptr t) : operation(column, std::move(t)) { } - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override; + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) override; }; - static void do_put(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params, + static void do_put(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params, shared_ptr value, const column_definition& column); class discarder_by_key : public operation { @@ -145,7 +145,7 @@ public: discarder_by_key(const column_definition& column, shared_ptr k) : operation(column, std::move(k)) { } - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override; + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) override; }; }; diff --git a/cql3/operation.cc b/cql3/operation.cc index cada57f590..66067a3f48 100644 --- a/cql3/operation.cc +++ b/cql3/operation.cc @@ -215,7 +215,7 @@ operation::set_counter_value_from_tuple_list::prepare(database& db, const sstrin bool is_raw_counter_shard_write() const override { return true; } - void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override { + void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) override { const auto& value = _t->bind(params._options); auto&& list_value = dynamic_pointer_cast(value); diff --git a/cql3/operation.hh b/cql3/operation.hh index 702774a8a2..7cc3627162 100644 --- a/cql3/operation.hh +++ b/cql3/operation.hh @@ -130,7 +130,7 @@ public: /** * Execute the operation. */ - virtual void execute(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) = 0; + virtual void execute(mutation& m, const clustering_key_prefix& prefix, const update_parameters& params) = 0; /** * A parsed raw UPDATE operation. diff --git a/cql3/sets.cc b/cql3/sets.cc index 9701acb4fb..28b29b63b8 100644 --- a/cql3/sets.cc +++ b/cql3/sets.cc @@ -224,7 +224,7 @@ sets::marker::bind(const query_options& options) { } void -sets::setter::execute(mutation& m, const exploded_clustering_prefix& row_key, const update_parameters& params) { +sets::setter::execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params) { const auto& value = _t->bind(params._options); if (value == constants::UNSET_VALUE) { return; @@ -241,7 +241,7 @@ sets::setter::execute(mutation& m, const exploded_clustering_prefix& row_key, co } void -sets::adder::execute(mutation& m, const exploded_clustering_prefix& row_key, const update_parameters& params) { +sets::adder::execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params) { const auto& value = _t->bind(params._options); if (value == constants::UNSET_VALUE) { return; @@ -251,7 +251,7 @@ sets::adder::execute(mutation& m, const exploded_clustering_prefix& row_key, con } void -sets::adder::do_add(mutation& m, const exploded_clustering_prefix& row_key, const update_parameters& params, +sets::adder::do_add(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params, shared_ptr value, const column_definition& column) { auto set_value = dynamic_pointer_cast(std::move(value)); auto set_type = dynamic_pointer_cast(column.type); @@ -281,7 +281,7 @@ sets::adder::do_add(mutation& m, const exploded_clustering_prefix& row_key, cons } void -sets::discarder::execute(mutation& m, const exploded_clustering_prefix& row_key, const update_parameters& params) { +sets::discarder::execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params) { assert(column.type->is_multi_cell()); // "Attempted to remove items from a frozen set"; auto&& value = _t->bind(params._options); @@ -305,7 +305,7 @@ sets::discarder::execute(mutation& m, const exploded_clustering_prefix& row_key, ctype->serialize_mutation_form(mut))); } -void sets::element_discarder::execute(mutation& m, const exploded_clustering_prefix& row_key, const update_parameters& params) +void sets::element_discarder::execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params) { assert(column.type->is_multi_cell() && "Attempted to remove items from a frozen set"); auto elt = _t->bind(params._options); diff --git a/cql3/sets.hh b/cql3/sets.hh index ccd5ea9d76..88fa757ec0 100644 --- a/cql3/sets.hh +++ b/cql3/sets.hh @@ -112,7 +112,7 @@ public: setter(const column_definition& column, shared_ptr t) : operation(column, std::move(t)) { } - virtual void execute(mutation& m, const exploded_clustering_prefix& row_key, const update_parameters& params) override; + virtual void execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params) override; }; class adder : public operation { @@ -120,8 +120,8 @@ public: adder(const column_definition& column, shared_ptr t) : operation(column, std::move(t)) { } - virtual void execute(mutation& m, const exploded_clustering_prefix& row_key, const update_parameters& params) override; - static void do_add(mutation& m, const exploded_clustering_prefix& row_key, const update_parameters& params, + virtual void execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params) override; + static void do_add(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params, shared_ptr value, const column_definition& column); }; @@ -131,14 +131,14 @@ public: discarder(const column_definition& column, shared_ptr t) : operation(column, std::move(t)) { } - virtual void execute(mutation& m, const exploded_clustering_prefix& row_key, const update_parameters& params) override; + virtual void execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params) override; }; class element_discarder : public operation { public: element_discarder(const column_definition& column, shared_ptr t) : operation(column, std::move(t)) { } - virtual void execute(mutation& m, const exploded_clustering_prefix& row_key, const update_parameters& params) override; + virtual void execute(mutation& m, const clustering_key_prefix& row_key, const update_parameters& params) override; }; }; diff --git a/cql3/statements/delete_statement.cc b/cql3/statements/delete_statement.cc index be509ebcc5..4baeaac357 100644 --- a/cql3/statements/delete_statement.cc +++ b/cql3/statements/delete_statement.cc @@ -63,7 +63,7 @@ void delete_statement::add_update_for_key(mutation& m, const query::clustering_r if (s->clustering_key_size() == 0 || range.is_full()) { m.partition().apply(params.make_tombstone()); } else if (range.is_singular()) { - m.partition().apply_delete(*s, exploded_clustering_prefix(range.start()->value().explode()), params.make_tombstone()); + m.partition().apply_delete(*s, range.start()->value(), params.make_tombstone()); } else { auto bvs = bound_view::from_range(range); m.partition().apply_delete(*s, range_tombstone(bvs.first, bvs.second, params.make_tombstone())); @@ -72,7 +72,7 @@ void delete_statement::add_update_for_key(mutation& m, const query::clustering_r } for (auto&& op : _column_operations) { - op->execute(m, range.start() ? exploded_clustering_prefix(range.start()->value().explode()) : exploded_clustering_prefix(), params); + op->execute(m, range.start() ? std::move(range.start()->value()) : clustering_key_prefix::make_empty(), params); } } diff --git a/cql3/statements/modification_statement.cc b/cql3/statements/modification_statement.cc index f4bcec2fca..3657a93b53 100644 --- a/cql3/statements/modification_statement.cc +++ b/cql3/statements/modification_statement.cc @@ -267,7 +267,7 @@ public: add_cell(cells, _schema->static_column_at(id), static_row_iterator.next_collection_cell()); } - _data.rows.emplace(std::make_pair(*_pkey, std::experimental::nullopt), std::move(cells)); + _data.rows.emplace(std::make_pair(*_pkey, clustering_key_prefix::make_empty()), std::move(cells)); } }; diff --git a/cql3/statements/update_statement.cc b/cql3/statements/update_statement.cc index 316044a176..18c9d93cc1 100644 --- a/cql3/statements/update_statement.cc +++ b/cql3/statements/update_statement.cc @@ -63,12 +63,11 @@ bool update_statement::allow_clustering_key_slices() const { } void update_statement::add_update_for_key(mutation& m, const query::clustering_range& range, const update_parameters& params) { - exploded_clustering_prefix prefix(range.start() ? range.start()->value().explode() : std::vector()); + auto prefix = range.start() ? std::move(range.start()->value()) : clustering_key_prefix::make_empty(); if (s->is_dense()) { - if (!prefix || (prefix.size() == 1 && prefix.components().front().empty())) { + if (prefix.is_empty(*s)) { throw exceptions::invalid_request_exception(sprint("Missing PRIMARY KEY part %s", s->clustering_key_columns().begin()->name_as_text())); } - // An empty name for the value is what we use to recognize the case where there is not column // outside the PK, see CreateStatement. if (s->regular_begin()->name().empty()) { @@ -84,9 +83,9 @@ void update_statement::add_update_for_key(mutation& m, const query::clustering_r } else { // If there are static columns, there also must be clustering columns, in which // case empty prefix can only refer to the static row. - bool is_static_prefix = s->has_static_columns() && !prefix; + bool is_static_prefix = s->has_static_columns() && prefix.is_empty(*s); if (type == statement_type::INSERT && !is_static_prefix && s->is_cql3_table()) { - auto& row = m.partition().clustered_row(*s, clustering_key::from_clustering_prefix(*s, prefix)); + auto& row = m.partition().clustered_row(*s, prefix); row.apply(row_marker(params.timestamp(), params.ttl(), params.expiry())); } } diff --git a/cql3/update_parameters.cc b/cql3/update_parameters.cc index a7b50dfbf3..1a0cf16b7a 100644 --- a/cql3/update_parameters.cc +++ b/cql3/update_parameters.cc @@ -45,8 +45,8 @@ namespace cql3 { const update_parameters::prefetch_data::cell_list* update_parameters::get_prefetched_list( - partition_key pkey, - std::experimental::optional ckey, + partition_key_view pkey, + clustering_key_view ckey, const column_definition& column) const { if (!_prefetched) { diff --git a/cql3/update_parameters.hh b/cql3/update_parameters.hh index 87ca91a492..b52fcf54da 100644 --- a/cql3/update_parameters.hh +++ b/cql3/update_parameters.hh @@ -60,7 +60,8 @@ class update_parameters final { public: // Holder for data needed by CQL list updates which depend on current state of the list. struct prefetch_data { - using key = std::pair>; + using key = std::pair; + using key_view = std::pair; struct key_hashing { partition_key::hashing pk_hash; clustering_key::hashing ck_hash; @@ -71,7 +72,11 @@ public: { } size_t operator()(const key& k) const { - return pk_hash(k.first) ^ (k.second ? ck_hash(*k.second) : 0); + return pk_hash(k.first) ^ ck_hash(k.second); + } + + size_t operator()(const key_view& k) const { + return pk_hash(k.first) ^ ck_hash(k.second); } }; struct key_equality { @@ -84,8 +89,13 @@ public: { } bool operator()(const key& k1, const key& k2) const { - return pk_eq(k1.first, k2.first) - && bool(k1.second) == bool(k2.second) && (!k1.second || ck_eq(*k1.second, *k2.second)); + return pk_eq(k1.first, k2.first) && ck_eq(k1.second, k2.second); + } + bool operator()(const key_view& k1, const key& k2) const { + return pk_eq(k1.first, k2.first) && ck_eq(k1.second, k2.second); + } + bool operator()(const key& k1, const key_view& k2) const { + return pk_eq(k1.first, k2.first) && ck_eq(k1.second, k2.second); } }; struct cell { @@ -188,8 +198,8 @@ public: const prefetch_data::cell_list* get_prefetched_list( - partition_key pkey, - std::experimental::optional ckey, + partition_key_view pkey, + clustering_key_view ckey, const column_definition& column) const; }; diff --git a/db/batchlog_manager.cc b/db/batchlog_manager.cc index 8731675093..f644db3c2c 100644 --- a/db/batchlog_manager.cc +++ b/db/batchlog_manager.cc @@ -162,9 +162,9 @@ mutation db::batchlog_manager::get_batch_log_mutation_for(const std::vector db::batchlog_manager::replay_all_failed_batches() { auto key = partition_key::from_singular(*schema, id); mutation m(key, schema); auto now = service::client_state(service::client_state::internal_tag()).get_timestamp(); - m.partition().apply_delete(*schema, {}, tombstone(now, gc_clock::now())); + m.partition().apply_delete(*schema, clustering_key_prefix::make_empty(), tombstone(now, gc_clock::now())); return _qp.proxy().local().mutate_locally(m); }); }; diff --git a/db/schema_tables.cc b/db/schema_tables.cc index 15abf7e995..aa438686c3 100644 --- a/db/schema_tables.cc +++ b/db/schema_tables.cc @@ -1082,11 +1082,10 @@ std::vector make_create_keyspace_mutations(lw_shared_ptrname()); mutation m(pkey, s); - exploded_clustering_prefix ckey; - m.set_cell(ckey, "durable_writes", keyspace->durable_writes(), timestamp); - m.set_cell(ckey, "strategy_class", keyspace->strategy_name(), timestamp); + m.set_cell(clustering_key_prefix::make_empty(), "durable_writes", keyspace->durable_writes(), timestamp); + m.set_cell(clustering_key_prefix::make_empty(), "strategy_class", keyspace->strategy_name(), timestamp); auto raw = json::to_json(keyspace->strategy_options()); - m.set_cell(ckey, "strategy_options", raw, timestamp); + m.set_cell(clustering_key_prefix::make_empty(), "strategy_options", raw, timestamp); mutations.emplace_back(std::move(m)); if (with_tables_and_types_and_functions) { diff --git a/keys.hh b/keys.hh index c79fde63fb..3d78982752 100644 --- a/keys.hh +++ b/keys.hh @@ -254,6 +254,9 @@ public: size_t operator()(const TopLevel& o) const { return _t->hash(o); } + size_t operator()(const TopLevelView& o) const { + return _t->hash(o.representation()); + } }; struct equality { diff --git a/mutation.cc b/mutation.cc index c66945505c..6dbb47f510 100644 --- a/mutation.cc +++ b/mutation.cc @@ -61,11 +61,6 @@ void mutation::set_static_cell(const bytes& name, const data_value& value, api:: partition().static_row().apply(*column_def, atomic_cell::make_live(timestamp, column_def->type->decompose(value), ttl)); } -void mutation::set_clustered_cell(const exploded_clustering_prefix& prefix, const column_definition& def, atomic_cell_or_collection&& value) { - auto& row = partition().clustered_row(*schema(), clustering_key::from_clustering_prefix(*schema(), prefix)).cells(); - row.apply(def, std::move(value)); -} - void mutation::set_clustered_cell(const clustering_key& key, const bytes& name, const data_value& value, api::timestamp_type timestamp, ttl_opt ttl) { auto column_def = schema()->get_column_definition(name); @@ -80,7 +75,7 @@ void mutation::set_clustered_cell(const clustering_key& key, const column_defini row.apply(def, std::move(value)); } -void mutation::set_cell(const exploded_clustering_prefix& prefix, const bytes& name, const data_value& value, +void mutation::set_cell(const clustering_key_prefix& prefix, const bytes& name, const data_value& value, api::timestamp_type timestamp, ttl_opt ttl) { auto column_def = schema()->get_column_definition(name); if (!column_def) { @@ -89,7 +84,7 @@ void mutation::set_cell(const exploded_clustering_prefix& prefix, const bytes& n return set_cell(prefix, *column_def, atomic_cell::make_live(timestamp, column_def->type->decompose(value), ttl)); } -void mutation::set_cell(const exploded_clustering_prefix& prefix, const column_definition& def, atomic_cell_or_collection&& value) { +void mutation::set_cell(const clustering_key_prefix& prefix, const column_definition& def, atomic_cell_or_collection&& value) { if (def.is_static()) { set_static_cell(def, std::move(value)); } else if (def.is_regular()) { diff --git a/mutation.hh b/mutation.hh index 90047dae0f..10c29c02db 100644 --- a/mutation.hh +++ b/mutation.hh @@ -70,11 +70,10 @@ public: void set_static_cell(const column_definition& def, atomic_cell_or_collection&& value); void set_static_cell(const bytes& name, const data_value& value, api::timestamp_type timestamp, ttl_opt ttl = {}); - void set_clustered_cell(const exploded_clustering_prefix& prefix, const column_definition& def, atomic_cell_or_collection&& value); void set_clustered_cell(const clustering_key& key, const bytes& name, const data_value& value, api::timestamp_type timestamp, ttl_opt ttl = {}); void set_clustered_cell(const clustering_key& key, const column_definition& def, atomic_cell_or_collection&& value); - void set_cell(const exploded_clustering_prefix& prefix, const bytes& name, const data_value& value, api::timestamp_type timestamp, ttl_opt ttl = {}); - void set_cell(const exploded_clustering_prefix& prefix, const column_definition& def, atomic_cell_or_collection&& value); + void set_cell(const clustering_key_prefix& prefix, const bytes& name, const data_value& value, api::timestamp_type timestamp, ttl_opt ttl = {}); + void set_cell(const clustering_key_prefix& prefix, const column_definition& def, atomic_cell_or_collection&& value); // Upgrades this mutation to a newer schema. The new schema must // be obtained using only valid schema transformation: diff --git a/mutation_partition.cc b/mutation_partition.cc index fd18875e8a..589682c641 100644 --- a/mutation_partition.cc +++ b/mutation_partition.cc @@ -418,17 +418,6 @@ mutation_partition::apply_row_tombstone(const schema& schema, range_tombstone rt _row_tombstones.apply(schema, std::move(rt)); } -void -mutation_partition::apply_delete(const schema& schema, const exploded_clustering_prefix& prefix, tombstone t) { - if (!prefix) { - apply(t); - } else if (prefix.is_full(schema)) { - apply_delete(schema, clustering_key::from_clustering_prefix(schema, prefix), t); - } else { - apply_row_tombstone(schema, clustering_key_prefix::from_clustering_prefix(schema, prefix), t); - } -} - void mutation_partition::apply_delete(const schema& schema, const clustering_key_prefix& prefix, tombstone t) { if (prefix.is_empty(schema)) { diff --git a/mutation_partition.hh b/mutation_partition.hh index 72770d38bc..58539de90c 100644 --- a/mutation_partition.hh +++ b/mutation_partition.hh @@ -778,7 +778,6 @@ public: friend std::ostream& operator<<(std::ostream& os, const mutation_partition& mp); public: void apply(tombstone t) { _tombstone.apply(t); } - void apply_delete(const schema& schema, const exploded_clustering_prefix& prefix, tombstone t); void apply_delete(const schema& schema, const clustering_key_prefix& prefix, tombstone t); void apply_delete(const schema& schema, range_tombstone rt); void apply_delete(const schema& schema, clustering_key_prefix&& prefix, tombstone t); diff --git a/service/storage_proxy.cc b/service/storage_proxy.cc index 3994e91cbe..28b8c5e483 100644 --- a/service/storage_proxy.cc +++ b/service/storage_proxy.cc @@ -1405,7 +1405,7 @@ storage_proxy::mutate_atomically(std::vector mutations, db::consistenc auto key = partition_key::from_exploded(*schema, {uuid_type->decompose(_batch_uuid)}); auto now = service::client_state(service::client_state::internal_tag()).get_timestamp(); mutation m(key, schema); - m.partition().apply_delete(*schema, {}, tombstone(now, gc_clock::now())); + m.partition().apply_delete(*schema, clustering_key_prefix::make_empty(), tombstone(now, gc_clock::now())); tracing::trace(_trace_state, "Sending a batchlog remove mutation"); return send_batchlog_mutation(std::move(m), db::consistency_level::ANY).handle_exception([] (std::exception_ptr eptr) { diff --git a/tests/sstable_datafile_test.cc b/tests/sstable_datafile_test.cc index 020263f3ee..f79cd8adb2 100644 --- a/tests/sstable_datafile_test.cc +++ b/tests/sstable_datafile_test.cc @@ -862,7 +862,7 @@ SEASTAR_TEST_CASE(datafile_generation_12) { auto mt = make_lw_shared(s); auto key = partition_key::from_exploded(*s, {to_bytes("key1")}); - auto cp = exploded_clustering_prefix({to_bytes("c1") }); + auto cp = clustering_key_prefix::from_exploded(*s, {to_bytes("c1")}); mutation m(key, s); @@ -899,7 +899,7 @@ static future<> sstable_compression_test(compressor c, unsigned generation) { auto mtp = make_lw_shared(s); auto key = partition_key::from_exploded(*s, {to_bytes("key1")}); - auto cp = exploded_clustering_prefix({to_bytes("c1") }); + auto cp = clustering_key_prefix::from_exploded(*s, {to_bytes("c1")}); mutation m(key, s); @@ -1392,7 +1392,7 @@ SEASTAR_TEST_CASE(datafile_generation_37) { auto key = partition_key::from_exploded(*s, {to_bytes("key1")}); mutation m(key, s); - auto c_key = exploded_clustering_prefix({to_bytes("cl1") }); + auto c_key = clustering_key_prefix::from_exploded(*s, {to_bytes("c1")}); const column_definition& cl2 = *s->get_column_definition("cl2"); m.set_clustered_cell(c_key, cl2, make_atomic_cell(bytes_type->decompose(data_value(to_bytes("cl2"))))); @@ -1407,8 +1407,7 @@ SEASTAR_TEST_CASE(datafile_generation_37) { }).then([sstp, s] (auto mutation) { auto& mp = mutation->partition(); - auto exploded = exploded_clustering_prefix({"cl1"}); - auto clustering = clustering_key::from_clustering_prefix(*s, exploded); + auto clustering = clustering_key_prefix::from_exploded(*s, {to_bytes("cl1")}); auto row = mp.clustered_row(*s, clustering); match_live_cell(row.cells(), *s, "cl2", data_value(to_bytes("cl2"))); @@ -1429,8 +1428,7 @@ SEASTAR_TEST_CASE(datafile_generation_38) { auto key = partition_key::from_exploded(*s, {to_bytes("key1")}); mutation m(key, s); - auto exploded = exploded_clustering_prefix({"cl1", "cl2"}); - auto c_key = clustering_key::from_clustering_prefix(*s, exploded); + auto c_key = clustering_key_prefix::from_exploded(*s, {to_bytes("cl1"), to_bytes("cl2")}); const column_definition& cl3 = *s->get_column_definition("cl3"); m.set_clustered_cell(c_key, cl3, make_atomic_cell(bytes_type->decompose(data_value(to_bytes("cl3"))))); @@ -1444,8 +1442,7 @@ SEASTAR_TEST_CASE(datafile_generation_38) { return mutation_from_streamed_mutation(std::move(sm)); }).then([sstp, s] (auto mutation) { auto& mp = mutation->partition(); - auto exploded = exploded_clustering_prefix({"cl1", "cl2"}); - auto clustering = clustering_key::from_clustering_prefix(*s, exploded); + auto clustering = clustering_key_prefix::from_exploded(*s, {to_bytes("cl1"), to_bytes("cl2")}); auto row = mp.clustered_row(*s, clustering); match_live_cell(row.cells(), *s, "cl3", data_value(to_bytes("cl3"))); @@ -3249,7 +3246,7 @@ SEASTAR_TEST_CASE(sstable_tombstone_metadata_check) { .build(); auto tmp = make_lw_shared(); auto key = partition_key::from_exploded(*s, {to_bytes("key1")}); - auto c_key = exploded_clustering_prefix({to_bytes("c1") }); + auto c_key = clustering_key_prefix::from_exploded(*s, {to_bytes("c1")}); const column_definition& r1_col = *s->get_column_definition("r1"); {