Commit Graph

15 Commits

Author SHA1 Message Date
Michał Chojnowski
80c8a6d0e6 partition_version: make partition_entry::upgrade() gentle
Preceding commits in this patch series have extended the MVCC
mechanism to allow for versions with different schemas
in the same entry/snapshot, with on-the-fly and background
schema upgrades to the most recent version in the chain.

Given that, we can perform gentle schema upgrades by simply
adding an empty version with the target schema to the front
of the entry.

This patch is intended to be the first and only behaviour-changing patch in the
series. Previous patches added code paths for multi-schema snapshots, but never
exercised them, because before this patch two different schemas within a single
MVCC chain never happened. This patch makes it happen and thus exercises all the
code in the series up until now.

Fixes #2577
2023-05-04 03:35:15 +02:00
Michał Chojnowski
fe576f8f29 partition_version: handle multi-schema snapshots in merge_partition_versions
Each partition_version is allowed to have a different schema now.
As of this patch, all versions reachable from a snapshot/entry always
have the same schema, but this will change in an upcoming patch.
This commit prepares merge_partition_versions() for that.

See code comments added in this patch for a detailed description.

The design chosen in this patch requires adding a bit of information to
partition_version. Due to alignment, it results in a regrettable waste of 8
bytes per partition. If we want, we can recover that in the future by squeezing
the bit into some free bit in other fields, for example the highest or lowest
bits of one of the pointers in partition_version.

After this patch, MVCC should be prepared for replacing the atomic schema
upgrade() of cache/memtable entries with a gentle upgrade().
2023-05-04 03:35:15 +02:00
Michał Chojnowski
0273101890 partition_version: remove the unused "from" argument in partition_entry::upgrade()
partition_entry now contains a reference to its schema, so it doesn't have to
be supplied by the caller anymore.
2023-05-04 02:37:30 +02:00
Michał Chojnowski
db6a35e3a8 partition_version: handle multi-schema entries in partition_entry::squashed
An upcoming patch will enable multiple schemas within a single entry,
after the entry is upgraded.
partition_entry::squashed isn't prepared for that yet.
This patch prepares it.
2023-05-04 02:37:30 +02:00
Michał Chojnowski
f4e853b32d partiton_version: prepare partition_snapshot::squashed() for multi-schema snapshots
When in upcoming patches we allow multiple schema versions within a single
snapshot, reads will have to upgrade rows on the fly.
This also applies to squashed()
2023-05-04 02:37:29 +02:00
Michał Chojnowski
a2e3cf7463 partition_version: prepare partition_snapshot::static_row() for multi-schema snapshots
When in upcoming patches we allow multiple schema versions within a single
snapshot, reads will have to upgrade rows on the fly.
This also applies to the static row.
2023-05-04 02:37:29 +02:00
Michał Chojnowski
94e4dc3d8d partition_version: add a logalloc::region argument to partition_entry::upgrade()
The argument is currently unused, but will be further propagated to
add_version() in an upcoming patch.
2023-05-04 02:37:29 +02:00
Michał Chojnowski
caaf0bd6bf partition_version: remove _schema from partition_entry::operator<<
operator<< accepts a schema& and a partition_entry&. But since the latter
now contains a reference to its schema inside, the former is redundant.
Remove it.
2023-05-04 02:37:29 +02:00
Michał Chojnowski
f6e11c95e2 partition_version: remove the schema argument from partition_entry::read()
partition_entry now contains a reference to its schema, so it no longer
needs to be supplied by the caller.
2023-05-04 02:37:29 +02:00
Michał Chojnowski
d7d6449a8f partition_version: remove the _schema field from partition_snapshot
After adding a _schema field to each partition version,
the field in partition_snapshot is redundant. It can be always recovered
from the latest version. Remove it.
2023-05-04 02:37:29 +02:00
Michał Chojnowski
1d01a4a168 partition_version: add a _schema field to partition_version
Currently, partition_version does not reference its schema.
All partition_version reachable from a entry/snapshot have the same schema,
which is referenced in memtable_entry/cache_entry/partition_snapshot.

To enable gentle schema upgrades, we want to use the existing background
version merging mechanism. To achieve that, we will move the schema reference
into partition_version, and we will allow neighbouring MVCC versions to have
different schemas, and we will merge them on-the-fly during reads and
persistently during background version merges.
This way, an upgrade will boil down to adding a new empty version with
the new schema.

This patch adds the _schema field to partition_version and propagates
the schema pointer to it from the version's containers (entry/snapshot).
Subsequent patches will remove the schema references from the containers,
because they are now redundant.
2023-05-04 02:37:29 +02:00
Michał Chojnowski
781514acfe mutation_partition_v2: change schema_ptr to schema& in mutation_partition_v2 constructor
We don't have a convention for when to pass `schema_ptr` and and when to pass
`const schema&` around.
In general, IMHO the natural convention for such a situation is to pass the
shared pointer if the callee might extend the lifetime of shared_ptr,
and pass a reference otherwise. But we convert between them willy-nilly
through shared_from_this().

While passing a reference to a function which actually expects a shared_ptr
can make sense (e.g. due to the fact that smart pointers can't be passed in
registers), the other way around is rather pointless.

This patch takes one occurence of that and modifies the parameter to a reference.

Since enable_shared_from_this makes shared pointer parameters and reference
parameters interchangeable, this is a purely cosmetic change.
2023-05-04 02:37:29 +02:00
Michał Chojnowski
49a02b08de mutation_partition_v2: clean up variants of apply()
Most variants of apply() and apply_monotonically() in mutation_partition_v2
are leftovers from mutation_partition, and are unused. Thus they only
add confusion and maintenance burden. Since we will be modifying
apply_monotonically() in upcoming patches, let's clean them up, lest
the variants become stale.

This patch removes all unused variants of apply() and apply_monotonically()
and "manually inlines" the variants which aren't used often enough to carry
their own weight.

In the end, we are left with a single apply_monotonically() and two convenience
apply() helpers.

The single apply_monotonically() accepts two schema arguments. This facility
is unimplemented and unused as of this patch - the two arguments are always
the same - but it will be implemented and used in later parts of the series.
2023-05-04 02:37:29 +02:00
Kefu Chai
0cb842797a treewide: do not define/capture unused variables
these warnings are found by Clang-17 after removing
`-Wno-unused-lambda-capture` and '-Wno-unused-variable' from
the list of disabled warnings in `configure.py`.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
2023-02-15 22:57:18 +02:00
Avi Kivity
c5e4bf51bd Introduce mutation/ module
Move mutation-related files to a new mutation/ directory. The names
are kept in the global namespace to reduce churn; the names are
unambiguous in any case.

mutation_reader remains in the readers/ module.

mutation_partition_v2.cc was missing from CMakeLists.txt; it's added in this
patch.

This is a step forward towards librarization or modularization of the
source base.

Closes #12788
2023-02-14 11:19:03 +02:00