mcp: auto-route read_data_product to the data product's catalog cluster#36619
Conversation
ggevay
left a comment
There was a problem hiding this comment.
LGTM, just minor comments.
| // | ||
| // TODO: Remove this extra round-trip once catalog errors get specific | ||
| // SQL error codes (see TODO in src/adapter/src/error.rs `fn code()`), | ||
| // then we can translate the query error directly and drop the lookup. |
There was a problem hiding this comment.
nit: The TODO went a bit stale. Solving the error stuff now wouldn't be enough to remove this extra query.
There was a problem hiding this comment.
Good catch, removed it!
|
|
||
| // Override beats catalog; catalog beats session default. The override | ||
| // path is unchanged from before, so explicit callers are not affected | ||
| // by the auto-routing change. |
There was a problem hiding this comment.
nit: This is more a PR comment than a code comment. I'd just remove this from the code.
There was a problem hiding this comment.
Yep agreed, trimmed it down to just the precedence rule.
| "SELECT cluster FROM mz_internal.mz_mcp_data_products \ | ||
| WHERE object_name = {} \ | ||
| ORDER BY cluster NULLS LAST \ | ||
| LIMIT 1", |
There was a problem hiding this comment.
I'm wondering whether the
ORDER BY cluster NULLS LAST \
LIMIT 1
is needed. Could this even return multiple rows without the LIMIT 1? I would expect not, because object_name seems fully qualified. We could maybe soft_assert_or_log! that it has exactly 1 result row.
There was a problem hiding this comment.
So looking at the view, it joins mz_indexes and the cluster column is COALESCE(c_idx.name, c_obj.name). An MV indexed on more than one cluster would surface once per index/cluster pair, so a soft_assert for exactly 1 row would fire on that case. Does that match what you'd expect or am I missing something?
5f2b464 to
5a5a3ce
Compare
|
QA LLM review noted some issues, which I think can be considered acceptable? Since I'm not sure, posting them here in case it's helpful: MEDIUM — Auto-routing requires USAGE on the data product's home cluster, silently breaking valid RBAC patternsLocation: The new code unconditionally routes a default-cluster read to whatever cluster let target_cluster = cluster_override.or(catalog_cluster);
...
let read_query = build_read_query(&safe_name, limit, target_cluster);The catalog view In Materialize this is a normal, supported pattern:
Before this commit, So a call that previously succeeded silently degrades to a hard failure. The The PR description (DEX-27) frames this as fixing a docs/behavior mismatch, Suggested fixes (in order of preference):
LOW — Auto-routing fast-path almost never fires
So in practice the fast-path is unreachable for legitimate data products. |
Fixes https://linear.app/materializeinc/issue/DEX-27/fix-read-data-product-cluster-parameter-docs-vs-behavior-mismatch.