Module mz_catalog::durable::upgrade
source · Expand description
This module contains all the helpers and code paths for upgrading/migrating the Catalog
.
We facilitate migrations by keeping snapshots of the objects we previously stored, and relying
entirely on these snapshots. These snapshots exist in the mz_catalog_protos
crate in the
form of catalog-protos/protos/objects_vXX.proto
. By maintaining and relying on snapshots we
don’t have to worry about changes elsewhere in the codebase effecting our migrations because
our application and serialization logic is decoupled, and the objects of the Catalog for a
given version are “frozen in time”.
Note: The protobuf snapshot files themselves live in a separate crate because it takes a relatively significant amount of time to codegen and build them. By placing them in a separate crate we don’t have to pay this compile time cost when building the catalog, allowing for faster iteration.
You cannot make any changes to the following message or anything that they depend on:
- Config
- Setting
- FenceToken
- AuditLog
When you want to make a change to the Catalog
you need to follow these steps:
- Check the current
CATALOG_VERSION
, make sure anobjects_v<CATALOG_VERSION>.proto
file exists. If one doesn’t, copy and paste the currentobjects.proto
file, renaming it toobjects_v<CATALOG_VERSION>.proto
. - Bump
CATALOG_VERSION
by one. - Make your changes to
objects.proto
. - Copy and paste
objects.proto
, naming the copyobjects_v<CATALOG_VERSION>.proto
. Update the package name of the.proto
topackage objects_v<CATALOG_VERSION>;
- We should now have a copy of the protobuf objects as they currently exist, and a copy of
how we want them to exist. For example, if the version of the Catalog before we made our
changes was 15, we should now have
objects_v15.proto
andobjects_v16.proto
. - Rebuild Materialize which will error because the hashes stored in
src/catalog-protos/protos/hashes.json
have now changed. Update these to match the new hashes for objects.proto andobjects_v<CATALOG_VERSION>.proto
. - Add
v<CATALOG_VERSION>
to the call to theobjects!
macro in this file, and to theproto_objects!
macro in themz_catalog_protos
crate. - Add a new file to
catalog/src/durable/upgrade
which is where we’ll put the new migration path. - Write upgrade functions using the two versions of the protos we now have, e.g.
objects_v15.proto
andobjects_v16.proto
. In this migration code you should not import any defaults or constants from elsewhere in the codebase, because then a future change could then impact a previous migration. - Add an import for your new module to this file: mod v<CATALOG_VERSION-1>_to_v<CATALOG_VERSION>;
- Call your upgrade function in
run_upgrade()
. - Generate a test file for the new version:
ⓘ
cargo test --package mz-catalog --lib durable::upgrade::tests::generate_missing_encodings -- --ignored
When in doubt, reach out to the Surfaces team, and we’ll be more than happy to help :)
Modules§
Macros§
- objects 🔒
Enums§
- Describes a single action to take during a migration from
V1
toV2
.
Constants§
- The current version of the
Catalog
. The current version of theCatalog
. - The minimum
Catalog
version number that we support migrating from. The minimumCatalog
version number that we support migrating from.
Functions§
- Determines which upgrade to run for the
version
and executes it. - Runs
migration_logic
on the contents of the current catalog assuming a current version ofcurrent_version
. - upgrade 🔒Upgrades the data in the catalog to version
CATALOG_VERSION
. - Generates a
proto::StateUpdateKind
to update the user version.