Currently, we use std::vector<*mutation> to keep
a list of mutations for processing.
This can lead to large allocation, e.g. when the vector
size is a function of the number of tables.
Use a chunked vector instead to prevent oversized allocations.
`perf-simple-query --smp 1` results obtained for fixed 400MHz frequency
and PGO disabled:
Before (read path):
```
enable-cache=1
Running test with config: {partitions=10000, concurrency=100, mode=read, query_single_key=no, counters=no}
Disabling auto compaction
Creating 10000 partitions...
89055.97 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39417 insns/op, 18003 cycles/op, 0 errors)
103372.72 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39380 insns/op, 17300 cycles/op, 0 errors)
98942.27 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39413 insns/op, 17336 cycles/op, 0 errors)
103752.93 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39407 insns/op, 17252 cycles/op, 0 errors)
102516.77 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39403 insns/op, 17288 cycles/op, 0 errors)
throughput:
mean= 99528.13 standard-deviation=6155.71
median= 102516.77 median-absolute-deviation=3844.59
maximum=103752.93 minimum=89055.97
instructions_per_op:
mean= 39403.99 standard-deviation=14.25
median= 39406.75 median-absolute-deviation=9.30
maximum=39416.63 minimum=39380.39
cpu_cycles_per_op:
mean= 17435.81 standard-deviation=318.24
median= 17300.40 median-absolute-deviation=147.59
maximum=18002.53 minimum=17251.75
```
After (read path)
```
enable-cache=1
Running test with config: {partitions=10000, concurrency=100, mode=read, query_single_key=no, counters=no}
Disabling auto compaction
Creating 10000 partitions...
59755.04 tps ( 66.2 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39466 insns/op, 22834 cycles/op, 0 errors)
71854.16 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39417 insns/op, 17883 cycles/op, 0 errors)
82149.45 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39411 insns/op, 17409 cycles/op, 0 errors)
49640.04 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.3 tasks/op, 39474 insns/op, 19975 cycles/op, 0 errors)
54963.22 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.3 tasks/op, 39474 insns/op, 18235 cycles/op, 0 errors)
throughput:
mean= 63672.38 standard-deviation=13195.12
median= 59755.04 median-absolute-deviation=8709.16
maximum=82149.45 minimum=49640.04
instructions_per_op:
mean= 39448.38 standard-deviation=31.60
median= 39466.17 median-absolute-deviation=25.75
maximum=39474.12 minimum=39411.42
cpu_cycles_per_op:
mean= 19267.01 standard-deviation=2217.03
median= 18234.80 median-absolute-deviation=1384.25
maximum=22834.26 minimum=17408.67
```
`perf-simple-query --smp 1 --write` results obtained for fixed 400MHz frequency
and PGO disabled:
Before (write path):
```
enable-cache=1
Running test with config: {partitions=10000, concurrency=100, mode=write, query_single_key=no, counters=no}
Disabling auto compaction
63736.96 tps ( 59.4 allocs/op, 16.4 logallocs/op, 14.3 tasks/op, 49667 insns/op, 19924 cycles/op, 0 errors)
64109.41 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 49992 insns/op, 20084 cycles/op, 0 errors)
56950.47 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 50005 insns/op, 20501 cycles/op, 0 errors)
44858.42 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 50014 insns/op, 21947 cycles/op, 0 errors)
28592.87 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 50027 insns/op, 27659 cycles/op, 0 errors)
throughput:
mean= 51649.63 standard-deviation=15059.74
median= 56950.47 median-absolute-deviation=12087.33
maximum=64109.41 minimum=28592.87
instructions_per_op:
mean= 49941.18 standard-deviation=153.76
median= 50005.24 median-absolute-deviation=73.01
maximum=50027.07 minimum=49667.05
cpu_cycles_per_op:
mean= 22023.01 standard-deviation=3249.92
median= 20500.74 median-absolute-deviation=1938.76
maximum=27658.75 minimum=19924.32
```
After (write path)
```
enable-cache=1
Running test with config: {partitions=10000, concurrency=100, mode=write, query_single_key=no, counters=no}
Disabling auto compaction
53395.93 tps ( 59.4 allocs/op, 16.5 logallocs/op, 14.3 tasks/op, 50326 insns/op, 21252 cycles/op, 0 errors)
46527.83 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 50704 insns/op, 21555 cycles/op, 0 errors)
55846.30 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 50731 insns/op, 21060 cycles/op, 0 errors)
55669.30 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 50735 insns/op, 21521 cycles/op, 0 errors)
52130.17 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 50757 insns/op, 21334 cycles/op, 0 errors)
throughput:
mean= 52713.91 standard-deviation=3795.38
median= 53395.93 median-absolute-deviation=2955.40
maximum=55846.30 minimum=46527.83
instructions_per_op:
mean= 50650.57 standard-deviation=182.46
median= 50731.38 median-absolute-deviation=84.09
maximum=50756.62 minimum=50325.87
cpu_cycles_per_op:
mean= 21344.42 standard-deviation=202.86
median= 21334.00 median-absolute-deviation=176.37
maximum=21554.61 minimum=21060.24
```
Fixes #24815
Improvement for rare corner cases. No backport required
Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
Closes scylladb/scylladb#24919
164 lines
7.2 KiB
C++
164 lines
7.2 KiB
C++
/*
|
|
* Copyright 2015-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
|
|
*/
|
|
|
|
#include "schema_mutations.hh"
|
|
#include "mutation/canonical_mutation.hh"
|
|
#include "db/schema_tables.hh"
|
|
#include "utils/hashers.hh"
|
|
#include "utils/UUID_gen.hh"
|
|
|
|
schema_mutations::schema_mutations(canonical_mutation columnfamilies,
|
|
canonical_mutation columns,
|
|
bool is_view,
|
|
std::optional<canonical_mutation> indices,
|
|
std::optional<canonical_mutation> dropped_columns,
|
|
std::optional<canonical_mutation> scylla_tables,
|
|
std::optional<canonical_mutation> view_virtual_columns,
|
|
std::optional<canonical_mutation> computed_columns)
|
|
: _columnfamilies(columnfamilies.to_mutation(is_view ? db::schema_tables::views() : db::schema_tables::tables()))
|
|
, _columns(columns.to_mutation(db::schema_tables::columns()))
|
|
, _view_virtual_columns(view_virtual_columns ? mutation_opt{view_virtual_columns.value().to_mutation(db::schema_tables::view_virtual_columns())} : std::nullopt)
|
|
, _computed_columns(computed_columns ? mutation_opt{computed_columns.value().to_mutation(db::schema_tables::computed_columns())} : std::nullopt)
|
|
, _indices(indices ? mutation_opt{indices.value().to_mutation(db::schema_tables::indexes())} : std::nullopt)
|
|
, _dropped_columns(dropped_columns ? mutation_opt{dropped_columns.value().to_mutation(db::schema_tables::dropped_columns())} : std::nullopt)
|
|
, _scylla_tables(scylla_tables ? mutation_opt{scylla_tables.value().to_mutation(db::schema_tables::scylla_tables())} : std::nullopt)
|
|
{}
|
|
|
|
void schema_mutations::copy_to(utils::chunked_vector<mutation>& dst) const {
|
|
dst.push_back(_columnfamilies);
|
|
dst.push_back(_columns);
|
|
if (_view_virtual_columns) {
|
|
dst.push_back(*_view_virtual_columns);
|
|
}
|
|
if (_computed_columns) {
|
|
dst.push_back(*_computed_columns);
|
|
}
|
|
if (_indices) {
|
|
dst.push_back(*_indices);
|
|
}
|
|
if (_dropped_columns) {
|
|
dst.push_back(*_dropped_columns);
|
|
}
|
|
if (_scylla_tables) {
|
|
dst.push_back(*_scylla_tables);
|
|
}
|
|
}
|
|
|
|
table_schema_version schema_mutations::digest(db::schema_features sf) const {
|
|
if (_scylla_tables) {
|
|
auto rs = query::result_set(*_scylla_tables);
|
|
if (!rs.empty()) {
|
|
auto&& row = rs.row(0);
|
|
auto val = row.get<utils::UUID>("version");
|
|
if (val) {
|
|
return table_schema_version(*val);
|
|
}
|
|
}
|
|
}
|
|
|
|
md5_hasher h;
|
|
|
|
if (!sf.contains<db::schema_feature::TABLE_DIGEST_INSENSITIVE_TO_EXPIRY>()) {
|
|
// Disable this feature so that the digest remains compactible with Scylla
|
|
// versions prior to this feature.
|
|
// This digest affects the table schema version calculation and it's important
|
|
// that all nodes arrive at the same table schema version to avoid needless schema version
|
|
// pulls. It used to be the case that when table schema versions were calculated on boot we
|
|
// didn't yet know all the cluster features, so we could get different table versions after reboot
|
|
// in an already upgraded cluster. However, they are now available, and if
|
|
// TABLE_DIGEST_INSENSITIVE_TO_EXPIRY is enabled, we can compute with DIGEST_INSENSITIVE_TO_EXPIRY
|
|
// enabled.
|
|
sf.remove<db::schema_feature::DIGEST_INSENSITIVE_TO_EXPIRY>();
|
|
}
|
|
|
|
db::schema_tables::feed_hash_for_schema_digest(h, _columnfamilies, sf);
|
|
db::schema_tables::feed_hash_for_schema_digest(h, _columns, sf);
|
|
if (_view_virtual_columns && !_view_virtual_columns->partition().empty()) {
|
|
db::schema_tables::feed_hash_for_schema_digest(h, *_view_virtual_columns, sf);
|
|
}
|
|
if (_computed_columns && !_computed_columns->partition().empty()) {
|
|
db::schema_tables::feed_hash_for_schema_digest(h, *_computed_columns, sf);
|
|
}
|
|
if (_indices && !_indices->partition().empty()) {
|
|
db::schema_tables::feed_hash_for_schema_digest(h, *_indices, sf);
|
|
}
|
|
if (_dropped_columns && !_dropped_columns->partition().empty()) {
|
|
db::schema_tables::feed_hash_for_schema_digest(h, *_dropped_columns, sf);
|
|
}
|
|
if (_scylla_tables) {
|
|
db::schema_tables::feed_hash_for_schema_digest(h, *_scylla_tables, sf);
|
|
}
|
|
return table_schema_version(utils::UUID_gen::get_name_UUID(h.finalize()));
|
|
}
|
|
|
|
std::optional<sstring> schema_mutations::partitioner() const {
|
|
if (_scylla_tables) {
|
|
auto rs = query::result_set(*_scylla_tables);
|
|
if (!rs.empty()) {
|
|
return rs.row(0).get<sstring>("partitioner");
|
|
}
|
|
}
|
|
return { };
|
|
}
|
|
|
|
static mutation_opt compact(const mutation_opt& m) {
|
|
if (!m) {
|
|
return m;
|
|
}
|
|
return db::schema_tables::compact_for_schema_digest(*m);
|
|
}
|
|
|
|
static mutation_opt compact(const mutation& m) {
|
|
return db::schema_tables::compact_for_schema_digest(m);
|
|
}
|
|
|
|
bool schema_mutations::operator==(const schema_mutations& other) const {
|
|
return compact(_columnfamilies) == compact(other._columnfamilies)
|
|
&& compact(_columns) == compact(other._columns)
|
|
&& compact(_view_virtual_columns) == compact(other._view_virtual_columns)
|
|
&& compact(_computed_columns) == compact(other._computed_columns)
|
|
&& compact(_indices) == compact(other._indices)
|
|
&& compact(_dropped_columns) == compact(other._dropped_columns)
|
|
&& compact(_scylla_tables) == compact(other._scylla_tables)
|
|
;
|
|
}
|
|
|
|
bool schema_mutations::live() const {
|
|
return _columnfamilies.live_row_count() > 0 || _columns.live_row_count() > 0 ||
|
|
(_view_virtual_columns && _view_virtual_columns->live_row_count() > 0) ||
|
|
(_computed_columns && _computed_columns->live_row_count() > 0);
|
|
}
|
|
|
|
bool schema_mutations::is_view() const {
|
|
return _columnfamilies.schema() == db::schema_tables::views();
|
|
}
|
|
|
|
auto fmt::formatter<schema_mutations>::format(const schema_mutations& sm, fmt::format_context& ctx) const
|
|
-> decltype(ctx.out()) {
|
|
auto out = fmt::format_to(ctx.out(), "schema_mutations{{\n");
|
|
out = fmt::format_to(out, " tables={},\n", sm.columnfamilies_mutation());
|
|
out = fmt::format_to(out, " scylla_tables={},\n", sm.scylla_tables());
|
|
out = fmt::format_to(out, " tables={},\n", sm.columns_mutation());
|
|
out = fmt::format_to(out, " dropped_columns={},\n", sm.dropped_columns_mutation());
|
|
out = fmt::format_to(out, " indices={},\n", sm.indices_mutation());
|
|
out = fmt::format_to(out, " computed_columns={},\n", sm.computed_columns_mutation());
|
|
out = fmt::format_to(out, " view_virtual_columns={},\n", sm.view_virtual_columns_mutation());
|
|
return fmt::format_to(out, "}}");
|
|
}
|
|
|
|
schema_mutations& schema_mutations::operator+=(schema_mutations&& sm) {
|
|
_columnfamilies += std::move(sm._columnfamilies);
|
|
_columns += std::move(sm._columns);
|
|
apply(_computed_columns, std::move(sm._computed_columns));
|
|
apply(_view_virtual_columns, std::move(sm._view_virtual_columns));
|
|
apply(_indices, std::move(sm._indices));
|
|
apply(_dropped_columns, std::move(sm._dropped_columns));
|
|
apply(_scylla_tables, std::move(sm._scylla_tables));
|
|
return *this;
|
|
}
|