cdc: Handle compact storage tables correctly

When a table with compact storage has no regular column (only primary
key columns), an artificial column of type empty is added. Such column
type can't be returned via CQL so CDC Log shouldn't contain a column
that reflects this artificial column.

This patch does two things:
1. Make sure that CDC Log schema does not contain columns that reflect
   the artificial column from a base table.
2. When composing mutation to CDC Log, ommit the artificial column.

Fixes #8410

Test: unit(dev)

Signed-off-by: Piotr Jastrzebski <piotr@scylladb.com>

Closes #8988
This commit is contained in:
Piotr Jastrzebski
2021-06-25 10:11:15 +02:00
committed by Nadav Har'El
parent 2cc8c40c07
commit c010cefc4d
3 changed files with 43 additions and 0 deletions

View File

@@ -543,6 +543,12 @@ static schema_ptr create_log_schema(const schema& s, std::optional<utils::UUID>
auto add_columns = [&] (const schema::const_iterator_range_type& columns, bool is_data_col = false) {
for (const auto& column : columns) {
auto type = column.type;
if (type->get_kind() == abstract_type::kind::empty) {
if (!(s.is_dense() && s.regular_columns_count() == 1)) {
on_internal_error(cdc_log, "Unexpected column with EMPTY type");
}
continue;
}
if (is_data_col && type->is_multi_cell()) {
type = visit(*type, make_visitor(
// non-frozen lists are represented as map<timeuuid, value_type>. Otherwise we cannot express delta
@@ -1049,6 +1055,11 @@ struct process_row_visitor {
void live_atomic_cell(const column_definition& cdef, const atomic_cell_view& cell) {
_ttl_column = get_ttl(cell);
if (cdef.type->get_kind() == abstract_type::kind::empty) {
return;
}
managed_bytes value = get_managed_bytes(cell);
// delta

View File

@@ -0,0 +1,4 @@
create table tb2 (pk int, ck int, PRIMARY KEY (pk, ck)) with compact storage and cdc = {'enabled': true, 'preimage': true, 'postimage': true};
-- Should add 3 rows (preimage + postimage + delta). Delta has only key columns and "pk" + "ck"
insert into tb2 (pk, ck) VALUES (2, 22) USING TTL 2222;
select "cdc$batch_seq_no", "cdc$operation", "cdc$ttl", pk, ck from tb2_scylla_cdc_log;

View File

@@ -0,0 +1,28 @@
create table tb2 (pk int, ck int, PRIMARY KEY (pk, ck)) with compact storage and cdc = {'enabled': true, 'preimage': true, 'postimage': true};
{
"status" : "ok"
}
-- Should add 3 rows (preimage + postimage + delta). Delta has only key columns and "pk" + "ck"
insert into tb2 (pk, ck) VALUES (2, 22) USING TTL 2222;
{
"status" : "ok"
}
select "cdc$batch_seq_no", "cdc$operation", "cdc$ttl", pk, ck from tb2_scylla_cdc_log;
{
"rows" :
[
{
"cdc$batch_seq_no" : "0",
"cdc$operation" : "1",
"cdc$ttl" : "2222",
"ck" : "22",
"pk" : "2"
},
{
"cdc$batch_seq_no" : "1",
"cdc$operation" : "9",
"ck" : "22",
"pk" : "2"
}
]
}