From ab6dbe654f32a153692e9d304d1cd179c761412f Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Fri, 28 Jul 2023 15:54:13 +0300 Subject: [PATCH] schema_tables: Extract query_processor from system_keyspace for querying The schema_tables() column-mapping code runs queries over system. table, but it needs LOCAL_ONE CL and cherry-pick on caching, so regular system_keyspace::execute_cql() won't work here. However, since schema_tables is somewhat part of system_keyspace, it's natural to let the former fetch private query_processor& from the latter Signed-off-by: Pavel Emelyanov --- db/schema_tables.cc | 6 +++--- db/system_keyspace.hh | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/db/schema_tables.cc b/db/schema_tables.cc index ddf5a071e4..382e638458 100644 --- a/db/schema_tables.cc +++ b/db/schema_tables.cc @@ -3705,7 +3705,7 @@ static auto GET_COLUMN_MAPPING_QUERY = format("SELECT column_name, clustering_or db::schema_tables::SCYLLA_TABLE_SCHEMA_HISTORY); future get_column_mapping(db::system_keyspace& sys_ks, ::table_id table_id, table_schema_version version) { - shared_ptr results = co_await qctx->qp().execute_internal( + shared_ptr results = co_await sys_ks._qp.execute_internal( GET_COLUMN_MAPPING_QUERY, db::consistency_level::LOCAL_ONE, {table_id.uuid(), version.uuid()}, @@ -3746,7 +3746,7 @@ future get_column_mapping(db::system_keyspace& sys_ks, ::table_i } future column_mapping_exists(db::system_keyspace& sys_ks, table_id table_id, table_schema_version version) { - shared_ptr results = co_await qctx->qp().execute_internal( + shared_ptr results = co_await sys_ks._qp.execute_internal( GET_COLUMN_MAPPING_QUERY, db::consistency_level::LOCAL_ONE, {table_id.uuid(), version.uuid()}, @@ -3759,7 +3759,7 @@ future<> drop_column_mapping(db::system_keyspace& sys_ks, table_id table_id, tab const static sstring DEL_COLUMN_MAPPING_QUERY = format("DELETE FROM system.{} WHERE cf_id = ? and schema_version = ?", db::schema_tables::SCYLLA_TABLE_SCHEMA_HISTORY); - co_await qctx->qp().execute_internal( + co_await sys_ks._qp.execute_internal( DEL_COLUMN_MAPPING_QUERY, db::consistency_level::LOCAL_ONE, {table_id.uuid(), version.uuid()}, diff --git a/db/system_keyspace.hh b/db/system_keyspace.hh index 72928df805..f5bb61e901 100644 --- a/db/system_keyspace.hh +++ b/db/system_keyspace.hh @@ -78,6 +78,13 @@ namespace db { sstring system_keyspace_name(); +class system_keyspace; +namespace schema_tables { +future get_column_mapping(db::system_keyspace& sys_ks, ::table_id table_id, table_schema_version version); +future column_mapping_exists(db::system_keyspace& sys_ks, table_id table_id, table_schema_version version); +future<> drop_column_mapping(db::system_keyspace& sys_ks, table_id table_id, table_schema_version version); +} + class config; struct local_cache; @@ -509,6 +516,10 @@ public: future<::shared_ptr> execute_cql(sstring req, Args&&... args) { return execute_cql(req, { data_value(std::forward(args))... }); } + + friend future db::schema_tables::get_column_mapping(db::system_keyspace& sys_ks, ::table_id table_id, table_schema_version version); + friend future db::schema_tables::column_mapping_exists(db::system_keyspace& sys_ks, table_id table_id, table_schema_version version); + friend future<> db::schema_tables::drop_column_mapping(db::system_keyspace& sys_ks, table_id table_id, table_schema_version version); }; // class system_keyspace } // namespace db