singhpk234 commented on code in PR #15863: URL: https://github.com/apache/iceberg/pull/15863#discussion_r3031061879
########## api/src/main/java/org/apache/iceberg/exceptions/RemotePlanTimeoutException.java: ########## @@ -0,0 +1,39 @@ +/* + * 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.iceberg.exceptions; + +import com.google.errorprone.annotations.FormatMethod; + +/** + * Exception thrown when remote scan planning does not complete within configured limits. + * + * <p>Clients may catch this to fall back to client-side planning when server-side planning is too + * slow. Review Comment: isn't this then violation of server mode being sent as part of loadTable ? would it be better to say try with larger timeout ? ########## core/src/test/java/org/apache/iceberg/rest/TestRESTScanPlanning.java: ########## @@ -1153,6 +1154,119 @@ public void serverSupportsPlanningButNotCancellation() throws IOException { assertThat(cancelled).isFalse(); } + @Test + public void asyncPlanningRespectsConfigurablePollTimeout() { + // Create an adapter that always returns SUBMITTED (never completes) + List<Endpoint> endpoints = + endpointsWithPlanning( + Endpoint.V1_SUBMIT_TABLE_SCAN_PLAN, + Endpoint.V1_FETCH_TABLE_SCAN_PLAN, + Endpoint.V1_CANCEL_TABLE_SCAN_PLAN, + Endpoint.V1_FETCH_TABLE_SCAN_PLAN_TASKS); + + RESTCatalogAdapter adapter = + Mockito.spy( + new RESTCatalogAdapter(backendCatalog) { + @Override + public <T extends RESTResponse> T execute( + HTTPRequest request, + Class<T> responseType, + Consumer<ErrorResponse> errorHandler, + Consumer<Map<String, String>> responseHeaders, + ParserContext parserContext) { + if (ResourcePaths.config().equals(request.path())) { + return castResponse( + responseType, ConfigResponse.builder().withEndpoints(endpoints).build()); + } + T response = + super.execute( + request, responseType, errorHandler, responseHeaders, parserContext); + if (response instanceof LoadTableResponse) { + return castResponse( + responseType, + withPlanningMode( + (LoadTableResponse) response, + RESTCatalogProperties.ScanPlanningMode.SERVER.modeName())); + } + + // Override fetch responses to always return SUBMITTED so the poll never completes + if (response instanceof FetchPlanningResultResponse) { + return castResponse( + responseType, + FetchPlanningResultResponse.builder() + .withPlanStatus(PlanStatus.SUBMITTED) + .build()); + } + + return response; + } + }); + + adapter.setPlanningBehavior(TestPlanningBehavior.builder().asynchronous().build()); + + RESTCatalog catalog = + new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) -> adapter); + catalog.initialize( + "test-poll-timeout", + ImmutableMap.of( + CatalogProperties.FILE_IO_IMPL, + "org.apache.iceberg.inmemory.InMemoryFileIO", + RESTCatalogProperties.SCAN_PLANNING_MODE, + RESTCatalogProperties.ScanPlanningMode.SERVER.modeName(), + RESTCatalogProperties.REST_SCAN_PLANNING_POLL_TIMEOUT_MS, + "1")); + + RESTTable table = restTableFor(catalog, "poll_timeout_test"); + setParserContext(table); + RESTTableScan scan = restTableScanFor(table); + + // With a 1ms timeout and a server that never completes, planFiles should fail + assertThatThrownBy(scan::planFiles) + .isInstanceOf(RemotePlanTimeoutException.class) + .hasMessageContaining("did not complete within configured limits"); + } + + @Test + public void asyncPlanningSucceedsWithCustomTimeout() { + configurePlanningBehavior(TestPlanningBehavior.Builder::asynchronous); + RESTTable table = restTableFor(restCatalog, "custom_timeout_success"); + setParserContext(table); + // default catalog uses the default 5-minute timeout, which is sufficient for async planning Review Comment: The test name is `asyncPlanningSucceedsWithCustomTimeout` but we are relying on default timeout, is this intented ? [optional] also i would say set the value explicitly in case some one fiddles with the default -- 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]
