dlmarion commented on code in PR #4861: URL: https://github.com/apache/accumulo/pull/4861#discussion_r1758938383
########## core/src/main/java/org/apache/accumulo/core/lock/ServiceLockPaths.java: ########## @@ -0,0 +1,385 @@ +/* + * 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 + * + * https://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.accumulo.core.lock; + +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.apache.accumulo.core.Constants; +import org.apache.accumulo.core.clientImpl.ClientContext; +import org.apache.accumulo.core.fate.zookeeper.ZooCache; +import org.apache.accumulo.core.fate.zookeeper.ZooCache.ZcStat; + +import com.google.common.base.Preconditions; +import com.google.common.net.HostAndPort; + +/** + * Class for creating and retrieving ServiceLockPath objects + */ +public class ServiceLockPaths { + + public static class ServiceLockPath { + private final String type; + private final String resourceGroup; + private final String server; + private final String path; + + /** + * Exists for ServiceLockIt + */ + protected ServiceLockPath(String path) { + this.type = null; + this.resourceGroup = null; + this.server = null; + this.path = path; + } + + /** + * Create a ServiceLockPath for a management process + */ + private ServiceLockPath(String root, String type) { + Objects.requireNonNull(root); + this.type = Objects.requireNonNull(type); + Preconditions.checkArgument(this.type.equals(Constants.ZGC_LOCK) + || this.type.equals(Constants.ZMANAGER_LOCK) || this.type.equals(Constants.ZMONITOR_LOCK) + || this.type.equals(Constants.ZTABLE_LOCKS), "Unsupported type: " + type); + // These server types support only one active instance, so they use a lock at + // a known path, not the server's address. + this.resourceGroup = null; + this.server = null; + this.path = root + this.type; + } + + /** + * Create a ServiceLockPath for ZTABLE_LOCKS + */ + private ServiceLockPath(String root, String type, String content) { + Objects.requireNonNull(root); + this.type = Objects.requireNonNull(type); + Preconditions.checkArgument( + this.type.equals(Constants.ZTABLE_LOCKS) || this.type.equals(Constants.ZMINI_LOCK), + "Unsupported type: " + type); + this.resourceGroup = null; + this.server = Objects.requireNonNull(content); + this.path = root + this.type + "/" + this.server; + } + + /** + * Create a ServiceLockPath for a worker process + */ + private ServiceLockPath(String root, String type, String resourceGroup, String server) { + Objects.requireNonNull(root); + this.type = Objects.requireNonNull(type); + Preconditions.checkArgument( + this.type.equals(Constants.ZCOMPACTORS) || this.type.equals(Constants.ZSSERVERS) + || this.type.equals(Constants.ZTSERVERS) || this.type.equals(Constants.ZDEADTSERVERS), + "Unsupported type: " + type); + this.resourceGroup = Objects.requireNonNull(resourceGroup); + this.server = Objects.requireNonNull(server); + this.path = root + this.type + "/" + this.resourceGroup + "/" + this.server; + } + + public String getType() { + return type; + } + + public String getResourceGroup() { + return resourceGroup; + } + + public String getServer() { + return server; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ServiceLockPath other = (ServiceLockPath) obj; + if (path == null) { + if (other.path != null) { + return false; + } + } else if (!path.equals(other.path)) { + return false; + } + if (resourceGroup == null) { + if (other.resourceGroup != null) { + return false; + } + } else if (!resourceGroup.equals(other.resourceGroup)) { + return false; + } + if (server == null) { + if (other.server != null) { + return false; + } + } else if (!server.equals(other.server)) { + return false; + } + if (type == null) { + if (other.type != null) { + return false; + } + } else if (!type.equals(other.type)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + ((resourceGroup == null) ? 0 : resourceGroup.hashCode()); + result = prime * result + ((server == null) ? 0 : server.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + return result; + } + + @Override + public String toString() { + return this.path; + } + + } + + private final ClientContext ctx; + + public ServiceLockPaths(ClientContext context) { + this.ctx = context; + } + + private static String determineServerType(final String path) { + if (path.contains(Constants.ZGC_LOCK)) { + return Constants.ZGC_LOCK; + } else if (path.contains(Constants.ZMANAGER_LOCK)) { + return Constants.ZMANAGER_LOCK; + } else if (path.contains(Constants.ZMONITOR_LOCK)) { + return Constants.ZMONITOR_LOCK; + } else if (path.contains(Constants.ZMINI_LOCK)) { + return Constants.ZMINI_LOCK; + } else if (path.contains(Constants.ZCOMPACTORS)) { + return Constants.ZCOMPACTORS; + } else if (path.contains(Constants.ZSSERVERS)) { + return Constants.ZSSERVERS; + } else if (path.contains(Constants.ZDEADTSERVERS)) { + // This has to be before TSERVERS + return Constants.ZDEADTSERVERS; + } else if (path.contains(Constants.ZTSERVERS)) { + return Constants.ZTSERVERS; + } else { + throw new IllegalArgumentException("Unhandled to determine server type from path: " + path); + } + } + + /** + * Parse a ZooKeeper path string and return a ServiceLockPath + */ + public static ServiceLockPath parse(Optional<String> serverType, String path) { + Objects.requireNonNull(serverType); + Objects.requireNonNull(path); + + final String type = serverType.isEmpty() ? determineServerType(path) : serverType.orElseThrow(); Review Comment: Nice, I didn't know about that. Updated in 69f40d6. ########## server/base/src/main/java/org/apache/accumulo/server/manager/LiveTServerSet.java: ########## @@ -228,15 +230,13 @@ public synchronized void scanServers() { final Set<TServerInstance> updates = new HashSet<>(); final Set<TServerInstance> doomed = new HashSet<>(); - final String path = context.getZooKeeperRoot() + Constants.ZTSERVERS; + Set<ServiceLockPath> tservers = + context.getServerPaths().getTabletServer(Optional.empty(), Optional.empty()); Review Comment: Updated in 69f40d6. -- 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]
