brianloss commented on a change in pull request #1912:
URL: https://github.com/apache/accumulo/pull/1912#discussion_r572373389



##########
File path: 
server/manager/src/main/java/org/apache/accumulo/manager/upgrade/RenameMasterDirInZK.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.accumulo.manager.upgrade;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.conf.SiteConfiguration;
+import org.apache.accumulo.fate.zookeeper.ZooReaderWriter;
+import org.apache.accumulo.fate.zookeeper.ZooUtil;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.zookeeper.KeeperException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A utility to handle the renaming of "/masters" to "/managers" in Zookeeper 
when upgrading from a
+ * 2.0 (or earlier) to 2.1 instance. This utility is invoked automatically by
+ * {@link org.apache.accumulo.manager.state.SetGoalState} (which normally runs 
first as a part of
+ * accumulo startup scripts). However, if a user is not using the standard 
scripts or wishes to
+ * perform the upgrade as a separate process, this utility can be invoked with:
+ *
+ * <pre>
+ * {@code
+ * bin/accumulo org.apache.accumulo.manager.upgrade.RenameMasterDirInZK
+ * }
+ * </pre>
+ */
+public class RenameMasterDirInZK {
+  private static final Logger LOG = 
LoggerFactory.getLogger(RenameMasterDirInZK.class);
+
+  public static void main(String[] args) {
+    var ctx = new ServerContext(SiteConfiguration.auto());
+    if (!renameMasterDirInZK(ctx)) {
+      LOG.info("Managers directory already exists in ZooKeeper. Not attempting 
rename.");
+    }
+  }
+
+  public static boolean renameMasterDirInZK(ServerContext ctx) {
+    final ZooReaderWriter zoo = ctx.getZooReaderWriter();
+    final String mastersZooDir = ctx.getZooKeeperRoot() + "/masters";
+    final String managersZooDir = ctx.getZooKeeperRoot() + Constants.ZMANAGERS;
+    try {
+      boolean managersDirMissing = !zoo.exists(managersZooDir);

Review comment:
       Hmm, I was checking the lack of existence of the managers dir, since the 
manager won't be able to start without it. Thinking through it, though, I 
suppose the problem would be if the recursive copy doesn't complete 
successfully. If we switch the check, then the concern would be if the 
recursive delete of /masters doesn't complete. That's probably not a problem 
since startup will fail. Next time around, we'll try to copy whatever's left 
from /masters to /managers (which should be ok since the manager never started 
so nothing under /managers got updated). So given that, then sure, I think it 
makes sense to flip the check. I'll take care of that.




----------------------------------------------------------------
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]


Reply via email to