Warn user about using SimpleStrategy with Multi DC deployment

If the user creates a keyspace with the 'SimpleStrategy' replication class
in a multi-datacenter environment, they will receive a warning in the CQL shell
and in the server logs.
Resolves #4481.

Signed-off-by: Kamil Braun <kbraun@scylladb.com>
This commit is contained in:
Kamil Braun
2019-07-04 17:18:42 +02:00
parent 35dbe9371c
commit c0915c40eb
2 changed files with 28 additions and 0 deletions

View File

@@ -43,6 +43,8 @@
#include "prepared_statement.hh"
#include "database.hh"
#include "service/migration_manager.hh"
#include "service/storage_service.hh"
#include "transport/messages/result_message.hh"
#include <regex>
@@ -52,6 +54,8 @@ namespace cql3 {
namespace statements {
logging::logger create_keyspace_statement::_logger("create_keyspace");
create_keyspace_statement::create_keyspace_statement(const sstring& name, shared_ptr<ks_prop_defs> attrs, bool if_not_exists)
: _name{name}
, _attrs{attrs}
@@ -139,6 +143,24 @@ future<> cql3::statements::create_keyspace_statement::grant_permissions_to_creat
});
}
future<::shared_ptr<messages::result_message>>
create_keyspace_statement::execute(service::storage_proxy& proxy, service::query_state& state, const query_options& options) {
return schema_altering_statement::execute(proxy, state, options).then([this] (::shared_ptr<messages::result_message> msg) {
bool multidc = service::get_local_storage_service().get_token_metadata().
get_topology().get_datacenter_endpoints().size() > 1;
bool simple = _attrs->get_replication_strategy_class() == "SimpleStrategy";
if (multidc && simple) {
static const auto warning = "Using SimpleStrategy in a multi-datacenter environment is not recommended.";
msg->add_warning(warning);
_logger.warn(warning);
}
return msg;
});
}
}
}

View File

@@ -44,6 +44,7 @@
#include "cql3/statements/schema_altering_statement.hh"
#include "cql3/statements/ks_prop_defs.hh"
#include "transport/event.hh"
#include "log.hh"
#include <seastar/core/shared_ptr.hh>
@@ -54,6 +55,8 @@ namespace statements {
/** A <code>CREATE KEYSPACE</code> statement parsed from a CQL query. */
class create_keyspace_statement : public schema_altering_statement {
private:
static logging::logger _logger;
sstring _name;
shared_ptr<ks_prop_defs> _attrs;
bool _if_not_exists;
@@ -86,6 +89,9 @@ public:
virtual std::unique_ptr<prepared> prepare(database& db, cql_stats& stats) override;
virtual future<> grant_permissions_to_creator(const service::client_state&) override;
virtual future<::shared_ptr<messages::result_message>>
execute(service::storage_proxy& proxy, service::query_state& state, const query_options& options) override;
};
}