danny0405 commented on code in PR #9651: URL: https://github.com/apache/hudi/pull/9651#discussion_r1327886335
########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/util/TimelineServerHelper.java: ########## @@ -0,0 +1,103 @@ +/* + * 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.hudi.util; + +import org.apache.hudi.config.HoodieWriteConfig; +import org.apache.hudi.exception.HoodieException; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.http.client.fluent.Request; +import org.apache.http.client.fluent.Response; +import org.apache.http.client.utils.URIBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Map; + +/** + * Helper class for executing timeline server requests. + */ +public class TimelineServerHelper { + + private static final Logger LOG = LoggerFactory.getLogger(TimelineServerHelper.class); + private final ObjectMapper mapper; + private final String timelineServerHost; + private final int timelineServerPort; + private final int timeoutSecs; + + public TimelineServerHelper(HoodieWriteConfig writeConfig) { + this(writeConfig.getViewStorageConfig().getRemoteViewServerHost(), + writeConfig.getViewStorageConfig().getRemoteViewServerPort(), + writeConfig.getViewStorageConfig().getRemoteTimelineClientTimeoutSecs()); + } + + public TimelineServerHelper(String timelineServerHost, int timelineServerPort, int timeoutSecs) { + this.mapper = new ObjectMapper(); + this.timelineServerHost = timelineServerHost; + this.timelineServerPort = timelineServerPort; + this.timeoutSecs = timeoutSecs; + } + + public <T> T executeRequestToTimelineServerWithRetry(String requestPath, Map<String, String> queryParameters, + TypeReference reference, RequestMethod method) { + int retry = 5; + while (--retry >= 0) { + long start = System.currentTimeMillis(); + try { + return executeRequestToTimelineServer(requestPath, queryParameters, reference, method); + } catch (IOException e) { + LOG.warn("Failed to execute request (" + requestPath + ") to timeline server", e); + } finally { + LOG.info("Execute request : (" + requestPath + "), costs: " + (System.currentTimeMillis() - start) + " ms"); Review Comment: Can we make the retry times not hard coded? Do we need to log for each request? -- 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]
