hello-stephen commented on code in PR #71298:
URL: https://github.com/apache/doris/pull/71298#discussion_r4797133476


##########
fe/fe-core/src/main/java/org/apache/doris/tablefunction/CdcStreamTableValuedFunction.java:
##########
@@ -223,24 +255,33 @@ private void generateFileStatus() {
 
     @Override
     public List<Column> getTableColumns() throws AnalysisException {
-        DataSourceType dataSourceType =
-                
DataSourceType.valueOf(processedParams.get(DataSourceConfigKeys.TYPE).toUpperCase());
-        JdbcClient jdbcClient = 
StreamingJobUtils.getJdbcClient(dataSourceType, processedParams);
+        DataSourceType sourceType = DataSourceType.valueOf(
+                processedParams.get(DataSourceConfigKeys.TYPE).toUpperCase());
         try {
-            String database = 
StreamingJobUtils.getRemoteDbName(dataSourceType, processedParams);
-            String table = processedParams.get(DataSourceConfigKeys.TABLE);
-            if (!jdbcClient.isTableExist(database, table)) {
-                throw new AnalysisException("Table does not exist: " + table);
+            String computeGroup = Config.isCloudMode() ? 
ConnectContext.get().getCloudCluster() : null;
+            List<CdcTableSchema> tables = 
StreamingJobUtils.getTableSchemas(sourceType, processedParams,

Review Comment:
   [P2] Resolve the CDC schema before taking planner table locks
   
   For `INSERT INTO target SELECT … FROM cdc_stream(...)`, `NereidsPlanner` 
takes the OLAP target's read lock before analysis, and 
`LogicalTVFRelation.computeOutput()` reaches this lookup while the lock is 
held. The new synchronous call can wait for CDC client startup and the heavy 
RPC deadline on one BE. A stalled BE can therefore hold up DDL on the target 
for minutes even when the upstream JDBC source is healthy, a dependency the old 
direct lookup did not have. Preload and reuse the schema before taking the 
planner locks, as the planner does for other external metadata.



##########
fe/fe-core/src/main/java/org/apache/doris/tablefunction/CdcStreamTableValuedFunction.java:
##########
@@ -61,13 +63,42 @@ public class CdcStreamTableValuedFunction extends 
ExternalFileTableValuedFunctio
     private final boolean includeDeleteSign;
 
     public CdcStreamTableValuedFunction(Map<String, String> properties) throws 
AnalysisException {
+        this(properties, ConnectContext.get() == null || 
!ConnectContext.get().getState().isInternal());
+    }
+
+    /** ALTER may reuse an unchanged URL after checking source identity. */
+    public CdcStreamTableValuedFunction(Map<String, String> properties, 
boolean validateJdbcUrl)
+            throws AnalysisException {
+        properties = 
StreamingJobUtils.normalizeSourceTableProperties(properties);
         validateProperties(properties);
+        if (validateJdbcUrl) {
+            try {
+                StreamingJdbcUrlNormalizer.validate(DataSourceType.valueOf(
+                        
properties.get(DataSourceConfigKeys.TYPE).toUpperCase(java.util.Locale.ROOT)),
+                        properties.get(DataSourceConfigKeys.JDBC_URL));
+            } catch (IllegalArgumentException e) {
+                throw new AnalysisException(e.getMessage());
+            }
+        }
         includeDeleteSign = 
Boolean.parseBoolean(properties.getOrDefault(INCLUDE_DELETE_SIGN, "false"));
         processProps(properties);
     }
 
     private void processProps(Map<String, String> properties) throws 
AnalysisException {
-        Map<String, String> copyProps = new HashMap<>(properties);
+        Map<String, String> copyProps;
+        try {
+            copyProps = new HashMap<>(properties);
+            String certificate = 
properties.get(DataSourceConfigKeys.SSL_ROOTCERT);
+            if (certificate != null) {
+                var database = Env.getCurrentEnv().getInternalCatalog()
+                        .getDbNullable(ConnectContext.get().getDatabase());
+                Preconditions.checkNotNull(database,
+                        "A current database is required to resolve 
ssl_rootcert");
+                copyProps = 
StreamingJobUtils.convertCertFile(database.getId(), properties);

Review Comment:
   [P2] Pass the FE address to the CDC TVF scan
   
   This resolves `ssl_rootcert` into a file reference for both discovery and 
the scan. Discovery sends the FE address in `GetTableSchemasRequest`, but 
`generateParams()` leaves it out of `FetchRecordRequest`. The scan planner can 
choose a different BE from discovery. On a fresh scan BE, the CDC client then 
rejects the file reference because `SmallFileMgr` has no FE address, even 
though discovery succeeded. Put the trusted FE address in the scan request and 
cover a query where discovery and scanning use different BEs.



##########
fs_brokers/cdc_client/src/test/java/org/apache/doris/cdcclient/itcase/MockDorisServer.java:
##########
@@ -113,9 +113,12 @@ private void handle(HttpExchange exchange) throws 
IOException {
                             + String.join(",", properties)
                             + "]}}";
         } else if (path.equals("/api/streaming/schema_change")) {
-            // FE schema-change endpoint: body is {"stmt":"<DDL>"}
+            // Mirror the structured schema-change endpoint.
             JsonNode node = MAPPER.readTree(body);
-            executedDdls.add(node.path("stmt").asText(""));
+            org.apache.doris.job.cdc.request.AlterTableRequest change = 
MAPPER.treeToValue(node,
+                    org.apache.doris.job.cdc.request.AlterTableRequest.class);
+            String description = 
org.apache.doris.cdcclient.utils.SchemaChangeTestUtils.describe(change, 
"doris_db");

Review Comment:
   [P2] Preserve the target database in the vector integration fixture
   
   The mock now records every structured DDL request under `doris_db`. The 
existing `MySqlVectorITCase` initializes its harness with `doris_target_db` and 
asserts the exact qualified ADD COLUMN statement, so it fails even when the 
request is correct. Have the harness supply its target database to the mock, or 
assert the structured request in this test and keep database routing assertions 
in the FE test.



##########
fe/fe-core/src/main/java/org/apache/doris/job/util/CdcSchemaClient.java:
##########
@@ -0,0 +1,176 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.job.util;
+
+import org.apache.doris.catalog.Env;
+import org.apache.doris.cloud.catalog.CloudEnv;
+import org.apache.doris.common.Config;
+import org.apache.doris.job.cdc.CdcColumn;
+import org.apache.doris.job.cdc.CdcTableSchema;
+import org.apache.doris.job.cdc.DataSourceConfigKeys;
+import org.apache.doris.job.cdc.request.GetTableSchemasRequest;
+import org.apache.doris.job.cdc.response.GetTableSchemasResult;
+import org.apache.doris.job.exception.JobException;
+import org.apache.doris.proto.InternalService;
+import org.apache.doris.rpc.BackendServiceProxy;
+import org.apache.doris.system.Backend;
+import org.apache.doris.thrift.TNetworkAddress;
+import org.apache.doris.thrift.TStatusCode;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+/** Fetches source schemas through a BE and its CDC client; FE does not 
connect to the source. */
+public final class CdcSchemaClient {
+    private static final ObjectMapper MAPPER = new ObjectMapper();
+
+    private CdcSchemaClient() {
+    }
+
+    public static List<CdcTableSchema> getTableSchemas(GetTableSchemasRequest 
request,
+            String computeGroup) throws JobException {
+        if (Config.isCloudMode()) {
+            if (StringUtils.isBlank(computeGroup)) {
+                throw new JobException("compute_group is required for source 
schema inspection");
+            }
+            try {
+                ((CloudEnv) 
Env.getCurrentEnv()).checkCloudClusterPriv(computeGroup);
+            } catch (Exception e) {
+                throw new JobException("No access to compute_group: " + 
computeGroup, e);
+            }
+        }
+        Backend backend = StreamingJobUtils.selectBackend(computeGroup);

Review Comment:
   [P2] Use TVF scan backend eligibility for schema discovery
   
   Outside cloud mode, this call goes through the global load-available backend 
pool, while `TVFScanNode` restricts the scan to the session user's resource 
group. If the FE and the user's tagged BEs can reach the source but a BE 
outside that group cannot, an existing TVF query can now fail during schema 
discovery whenever the unrelated BE is selected, even on a fully upgraded 
cluster. Use the TVF's eligible query backends for discovery and cover separate 
resource tags in the routing test.



##########
regression-test/data/job_p0/streaming_job/cdc/test_streaming_mysql_type_contract.out:
##########
@@ -0,0 +1,61 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !initial_types --
+id     int(11)
+doc    json
+amount decimalv3(20, 6)
+event_time     datetime(6)
+unsigned_value largeint
+p38    decimalv3(38, 6)
+p39    string
+u37    decimalv3(38, 6)
+u38    string
+time_default   datetime
+c85    char(255)
+c86    varchar(258)
+v21844 varchar(65532)
+v21845 string
+
+-- !snapshot_values --
+1      1       12345678901234.123456   2026-01-02 03:04:05.123456      
18446744073709551615
+
+-- !tvf_types --

Review Comment:
   [P2] Regenerate the contract goldens in assertion order
   
   The MySQL suite calls `qt_snapshot_boundaries` before `qt_tvf_types`, but 
this file stores the blocks in the opposite order. The PostgreSQL suite has the 
same problem with `qt_numeric_nullability` and `qt_tvf_types`. 
`OutputBlocksIterator.hasNextTagBlock()` consumes skipped blocks and cannot 
rewind, so both suites will later report a missing `tvf_types` block even if 
every query result is correct. Regenerate both result files with the current 
suites.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to