shuzirra commented on a change in pull request #3551: URL: https://github.com/apache/hadoop/pull/3551#discussion_r737442588
########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAppLifetimeAndLimitSettings.java ########## @@ -0,0 +1,132 @@ +/* + * 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.hadoop.yarn.server.resourcemanager.scheduler.capacity; + +import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; + +/** + * This class determines application lifetime and max parallel apps settings based on the + * {@link CapacitySchedulerConfiguration} and other queue + * properties. + **/ +public class QueueAppLifetimeAndLimitSettings { + // -1 indicates lifetime is disabled + private volatile long maxApplicationLifetime = -1; + private volatile long defaultApplicationLifetime = -1; + + // Indicates if this queue's default lifetime was set by a config property, + // either at this level or anywhere in the queue's hierarchy. + private volatile boolean defaultAppLifetimeWasSpecifiedInConfig = false; + + private int maxParallelApps; + + public QueueAppLifetimeAndLimitSettings(CapacitySchedulerConfiguration configuration, + AbstractCSQueue q, String queuePath) { + // Store max parallel apps property + this.maxParallelApps = configuration.getMaxParallelAppsForQueue(queuePath); + this.maxApplicationLifetime = getInheritedMaxAppLifetime(q, configuration); + this.defaultApplicationLifetime = getInheritedDefaultAppLifetime(q, queuePath, configuration, + maxApplicationLifetime); + } + + private long getInheritedMaxAppLifetime(CSQueue q, CapacitySchedulerConfiguration conf) { + CSQueue parentQ = q.getParent(); + long maxAppLifetime = conf.getMaximumLifetimePerQueue(q.getQueuePath()); + + // If q is the root queue, then get max app lifetime from conf. + if (parentQ == null) { + return maxAppLifetime; + } + + // If this is not the root queue, get this queue's max app lifetime + // from the conf. The parent's max app lifetime will be used if it's + // not set for this queue. + // A value of 0 will override the parent's value and means no max lifetime. + // A negative value means that the parent's max should be used. + long parentsMaxAppLifetime = parentQ.getMaximumApplicationLifetime(); + return (maxAppLifetime >= 0) ? maxAppLifetime : parentsMaxAppLifetime; + } + + private long getInheritedDefaultAppLifetime(CSQueue q, Review comment: Method name is a bit misleading, it suggests to be a getter, but it actually sets fields like defaultAppLifetimeWasSpecifiedInConfig . ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAllocationSettings.java ########## @@ -0,0 +1,97 @@ +/* + * 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.hadoop.yarn.server.resourcemanager.scheduler.capacity; + +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.api.records.ResourceInformation; +import org.apache.hadoop.yarn.util.resource.ResourceUtils; +import org.apache.hadoop.yarn.util.resource.Resources; + +import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.UNDEFINED; + +/** + * This class determines minimum and maximum allocation settings based on the + * {@link CapacitySchedulerConfiguration} and other queue + * properties. + **/ +public class QueueAllocationSettings { + private final Resource minimumAllocation; + private volatile Resource maximumAllocation; + + public QueueAllocationSettings(CapacitySchedulerContext csContext) { + this.minimumAllocation = csContext.getMinimumResourceCapability(); + } + + void setupMaximumAllocation(CapacitySchedulerConfiguration csConf, String queuePath, Review comment: Please check if this class needs to be thread safe, if not, volatile keywords can be removed, if it needs to be, then we shall make this method thread safe. ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAppLifetimeAndLimitSettings.java ########## @@ -0,0 +1,132 @@ +/* + * 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.hadoop.yarn.server.resourcemanager.scheduler.capacity; + +import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; + +/** + * This class determines application lifetime and max parallel apps settings based on the + * {@link CapacitySchedulerConfiguration} and other queue + * properties. + **/ +public class QueueAppLifetimeAndLimitSettings { + // -1 indicates lifetime is disabled + private volatile long maxApplicationLifetime = -1; + private volatile long defaultApplicationLifetime = -1; + + // Indicates if this queue's default lifetime was set by a config property, + // either at this level or anywhere in the queue's hierarchy. + private volatile boolean defaultAppLifetimeWasSpecifiedInConfig = false; Review comment: Field is only set in getInheritedDefaultAppLifetime, which is only called from constructor once, this can be final instead of volatile. ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAllocationSettings.java ########## @@ -0,0 +1,97 @@ +/* + * 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.hadoop.yarn.server.resourcemanager.scheduler.capacity; + +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.api.records.ResourceInformation; +import org.apache.hadoop.yarn.util.resource.ResourceUtils; +import org.apache.hadoop.yarn.util.resource.Resources; + +import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.UNDEFINED; + +/** + * This class determines minimum and maximum allocation settings based on the + * {@link CapacitySchedulerConfiguration} and other queue + * properties. + **/ +public class QueueAllocationSettings { + private final Resource minimumAllocation; + private volatile Resource maximumAllocation; Review comment: Volatile won't help much here, this class is not thread safe at all, and this keyword won't make it so. Also volatile will only make the reference to the object "volatile" not to the contents of it, so if anything changes inside the Resource, it will be still cached. ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAppLifetimeAndLimitSettings.java ########## @@ -0,0 +1,132 @@ +/* + * 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.hadoop.yarn.server.resourcemanager.scheduler.capacity; + +import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; + +/** + * This class determines application lifetime and max parallel apps settings based on the + * {@link CapacitySchedulerConfiguration} and other queue + * properties. + **/ +public class QueueAppLifetimeAndLimitSettings { + // -1 indicates lifetime is disabled + private volatile long maxApplicationLifetime = -1; + private volatile long defaultApplicationLifetime = -1; Review comment: These fields are only written from the constructor, they can be final rather than volatile. -- 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]
