Repository navigation
feat(transaction): add ReplaceTableAction for REPLACE TABLE - #3778
xanderbailey wants to merge 5 commits into
Conversation
Replaces the schema, partition spec and sort order through build_replacement and asserts the base it replaced, including main, so the first-requirement rule drops the main assertion of the append that adds the new contents. staged_table gives writers the replaced schema and spec. A retry recomputes the replacement against the refreshed table and fails without retrying if the table was recreated or the ids would differ from the staged table. Part of apache#3056.
Retries send the replacement computed against the transaction's table instead of recomputing it, so concurrent column drops no longer change its ids. Like Java, it resets main, the current schema, default spec and default sort order when the staged changes leave them out, and fails if the last assigned column or partition ids moved. Unlike Java, it also fails when the catalog would renumber the staged spec or sort order.
| let staged = self.replace(original)?; | ||
| let sets = |matches: fn(&TableUpdate) -> bool| staged.changes.iter().any(matches); | ||
| let mut updates = Vec::new(); | ||
| // main didn't exist when staged, but a concurrent commit such as a first append created it. |
There was a problem hiding this comment.
I'm normally anti-comment but i've added comments for each of these cases to make it clear what case we're covering
|
@CTTY very interested to see what you think of this setup and how it fits into your vision for the new Txn work.
|
Which issue does this PR close?
What changes are included in this PR?
Adds
Transaction::replace_table, which replaces the schema, partition spec and sort order usingbuild_replacement. Write the new data againststaged_table()and add it with a fast append in the same transaction.On retry the staged replacement is committed again, as in Java. The commit fails if the table was recreated, a concurrent change assigned new ids, or the catalog would renumber the staged spec or sort order.
Unlike the other actions,
ReplaceTableActionkeeps the table it was created from. Data files are written againststaged_table(), so the commit has to pin the replacement to that table, but on retry actions only see the refreshed one. Java has a separate replace transaction for this. Here it follows the stateful transaction RFC: the replacement is derived from that base and reused on retry behind the uuid, last assigned id and layout checks.Are these changes tested?
Yes, unit tests and
MemoryCatalogtests.AI Disclosure
Used to investigate and write tests