somandal commented on code in PR #16857: URL: https://github.com/apache/pinot/pull/16857#discussion_r2369051717
########## pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/DistributedTaskLockManager.java: ########## @@ -0,0 +1,563 @@ +/** + * 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.pinot.controller.helix.core.minion; + +import com.google.common.annotations.VisibleForTesting; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.annotation.Nullable; +import org.apache.helix.AccessOption; +import org.apache.helix.store.zk.ZkHelixPropertyStore; +import org.apache.helix.zookeeper.datamodel.ZNRecord; +import org.apache.pinot.common.metadata.ZKMetadataProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Manages distributed locks for minion task generation using ZooKeeper ephemeral sequential nodes. + * Uses ephemeral nodes that automatically disappear when the controller session ends. + * This approach provides automatic cleanup and is suitable for long-running task generation. + * Locks are held until explicitly released or the controller session terminates. + * Locks are at the table level, to ensure that only one type of task can be generated per table at any given time. + */ +public class DistributedTaskLockManager { Review Comment: Sure, I can update the comments to document this better, to answer your questions: - "-State" ZNode is not actually needed here - I had added it as a potential mechanism to check status of the task generation, but frankly don't see a need for this. I've been debating in my head and think it'll be better to remove this (let me know if you want me to keep it though). I believe there is already mechanisms in place to identify if the task generation went through or not? Can always add it back later if we see a real need, and even then need a better approach to maybe make this task specific or run specific - The "-Lock" creation - the algorithm I've used is a standard ZK lock recipe, which uses EPHEMERAL_SEQUENTIAL nodes to create the lock objects. You specify a lockPrefix (which in my code is - controllerName-lock-uuid), and ZK appends a sequence ID. The winner of the lock is the one with the lowest sequence ID. - IMO this is better than just trying to create a lock with a fixed name if it doesn't exist is to handle scenarios where multiple controllers / threads within the same controller do the check, find no lock, and proceed to try to create the lock. Using sequential nodes, we can easily choose who the winner is in such cases. Let me know if you'd like more discussion on this -- 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]
