From 10213c42114367c2d1da58eec0772bf5b1fe20c7 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Tue, 31 May 2016 20:53:37 +0300 Subject: [PATCH 1/8] cql3: extract raw modification_statement into raw sub-namespace --- cql3/Cql.g | 4 +- cql3/statements/batch_statement.hh | 5 +- cql3/statements/delete_statement.cc | 2 +- cql3/statements/delete_statement.hh | 5 +- cql3/statements/modification_statement.cc | 19 +++- cql3/statements/modification_statement.hh | 25 +---- cql3/statements/raw/modification_statement.hh | 97 +++++++++++++++++++ cql3/statements/update_statement.cc | 4 +- cql3/statements/update_statement.hh | 9 +- 9 files changed, 131 insertions(+), 39 deletions(-) create mode 100644 cql3/statements/raw/modification_statement.hh diff --git a/cql3/Cql.g b/cql3/Cql.g index 1099e3592b..f6edd23507 100644 --- a/cql3/Cql.g +++ b/cql3/Cql.g @@ -570,7 +570,7 @@ batchStatement returns [shared_ptr ex @init { using btype = cql3::statements::batch_statement::type; btype type = btype::LOGGED; - std::vector> statements; + std::vector> statements; auto attrs = make_shared(); } : K_BEGIN @@ -583,7 +583,7 @@ batchStatement returns [shared_ptr ex } ; -batchStatementObjective returns [shared_ptr statement] +batchStatementObjective returns [shared_ptr statement] : i=insertStatement { $statement = i; } | u=updateStatement { $statement = u; } | d=deleteStatement { $statement = d; } diff --git a/cql3/statements/batch_statement.hh b/cql3/statements/batch_statement.hh index d18049eec2..728e967890 100644 --- a/cql3/statements/batch_statement.hh +++ b/cql3/statements/batch_statement.hh @@ -39,6 +39,7 @@ #include "cql3/cql_statement.hh" #include "modification_statement.hh" +#include "raw/modification_statement.hh" #include "service/storage_proxy.hh" #include "transport/messages/result_message.hh" #include "timestamp.hh" @@ -321,12 +322,12 @@ public: class parsed : public raw::cf_statement { type _type; shared_ptr _attrs; - std::vector> _parsed_statements; + std::vector> _parsed_statements; public: parsed( type type_, shared_ptr attrs, - std::vector> parsed_statements) + std::vector> parsed_statements) : cf_statement(nullptr) , _type(type_) , _attrs(std::move(attrs)) diff --git a/cql3/statements/delete_statement.cc b/cql3/statements/delete_statement.cc index e5847ec764..8e48b34ca9 100644 --- a/cql3/statements/delete_statement.cc +++ b/cql3/statements/delete_statement.cc @@ -110,7 +110,7 @@ delete_statement::parsed::parsed(::shared_ptr name, std::vector<::shared_ptr> where_clause, conditions_vector conditions, bool if_exists) - : modification_statement::parsed(std::move(name), std::move(attrs), std::move(conditions), false, if_exists) + : raw::modification_statement(std::move(name), std::move(attrs), std::move(conditions), false, if_exists) , _deletions(std::move(deletions)) , _where_clause(std::move(where_clause)) { } diff --git a/cql3/statements/delete_statement.hh b/cql3/statements/delete_statement.hh index aeeddaae04..9aa425e79e 100644 --- a/cql3/statements/delete_statement.hh +++ b/cql3/statements/delete_statement.hh @@ -42,6 +42,7 @@ #pragma once #include "cql3/statements/modification_statement.hh" +#include "cql3/statements/raw/modification_statement.hh" #include "cql3/attributes.hh" #include "cql3/operation.hh" #include "database_fwd.hh" @@ -80,7 +81,7 @@ public: } #endif - class parsed : public modification_statement::parsed { + class parsed : public raw::modification_statement { private: std::vector<::shared_ptr> _deletions; std::vector<::shared_ptr> _where_clause; @@ -92,7 +93,7 @@ public: conditions_vector conditions, bool if_exists); protected: - virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, + virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, ::shared_ptr bound_names, std::unique_ptr attrs); }; }; diff --git a/cql3/statements/modification_statement.cc b/cql3/statements/modification_statement.cc index fb098bfb54..c99edfd178 100644 --- a/cql3/statements/modification_statement.cc +++ b/cql3/statements/modification_statement.cc @@ -40,6 +40,7 @@ */ #include "cql3/statements/modification_statement.hh" +#include "cql3/statements/raw/modification_statement.hh" #include "cql3/statements/prepared_statement.hh" #include "cql3/restrictions/single_column_restriction.hh" #include "cql3/single_column_relation.hh" @@ -561,21 +562,23 @@ modification_statement::process_where_clause(database& db, std::vector -modification_statement::parsed::prepare(database& db) { +modification_statement::modification_statement::prepare(database& db) { auto bound_names = get_bound_variables(); auto statement = prepare(db, bound_names); return ::make_shared(std::move(statement), *bound_names); } -::shared_ptr -modification_statement::parsed::prepare(database& db, ::shared_ptr bound_names) { +::shared_ptr +modification_statement::prepare(database& db, ::shared_ptr bound_names) { schema_ptr schema = validation::validate_column_family(db, keyspace(), column_family()); auto prepared_attributes = _attrs->prepare(db, keyspace(), column_family()); prepared_attributes->collect_marker_specification(bound_names); - ::shared_ptr stmt = prepare_internal(db, schema, bound_names, std::move(prepared_attributes)); + ::shared_ptr stmt = prepare_internal(db, schema, bound_names, std::move(prepared_attributes)); if (_if_not_exists || _if_exists || !_conditions.empty()) { if (stmt->is_counter()) { @@ -617,6 +620,8 @@ modification_statement::parsed::prepare(database& db, ::shared_ptr&, const service::client_state& state) { if (has_conditions() && attrs->is_timestamp_set()) { @@ -689,7 +694,9 @@ void modification_statement::validate_where_clause_for_conditions() { // no-op by default } -modification_statement::parsed::parsed(::shared_ptr name, ::shared_ptr attrs, conditions_vector conditions, bool if_not_exists, bool if_exists) +namespace raw { + +modification_statement::modification_statement(::shared_ptr name, ::shared_ptr attrs, conditions_vector conditions, bool if_not_exists, bool if_exists) : cf_statement{std::move(name)} , _attrs{std::move(attrs)} , _conditions{std::move(conditions)} @@ -700,3 +707,5 @@ modification_statement::parsed::parsed(::shared_ptr name, ::shared_ptr< } } + +} diff --git a/cql3/statements/modification_statement.hh b/cql3/statements/modification_statement.hh index 99ce9ceeaa..790d06e1ec 100644 --- a/cql3/statements/modification_statement.hh +++ b/cql3/statements/modification_statement.hh @@ -66,6 +66,9 @@ namespace cql3 { namespace statements { + +namespace raw { class modification_statement; } + /* * Abstract parent class of individual modifications, i.e. INSERT, UPDATE and DELETE. */ @@ -345,27 +348,7 @@ protected: * @throws InvalidRequestException */ virtual void validate_where_clause_for_conditions(); - -public: - class parsed : public raw::cf_statement { - public: - using conditions_vector = std::vector, ::shared_ptr>>; - protected: - const ::shared_ptr _attrs; - const std::vector, ::shared_ptr>> _conditions; - private: - const bool _if_not_exists; - const bool _if_exists; - protected: - parsed(::shared_ptr name, ::shared_ptr attrs, conditions_vector conditions, bool if_not_exists, bool if_exists); - - public: - virtual ::shared_ptr prepare(database& db) override; - ::shared_ptr prepare(database& db, ::shared_ptr bound_names);; - protected: - virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, - ::shared_ptr bound_names, std::unique_ptr attrs) = 0; - }; + friend class raw::modification_statement; }; std::ostream& operator<<(std::ostream& out, modification_statement::statement_type t); diff --git a/cql3/statements/raw/modification_statement.hh b/cql3/statements/raw/modification_statement.hh new file mode 100644 index 0000000000..d8ea5aa3aa --- /dev/null +++ b/cql3/statements/raw/modification_statement.hh @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (C) 2015 ScyllaDB + * + * Modified by ScyllaDB + */ + +/* + * This file is part of Scylla. + * + * Scylla is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Scylla is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Scylla. If not, see . + */ + +#pragma once + +#include "cql3/restrictions/restriction.hh" +#include "cql3/statements/raw/cf_statement.hh" +#include "cql3/column_identifier.hh" +#include "cql3/update_parameters.hh" +#include "cql3/column_condition.hh" +#include "cql3/cql_statement.hh" +#include "cql3/attributes.hh" +#include "cql3/operation.hh" +#include "cql3/relation.hh" + +#include "db/consistency_level.hh" + +#include "core/shared_ptr.hh" +#include "core/future-util.hh" + +#include "unimplemented.hh" +#include "validation.hh" +#include "service/storage_proxy.hh" + +#include + +namespace cql3 { + +namespace statements { + +class modification_statement; + +namespace raw { + +class modification_statement : public cf_statement { +public: + using conditions_vector = std::vector, ::shared_ptr>>; +protected: + const ::shared_ptr _attrs; + const std::vector, ::shared_ptr>> _conditions; +private: + const bool _if_not_exists; + const bool _if_exists; +protected: + modification_statement(::shared_ptr name, ::shared_ptr attrs, conditions_vector conditions, bool if_not_exists, bool if_exists); + +public: + virtual ::shared_ptr prepare(database& db) override; + ::shared_ptr prepare(database& db, ::shared_ptr bound_names);; +protected: + virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, + ::shared_ptr bound_names, std::unique_ptr attrs) = 0; +}; + +} + +} + +} diff --git a/cql3/statements/update_statement.cc b/cql3/statements/update_statement.cc index e310ba5af6..812d8279de 100644 --- a/cql3/statements/update_statement.cc +++ b/cql3/statements/update_statement.cc @@ -113,7 +113,7 @@ update_statement::parsed_insert::parsed_insert(::shared_ptr name, std::vector<::shared_ptr> column_names, std::vector<::shared_ptr> column_values, bool if_not_exists) - : modification_statement::parsed{std::move(name), std::move(attrs), conditions_vector{}, if_not_exists, false} + : raw::modification_statement{std::move(name), std::move(attrs), conditions_vector{}, if_not_exists, false} , _column_names{std::move(column_names)} , _column_values{std::move(column_values)} { } @@ -169,7 +169,7 @@ update_statement::parsed_update::parsed_update(::shared_ptr name, std::vector, ::shared_ptr>> updates, std::vector where_clause, conditions_vector conditions) - : modification_statement::parsed(std::move(name), std::move(attrs), std::move(conditions), false, false) + : modification_statement(std::move(name), std::move(attrs), std::move(conditions), false, false) , _updates(std::move(updates)) , _where_clause(std::move(where_clause)) { } diff --git a/cql3/statements/update_statement.hh b/cql3/statements/update_statement.hh index 28b9229652..441c9e436d 100644 --- a/cql3/statements/update_statement.hh +++ b/cql3/statements/update_statement.hh @@ -42,6 +42,7 @@ #pragma once #include "cql3/statements/modification_statement.hh" +#include "cql3/statements/raw/modification_statement.hh" #include "cql3/column_identifier.hh" #include "cql3/term.hh" @@ -70,7 +71,7 @@ private: virtual void add_update_for_key(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override; public: - class parsed_insert : public modification_statement::parsed { + class parsed_insert : public raw::modification_statement { private: const std::vector<::shared_ptr> _column_names; const std::vector<::shared_ptr> _column_values; @@ -89,12 +90,12 @@ public: std::vector<::shared_ptr> column_values, bool if_not_exists); - virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, + virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, ::shared_ptr bound_names, std::unique_ptr attrs) override; }; - class parsed_update : public modification_statement::parsed { + class parsed_update : public raw::modification_statement { private: // Provided for an UPDATE std::vector, ::shared_ptr>> _updates; @@ -115,7 +116,7 @@ public: std::vector where_clause, conditions_vector conditions); protected: - virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, + virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, ::shared_ptr bound_names, std::unique_ptr attrs); }; }; From e596799962c09c8417f22de12bb35adbc2a4ad35 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Tue, 31 May 2016 20:53:37 +0300 Subject: [PATCH 2/8] cql3: extract raw update_statement into raw sub-namespace update_statment also has an insert_statement counterpart, convert it too. --- cql3/Cql.g | 11 +-- cql3/statements/raw/insert_statement.hh | 88 ++++++++++++++++++++++++ cql3/statements/raw/update_statement.hh | 91 +++++++++++++++++++++++++ cql3/statements/update_statement.cc | 26 ++++--- cql3/statements/update_statement.hh | 49 ------------- 5 files changed, 202 insertions(+), 63 deletions(-) create mode 100644 cql3/statements/raw/insert_statement.hh create mode 100644 cql3/statements/raw/update_statement.hh diff --git a/cql3/Cql.g b/cql3/Cql.g index f6edd23507..f040281a90 100644 --- a/cql3/Cql.g +++ b/cql3/Cql.g @@ -46,7 +46,8 @@ options { #include "cql3/statements/property_definitions.hh" #include "cql3/statements/drop_table_statement.hh" #include "cql3/statements/truncate_statement.hh" -#include "cql3/statements/update_statement.hh" +#include "cql3/statements/raw/update_statement.hh" +#include "cql3/statements/raw/insert_statement.hh" #include "cql3/statements/delete_statement.hh" #include "cql3/statements/index_prop_defs.hh" #include "cql3/statements/use_statement.hh" @@ -439,7 +440,7 @@ orderByClause[raw::select_statement::parameters::orderings_type& orderings] * USING TIMESTAMP ; * */ -insertStatement returns [::shared_ptr expr] +insertStatement returns [::shared_ptr expr] @init { auto attrs = ::make_shared(); std::vector<::shared_ptr> column_names; @@ -454,7 +455,7 @@ insertStatement returns [::shared_ptr expr] ( K_IF K_NOT K_EXISTS { if_not_exists = true; } )? ( usingClause[attrs] )? { - $expr = ::make_shared(std::move(cf), + $expr = ::make_shared(std::move(cf), std::move(attrs), std::move(column_names), std::move(values), @@ -477,7 +478,7 @@ usingClauseObjective[::shared_ptr attrs] * SET name1 = value1, name2 = value2 * WHERE key = value; */ -updateStatement returns [::shared_ptr expr] +updateStatement returns [::shared_ptr expr] @init { auto attrs = ::make_shared(); std::vector, ::shared_ptr>> operations; @@ -488,7 +489,7 @@ updateStatement returns [::shared_ptr expr] K_WHERE wclause=whereClause ( K_IF conditions=updateConditions )? { - return ::make_shared(std::move(cf), + return ::make_shared(std::move(cf), std::move(attrs), std::move(operations), std::move(wclause), diff --git a/cql3/statements/raw/insert_statement.hh b/cql3/statements/raw/insert_statement.hh new file mode 100644 index 0000000000..5c88cd9ea0 --- /dev/null +++ b/cql3/statements/raw/insert_statement.hh @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (C) 2015 ScyllaDB + * + * Modified by ScyllaDB + */ + +/* + * This file is part of Scylla. + * + * Scylla is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Scylla is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Scylla. If not, see . + */ + +#pragma once + +#include "cql3/statements/modification_statement.hh" +#include "cql3/statements/raw/modification_statement.hh" +#include "cql3/column_identifier.hh" +#include "cql3/term.hh" + +#include "database_fwd.hh" + +#include +#include "unimplemented.hh" + +namespace cql3 { + +namespace statements { + +namespace raw { + +class insert_statement : public raw::modification_statement { +private: + const std::vector<::shared_ptr> _column_names; + const std::vector<::shared_ptr> _column_values; +public: + /** + * A parsed INSERT statement. + * + * @param name column family being operated on + * @param columnNames list of column names + * @param columnValues list of column values (corresponds to names) + * @param attrs additional attributes for statement (CL, timestamp, timeToLive) + */ + insert_statement(::shared_ptr name, + ::shared_ptr attrs, + std::vector<::shared_ptr> column_names, + std::vector<::shared_ptr> column_values, + bool if_not_exists); + + virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, + ::shared_ptr bound_names, std::unique_ptr attrs) override; + +}; + +} + +} + +} diff --git a/cql3/statements/raw/update_statement.hh b/cql3/statements/raw/update_statement.hh new file mode 100644 index 0000000000..ef763a0c4e --- /dev/null +++ b/cql3/statements/raw/update_statement.hh @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (C) 2015 ScyllaDB + * + * Modified by ScyllaDB + */ + +/* + * This file is part of Scylla. + * + * Scylla is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Scylla is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Scylla. If not, see . + */ + +#pragma once + +#include "cql3/statements/modification_statement.hh" +#include "cql3/statements/raw/modification_statement.hh" +#include "cql3/column_identifier.hh" +#include "cql3/term.hh" + +#include "database_fwd.hh" + +#include +#include "unimplemented.hh" + +namespace cql3 { + +namespace statements { + +class update_statement; + +namespace raw { + +class update_statement : public raw::modification_statement { +private: + // Provided for an UPDATE + std::vector, ::shared_ptr>> _updates; + std::vector _where_clause; +public: + /** + * Creates a new UpdateStatement from a column family name, columns map, consistency + * level, and key term. + * + * @param name column family being operated on + * @param attrs additional attributes for statement (timestamp, timeToLive) + * @param updates a map of column operations to perform + * @param whereClause the where clause + */ + update_statement(::shared_ptr name, + ::shared_ptr attrs, + std::vector, ::shared_ptr>> updates, + std::vector where_clause, + conditions_vector conditions); +protected: + virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, + ::shared_ptr bound_names, std::unique_ptr attrs); +}; + +} + +} + +} diff --git a/cql3/statements/update_statement.cc b/cql3/statements/update_statement.cc index 812d8279de..223baa75b4 100644 --- a/cql3/statements/update_statement.cc +++ b/cql3/statements/update_statement.cc @@ -40,6 +40,8 @@ */ #include "update_statement.hh" +#include "raw/update_statement.hh" +#include "raw/insert_statement.hh" #include "unimplemented.hh" #include "cql3/operation_impl.hh" @@ -108,7 +110,9 @@ void update_statement::add_update_for_key(mutation& m, const exploded_clustering #endif } -update_statement::parsed_insert::parsed_insert(::shared_ptr name, +namespace raw { + +insert_statement::insert_statement( ::shared_ptr name, ::shared_ptr attrs, std::vector<::shared_ptr> column_names, std::vector<::shared_ptr> column_values, @@ -118,11 +122,12 @@ update_statement::parsed_insert::parsed_insert(::shared_ptr name, , _column_values{std::move(column_values)} { } -::shared_ptr -update_statement::parsed_insert::prepare_internal(database& db, schema_ptr schema, +::shared_ptr +insert_statement::prepare_internal(database& db, schema_ptr schema, ::shared_ptr bound_names, std::unique_ptr attrs) { - auto stmt = ::make_shared(statement_type::INSERT, bound_names->size(), schema, std::move(attrs)); + using statement_type = cql3::statements::modification_statement::statement_type; + auto stmt = ::make_shared(statement_type::INSERT, bound_names->size(), schema, std::move(attrs)); // Created from an INSERT if (stmt->is_counter()) { @@ -164,21 +169,22 @@ update_statement::parsed_insert::prepare_internal(database& db, schema_ptr schem return stmt; } -update_statement::parsed_update::parsed_update(::shared_ptr name, +update_statement::update_statement( ::shared_ptr name, ::shared_ptr attrs, std::vector, ::shared_ptr>> updates, std::vector where_clause, conditions_vector conditions) - : modification_statement(std::move(name), std::move(attrs), std::move(conditions), false, false) + : raw::modification_statement(std::move(name), std::move(attrs), std::move(conditions), false, false) , _updates(std::move(updates)) , _where_clause(std::move(where_clause)) { } -::shared_ptr -update_statement::parsed_update::prepare_internal(database& db, schema_ptr schema, +::shared_ptr +update_statement::prepare_internal(database& db, schema_ptr schema, ::shared_ptr bound_names, std::unique_ptr attrs) { - auto stmt = ::make_shared(statement_type::UPDATE, bound_names->size(), schema, std::move(attrs)); + using statement_type = cql3::statements::modification_statement::statement_type; + auto stmt = ::make_shared(statement_type::UPDATE, bound_names->size(), schema, std::move(attrs)); for (auto&& entry : _updates) { auto id = entry.first->prepare_column_identifier(schema); @@ -203,3 +209,5 @@ update_statement::parsed_update::prepare_internal(database& db, schema_ptr schem } } + +} diff --git a/cql3/statements/update_statement.hh b/cql3/statements/update_statement.hh index 441c9e436d..cf604f7f7c 100644 --- a/cql3/statements/update_statement.hh +++ b/cql3/statements/update_statement.hh @@ -70,55 +70,6 @@ private: virtual bool require_full_clustering_key() const override; virtual void add_update_for_key(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) override; -public: - class parsed_insert : public raw::modification_statement { - private: - const std::vector<::shared_ptr> _column_names; - const std::vector<::shared_ptr> _column_values; - public: - /** - * A parsed INSERT statement. - * - * @param name column family being operated on - * @param columnNames list of column names - * @param columnValues list of column values (corresponds to names) - * @param attrs additional attributes for statement (CL, timestamp, timeToLive) - */ - parsed_insert(::shared_ptr name, - ::shared_ptr attrs, - std::vector<::shared_ptr> column_names, - std::vector<::shared_ptr> column_values, - bool if_not_exists); - - virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, - ::shared_ptr bound_names, std::unique_ptr attrs) override; - - }; - - class parsed_update : public raw::modification_statement { - private: - // Provided for an UPDATE - std::vector, ::shared_ptr>> _updates; - std::vector _where_clause; - public: - /** - * Creates a new UpdateStatement from a column family name, columns map, consistency - * level, and key term. - * - * @param name column family being operated on - * @param attrs additional attributes for statement (timestamp, timeToLive) - * @param updates a map of column operations to perform - * @param whereClause the where clause - */ - parsed_update(::shared_ptr name, - ::shared_ptr attrs, - std::vector, ::shared_ptr>> updates, - std::vector where_clause, - conditions_vector conditions); - protected: - virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, - ::shared_ptr bound_names, std::unique_ptr attrs); - }; }; } From 1d144699f6149a394db17644fb10625a5baf658d Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Tue, 31 May 2016 20:53:37 +0300 Subject: [PATCH 3/8] cql3: extract raw delete_statement into raw sub-namespace --- cql3/Cql.g | 6 +- cql3/statements/delete_statement.cc | 15 +++-- cql3/statements/delete_statement.hh | 16 ------ cql3/statements/raw/delete_statement.hh | 76 +++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 24 deletions(-) create mode 100644 cql3/statements/raw/delete_statement.hh diff --git a/cql3/Cql.g b/cql3/Cql.g index f040281a90..4acb3d2465 100644 --- a/cql3/Cql.g +++ b/cql3/Cql.g @@ -48,7 +48,7 @@ options { #include "cql3/statements/truncate_statement.hh" #include "cql3/statements/raw/update_statement.hh" #include "cql3/statements/raw/insert_statement.hh" -#include "cql3/statements/delete_statement.hh" +#include "cql3/statements/raw/delete_statement.hh" #include "cql3/statements/index_prop_defs.hh" #include "cql3/statements/use_statement.hh" #include "cql3/statements/batch_statement.hh" @@ -508,7 +508,7 @@ updateConditions returns [conditions_type conditions] * WHERE KEY = keyname [IF (EXISTS | name = value, ...)]; */ -deleteStatement returns [::shared_ptr expr] +deleteStatement returns [::shared_ptr expr] @init { auto attrs = ::make_shared(); std::vector<::shared_ptr> column_deletions; @@ -520,7 +520,7 @@ deleteStatement returns [::shared_ptr expr] K_WHERE wclause=whereClause ( K_IF ( K_EXISTS { if_exists = true; } | conditions=updateConditions ))? { - return ::make_shared(cf, + return ::make_shared(cf, std::move(attrs), std::move(column_deletions), std::move(wclause), diff --git a/cql3/statements/delete_statement.cc b/cql3/statements/delete_statement.cc index 8e48b34ca9..1293cb44a7 100644 --- a/cql3/statements/delete_statement.cc +++ b/cql3/statements/delete_statement.cc @@ -40,6 +40,7 @@ */ #include "delete_statement.hh" +#include "raw/delete_statement.hh" namespace cql3 { @@ -76,11 +77,13 @@ void delete_statement::add_update_for_key(mutation& m, const exploded_clustering } } -::shared_ptr -delete_statement::parsed::prepare_internal(database& db, schema_ptr schema, ::shared_ptr bound_names, - std::unique_ptr attrs) { +namespace raw { - auto stmt = ::make_shared(statement_type::DELETE, bound_names->size(), schema, std::move(attrs)); +::shared_ptr +delete_statement::prepare_internal(database& db, schema_ptr schema, ::shared_ptr bound_names, + std::unique_ptr attrs) { + using statement_type = cql3::statements::modification_statement::statement_type; + auto stmt = ::make_shared(statement_type::DELETE, bound_names->size(), schema, std::move(attrs)); for (auto&& deletion : _deletions) { auto&& id = deletion->affected_column()->prepare_column_identifier(schema); @@ -104,7 +107,7 @@ delete_statement::parsed::prepare_internal(database& db, schema_ptr schema, ::sh return stmt; } -delete_statement::parsed::parsed(::shared_ptr name, +delete_statement::delete_statement(::shared_ptr name, ::shared_ptr attrs, std::vector<::shared_ptr> deletions, std::vector<::shared_ptr> where_clause, @@ -118,3 +121,5 @@ delete_statement::parsed::parsed(::shared_ptr name, } } + +} diff --git a/cql3/statements/delete_statement.hh b/cql3/statements/delete_statement.hh index 9aa425e79e..7e32899277 100644 --- a/cql3/statements/delete_statement.hh +++ b/cql3/statements/delete_statement.hh @@ -80,22 +80,6 @@ public: } #endif - - class parsed : public raw::modification_statement { - private: - std::vector<::shared_ptr> _deletions; - std::vector<::shared_ptr> _where_clause; - public: - parsed(::shared_ptr name, - ::shared_ptr attrs, - std::vector<::shared_ptr> deletions, - std::vector<::shared_ptr> where_clause, - conditions_vector conditions, - bool if_exists); - protected: - virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, - ::shared_ptr bound_names, std::unique_ptr attrs); - }; }; } diff --git a/cql3/statements/raw/delete_statement.hh b/cql3/statements/raw/delete_statement.hh new file mode 100644 index 0000000000..731b4b7d1d --- /dev/null +++ b/cql3/statements/raw/delete_statement.hh @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (C) 2015 ScyllaDB + * + * Modified by ScyllaDB + */ + +/* + * This file is part of Scylla. + * + * Scylla is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Scylla is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Scylla. If not, see . + */ + +#pragma once + +#include "cql3/statements/modification_statement.hh" +#include "cql3/statements/raw/modification_statement.hh" +#include "cql3/attributes.hh" +#include "cql3/operation.hh" +#include "database_fwd.hh" + +namespace cql3 { + +namespace statements { + +namespace raw { + +class delete_statement : public modification_statement { +private: + std::vector<::shared_ptr> _deletions; + std::vector<::shared_ptr> _where_clause; +public: + delete_statement(::shared_ptr name, + ::shared_ptr attrs, + std::vector<::shared_ptr> deletions, + std::vector<::shared_ptr> where_clause, + conditions_vector conditions, + bool if_exists); +protected: + virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, + ::shared_ptr bound_names, std::unique_ptr attrs); +}; + +} + +} + +} From c8b5104aa5e8dd59d3e43b3bd725c7c132b22e99 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Tue, 31 May 2016 20:53:37 +0300 Subject: [PATCH 4/8] cql3: extract raw batch_statement into raw sub-namespace prepare() was moved to .cc to avoid circular dependencies. --- cql3/Cql.g | 8 +-- cql3/statements/batch_statement.cc | 25 +++++++ cql3/statements/batch_statement.hh | 45 +------------ cql3/statements/raw/batch_statement.hh | 93 ++++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 47 deletions(-) create mode 100644 cql3/statements/raw/batch_statement.hh diff --git a/cql3/Cql.g b/cql3/Cql.g index 4acb3d2465..9e93b85812 100644 --- a/cql3/Cql.g +++ b/cql3/Cql.g @@ -51,7 +51,7 @@ options { #include "cql3/statements/raw/delete_statement.hh" #include "cql3/statements/index_prop_defs.hh" #include "cql3/statements/use_statement.hh" -#include "cql3/statements/batch_statement.hh" +#include "cql3/statements/raw/batch_statement.hh" #include "cql3/statements/create_user_statement.hh" #include "cql3/statements/alter_user_statement.hh" #include "cql3/statements/drop_user_statement.hh" @@ -567,9 +567,9 @@ usingClauseDelete[::shared_ptr attrs] * ... * APPLY BATCH */ -batchStatement returns [shared_ptr expr] +batchStatement returns [shared_ptr expr] @init { - using btype = cql3::statements::batch_statement::type; + using btype = cql3::statements::raw::batch_statement::type; btype type = btype::LOGGED; std::vector> statements; auto attrs = make_shared(); @@ -580,7 +580,7 @@ batchStatement returns [shared_ptr ex ( s=batchStatementObjective ';'? { statements.push_back(std::move(s)); } )* K_APPLY K_BATCH { - $expr = ::make_shared(type, std::move(attrs), std::move(statements)); + $expr = ::make_shared(type, std::move(attrs), std::move(statements)); } ; diff --git a/cql3/statements/batch_statement.cc b/cql3/statements/batch_statement.cc index f179ed5dee..d465114443 100644 --- a/cql3/statements/batch_statement.cc +++ b/cql3/statements/batch_statement.cc @@ -38,6 +38,7 @@ */ #include "batch_statement.hh" +#include "raw/batch_statement.hh" #include "db/config.hh" namespace cql3 { @@ -100,6 +101,30 @@ void batch_statement::verify_batch_size(const std::vector& mutations) } } +namespace raw { + +shared_ptr +batch_statement::prepare(database& db) { + auto&& bound_names = get_bound_variables(); + + std::vector> statements; + for (auto&& parsed : _parsed_statements) { + statements.push_back(parsed->prepare(db, bound_names)); + } + + auto&& prep_attrs = _attrs->prepare(db, "[batch]", "[batch]"); + prep_attrs->collect_marker_specification(bound_names); + + cql3::statements::batch_statement batch_statement_(bound_names->size(), _type, std::move(statements), std::move(prep_attrs)); + batch_statement_.validate(); + + return ::make_shared(make_shared(std::move(batch_statement_)), + bound_names->get_specifications()); +} + +} + + } } diff --git a/cql3/statements/batch_statement.hh b/cql3/statements/batch_statement.hh index 728e967890..9c05881346 100644 --- a/cql3/statements/batch_statement.hh +++ b/cql3/statements/batch_statement.hh @@ -40,6 +40,7 @@ #include "cql3/cql_statement.hh" #include "modification_statement.hh" #include "raw/modification_statement.hh" +#include "raw/batch_statement.hh" #include "service/storage_proxy.hh" #include "transport/messages/result_message.hh" #include "timestamp.hh" @@ -64,9 +65,7 @@ namespace statements { class batch_statement : public cql_statement_no_metadata { static logging::logger _logger; public: - enum class type { - LOGGED, UNLOGGED, COUNTER - }; + using type = raw::batch_statement::type; private: int _bound_terms; public: @@ -318,46 +317,6 @@ public: return sprint("BatchStatement(type=%s, statements=%s)", _type, join(", ", _statements)); } #endif - - class parsed : public raw::cf_statement { - type _type; - shared_ptr _attrs; - std::vector> _parsed_statements; - public: - parsed( - type type_, - shared_ptr attrs, - std::vector> parsed_statements) - : cf_statement(nullptr) - , _type(type_) - , _attrs(std::move(attrs)) - , _parsed_statements(std::move(parsed_statements)) { - } - - virtual void prepare_keyspace(const service::client_state& state) override { - for (auto&& s : _parsed_statements) { - s->prepare_keyspace(state); - } - } - - virtual shared_ptr prepare(database& db) override { - auto&& bound_names = get_bound_variables(); - - std::vector> statements; - for (auto&& parsed : _parsed_statements) { - statements.push_back(parsed->prepare(db, bound_names)); - } - - auto&& prep_attrs = _attrs->prepare(db, "[batch]", "[batch]"); - prep_attrs->collect_marker_specification(bound_names); - - batch_statement batch_statement_(bound_names->size(), _type, std::move(statements), std::move(prep_attrs)); - batch_statement_.validate(); - - return ::make_shared(make_shared(std::move(batch_statement_)), - bound_names->get_specifications()); - } - }; }; } diff --git a/cql3/statements/raw/batch_statement.hh b/cql3/statements/raw/batch_statement.hh new file mode 100644 index 0000000000..de83c53233 --- /dev/null +++ b/cql3/statements/raw/batch_statement.hh @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * Modified by ScyllaDB + * Copyright (C) 2015 ScyllaDB + */ + +/* + * This file is part of Scylla. + * + * Scylla is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Scylla is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Scylla. If not, see . + */ + +#include "cql3/cql_statement.hh" +#include "modification_statement.hh" +#include "service/storage_proxy.hh" +#include "transport/messages/result_message.hh" +#include "timestamp.hh" +#include "log.hh" +#include "to_string.hh" +#include +#include +#include +#include +#include + +#pragma once + +namespace cql3 { + +namespace statements { + +namespace raw { + +class batch_statement : public raw::cf_statement { +public: + enum class type { + LOGGED, UNLOGGED, COUNTER + }; +private: + type _type; + shared_ptr _attrs; + std::vector> _parsed_statements; +public: + batch_statement( + type type_, + shared_ptr attrs, + std::vector> parsed_statements) + : cf_statement(nullptr) + , _type(type_) + , _attrs(std::move(attrs)) + , _parsed_statements(std::move(parsed_statements)) { + } + + virtual void prepare_keyspace(const service::client_state& state) override { + for (auto&& s : _parsed_statements) { + s->prepare_keyspace(state); + } + } + + virtual shared_ptr prepare(database& db) override; +}; + +} + +} +} From fa5354dda497766ccde5872ee807d84cc558ab35 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 1 Jun 2016 14:40:45 +0300 Subject: [PATCH 5/8] sstables: Add optional filename to malformed_sstable_exception Add a constructor to malformed_sstable_exception that accepts a error message and a sstable name. --- sstables/exceptions.hh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sstables/exceptions.hh b/sstables/exceptions.hh index 68d43f2f47..3da97d1ed7 100644 --- a/sstables/exceptions.hh +++ b/sstables/exceptions.hh @@ -25,6 +25,9 @@ namespace sstables { class malformed_sstable_exception : public std::exception { sstring _msg; public: + malformed_sstable_exception(sstring msg, sstring filename) + : malformed_sstable_exception{sprint("%s in sstable %s", msg, filename)} + {} malformed_sstable_exception(sstring s) : _msg(s) {} const char *what() const noexcept { return _msg.c_str(); From 3ca7fc2a8b1a8aa6abee14881306d5945a60d99b Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 1 Jun 2016 14:56:10 +0300 Subject: [PATCH 6/8] database: Add sstable filename to thrown malformed_sstable_exceptions --- database.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/database.cc b/database.cc index df5ecb8943..9fb9e0f2b4 100644 --- a/database.cc +++ b/database.cc @@ -1177,7 +1177,8 @@ future<> column_family::populate(sstring sstdir) { return do_with(std::vector>(), [this, sstdir, verifier, descriptor] (std::vector>& futures) { return lister::scan_dir(sstdir, { directory_entry_type::regular }, [this, sstdir, verifier, descriptor, &futures] (directory_entry de) { // FIXME: The secondary indexes are in this level, but with a directory type, (starting with ".") - auto f = probe_file(sstdir, de.name).then([verifier, descriptor, sstdir] (auto entry) { + auto f = probe_file(sstdir, de.name).then([verifier, descriptor, sstdir, de] (auto entry) { + auto filename = sstdir + "/" + de.name; if (entry.component == sstables::sstable::component_type::TemporaryStatistics) { return remove_file(sstables::sstable::filename(sstdir, entry.ks, entry.cf, entry.version, entry.generation, entry.format, sstables::sstable::component_type::TemporaryStatistics)); @@ -1186,9 +1187,9 @@ future<> column_family::populate(sstring sstdir) { if (verifier->count(entry.generation)) { if (verifier->at(entry.generation) == status::has_toc_file) { if (entry.component == sstables::sstable::component_type::TOC) { - throw sstables::malformed_sstable_exception("Invalid State encountered. TOC file already processed"); + throw sstables::malformed_sstable_exception("Invalid State encountered. TOC file already processed", filename); } else if (entry.component == sstables::sstable::component_type::TemporaryTOC) { - throw sstables::malformed_sstable_exception("Invalid State encountered. Temporary TOC file found after TOC file was processed"); + throw sstables::malformed_sstable_exception("Invalid State encountered. Temporary TOC file found after TOC file was processed", filename); } } else if (entry.component == sstables::sstable::component_type::TOC) { verifier->at(entry.generation) = status::has_toc_file; From 94c35cc135f2fb586712515b4e0efb3f263f26be Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 1 Jun 2016 15:00:53 +0300 Subject: [PATCH 7/8] sstables/sstables: Add sstable filename to thrown malformed_sstable_exceptions --- sstables/sstables.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sstables/sstables.cc b/sstables/sstables.cc index 0c7f989a37..f931a573f2 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -708,17 +708,17 @@ future<> sstable::read_toc() { sstlog.debug("Reading TOC file {} ", file_path); - return open_checked_file_dma(sstable_read_error, file_path, open_flags::ro).then([this] (file f) { + return open_checked_file_dma(sstable_read_error, file_path, open_flags::ro).then([this, file_path] (file f) { auto bufptr = allocate_aligned_buffer(4096, 4096); auto buf = bufptr.get(); auto fut = f.dma_read(0, buf, 4096); - return std::move(fut).then([this, f = std::move(f), bufptr = std::move(bufptr)] (size_t size) mutable { + return std::move(fut).then([this, f = std::move(f), bufptr = std::move(bufptr), file_path] (size_t size) mutable { // This file is supposed to be very small. Theoretically we should check its size, // but if we so much as read a whole page from it, there is definitely something fishy // going on - and this simplifies the code. if (size >= 4096) { - throw malformed_sstable_exception("SSTable too big: " + to_sstring(size) + " bytes."); + throw malformed_sstable_exception("SSTable too big: " + to_sstring(size) + " bytes", file_path); } std::experimental::string_view buf(bufptr.get(), size); @@ -735,11 +735,11 @@ future<> sstable::read_toc() { _components.insert(reverse_map(c, _component_map)); } catch (std::out_of_range& oor) { _components.clear(); // so subsequent read_toc will be forced to fail again - throw malformed_sstable_exception("Unrecognized TOC component: " + c); + throw malformed_sstable_exception("Unrecognized TOC component: " + c, file_path); } } if (!_components.size()) { - throw malformed_sstable_exception("Empty TOC"); + throw malformed_sstable_exception("Empty TOC", file_path); } return f.close().finally([f] {}); }); From 26b50eb8f4652a9de1ec5d4bbb19b2be1c09492d Mon Sep 17 00:00:00 2001 From: Gleb Natapov Date: Wed, 1 Jun 2016 16:26:41 +0300 Subject: [PATCH 8/8] storage_proxy: drop debug output Message-Id: <20160601132641.GK2381@scylladb.com> --- service/storage_proxy.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/service/storage_proxy.cc b/service/storage_proxy.cc index 4cbd66bb3f..26d3b699c2 100644 --- a/service/storage_proxy.cc +++ b/service/storage_proxy.cc @@ -2058,7 +2058,6 @@ public: auto write_timeout = exec->_proxy->_db.local().get_config().write_request_timeout_in_ms() * 1000; auto delta = __int128_t(digest_resolver->last_modified()) - __int128_t(exec->_cmd->read_timestamp); if (std::abs(delta) <= write_timeout) { - print("HERE %d\n", int64_t(delta)); exec->_proxy->_stats.global_read_repairs_canceled_due_to_concurrent_write++; // if CL is local and non matching data is modified less then write_timeout ms ago do only local repair auto i = boost::range::remove_if(exec->_targets, std::not1(std::cref(db::is_local)));