Skip to content

Commit 0add23e

Browse files
committed
Merge branch '3.1'
2 parents 7fada71 + 98cbd85 commit 0add23e

File tree

4 files changed

+63
-13
lines changed

4 files changed

+63
-13
lines changed

core/src/main/java/org/apache/accumulo/core/fate/zookeeper/ZooCache.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,10 @@ public void clear(Predicate<String> pathPredicate) {
517517

518518
Predicate<String> pathPredicateToUse;
519519
if (log.isTraceEnabled()) {
520-
pathPredicateToUse = path -> {
521-
boolean testResult = pathPredicate.test(path);
522-
if (testResult) {
523-
log.trace("{} removing {} from cache", cacheId, path);
524-
}
525-
return testResult;
526-
};
520+
pathPredicateToUse = pathPredicate.and(path -> {
521+
log.trace("removing {} from cache", path);
522+
return true;
523+
});
527524
} else {
528525
pathPredicateToUse = pathPredicate;
529526
}

minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterControl.java

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.accumulo.minicluster.ServerType;
3838
import org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl.ProcessInfo;
3939
import org.apache.accumulo.server.util.Admin;
40+
import org.apache.accumulo.server.util.ZooZap;
4041
import org.slf4j.Logger;
4142
import org.slf4j.LoggerFactory;
4243

@@ -270,6 +271,11 @@ public synchronized void stop(ServerType server, String hostname) throws IOExcep
270271
if (managerProcess != null) {
271272
try {
272273
cluster.stopProcessWithTimeout(managerProcess, 30, TimeUnit.SECONDS);
274+
try {
275+
new ZooZap().zap(cluster.getServerContext().getSiteConfiguration(), "-manager");
276+
} catch (RuntimeException e) {
277+
log.error("Error zapping Manager zookeeper lock", e);
278+
}
273279
} catch (ExecutionException | TimeoutException e) {
274280
log.warn("Manager did not fully stop after 30 seconds", e);
275281
} catch (InterruptedException e) {

minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java

+38-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import java.util.concurrent.atomic.AtomicBoolean;
5858
import java.util.concurrent.atomic.AtomicReference;
5959
import java.util.function.Function;
60+
import java.util.function.Predicate;
6061
import java.util.function.Supplier;
6162
import java.util.stream.Collectors;
6263
import java.util.stream.Stream;
@@ -109,6 +110,7 @@
109110
import org.apache.accumulo.server.init.Initialize;
110111
import org.apache.accumulo.server.util.AccumuloStatus;
111112
import org.apache.accumulo.server.util.PortUtils;
113+
import org.apache.accumulo.server.util.ZooZap;
112114
import org.apache.accumulo.start.Main;
113115
import org.apache.accumulo.start.spi.KeywordExecutable;
114116
import org.apache.accumulo.start.util.MiniDFSUtil;
@@ -994,10 +996,45 @@ public synchronized void stop() throws IOException, InterruptedException {
994996
control.stop(ServerType.GARBAGE_COLLECTOR, null);
995997
control.stop(ServerType.MANAGER, null);
996998
control.stop(ServerType.TABLET_SERVER, null);
997-
control.stop(ServerType.ZOOKEEPER, null);
998999
control.stop(ServerType.COMPACTOR, null);
9991000
control.stop(ServerType.SCAN_SERVER, null);
10001001

1002+
// The method calls above kill the server
1003+
// Clean up the locks in ZooKeeper fo that if the cluster
1004+
// is restarted, then the processes will start right away
1005+
// and not wait for the old locks to be cleaned up.
1006+
try {
1007+
new ZooZap().zap(getServerContext().getSiteConfiguration(), "-manager", "-tservers",
1008+
"-compactors", "-sservers");
1009+
} catch (RuntimeException e) {
1010+
log.error("Error zapping zookeeper locks", e);
1011+
}
1012+
control.stop(ServerType.ZOOKEEPER, null);
1013+
1014+
// Clear the location of the servers in ZooCache.
1015+
// When ZooKeeper was stopped in the previous method call,
1016+
// the local ZooKeeper watcher did not fire. If MAC is
1017+
// restarted, then ZooKeeper will start on the same port with
1018+
// the same data, but no Watchers will fire.
1019+
boolean startCalled = true;
1020+
try {
1021+
getServerContext().getZooKeeperRoot();
1022+
} catch (IllegalStateException e) {
1023+
if (e.getMessage().startsWith("Accumulo not initialized")) {
1024+
startCalled = false;
1025+
}
1026+
}
1027+
if (startCalled) {
1028+
final ServerContext ctx = getServerContext();
1029+
final String zRoot = ctx.getZooKeeperRoot();
1030+
Predicate<String> pred = path -> false;
1031+
for (String lockPath : Set.of(Constants.ZMANAGER_LOCK, Constants.ZGC_LOCK,
1032+
Constants.ZCOMPACTORS, Constants.ZSSERVERS, Constants.ZTSERVERS)) {
1033+
pred = pred.or(path -> path.startsWith(zRoot + lockPath));
1034+
}
1035+
ctx.getZooCache().clear(pred);
1036+
}
1037+
10011038
// ACCUMULO-2985 stop the ExecutorService after we finished using it to stop accumulo procs
10021039
if (executor != null) {
10031040
List<Runnable> tasksRemaining = executor.shutdownNow();

server/base/src/main/java/org/apache/accumulo/server/util/ZooZap.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.accumulo.core.lock.ServiceLockPaths.ServiceLockPath;
3434
import org.apache.accumulo.core.singletons.SingletonManager;
3535
import org.apache.accumulo.core.singletons.SingletonManager.Mode;
36+
import org.apache.accumulo.core.zookeeper.ZooSession;
3637
import org.apache.accumulo.server.ServerContext;
3738
import org.apache.accumulo.server.security.SecurityUtil;
3839
import org.apache.accumulo.start.spi.KeywordExecutable;
@@ -86,6 +87,19 @@ public static void main(String[] args) throws Exception {
8687

8788
@Override
8889
public void execute(String[] args) throws Exception {
90+
try {
91+
var siteConf = SiteConfiguration.auto();
92+
// Login as the server on secure HDFS
93+
if (siteConf.getBoolean(Property.INSTANCE_RPC_SASL_ENABLED)) {
94+
SecurityUtil.serverLogin(siteConf);
95+
}
96+
zap(siteConf, args);
97+
} finally {
98+
SingletonManager.setMode(Mode.CLOSED);
99+
}
100+
}
101+
102+
public void zap(SiteConfiguration siteConf, String... args) {
89103
Opts opts = new Opts();
90104
opts.parseArgs(keyword(), args);
91105

@@ -94,8 +108,7 @@ public void execute(String[] args) throws Exception {
94108
return;
95109
}
96110

97-
try {
98-
var siteConf = SiteConfiguration.auto();
111+
try (var zk = new ZooSession(getClass().getSimpleName(), siteConf)) {
99112
// Login as the server on secure HDFS
100113
if (siteConf.getBoolean(Property.INSTANCE_RPC_SASL_ENABLED)) {
101114
SecurityUtil.serverLogin(siteConf);
@@ -175,10 +188,7 @@ public void execute(String[] args) throws Exception {
175188
}
176189
}
177190

178-
} finally {
179-
SingletonManager.setMode(Mode.CLOSED);
180191
}
181-
182192
}
183193

184194
private static void zapDirectory(ZooReaderWriter zoo, ServiceLockPath path, Opts opts)

0 commit comments

Comments
 (0)