Repository navigation
adapter: notice when single-replica sources meet multiple replicas - #38139
Conversation
cb0fef6 to
9c1e1ce
Compare
martykulma
left a comment
There was a problem hiding this comment.
Thanks @ggevay! I only had minor comments, nothing blocking!
| /// sources that run on only one replica. Call after a command that added a | ||
| /// replica or such a source. | ||
| pub(crate) fn notify_single_replica_sources(&self, session: &Session, cluster: &Cluster) { | ||
| if cluster.replicas().count() <= 1 { |
There was a problem hiding this comment.
Probably worth a note that this includes replicas in the pending state. If someone runs ALTER CLUSTER to change the replica size and during the replica change, run CREATE SOURCE against that cluster, my understanding is they will see the NOTICE.
There was a problem hiding this comment.
Good point, and we went one step further: rather than noting the behavior, the decision now excludes reconfiguration replicas entirely. For managed clusters the check counts the replication factor (taking the target of an in-progress reconfiguration over the realized one) plus INTERNAL/BILLED AS replicas, instead of counting replicas. That excludes the hydrate-overlap replicas of both mechanisms, the legacy graceful alter (which marks them pending) and the cluster controller (which creates them as ordinary replicas of the target shape), so a CREATE SOURCE during a resize no longer warns spuriously.
| if cluster.replicas().count() <= 1 { | ||
| return; | ||
| } | ||
| let sources = self.single_replica_source_names(cluster); |
There was a problem hiding this comment.
Should we cap the length of sources here? If the customer had 20 sources on a cluster, this is a long notice.
There was a problem hiding this comment.
Done, the message now lists at most 3 sources and appends ", and N more" beyond that.
| .filter(|id| { | ||
| self.catalog().get_entry(id).source().is_some_and(|source| { | ||
| match &source.data_source { | ||
| DataSourceDesc::Ingestion { desc, .. } | ||
| | DataSourceDesc::OldSyntaxIngestion { desc, .. } => { | ||
| desc.connection.prefers_single_replica() | ||
| } | ||
| _ => false, | ||
| } | ||
| }) | ||
| }) | ||
| .map(|id| { | ||
| let name = self.catalog().get_entry(id).name(); | ||
| self.catalog().resolve_full_name(name, None).to_string() | ||
| }) |
There was a problem hiding this comment.
nit: could merge these into a filter_map, since these both rely on self.catalog().get_entry(id).
def-
left a comment
There was a problem hiding this comment.
Added a failing test, notice seems to be missing:
diff --git a/test/pg-cdc/mzcompose.py b/test/pg-cdc/mzcompose.py
index 8c4447e35a..ec7bddea04 100644
--- a/test/pg-cdc/mzcompose.py
+++ b/test/pg-cdc/mzcompose.py
@@ -364,6 +364,7 @@ def workflow_single_replica_source_notice(
cur.execute("DROP CLUSTER IF EXISTS c1 CASCADE")
cur.execute("DROP CLUSTER IF EXISTS c2 CASCADE")
cur.execute("DROP CLUSTER IF EXISTS c3 CASCADE")
+ cur.execute("DROP CLUSTER IF EXISTS c4 CASCADE")
notices.clear()
cur.execute("CREATE SECRET pgpass AS 'postgres'")
@@ -416,6 +417,20 @@ def workflow_single_replica_source_notice(
)
expect_notice(notices, "c2", '"materialize.public.src2"')
+ # Creating such a source in a DDL transaction uses the staged
+ # catalog when deciding which sources to include in the notice.
+ cur.execute(
+ f"CREATE CLUSTER c4 (SIZE '{size}', REPLICATION FACTOR 2)".encode()
+ )
+ expect_no_notice(notices)
+ cur.execute("BEGIN")
+ cur.execute(
+ "CREATE SOURCE src4 IN CLUSTER c4 "
+ "FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source')"
+ )
+ cur.execute("COMMIT")
+ expect_notice(notices, "c4", '"materialize.public.src4"')
+
# Adding a replica to an unmanaged cluster with such a source emits
# the notice.
cur.execute(f"CREATE CLUSTER c3 REPLICAS (r1 (SIZE '{size}'))".encode())Running bin/mzcompose --find pg-cdc run single-replica-source-notice:
==> mzcompose: test case workflow-single-replica-source-notice failed: builtins.AssertionError: expected notice 'cluster "c4" has more than one replica, but the following sources in it always run on only the first replica: "materialize.public.src4"' in []
Traceback (most recent call last):
File "/home/deen/git/materialize3/misc/python/materialize/mzcompose/composition.py", line 733, in test_case
yield
File "/home/deen/git/materialize3/misc/python/materialize/cli/mzcompose.py", line 868, in handle_composition
composition.workflow(
~~~~~~~~~~~~~~~~~~~~^
workflow_name, *args.unknown_subargs[1:], *extra_args
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/home/deen/git/materialize3/misc/python/materialize/mzcompose/composition.py", line 615, in workflow
func(self, parser)
~~~~^^^^^^^^^^^^^^
File "/home/deen/git/materialize3/test/pg-cdc/mzcompose.py", line 432, in workflow_single_replica_source_notice
expect_notice(notices, "c4", '"materialize.public.src4"')
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/deen/git/materialize3/test/pg-cdc/mzcompose.py", line 347, in expect_notice
expected in collected
AssertionError: expected notice 'cluster "c4" has more than one replica, but the following sources in it always run on only the first replica: "materialize.public.src4"' in []
Emit a pgwire notice whenever a command puts a cluster in a state where it has more than one replica while containing sources that run on only one replica (PostgreSQL, MySQL, SQL Server): raising the replication factor of a cluster with such a source, adding a replica to it, or creating such a source on a cluster that already has multiple replicas. The extra replicas do not make these sources more fault tolerant and do not increase their ingestion throughput, so call that out. Tested by a new pg-cdc mzcompose workflow that captures notices over pgwire and checks all three directions plus negative cases. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018LtD2Q4pdLfPiSHSsR6YAN
Count the replication factor plus INTERNAL and BILLED AS replicas instead of counting replicas for managed clusters, so the hydrate-overlap replicas of an in-progress reconfiguration do not trigger the notice. Include the created source in the notice explicitly, fixing the missing notice when CREATE SOURCE is staged in a DDL transaction. List at most 3 sources in the notice message. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018LtD2Q4pdLfPiSHSsR6YAN
33af171 to
21dbd05
Compare
|
@def- Thanks for the failing test! Fixed: the notice now carries the name of the source being created explicitly instead of relying on it being visible in the catalog, so the staged-in-a-DDL-transaction case emits it too. Adopted your test scenario. |
A size-only reshape and a CREATE SOURCE during its overlap emit no spurious notice, and a shape change combined with a replication factor raise emits the notice via the reconfiguration path. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018LtD2Q4pdLfPiSHSsR6YAN
|
Thank you for the reviews! |
Emit a pgwire notice whenever a command puts a cluster in a state where it has more than one replica while containing sources that run on only one replica (PostgreSQL, MySQL, SQL Server): raising the replication factor of a cluster with such a source, adding a replica to it, or creating such a source on a cluster that already has multiple replicas. The extra replicas do not make these sources more fault tolerant and do not increase their ingestion throughput, so call that out.
Tested by a new pg-cdc mzcompose workflow that captures notices over pgwire and checks all three directions plus negative cases.
Motivation: incident-1223
Example