diff --git a/service/storage_proxy.cc b/service/storage_proxy.cc index 97854f30a8..0238431474 100644 --- a/service/storage_proxy.cc +++ b/service/storage_proxy.cc @@ -92,6 +92,7 @@ #include "utils/result_loop.hh" #include "utils/overloaded_functor.hh" #include "utils/result_try.hh" +#include "utils/error_injection.hh" namespace bi = boost::intrusive; @@ -4466,6 +4467,7 @@ storage_proxy::query(schema_ptr s, db::consistency_level cl, storage_proxy::coordinator_query_options query_options) { + utils::get_local_injector().inject("storage_proxy_query_failure", [] { throw std::runtime_error("Error injection: failing a query"); }); return query_result(std::move(s), std::move(cmd), std::move(partition_ranges), cl, std::move(query_options)) .then(utils::result_into_future>); } diff --git a/test/boost/secondary_index_test.cc b/test/boost/secondary_index_test.cc index a3547a3236..b463ad5be6 100644 --- a/test/boost/secondary_index_test.cc +++ b/test/boost/secondary_index_test.cc @@ -17,6 +17,7 @@ #include "test/lib/exception_utils.hh" #include "cql3/statements/select_statement.hh" #include "test/lib/select_statement_utils.hh" +#include "utils/error_injection.hh" using namespace std::chrono_literals; @@ -1934,3 +1935,20 @@ SEASTAR_TEST_CASE(test_deleting_ghost_rows) { }); }); } + +SEASTAR_TEST_CASE(test_returning_failure_from_ghost_rows_deletion) { + return do_with_cql_env_thread([] (auto& e) { + cquery_nofail(e, "CREATE TABLE t (p int, c int, v int, PRIMARY KEY (p, c))"); + cquery_nofail(e, "CREATE MATERIALIZED VIEW tv AS SELECT v, p, c FROM t WHERE v IS NOT NULL AND c IS NOT NULL PRIMARY KEY (v, p, c);"); + cquery_nofail(e, "INSERT INTO t (p,c,v) VALUES (1,1,1)"); + cquery_nofail(e, "INSERT INTO t (p,c,v) VALUES (1,2,3)"); + cquery_nofail(e, "INSERT INTO t (p,c,v) VALUES (2,4,6)"); + utils::get_local_injector().enable("storage_proxy_query_failure", true); + // If error injection is disabled, this check is skipped + if (!utils::get_local_injector().enabled_injections().empty()) { + // Test that when a single query to the base table fails, it is propagated + // to the user + BOOST_REQUIRE_THROW(e.execute_cql("PRUNE MATERIALIZED VIEW tv").get0(), std::runtime_error); + } + }); +}