database: Move ks_meta_data definition to database.hh

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
This commit is contained in:
Pekka Enberg
2015-05-19 11:01:26 +03:00
parent 1931165021
commit 032af4d53b
11 changed files with 57 additions and 105 deletions

View File

@@ -22,12 +22,8 @@
* Modified by Cloudius Systems
*/
#include "config/ks_meta_data.hh"
#include "database.hh"
namespace config {
ks_meta_data::ks_meta_data(sstring name,
sstring strategy_name,
std::unordered_map<sstring, sstring> strategy_options,
@@ -54,5 +50,3 @@ ks_meta_data::new_keyspace(sstring name,
{
return ::make_lw_shared<ks_meta_data>(name, strategy_name, options, durables_writes, cf_defs);
}
}

View File

@@ -1,79 +0,0 @@
/*
* 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 2015 Cloudius Systems
*
* Modified by Cloudius Systems
*/
#pragma once
#include "schema.hh"
#include "core/shared_ptr.hh"
#include <unordered_map>
class user_types_metadata;
namespace config {
class ks_meta_data final {
sstring _name;
sstring _strategy_name;
std::unordered_map<sstring, sstring> _strategy_options;
std::unordered_map<sstring, schema_ptr> _cf_meta_data;
bool _durable_writes;
::shared_ptr<user_types_metadata> _user_types;
public:
ks_meta_data(sstring name,
sstring strategy_name,
std::unordered_map<sstring, sstring> strategy_options,
bool durable_writes,
std::vector<schema_ptr> cf_defs = std::vector<schema_ptr>{},
shared_ptr<user_types_metadata> user_types = ::make_shared<user_types_metadata>());
static lw_shared_ptr<ks_meta_data>
new_keyspace(sstring name,
sstring strategy_name,
std::unordered_map<sstring, sstring> options,
bool durables_writes,
std::vector<schema_ptr> cf_defs = std::vector<schema_ptr>{});
const sstring& name() const {
return _name;
}
const sstring& strategy_name() const {
return _strategy_name;
}
const std::unordered_map<sstring, sstring>& strategy_options() const {
return _strategy_options;
}
const std::unordered_map<sstring, schema_ptr>& cf_meta_data() const {
return _cf_meta_data;
}
bool durable_writes() const {
return _durable_writes;
}
const ::shared_ptr<user_types_metadata>& user_types() const {
return _user_types;
}
};
}

View File

@@ -27,7 +27,6 @@
#include "cql3/statements/schema_altering_statement.hh"
#include "cql3/statements/ks_prop_defs.hh"
#include "service/migration_manager.hh"
#include "config/ks_meta_data.hh"
#include "transport/event.hh"
#include "core/shared_ptr.hh"

View File

@@ -25,7 +25,6 @@
#pragma once
#include "cql3/statements/property_definitions.hh"
#include "config/ks_meta_data.hh"
#include "core/sstring.hh"
#include <experimental/optional>
@@ -83,8 +82,8 @@ public:
return _strategy_class;
}
lw_shared_ptr<config::ks_meta_data> as_ks_metadata(sstring ks_name) {
return config::ks_meta_data::new_keyspace(ks_name, get_replication_strategy_class().value(), get_replication_options(), get_boolean(KW_DURABLE_WRITES, true));
lw_shared_ptr<ks_meta_data> as_ks_metadata(sstring ks_name) {
return ks_meta_data::new_keyspace(ks_name, get_replication_strategy_class().value(), get_replication_options(), get_boolean(KW_DURABLE_WRITES, true));
}
#if 0

View File

@@ -530,7 +530,7 @@ const column_family& database::find_column_family(const utils::UUID& uuid) const
}
void
keyspace::create_replication_strategy(::config::ks_meta_data& ksm) {
keyspace::create_replication_strategy(ks_meta_data& ksm) {
static thread_local locator::token_metadata tm;
static locator::simple_snitch snitch;
static std::unordered_map<sstring, sstring> options = {{"replication_factor", "3"}};

View File

@@ -6,7 +6,6 @@
#define DATABASE_HH_
#include "dht/i_partitioner.hh"
#include "config/ks_meta_data.hh"
#include "locator/abstract_replication_strategy.hh"
#include "core/sstring.hh"
#include "core/shared_ptr.hh"
@@ -134,6 +133,48 @@ public:
}
};
class ks_meta_data final {
sstring _name;
sstring _strategy_name;
std::unordered_map<sstring, sstring> _strategy_options;
std::unordered_map<sstring, schema_ptr> _cf_meta_data;
bool _durable_writes;
::shared_ptr<user_types_metadata> _user_types;
public:
ks_meta_data(sstring name,
sstring strategy_name,
std::unordered_map<sstring, sstring> strategy_options,
bool durable_writes,
std::vector<schema_ptr> cf_defs = std::vector<schema_ptr>{},
shared_ptr<user_types_metadata> user_types = ::make_shared<user_types_metadata>());
static lw_shared_ptr<ks_meta_data>
new_keyspace(sstring name,
sstring strategy_name,
std::unordered_map<sstring, sstring> options,
bool durables_writes,
std::vector<schema_ptr> cf_defs = std::vector<schema_ptr>{});
const sstring& name() const {
return _name;
}
const sstring& strategy_name() const {
return _strategy_name;
}
const std::unordered_map<sstring, sstring>& strategy_options() const {
return _strategy_options;
}
const std::unordered_map<sstring, schema_ptr>& cf_meta_data() const {
return _cf_meta_data;
}
bool durable_writes() const {
return _durable_writes;
}
const ::shared_ptr<user_types_metadata>& user_types() const {
return _user_types;
}
};
class keyspace {
public:
struct config {
@@ -147,7 +188,7 @@ private:
public:
explicit keyspace(config cfg) : _config(std::move(cfg)) {}
user_types_metadata _user_types;
void create_replication_strategy(::config::ks_meta_data& ksm);
void create_replication_strategy(ks_meta_data& ksm);
locator::abstract_replication_strategy& get_replication_strategy();
column_family::config make_column_family_config(const schema& s) const;
future<> make_directory_for_column_family(const sstring& name, utils::UUID uuid);

View File

@@ -820,7 +820,7 @@ std::vector<const char*> ALL { KEYSPACES, COLUMNFAMILIES, COLUMNS, TRIGGERS, USE
* Keyspace metadata serialization/deserialization.
*/
std::vector<mutation> make_create_keyspace_mutations(lw_shared_ptr<::config::ks_meta_data> keyspace, api::timestamp_type timestamp, bool with_tables_and_types_and_functions)
std::vector<mutation> make_create_keyspace_mutations(lw_shared_ptr<ks_meta_data> keyspace, api::timestamp_type timestamp, bool with_tables_and_types_and_functions)
{
std::vector<mutation> mutations;
schema_ptr s = keyspaces();
@@ -879,7 +879,7 @@ std::vector<const char*> ALL { KEYSPACES, COLUMNFAMILIES, COLUMNS, TRIGGERS, USE
*
* @param partition Keyspace attributes in serialized form
*/
lw_shared_ptr<::config::ks_meta_data> create_keyspace_from_schema_partition(const std::pair<dht::decorated_key, lw_shared_ptr<query::result_set>>& result)
lw_shared_ptr<ks_meta_data> create_keyspace_from_schema_partition(const std::pair<dht::decorated_key, lw_shared_ptr<query::result_set>>& result)
{
auto&& rs = result.second;
if (rs->empty()) {
@@ -890,7 +890,7 @@ std::vector<const char*> ALL { KEYSPACES, COLUMNFAMILIES, COLUMNS, TRIGGERS, USE
auto strategy_name = row.get_nonnull<sstring>("strategy_class");
std::unordered_map<sstring, sstring> strategy_options;
bool durable_writes = row.get_nonnull<bool>("durable_writes");
return make_lw_shared<::config::ks_meta_data>(keyspace_name, strategy_name, strategy_options, durable_writes);
return make_lw_shared<ks_meta_data>(keyspace_name, strategy_name, strategy_options, durable_writes);
}
#if 0

View File

@@ -24,7 +24,6 @@
#pragma once
#include "service/storage_proxy.hh"
#include "config/ks_meta_data.hh"
#include "mutation.hh"
#include "schema.hh"
@@ -66,11 +65,11 @@ future<> merge_schema(service::storage_proxy& proxy, std::vector<mutation> mutat
future<std::set<sstring>> merge_keyspaces(service::storage_proxy& proxy, schema_result&& before, schema_result&& after);
std::vector<mutation> make_create_keyspace_mutations(lw_shared_ptr<::config::ks_meta_data> keyspace, api::timestamp_type timestamp, bool with_tables_and_types_and_functions = true);
std::vector<mutation> make_create_keyspace_mutations(lw_shared_ptr<ks_meta_data> keyspace, api::timestamp_type timestamp, bool with_tables_and_types_and_functions = true);
lw_shared_ptr<::config::ks_meta_data> create_keyspace_from_schema_partition(const std::pair<dht::decorated_key, lw_shared_ptr<query::result_set>>& partition);
lw_shared_ptr<ks_meta_data> create_keyspace_from_schema_partition(const std::pair<dht::decorated_key, lw_shared_ptr<query::result_set>>& partition);
mutation make_create_keyspace_mutation(lw_shared_ptr<::config::ks_meta_data> keyspace, api::timestamp_type timestamp, bool with_tables_and_types_and_functions = true);
mutation make_create_keyspace_mutation(lw_shared_ptr<ks_meta_data> keyspace, api::timestamp_type timestamp, bool with_tables_and_types_and_functions = true);
void add_table_to_schema_mutation(schema_ptr table, api::timestamp_type timestamp, bool with_columns_and_triggers, const partition_key& pkey, std::vector<mutation>& mutations);

View File

@@ -25,7 +25,6 @@
#pragma once
#include "db/legacy_schema_tables.hh"
#include "config/ks_meta_data.hh"
#if 0
package org.apache.cassandra.service;
@@ -267,17 +266,17 @@ public:
}
#endif
static future<> announce_new_keyspace(service::storage_proxy& proxy, lw_shared_ptr<config::ks_meta_data> ksm)
static future<> announce_new_keyspace(service::storage_proxy& proxy, lw_shared_ptr<ks_meta_data> ksm)
{
return announce_new_keyspace(proxy, ksm, false);
}
static future<> announce_new_keyspace(service::storage_proxy& proxy, lw_shared_ptr<config::ks_meta_data> ksm, bool announce_locally)
static future<> announce_new_keyspace(service::storage_proxy& proxy, lw_shared_ptr<ks_meta_data> ksm, bool announce_locally)
{
return announce_new_keyspace(proxy, ksm, db_clock::now_in_usecs(), announce_locally);
}
static future<> announce_new_keyspace(service::storage_proxy& proxy, lw_shared_ptr<config::ks_meta_data> ksm, api::timestamp_type timestamp, bool announce_locally)
static future<> announce_new_keyspace(service::storage_proxy& proxy, lw_shared_ptr<ks_meta_data> ksm, api::timestamp_type timestamp, bool announce_locally)
{
#if 0
ksm.validate();

View File

@@ -95,7 +95,7 @@ public:
auto& ks = db.find_or_create_keyspace(ks_name);
auto cfg = ks.make_column_family_config(*cf_schema);
db.add_column_family(column_family(std::move(cf_schema), std::move(cfg)));
config::ks_meta_data ksm(ks_name,
ks_meta_data ksm(ks_name,
"org.apache.cassandra.locator.SimpleStrategy",
std::unordered_map<sstring, sstring>(),
false,

View File

@@ -463,7 +463,7 @@ public:
db.add_column_family(std::move(cf));
cf_defs.push_back(s);
}
config::ks_meta_data ksm(to_sstring(ks_def.name),
ks_meta_data ksm(to_sstring(ks_def.name),
to_sstring(ks_def.strategy_class),
std::unordered_map<sstring, sstring>(),//ks_def.strategy_options,
ks_def.durable_writes,