asdf2014 commented on a change in pull request #9172: Fix huge number of watches in zk URL: https://github.com/apache/druid/pull/9172#discussion_r368406513
########## File path: server/src/main/java/org/apache/druid/curator/announcement/NodeAnnouncer.java ########## @@ -0,0 +1,350 @@ +/* + * 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.druid.curator.announcement; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.api.transaction.CuratorOp; +import org.apache.curator.framework.recipes.cache.ChildData; +import org.apache.curator.framework.recipes.cache.NodeCache; +import org.apache.druid.java.util.common.IAE; +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.java.util.common.guava.CloseQuietly; +import org.apache.druid.java.util.common.io.Closer; +import org.apache.druid.java.util.common.lifecycle.LifecycleStart; +import org.apache.druid.java.util.common.lifecycle.LifecycleStop; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.server.ZKPathsUtils; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; + +import javax.annotation.concurrent.GuardedBy; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * NodeAnnouncer announces single node on Zookeeper and only watches this node, + * while {@link Announcer} watches all child paths, not only this node + */ +public class NodeAnnouncer +{ + private static final Logger log = new Logger(NodeAnnouncer.class); + + private final CuratorFramework curator; + + /** + * In case a path is added to this collection in {@link #announce} before zk is connected, + * should remember the path and do announce in {@link #start} later. + */ + private final List<Announceable> toAnnounce = new ArrayList<>(); + /** + * In case a path is added to this collection in {@link #update} before zk is connected, + * should remember the path and do update in {@link #start} later. + */ + @GuardedBy("toAnnounce") + private final List<Announceable> toUpdate = new ArrayList<>(); + private final ConcurrentMap<String, NodeCache> listeners = new ConcurrentHashMap<>(); + private final ConcurrentMap<String, byte[]> announcedPaths = new ConcurrentHashMap<>(); + /** + * Only the one created the parent path can drop the parent path, so should remember these created parents. + */ + private final List<String> pathsCreatedInThisAnnouncer = new CopyOnWriteArrayList<>(); Review comment: Done ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
