dlmarion commented on code in PR #5438: URL: https://github.com/apache/accumulo/pull/5438#discussion_r2029129251
########## server/base/src/main/java/org/apache/accumulo/server/util/UpgradePreparationUtil.java: ########## @@ -0,0 +1,155 @@ +/* + * 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.server.util; + +import org.apache.accumulo.core.Constants; +import org.apache.accumulo.core.cli.Help; +import org.apache.accumulo.core.conf.Property; +import org.apache.accumulo.core.conf.SiteConfiguration; +import org.apache.accumulo.core.data.InstanceId; +import org.apache.accumulo.core.fate.zookeeper.ServiceLock; +import org.apache.accumulo.core.fate.zookeeper.ServiceLock.ServiceLockPath; +import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter; +import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy; +import org.apache.accumulo.core.volume.VolumeConfiguration; +import org.apache.accumulo.server.fs.VolumeManager; +import org.apache.accumulo.server.security.SecurityUtil; +import org.apache.accumulo.start.spi.KeywordExecutable; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; +import org.apache.zookeeper.KeeperException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.beust.jcommander.JCommander; +import com.beust.jcommander.Parameter; +import com.google.auto.service.AutoService; + +@AutoService(KeywordExecutable.class) +public class UpgradePreparationUtil implements KeywordExecutable { + + private static final Logger LOG = LoggerFactory.getLogger(UpgradePreparationUtil.class); + + static class Opts extends Help { + @Parameter(names = "--prepare-for-upgrade", + description = "prepare an older version instance for an upgrade to a newer non-bugfix release." + + " This command should be run using the older version of software after the instance is shut down.") + boolean postShutdownUpgradeCheck = false; + + @Parameter(names = "--force", description = "allow --prepare-for-upgrade to run again") + boolean force = false; + } + + @Override + public String keyword() { + return "upgrade"; + } + + @Override + public String description() { + return "utility used to prepare an instance for a minor or major version upgrade"; + } + + @Override + public void execute(String[] args) throws Exception { + Opts opts = new Opts(); + opts.parseArgs(keyword(), args); + + if (!opts.postShutdownUpgradeCheck) { + new JCommander(opts).usage(); + return; + } + + var siteConf = SiteConfiguration.auto(); + // Login as the server on secure HDFS + if (siteConf.getBoolean(Property.INSTANCE_RPC_SASL_ENABLED)) { + SecurityUtil.serverLogin(siteConf); + } + + String volDir = VolumeConfiguration.getVolumeUris(siteConf).iterator().next(); + Path instanceDir = new Path(volDir, "instance_id"); + InstanceId iid = VolumeManager.getInstanceIDFromHdfs(instanceDir, new Configuration()); + ZooReaderWriter zoo = new ZooReaderWriter(siteConf); + + if (opts.postShutdownUpgradeCheck) { + final String zUpgradepath = Constants.ZROOT + "/" + iid + Constants.ZPREPARE_FOR_UPGRADE; + try { + if (zoo.exists(zUpgradepath)) { + if (!opts.force) { + throw new IllegalStateException( + "'accumulo upgrade --prepare-for-upgrade' must have already been run." + + " To run again use 'accumulo upgrade --prepare-for-upgrade --force'"); + } else { + zoo.delete(zUpgradepath); + } + } + } catch (KeeperException | InterruptedException e) { + throw new IllegalStateException("Error creating or checking for " + zUpgradepath + + " node in zookeeper: " + e.getMessage(), e); + } + + LOG.info("Upgrade specified, validating that Manager is stopped"); + final ServiceLockPath mgrPath = + ServiceLock.path(Constants.ZROOT + "/" + iid + Constants.ZMANAGER_LOCK); + try { + if (ServiceLock.getLockData(zoo.getZooKeeper(), mgrPath) != null) { + throw new IllegalStateException( + "Manager is running, shut it down and retry this operation"); + } + } catch (KeeperException | InterruptedException e) { + throw new IllegalStateException("Error trying to determine if Manager lock is held", e); Review Comment: I think we should add that to 4.0 vs adding a feature into ZooZap in a bugfix release. -- 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: notifications-unsubscr...@accumulo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org