j1wonpark commented on code in PR #4254: URL: https://github.com/apache/amoro/pull/4254#discussion_r3486971506
########## amoro-ams/src/main/java/org/apache/amoro/server/optimizing/dra/DynamicAllocationConfig.java: ########## @@ -0,0 +1,362 @@ +/* + * 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.amoro.server.optimizing.dra; + +import org.apache.amoro.Constants; +import org.apache.amoro.OptimizerProperties; +import org.apache.amoro.config.ConfigHelpers; +import org.apache.amoro.resource.ResourceGroup; +import org.apache.amoro.utils.PropertyUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.time.Duration; +import java.util.Map; + +/** + * Dynamic resource allocation (DRA) configuration of a resource group (AIP-5). Parsed from the + * group's properties; {@link #validate()} enforces the AIP-5 constraints. + */ +public class DynamicAllocationConfig { + + private static final Logger LOG = LoggerFactory.getLogger(DynamicAllocationConfig.class); + + private final String groupName; + private final String container; + private final boolean enabled; + private final int minParallelism; + private final String minParallelismRaw; + private final Integer maxParallelism; + private final Duration schedulerBacklogTimeout; + private final Duration sustainedBacklogTimeout; + private final Duration executorIdleTimeout; + private final Duration scaleDownCooldown; + private final Duration drainTimeout; + + private DynamicAllocationConfig( + String groupName, + String container, + boolean enabled, + int minParallelism, + String minParallelismRaw, + Integer maxParallelism, + Duration schedulerBacklogTimeout, + Duration sustainedBacklogTimeout, + Duration executorIdleTimeout, + Duration scaleDownCooldown, + Duration drainTimeout) { + this.groupName = groupName; + this.container = container; + this.enabled = enabled; + this.minParallelism = minParallelism; + this.minParallelismRaw = minParallelismRaw; + this.maxParallelism = maxParallelism; + this.schedulerBacklogTimeout = schedulerBacklogTimeout; + this.sustainedBacklogTimeout = sustainedBacklogTimeout; + this.executorIdleTimeout = executorIdleTimeout; + this.scaleDownCooldown = scaleDownCooldown; + this.drainTimeout = drainTimeout; + } + + /** + * Parse the DRA configuration of a resource group. Malformed numeric or duration values throw + * {@link IllegalArgumentException}; semantic constraints are checked by {@link #validate()}. + */ + public static DynamicAllocationConfig parse(ResourceGroup group) { + Map<String, String> properties = group.getProperties(); + boolean enabled = + PropertyUtil.propertyAsBoolean( + properties, + OptimizerProperties.DYNAMIC_ALLOCATION_ENABLED, + OptimizerProperties.DYNAMIC_ALLOCATION_ENABLED_DEFAULT); + int minParallelism = resolveMinParallelism(group); + String minParallelismRaw = rawMinParallelism(group); Review Comment: `min-parallelism` wasn't parsed strictly, so I added a guard for that — keeping both a lenient `int` and the raw `String` so `validate()` could tell "unset" from "explicitly set but malformed" (the lenient `int` collapses both to `0`). That turned out to be overkill. Simplified by dropping the dual representation: `min-parallelism` is now a single nullable `Integer`, parsed strictly in `parse()` (mirroring `max-parallelism`), with `null` meaning "unset". -- 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]
