0AyanamiRei commented on code in PR #61325: URL: https://github.com/apache/doris/pull/61325#discussion_r3048831399
########## fe/fe-core/src/main/java/org/apache/doris/datasource/kinesis/KinesisUtil.java: ########## @@ -0,0 +1,165 @@ +// 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.datasource.kinesis; + +import org.apache.doris.catalog.Env; +import org.apache.doris.common.Config; +import org.apache.doris.common.LoadException; +import org.apache.doris.metric.MetricRepo; +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 org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +public class KinesisUtil { + private static final Logger LOG = LogManager.getLogger(KinesisUtil.class); + + /** + * Get all shard IDs for the given Kinesis stream. + * This delegates to a BE node which uses the AWS SDK to call ListShards API. + * + * @param region AWS region of the stream + * @param stream Kinesis stream name + * @param endpoint optional custom endpoint (e.g. LocalStack), empty string for default + * @param convertedCustomProperties AWS credentials and other properties + * @return list of shard IDs + */ + public static List<String> getAllKinesisShards(String region, String stream, String endpoint, + Map<String, String> convertedCustomProperties) throws LoadException { + try { + InternalService.PKinesisLoadInfo.Builder kinesisInfoBuilder = + InternalService.PKinesisLoadInfo.newBuilder() + .setRegion(region) + .setStream(stream) + .addAllProperties(convertedCustomProperties.entrySet().stream() + .map(e -> InternalService.PStringPair.newBuilder() + .setKey(e.getKey()) + .setVal(e.getValue()) + .build()) + .collect(Collectors.toList())); + if (endpoint != null && !endpoint.isEmpty()) { + kinesisInfoBuilder.setEndpoint(endpoint); + } + + InternalService.PProxyRequest request = InternalService.PProxyRequest.newBuilder() + .setKinesisMetaRequest( + InternalService.PKinesisMetaProxyRequest.newBuilder() + .setKinesisInfo(kinesisInfoBuilder)) + .setTimeoutSecs(Config.max_get_kafka_meta_timeout_second) + .build(); + + return getInfoRequest(request, Config.max_get_kafka_meta_timeout_second) + .getKinesisMetaResult().getShardIdsList(); + } catch (Exception e) { + throw new LoadException( + "Failed to get shards of Kinesis stream: " + stream + ". error: " + e.getMessage()); + } + } + + private static InternalService.PProxyResult getInfoRequest(InternalService.PProxyRequest request, + int timeout) throws LoadException { + long startTime = System.currentTimeMillis(); + int retryTimes = 0; + TNetworkAddress address = null; + Future<InternalService.PProxyResult> future = null; + InternalService.PProxyResult result = null; + Set<Long> failedBeIds = new HashSet<>(); + TStatusCode code = null; + String errorMsg = null; + + try { + while (retryTimes < 3) { + List<Long> backendIds = new ArrayList<>(); + for (Long beId : Env.getCurrentSystemInfo().getAllBackendIds(true)) { + Backend backend = Env.getCurrentSystemInfo().getBackend(beId); Review Comment: 这个滚动升级的问题是说 KinesisUtil.java 里会随机选任意 load-available BE 发 kinesis_meta_request。 旧 BE 不认识这个新 protobuf 字段时会忽略它,并在 internal_service.cpp返回 OK(但没有 kinesis_meta_result)。FE 只看 status=OK,然后在 KinesisUtil.java (line 80) 直接读结果,最终拿到空 shard 列表,任务可能一直 NEED_SCHEDULE kinesis routine load这个feature可能是不支持在线滚动升级的 -- 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]
