Forward-ported from scylla-enterprise.
Note that the feature has been deprecated and the implementation
is provided only for backward compatibility with pre-existing
features and schema.
Tested manually after adding the following to feature_service:
```
gms::feature workload_prioritization { *this, "WORKLOAD_PRIORITIZATION"sv };
```
Launched a single-node cluster running 2023.1.10
```
cqlsh> create KEYSPACE ks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
cqlsh> create TABLE ks.test ( pk int PRIMARY KEY, val int ) WITH compaction = {'class': 'InMemoryCompactionStrategy'};
```
log:
```
Scylla version 2023.1.10-0.20241227.21cffccc1ccd with build-id bd65b8399cb13b713a87e57fe333cfcabfd50be7 starting ...
...
INFO 2024-12-27 19:45:16,563 [shard 0] migration_manager - Create new ColumnFamily: org.apache.cassandra.config.CFMetaData@0x600000f1b400[cfId=5529c630-c47a-11ef-bd1d-4295734ce5a8,ksName=ks,cfName=test,cfType=Standard,comparator=org.apache.cassandra.db.marshal.CompositeType(org.apache.cassandra.db.marshal.UTF8Type),comment=,readRepairChance=0,dcLocalReadRepairChance=0,tombstoneGcOptions={"mode":"timeout","propagation_delay_in_seconds":"3600"},gcGraceSeconds=864000,keyValidator=org.apache.cassandra.db.marshal.Int32Type,minCompactionThreshold=4,maxCompactionThreshold=32,columnMetadata=[ColumnDefinition{name=pk, type=org.apache.cassandra.db.marshal.Int32Type, kind=PARTITION_KEY, componentIndex=0, droppedAt=-9223372036854775808}, ColumnDefinition{name=val, type=org.apache.cassandra.db.marshal.Int32Type, kind=REGULAR, componentIndex=null, droppedAt=-9223372036854775808}],compactionStrategyClass=class org.apache.cassandra.db.compaction.InMemoryCompactionStrategy,compactionStrategyOptions={enabled=true},compressionParameters={sstable_compression=org.apache.cassandra.io.compress.LZ4Compressor},bloomFilterFpChance=0.01,memtableFlushPeriod=0,caching={"keys":"ALL","rows_per_partition":"ALL"},cdc={},defaultTimeToLive=0,minIndexInterval=128,maxIndexInterval=2048,speculativeRetry=99.0PERCENTILE,triggers=[],isDense=false,in_memory=false,version=5529c631-c47a-11ef-bd1d-4295734ce5a8,droppedColumns={},collections={},indices={}]
INFO 2024-12-27 19:45:16,564 [shard 0] schema_tables - Creating ks.test id=5529c630-c47a-11ef-bd1d-4295734ce5a8 version=ec88d510-6aff-344a-914d-541d37081440
```
Upgraded to this branch and started scylla.
Verified that ks.test was successfuly loaded:
log:
```
INFO 2024-12-27 19:48:58,115 [shard 0:main] init - Scylla version 6.3.0~dev-0.20241227.a64c6dfc153e with build-id f9496134a09cf2e55d3865b9e9ff499f672aa7da starting ...
...
WARN 2024-12-27 19:53:02,948 [shard 1:main] CompactionStrategy - InMemoryCompactionStrategy is no longer supported. Defaulting to NullCompactionStrategy.
...
INFO 2024-12-27 19:53:02,948 [shard 0:main] database - Keyspace ks: Reading CF test id=5529c630-c47a-11ef-bd1d-4295734ce5a8 version=ec88d510-6aff-344a-914d-541d37081440 storage=/home/bhalevy/scylladb/data/ks/test-5529c630c47a11efbd1d4295734ce5a8
```
Then, tested:
```
cqlsh> describe KEYSPACE ks;
CREATE KEYSPACE ks WITH replication = {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true AND tablets = {'enabled': false};
CREATE TABLE ks.test (
pk int,
val int,
PRIMARY KEY (pk)
) WITH bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'ALL'}
AND comment = ''
AND compaction = {'class': 'InMemoryCompactionStrategy'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND speculative_retry = '99.0PERCENTILE';
cqlsh> alter TABLE ks.test with compaction = {'class': 'SizeTieredCompactionStrategy'};
cqlsh> describe KEYSPACE ks;
CREATE KEYSPACE ks WITH replication = {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true AND tablets = {'enabled': false};
CREATE TABLE ks.test (
pk int,
val int,
PRIMARY KEY (pk)
) WITH bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'ALL'}
AND comment = ''
AND compaction = {'class': 'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND speculative_retry = '99.0PERCENTILE'
AND tombstone_gc = {'mode': 'timeout', 'propagation_delay_in_seconds': '3600'};
```
log:
```
INFO 2024-12-27 19:56:40,465 [shard 0:stmt] migration_manager - Update table 'ks.test' From org.apache.cassandra.config.CFMetaData@0x60000362d800[cfId=5529c630-c47a-11ef-bd1d-4295734ce5a8,ksName==ks,cfName=test,cfType=Standard,comparator=org.apache.cassandra.db.marshal.CompositeType(org.apache.cassandra.db.marshal.UTF8Type),comment=,tombstoneGcOptions={"mode":"timeout","propagation_delay_in_seconds":"3600"},gcGraceSeconds=864000,minCompactionThreshold=4,maxCompactionThreshold=32,columnMetadata=[ColumnDefinition{name=pk, type=org.apache.cassandra.db.marshal.Int32Type, kind=PARTITION_KEY, componentIndex=0, droppedAt=-9223372036854775808}, ColumnDefinition{name=val, type=org.apache.cassandra.db.marshal.Int32Type, kind=REGULAR, componentIndex=null, droppedAt=-9223372036854775808}],compactionStrategyClass=class org.apache.cassandra.db.compaction.InMemoryCompactionStrategy,compactionStrategyOptions={enabled=true},compressionParameters={sstable_compression=org.apache.cassandra.io.compress.LZ4Compressor},bloomFilterFpChance=0.01,memtableFlushPeriod=0,caching={"keys":"ALL","rows_per_partition":"ALL"},cdc={},defaultTimeToLive=0,minIndexInterval=128,maxIndexInterval=2048,speculativeRetry=99.0PERCENTILE,triggers=[],isDense=false,version=ec88d510-6aff-344a-914d-541d37081440,droppedColumns={},collections={},indices={}] To org.apache.cassandra.config.CFMetaData@0x60000336e000[cfId=5529c630-c47a-11ef-bd1d-4295734ce5a8,ksName==ks,cfName=test,cfType=Standard,comparator=org.apache.cassandra.db.marshal.CompositeType(org.apache.cassandra.db.marshal.UTF8Type),comment=,tombstoneGcOptions={"mode":"timeout","propagation_delay_in_seconds":"3600"},gcGraceSeconds=864000,minCompactionThreshold=4,maxCompactionThreshold=32,columnMetadata=[ColumnDefinition{name=pk, type=org.apache.cassandra.db.marshal.Int32Type, kind=PARTITION_KEY, componentIndex=0, droppedAt=-9223372036854775808}, ColumnDefinition{name=val, type=org.apache.cassandra.db.marshal.Int32Type, kind=REGULAR, componentIndex=null, droppedAt=-9223372036854775808}],compactionStrategyClass=class org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy,compactionStrategyOptions={enabled=true},compressionParameters={sstable_compression=org.apache.cassandra.io.compress.LZ4Compressor},bloomFilterFpChance=0.01,memtableFlushPeriod=0,caching={"keys":"ALL","rows_per_partition":"ALL"},cdc={},defaultTimeToLive=0,minIndexInterval=128,maxIndexInterval=2048,speculativeRetry=99.0PERCENTILE,triggers=[],isDense=false,version=ecccf010-c47b-11ef-b52c-622f2f0e87c4,droppedColumns={},collections={},indices={}]
INFO 2024-12-27 19:56:40,466 [shard 0: gms] schema_tables - Altering ks.test id=5529c630-c47a-11ef-bd1d-4295734ce5a8 version=ecccf010-c47b-11ef-b52c-622f2f0e87c4
```
Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
Closes scylladb/scylladb#22068
303 lines
10 KiB
C++
303 lines
10 KiB
C++
/*
|
|
* Copyright (C) 2015-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "schema.hh"
|
|
#include "replica/database_fwd.hh"
|
|
#include "cdc/log.hh"
|
|
#include "timestamp.hh"
|
|
#include "tombstone_gc_options.hh"
|
|
|
|
namespace db {
|
|
class per_partition_rate_limit_options;
|
|
}
|
|
|
|
struct schema_builder {
|
|
public:
|
|
enum class compact_storage { no, yes };
|
|
using static_configurator = noncopyable_function<void(const sstring& ks_name, const sstring& cf_name, schema_static_props&)>;
|
|
private:
|
|
struct from_hash {};
|
|
struct from_time {};
|
|
schema::raw_schema _raw;
|
|
std::optional<compact_storage> _compact_storage;
|
|
std::variant<from_time, from_hash, table_schema_version> _version = from_time{};
|
|
std::optional<raw_view_info> _view_info;
|
|
schema_builder(const schema::raw_schema&);
|
|
static std::vector<static_configurator>& static_configurators();
|
|
public:
|
|
schema_builder(std::string_view ks_name, std::string_view cf_name,
|
|
std::optional<table_id> = { },
|
|
data_type regular_column_name_type = utf8_type);
|
|
schema_builder(
|
|
std::optional<table_id> id,
|
|
std::string_view ks_name,
|
|
std::string_view cf_name,
|
|
std::vector<schema::column> partition_key,
|
|
std::vector<schema::column> clustering_key,
|
|
std::vector<schema::column> regular_columns,
|
|
std::vector<schema::column> static_columns,
|
|
data_type regular_column_name_type,
|
|
sstring comment = "");
|
|
schema_builder(const schema_ptr);
|
|
|
|
static int register_static_configurator(static_configurator&& configurator);
|
|
|
|
schema_builder& set_uuid(const table_id& id) {
|
|
_raw._id = id;
|
|
return *this;
|
|
}
|
|
const table_id& uuid() const {
|
|
return _raw._id;
|
|
}
|
|
schema_builder& set_regular_column_name_type(const data_type& t) {
|
|
_raw._regular_column_name_type = t;
|
|
return *this;
|
|
}
|
|
schema_builder& set_default_validation_class(const data_type& t) {
|
|
_raw._default_validation_class = t;
|
|
return *this;
|
|
}
|
|
const data_type& regular_column_name_type() const {
|
|
return _raw._regular_column_name_type;
|
|
}
|
|
const sstring& ks_name() const {
|
|
return _raw._ks_name;
|
|
}
|
|
const sstring& cf_name() const {
|
|
return _raw._cf_name;
|
|
}
|
|
schema_builder& set_comment(const sstring& s) {
|
|
_raw._comment = s;
|
|
return *this;
|
|
}
|
|
const sstring& comment() const {
|
|
return _raw._comment;
|
|
}
|
|
schema_builder& set_default_time_to_live(gc_clock::duration t) {
|
|
_raw._default_time_to_live = t;
|
|
return *this;
|
|
}
|
|
gc_clock::duration default_time_to_live() const {
|
|
return _raw._default_time_to_live;
|
|
}
|
|
|
|
schema_builder& set_gc_grace_seconds(int32_t gc_grace_seconds) {
|
|
_raw._gc_grace_seconds = gc_grace_seconds;
|
|
return *this;
|
|
}
|
|
|
|
int32_t get_gc_grace_seconds() const {
|
|
return _raw._gc_grace_seconds;
|
|
}
|
|
|
|
schema_builder& set_paxos_grace_seconds(int32_t seconds);
|
|
|
|
schema_builder& set_crc_check_chance(double chance) {
|
|
_raw._crc_check_chance = chance;
|
|
return *this;
|
|
}
|
|
|
|
double get_crc_check_chance() const {
|
|
return _raw._crc_check_chance;
|
|
}
|
|
|
|
schema_builder& set_min_compaction_threshold(int32_t t) {
|
|
_raw._min_compaction_threshold = t;
|
|
return *this;
|
|
}
|
|
|
|
int32_t get_min_compaction_threshold() const {
|
|
return _raw._min_compaction_threshold;
|
|
}
|
|
|
|
schema_builder& set_max_compaction_threshold(int32_t t) {
|
|
_raw._max_compaction_threshold = t;
|
|
return *this;
|
|
}
|
|
|
|
int32_t get_max_compaction_threshold() const {
|
|
return _raw._max_compaction_threshold;
|
|
}
|
|
|
|
schema_builder& set_compaction_enabled(bool enabled) {
|
|
_raw._compaction_enabled = enabled;
|
|
return *this;
|
|
}
|
|
|
|
bool compaction_enabled() const {
|
|
return _raw._compaction_enabled;
|
|
}
|
|
|
|
schema_builder& set_min_index_interval(int32_t t) {
|
|
_raw._min_index_interval = t;
|
|
return *this;
|
|
}
|
|
|
|
int32_t get_min_index_interval() const {
|
|
return _raw._min_index_interval;
|
|
}
|
|
|
|
schema_builder& set_max_index_interval(int32_t t) {
|
|
_raw._max_index_interval = t;
|
|
return *this;
|
|
}
|
|
|
|
int32_t get_max_index_interval() const {
|
|
return _raw._max_index_interval;
|
|
}
|
|
|
|
schema_builder& set_memtable_flush_period(int32_t t) {
|
|
_raw._memtable_flush_period = t;
|
|
return *this;
|
|
}
|
|
|
|
int32_t get_memtable_flush_period() const {
|
|
return _raw._memtable_flush_period;
|
|
}
|
|
|
|
schema_builder& set_speculative_retry(sstring retry_sstring) {
|
|
_raw._speculative_retry = speculative_retry::from_sstring(retry_sstring);
|
|
return *this;
|
|
}
|
|
|
|
const speculative_retry& get_speculative_retry() const {
|
|
return _raw._speculative_retry;
|
|
}
|
|
|
|
schema_builder& set_bloom_filter_fp_chance(double fp) {
|
|
_raw._bloom_filter_fp_chance = fp;
|
|
return *this;
|
|
}
|
|
double get_bloom_filter_fp_chance() const {
|
|
return _raw._bloom_filter_fp_chance;
|
|
}
|
|
schema_builder& set_compressor_params(const compression_parameters& cp) {
|
|
_raw._compressor_params = cp;
|
|
return *this;
|
|
}
|
|
schema_builder& set_extensions(schema::extensions_map exts) {
|
|
_raw._extensions = std::move(exts);
|
|
return *this;
|
|
}
|
|
schema_builder& add_extension(const sstring& name, ::shared_ptr<schema_extension> ext) {
|
|
_raw._extensions[name] = std::move(ext);
|
|
return *this;
|
|
}
|
|
const schema::extensions_map& get_extensions() const {
|
|
return _raw._extensions;
|
|
}
|
|
schema_builder& set_compaction_strategy(sstables::compaction_strategy_type type) {
|
|
_raw._compaction_strategy = type;
|
|
return *this;
|
|
}
|
|
|
|
schema_builder& set_compaction_strategy_options(std::map<sstring, sstring>&& options);
|
|
|
|
schema_builder& set_caching_options(caching_options c) {
|
|
_raw._caching_options = std::move(c);
|
|
return *this;
|
|
}
|
|
|
|
schema_builder& set_is_dense(bool is_dense) {
|
|
_raw._is_dense = is_dense;
|
|
return *this;
|
|
}
|
|
|
|
schema_builder& set_is_compound(bool is_compound) {
|
|
_raw._is_compound = is_compound;
|
|
return *this;
|
|
}
|
|
|
|
schema_builder& set_is_counter(bool is_counter) {
|
|
_raw._is_counter = is_counter;
|
|
return *this;
|
|
}
|
|
|
|
schema_builder& with_partitioner(sstring name);
|
|
schema_builder& with_sharder(unsigned shard_count, unsigned sharding_ignore_msb_bits);
|
|
schema_builder& set_in_memory(bool in_memory) {
|
|
_raw._in_memory = in_memory;
|
|
return *this;
|
|
}
|
|
|
|
class default_names {
|
|
public:
|
|
default_names(const schema_builder&);
|
|
default_names(const schema::raw_schema&);
|
|
|
|
sstring partition_key_name();
|
|
sstring clustering_name();
|
|
sstring compact_value_name();
|
|
private:
|
|
sstring unique_name(const sstring&, size_t&, size_t) const;
|
|
const schema::raw_schema& _raw;
|
|
size_t _partition_index, _clustering_index, _compact_index;
|
|
};
|
|
|
|
column_definition& find_column(const cql3::column_identifier&);
|
|
bool has_column(const cql3::column_identifier&);
|
|
schema_builder& with_column_ordered(const column_definition& c);
|
|
schema_builder& with_column(bytes name, data_type type, column_kind kind = column_kind::regular_column, column_view_virtual view_virtual = column_view_virtual::no);
|
|
schema_builder& with_computed_column(bytes name, data_type type, column_kind kind, column_computation_ptr computation);
|
|
schema_builder& remove_column(bytes name, std::optional<api::timestamp_type> timestamp = std::nullopt);
|
|
schema_builder& without_column(sstring name, api::timestamp_type timestamp);
|
|
schema_builder& without_column(sstring name, data_type, api::timestamp_type timestamp);
|
|
schema_builder& rename_column(bytes from, bytes to);
|
|
schema_builder& alter_column_type(bytes name, data_type new_type);
|
|
schema_builder& mark_column_computed(bytes name, column_computation_ptr computation);
|
|
|
|
// Adds information about collection that existed in the past but the column
|
|
// has since been removed. For adding colllections that are still alive
|
|
// use with_column().
|
|
schema_builder& with_collection(bytes name, data_type type);
|
|
|
|
schema_builder& with(compact_storage);
|
|
schema_builder& with_version(table_schema_version);
|
|
|
|
// Will cause the schema to be created with a version which is computed
|
|
// from the definition of the schema. Same schema definition
|
|
// will give the same version at different times of building and on
|
|
// different nodes.
|
|
//
|
|
// By default, the schema version generated by schema_builder is
|
|
// a unique time-UUID, which preserves monotonicity requirements
|
|
// of table_schema_version (even in ABA changes).
|
|
schema_builder& with_hash_version();
|
|
|
|
schema_builder& with_view_info(table_id base_id, sstring base_name, bool include_all_columns, sstring where_clause);
|
|
schema_builder& with_view_info(const schema& base_schema, bool include_all_columns, sstring where_clause) {
|
|
return with_view_info(base_schema.id(), base_schema.cf_name(), include_all_columns, where_clause);
|
|
}
|
|
|
|
schema_builder& with_index(const index_metadata& im);
|
|
schema_builder& without_index(const sstring& name);
|
|
schema_builder& without_indexes();
|
|
|
|
schema_builder& with_cdc_options(const cdc::options&);
|
|
schema_builder& with_tombstone_gc_options(const tombstone_gc_options& opts);
|
|
schema_builder& with_per_partition_rate_limit_options(const db::per_partition_rate_limit_options&);
|
|
|
|
default_names get_default_names() const {
|
|
return default_names(_raw);
|
|
}
|
|
|
|
// Equivalent to with(cp).build()
|
|
schema_ptr build(compact_storage cp);
|
|
|
|
schema_ptr build() &;
|
|
schema_ptr build() &&;
|
|
private:
|
|
schema_ptr build(schema::raw_schema& raw);
|
|
friend class default_names;
|
|
void prepare_dense_schema(schema::raw_schema& raw);
|
|
|
|
schema_builder& with_column(bytes name, data_type type, column_kind kind, column_id component_index, column_view_virtual view_virtual = column_view_virtual::no, column_computation_ptr computation = nullptr);
|
|
};
|