ACE Architecture and Design Documents
For information about feature design:
- For detailed information about ACE table-diff architecture, visit here.
- For detailed information about Merkle tree architecture, visit here.
Stored objects and upgrades
ACE does not upgrade the objects that it stores when it moves to a new major version: Merkle trees with their tree tables, key types and metadata, and diff results. After such an upgrade, every Merkle tree must be built again, and every diff must run again. mtree teardown drops the schema of ACE with every object in it (see Objects that ACE creates), so mtree teardown and mtree init once, then mtree build for each table, start from nothing. The schema of a release before this rule has no mark, and mtree teardown refuses it: the user removes the objects of that release by hand first, as the mtree init page describes.
So code does not read, convert or repair an object that an earlier major version stored. A new property of a stored object, such as a new index on a tree table or a new check at build time, applies only to objects that the new version builds. Code may rely on it for every object it uses, and it does not need a fallback for objects without it.
Code refuses an object of an earlier release, so that it never uses one by mistake. table-repair and table-rerun refuse a diff result by its format version. mtree update and mtree table-diff refuse a Merkle tree by its hash version and ask to build the tree again. mtree update, mtree table-diff and mtree build refuse a metadata table of an earlier release by its columns, before they change anything, and ask for mtree teardown and mtree init. A schema that a release before the rule of Objects that ACE creates created has no mark, so mtree init, mtree build, mtree update and mtree teardown refuse it, and the user removes the objects of that release by hand. A release that changes stored trees gets a hash version that no earlier release had. The version is raised once for a release, not for each change: if main already has a version that no release had, a new change does not raise it again.
This rule applies to every major version after v3.0.0. The upgrade from 2.1.x to v3.0.0 is the last one that converted Merkle trees in place (see v3.0.0 in the changelog).
Objects that ACE creates
ACE is not a PostgreSQL extension. The server knows which objects belong to an extension: DROP EXTENSION drops them and refuses when another object depends on them. ACE is a client program, so the server does not know which objects ACE created. Other ways to give the same guarantee, such as a registry of created objects, a check of each dependency before a drop, or a separate owner role that ACE switches to, make the code much more complex. ACE does not use them. It relies on two rules instead.
- ACE keeps its objects in its own schema,
mtree.schemainace.yaml.mtree initcreates this schema, marks it with a comment, and gives no privileges on it to other roles. ACE refuses a schema that exists without this comment, so this schema is never a schema of the user and neverpublic. Every object that ACE creates on a node is in this schema, except the publication and the replication slot of the CDC. Their names are stored in the schema, inace_cdc_metadata. - ACE connects with a role of its own. Applications do not use this role, and no other role is a member of it. Then only this role and a superuser can create an object that depends on an object of ACE. The user documentation lists the privileges of this role and what they do not cover (
docs/configuration.md, "The database role of ACE").
So the schema belongs to ACE. mtree teardown drops the publication and the slot, then drops the schema with CASCADE: every object in the schema goes, and every object that depends on one of them. ACE does not protect against a role that can use every schema (a superuser, pg_read_all_data, pg_write_all_data) or a member of its own role creating such objects; the user documentation names these cases. Code does not check for objects of other roles in the schema of ACE, or for objects that depend on it. A new object of ACE goes into this schema, so that mtree teardown drops it with no new code.
Data types
A column or a primary key can have a type that a user or an extension created. ACE expects such a type to follow the usual rules of PostgreSQL types:
- The input function of the type reads the text of its output function back into the same value: the value is equal to the original one, and its output is the same text.
- If the type has a cast to
text, the cast gives the same text as the output function. - If the type has a cast from
text, the cast gives the same value as the input function.
ACE does not check these rules. For a type that breaks them, a diff can report equal rows as different or miss rows that differ, and a repair can fail or write a wrong value (for a cast from text, see merkle.md). Code does not need special cases for such types. Built-in types are different: ACE handles their known exceptions, for example bpchar, whose cast to text removes trailing spaces (see the rule of equality in table_diff.md).