diff --git a/cql3/statements/ks_prop_defs.cc b/cql3/statements/ks_prop_defs.cc index 07eb5c66f6..fbb5bf3984 100644 --- a/cql3/statements/ks_prop_defs.cc +++ b/cql3/statements/ks_prop_defs.cc @@ -34,7 +34,7 @@ static std::map prepare_options( // but the other strategy used the 'replication_factor' option, it will also be expanded. // See issue CASSANDRA-14303. - sstring rf; + std::optional rf; auto it = options.find(ks_prop_defs::REPLICATION_FACTOR_KEY); if (it != options.end()) { // Expand: the user explicitly provided a 'replication_factor'. @@ -49,10 +49,10 @@ static std::map prepare_options( } } - if (!rf.empty()) { + if (rf.has_value()) { // The code below may end up not using "rf" at all (if all the DCs // already have rf settings), so let's validate it once (#8880). - locator::abstract_replication_strategy::validate_replication_factor(rf); + locator::abstract_replication_strategy::validate_replication_factor(*rf); // We keep previously specified DC factors for safety. for (const auto& opt : old_options) { @@ -62,7 +62,7 @@ static std::map prepare_options( } for (const auto& dc : tm.get_topology().get_datacenters()) { - options.emplace(dc, rf); + options.emplace(dc, *rf); } } diff --git a/test/boost/network_topology_strategy_test.cc b/test/boost/network_topology_strategy_test.cc index 0f8b16a13e..f1b3885e74 100644 --- a/test/boost/network_topology_strategy_test.cc +++ b/test/boost/network_topology_strategy_test.cc @@ -756,6 +756,9 @@ SEASTAR_TEST_CASE(test_invalid_dcs) { BOOST_REQUIRE_THROW(e.execute_cql("CREATE KEYSPACE abc WITH REPLICATION " "= {'class': 'NetworkTopologyStrategy', 'dc1':'" + incorrect + "'}").get(), exceptions::configuration_exception); + BOOST_REQUIRE_THROW(e.execute_cql("CREATE KEYSPACE abc WITH REPLICATION " + "= {'class': 'NetworkTopologyStrategy', 'replication_factor':'" + incorrect + "'}").get(), + exceptions::configuration_exception); BOOST_REQUIRE_THROW(e.execute_cql("CREATE KEYSPACE abc WITH REPLICATION " "= {'class': 'SimpleStrategy', 'replication_factor':'" + incorrect + "'}").get(), exceptions::configuration_exception);