Repository navigation
adapter: keep catalog upper up-to-date with read ts - #35402
Conversation
|
Thanks for opening this PR! Here are a few tips to help make the review process smooth for everyone. PR title guidelines
Pre-merge checklist
|
1f6f633 to
62ea854
Compare
| /// | ||
| /// Panics if not in `Writable` mode. | ||
| /// Panics if `next_upper` is not greater than `self.upper`. | ||
| async fn compare_and_append_inner( |
There was a problem hiding this comment.
Split out from compare_and_append so that we can also call it from advance_upper. In advance_upper, we don't need to sync the catalog afterwards, so calling compare_and_append would be needlessly expensive.
This commit introduces a way to advance the frontier of the catalog shard without appending any new updates and then uses that to keep the catalog shard's frontier up to date with the oracle read ts. This ensures that `mz_catalog_raw` is always readable with strict serializable isolation, since under that isolation level, the oracle read ts will be used as the query timestamp. This increases the amount of CRDB queries we make, instead of bumping only the txn-wal, we now additionally need to bump the catalog shard. But note that in two of the three instances the `advance_upper` call replaces a `confirm_leadership` call, which also did a CRDB query, so one can hope that the resulting number of CRDB calls is similar. This could potentially be further improved by moving the catalog shard into txn-wal, but that's a larger lift so we leave it as future work.
62ea854 to
903cecc
Compare
mtabebe
left a comment
There was a problem hiding this comment.
Change lgtm, mostly questions
| // read_ts do not block waiting for the catalog shard's upper to advance. | ||
| let catalog_upper_start = Instant::now(); | ||
| self.catalog | ||
| .advance_upper(advance_to) |
There was a problem hiding this comment.
So my understanding is that instead of just confirming leadership, we know also advance the upper which ends up being a write, even if there are no changes? Which is really the goal of this whole PR, so that it ensures strict serializability.
What is the performance trade-off of this? Or was it an incorrect behaviour before?
There was a problem hiding this comment.
It wasn't incorrect before when the catalog was not queryable. Before we didn't actually care about the timestamps used for the catalog shard, they could have just been a counter. I guess we decided to use the timestamp oracle for it instead, in preparation for making it queryable later, which saves me a lot of work now!
As to the performance impact, I hope it to be small. We are trading one database call with another. Before we had to fetch the current frontier of the catalog shard, which afaict amounts to running (a consensus "scan"):
SELECT sequence_number, data FROM consensus
WHERE shard = $1 AND sequence_number >= $2
ORDER BY sequence_number ASC LIMIT $3
Now we do a consensus compare-and-set, which translates to:
INSERT INTO consensus (shard, sequence_number, data)
SELECT $1, $2, $3
WHERE (SELECT sequence_number FROM consensus
WHERE shard = $1
ORDER BY sequence_number DESC LIMIT 1) = $4
The compare-and-set query is certainly more expensive than the scan query, so there will be some impact, a couple milliseconds. If that turns out to be too much, we can consider moving the compare-and-append off the coordinator thread, though we might have to re-introduce the confirm_leadership call then.
| async fn advance_upper(&mut self, new_upper: Timestamp) -> Result<(), CatalogError> { | ||
| if self.upper >= new_upper { | ||
| // We don't expect a no-op advancement, but if we are wrong we'd crash the process. | ||
| // Seems safer to only soft-assert and return gracefully in production. If we get here |
There was a problem hiding this comment.
Makes sense to gracefully introduce this assertion 👍
| simple conn=mz_system,user=mz_system | ||
| SET transaction_isolation = serializable; | ||
| SELECT data->'value'->>'name' FROM mz_internal.mz_catalog_raw WHERE data->>'kind' = 'Item' AND data->'value'->>'name' = 't'; | ||
| SELECT data->'value'->>'name' |
There was a problem hiding this comment.
Ah ok, so previously this was legal, and now it isn't.
Out of curiosity, if you tried to do this with serializable, what would happen? Do we expect to throw an error. Just silently act strictly serializable?
There was a problem hiding this comment.
It's still legal to query with serializable isolation! It's just not necessary anymore. Previously the frontier of mz_catalog_raw didn't advance with time, so queries with strict serializable isolation would hang until some catalog change happened, advancing the frontier to a current time. Now they work.
In tests strict serializable isolation is preferable since serializable is allowed to give you any past result, which could lead to flaky tests. For example, when creating a new table, and then querying mz_catalog_raw with serializable isolation afterwards, the new table isn't guaranteed to show up. It is guaranteed to show up with strict serializable though.
|
TFTRs! |
…5402) This PR introduces a way to advance the frontier of the catalog shard without appending any new updates and then uses that to keep the catalog shard's frontier up to date with the oracle read ts. This ensures that `mz_catalog_raw` is always readable with strict serializable isolation, since under that isolation level, the oracle read ts will be used as the query timestamp. This increases the amount of CRDB queries we make, instead of bumping only the txn-wal, we now additionally need to bump the catalog shard. But note that in two of the three instances the `advance_upper` call replaces a `confirm_leadership` call, which also did a CRDB query, so one can hope that the resulting number of CRDB calls is similar. This could potentially be further improved by moving the catalog shard into txn-wal, but that's a larger lift so we leave it as future work. ### Motivation Closes SQL-117
Review of MaterializeInc#38399 found several claims that no longer match the code: - The `allow_writes_in_read_only` tripwire falls back to a no-op, which now blocks promotion rather than leaving a cold collection at cut-over, and the storage-side check it points at is a hard assert, not a soft panic with a fallback. Say both, and say why compute is deliberately softer. - Exclusive ownership of a replacement shard holds per (build version, deploy generation), not per process. Two read-only processes of one generation both write the shard, the same shape as a multi-replica MV, which the self-correcting persist sink is built to tolerate. - The replica-side handler enables persist compaction process-wide, which this path is the first thing to trigger inside a read-only deployment. - "Replacement" meant two unrelated things three lines apart in `bootstrap`: user `REPLACEMENT FOR` DDL and the builtin-migration mechanism. The sets are disjoint, so this is wording only. - Record why a *new* builtin MV cannot be write-enabled the same way: its shard allocation lives only in the read-only savepoint, so the promoted leader allocates a different shard. - Cite PR MaterializeInc#35402 for the v26.17 leader floor, and note in `caught_up.rs` that a future `Replacement` of `mz_cluster_replica_frontiers` would make the gate read its own frontiers. The design doc stated the force-write unconditionally; give the two conditions and the exclude-from-gate fallback. Co-Authored-By: Claude Opus 5 <[email protected]>
Review of MaterializeInc#38399 found several claims that no longer match the code: - The `allow_writes_in_read_only` tripwire falls back to a no-op, which now blocks promotion rather than leaving a cold collection at cut-over, and the storage-side check it points at is a hard assert, not a soft panic with a fallback. Say both, and say why compute is deliberately softer. - Exclusive ownership of a replacement shard holds per (build version, deploy generation), not per process. Two read-only processes of one generation both write the shard, the same shape as a multi-replica MV, which the self-correcting persist sink is built to tolerate. - The replica-side handler enables persist compaction process-wide, which this path is the first thing to trigger inside a read-only deployment. - "Replacement" meant two unrelated things three lines apart in `bootstrap`: user `REPLACEMENT FOR` DDL and the builtin-migration mechanism. The sets are disjoint, so this is wording only. - Record why a *new* builtin MV cannot be write-enabled the same way: its shard allocation lives only in the read-only savepoint, so the promoted leader allocates a different shard. - Cite PR MaterializeInc#35402 for the v26.17 leader floor, and note in `caught_up.rs` that a future `Replacement` of `mz_cluster_replica_frontiers` would make the gate read its own frontiers. The design doc stated the force-write unconditionally; give the two conditions and the exclude-from-gate fallback. Co-Authored-By: Claude Opus 5 <[email protected]>
Review of MaterializeInc#38399 found several claims that no longer match the code: - The `allow_writes_in_read_only` tripwire falls back to a no-op, which now blocks promotion rather than leaving a cold collection at cut-over, and the storage-side check it points at is a hard assert, not a soft panic with a fallback. Say both, and say why compute is deliberately softer. - Exclusive ownership of a replacement shard holds per (build version, deploy generation), not per process. Two read-only processes of one generation both write the shard, the same shape as a multi-replica MV, which the self-correcting persist sink is built to tolerate. - The replica-side handler enables persist compaction process-wide, which this path is the first thing to trigger inside a read-only deployment. - "Replacement" meant two unrelated things three lines apart in `bootstrap`: user `REPLACEMENT FOR` DDL and the builtin-migration mechanism. The sets are disjoint, so this is wording only. - Record why a *new* builtin MV cannot be write-enabled the same way: its shard allocation lives only in the read-only savepoint, so the promoted leader allocates a different shard. - Cite PR MaterializeInc#35402 for the v26.17 leader floor, and note that forcing the replacement mechanism across all builtins, as the 0dt tests do, leaves the caught-up gate reading its own frontiers. The design doc stated the force-write unconditionally; give the two conditions and the exclude-from-gate fallback. Co-Authored-By: Claude Opus 5 <[email protected]>
Review of MaterializeInc#38399 found several claims that no longer match the code: - The `allow_writes_in_read_only` tripwire falls back to a no-op, which now blocks promotion rather than leaving a cold collection at cut-over, and the storage-side check it points at is a hard assert, not a soft panic with a fallback. Say both, and say why compute is deliberately softer. - Exclusive ownership of a replacement shard holds per (build version, deploy generation), not per process. Two read-only processes of one generation both write the shard, the same shape as a multi-replica MV, which the self-correcting persist sink is built to tolerate. - The replica-side handler enables persist compaction process-wide, which this path is the first thing to trigger inside a read-only deployment. - "Replacement" meant two unrelated things three lines apart in `bootstrap`: user `REPLACEMENT FOR` DDL and the builtin-migration mechanism. The sets are disjoint, so this is wording only. - Record why a *new* builtin MV cannot be write-enabled the same way: its shard allocation lives only in the read-only savepoint, so the promoted leader allocates a different shard. - Cite PR MaterializeInc#35402 for the v26.17 leader floor, and note that forcing the replacement mechanism across all builtins, as the 0dt tests do, leaves the caught-up gate reading its own frontiers. The design doc stated the force-write unconditionally; give the two conditions and the exclude-from-gate fallback. Co-Authored-By: Claude Opus 5 <[email protected]>
- Seed the caught-up gate's transitive-dependent walk from all of `new_builtin_collections`, not just the MVs, and require the write frontier to be within the allowed lag of `now` on the no-live-frontier path so a hydrated-then-stalled collection no longer passes the gate forever. - Document the `enable_0dt_hydrate_migrated_builtin_mvs` break-glass flag: it is read once at startup, so flipping it means changing the setting on the leader and restarting, and it is not an exact revert. - Correct the read-only write-enable comments to match the code: the `allow_writes_in_read_only` tripwire blocks promotion, exclusive shard ownership holds per (build version, deploy generation), a new builtin MV cannot be write-enabled, and cite PR MaterializeInc#35402 for the v26.17 leader floor.
- Seed the caught-up gate's transitive-dependent walk from all of `new_builtin_collections`, not just the MVs, and require the write frontier to be within the allowed lag of `now` on the no-live-frontier path so a hydrated-then-stalled collection no longer passes the gate forever. - Document the `enable_0dt_hydrate_migrated_builtin_mvs` break-glass flag: it is read once at startup, so flipping it means changing the setting on the leader and restarting, and it is not an exact revert. - Correct the read-only write-enable comments to match the code: the `allow_writes_in_read_only` tripwire blocks promotion, exclusive shard ownership holds per (build version, deploy generation), a new builtin MV cannot be write-enabled, and cite PR MaterializeInc#35402 for the v26.17 leader floor.
This PR introduces a way to advance the frontier of the catalog shard without appending any new updates and then uses that to keep the catalog shard's frontier up to date with the oracle read ts. This ensures that
mz_catalog_rawis always readable with strict serializable isolation, since under that isolation level, the oracle read ts will be used as the query timestamp.This increases the amount of CRDB queries we make, instead of bumping only the txn-wal, we now additionally need to bump the catalog shard. But note that in two of the three instances the
advance_uppercall replaces aconfirm_leadershipcall, which also did a CRDB query, so one can hope that the resulting number of CRDB calls is similar.This could potentially be further improved by moving the catalog shard into txn-wal, but that's a larger lift so we leave it as future work.
Motivation
Closes SQL-117