This is an automated email from the ASF dual-hosted git repository.
keith-turner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push:
new 1920199b96 Avoid primary manager when assigning Fate and Compaction
work (#6631)
1920199b96 is described below
commit 1920199b9676307caa8e48171d8ca13808b0e4bf
Author: Keith Turner <[email protected]>
AuthorDate: Tue Nov 17 10:14:35 2026 -0500
Avoid primary manager when assigning Fate and Compaction work (#6631)
When there is more than one manager process this change will avoid
assigning Fate and compaction coordinatoin to the primary manager.
The primary manager does a lot of work with balancing and the tablet
group watcher, with this change it can focus on that while other
manager processes do Fate and compaction coordination.
Co-authored-by: Dave Marion <[email protected]>
---
.../compaction/coordinator/CoordinatorManager.java | 10 +-
.../apache/accumulo/manager/fate/FateManager.java | 11 ++-
.../accumulo/manager/multi/ManagerAssignment.java | 20 ++--
.../manager/multi/ManagerAssignmentTest.java | 110 ++++++++++++++-------
.../accumulo/test/ComprehensiveMultiManagerIT.java | 11 ++-
.../accumulo/test/MultipleManagerCompactionIT.java | 16 +--
.../accumulo/test/MultipleManagerFateIT.java | 24 ++++-
7 files changed, 142 insertions(+), 60 deletions(-)
diff --git
a/server/manager/src/main/java/org/apache/accumulo/manager/compaction/coordinator/CoordinatorManager.java
b/server/manager/src/main/java/org/apache/accumulo/manager/compaction/coordinator/CoordinatorManager.java
index e31619a7c0..e8c8bdd78e 100644
---
a/server/manager/src/main/java/org/apache/accumulo/manager/compaction/coordinator/CoordinatorManager.java
+++
b/server/manager/src/main/java/org/apache/accumulo/manager/compaction/coordinator/CoordinatorManager.java
@@ -43,6 +43,7 @@ import
org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy;
import org.apache.accumulo.core.lock.ServiceLockPaths;
import org.apache.accumulo.core.rpc.ThriftUtil;
+import org.apache.accumulo.core.rpc.clients.ManagerClient;
import org.apache.accumulo.core.rpc.clients.ThriftClientTypes;
import org.apache.accumulo.core.trace.TraceUtil;
import org.apache.accumulo.core.util.UtilWaitThread;
@@ -101,7 +102,14 @@ public class CoordinatorManager {
log.trace("Configured groups {}", configuredGroups);
- var desired = computeAssignments(current, configuredGroups);
+ var primaryManager = ManagerClient.getPrimaryManagerLocation(context);
+ if (primaryManager == null) {
+ // This code is running in the primary manager, so should find
ourselves.
+ throw new IllegalStateException("No primary manager found");
+ }
+
+ var desired =
+ computeAssignments(HostAndPort.fromString(primaryManager),
current, configuredGroups);
log.trace("Desired assignments {}", desired);
if (!current.equals(desired)) {
diff --git
a/server/manager/src/main/java/org/apache/accumulo/manager/fate/FateManager.java
b/server/manager/src/main/java/org/apache/accumulo/manager/fate/FateManager.java
index 10e1152429..8c8fa5fe04 100644
---
a/server/manager/src/main/java/org/apache/accumulo/manager/fate/FateManager.java
+++
b/server/manager/src/main/java/org/apache/accumulo/manager/fate/FateManager.java
@@ -38,6 +38,7 @@ import
org.apache.accumulo.core.lock.ServiceLockPaths.AddressSelector;
import org.apache.accumulo.core.manager.thrift.FateWorkerService;
import org.apache.accumulo.core.metadata.SystemTables;
import org.apache.accumulo.core.rpc.ThriftUtil;
+import org.apache.accumulo.core.rpc.clients.ManagerClient;
import org.apache.accumulo.core.rpc.clients.ThriftClientTypes;
import org.apache.accumulo.core.trace.TraceUtil;
import org.apache.accumulo.core.util.CountDownTimer;
@@ -291,8 +292,16 @@ public class FateManager {
desiredAssignments.put(hp, new HashSet<>());
});
+ var primaryManager = ManagerClient.getPrimaryManagerLocation(context);
+ if (primaryManager == null) {
+ // This code is running in the primary manager, so should find ourselves.
+ throw new IllegalStateException("No primary manager found");
+ }
+ var primaryManagerHP = HostAndPort.fromString(primaryManager);
+
desiredParititions.forEach((fateType, desiredForType) -> {
- var assignments =
ManagerAssignment.computeAssignments(currentAssignments, desiredForType);
+ var assignments = ManagerAssignment.computeAssignments(primaryManagerHP,
currentAssignments,
+ desiredForType);
assignments.forEach((hp, parts) ->
desiredAssignments.get(hp).addAll(parts));
});
diff --git
a/server/manager/src/main/java/org/apache/accumulo/manager/multi/ManagerAssignment.java
b/server/manager/src/main/java/org/apache/accumulo/manager/multi/ManagerAssignment.java
index 378115d0b2..c896bf0d4f 100644
---
a/server/manager/src/main/java/org/apache/accumulo/manager/multi/ManagerAssignment.java
+++
b/server/manager/src/main/java/org/apache/accumulo/manager/multi/ManagerAssignment.java
@@ -23,6 +23,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
import com.google.common.net.HostAndPort;
@@ -30,19 +31,26 @@ public abstract class ManagerAssignment {
/**
* Generic utility code to assign partitions to host. It evenly spread the
partitions across host
- * and tries to keep partition already on a host in place if possible.
+ * and tries to keep partition already on a host in place if possible. When
there is more than one
+ * host, nothing is assigned to the primary host only the other host.
*/
- public static <T> Map<HostAndPort,Set<T>>
computeAssignments(Map<HostAndPort,Set<T>> current,
- Set<T> desiredPartitions) {
- if (current.isEmpty()) {
- return Map.of();
+ public static <T> Map<HostAndPort,Set<T>> computeAssignments(HostAndPort
primary,
+ Map<HostAndPort,Set<T>> current, Set<T> desiredPartitions) {
+ Preconditions.checkState(current.containsKey(primary), "primary %s not
seen in %s", primary,
+ current.keySet());
+
+ Map<HostAndPort,Set<T>> assignments = new HashMap<>();
+
+ if (!current.keySet().equals(Set.of(primary))) {
+ current = new HashMap<>(current);
+ current.remove(primary);
+ assignments.put(primary, Set.of());
}
int minAssignments = desiredPartitions.size() / current.size();
int maxAssignments = minAssignments + Math.min(desiredPartitions.size() %
current.size(), 1);
int hostThatCanHaveMax = desiredPartitions.size() % current.size();
- Map<HostAndPort,Set<T>> assignments = new HashMap<>();
Set<T> assigned = new HashSet<>();
Set<HostAndPort> hostThatHaveMax = new HashSet<>();
diff --git
a/server/manager/src/test/java/org/apache/accumulo/manager/multi/ManagerAssignmentTest.java
b/server/manager/src/test/java/org/apache/accumulo/manager/multi/ManagerAssignmentTest.java
index 9276eafc5a..cdaca51a14 100644
---
a/server/manager/src/test/java/org/apache/accumulo/manager/multi/ManagerAssignmentTest.java
+++
b/server/manager/src/test/java/org/apache/accumulo/manager/multi/ManagerAssignmentTest.java
@@ -20,6 +20,7 @@ package org.apache.accumulo.manager.multi;
import static
org.apache.accumulo.manager.multi.ManagerAssignment.computeAssignments;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashSet;
@@ -34,50 +35,50 @@ import com.google.common.net.HostAndPort;
public class ManagerAssignmentTest {
@Test
public void testComputeAssignments() {
- assertEquals(Map.of(), computeAssignments(Map.of(), Set.of("a", "b")));
-
+ var pm = HostAndPort.fromParts("127.0.0.1", 4999);
var hp1 = HostAndPort.fromParts("127.0.0.1", 5000);
var hp2 = HostAndPort.fromParts("127.0.0.1", 5001);
var hp3 = HostAndPort.fromParts("127.0.0.1", 5002);
var hp4 = HostAndPort.fromParts("127.0.0.1", 5003);
- runTest(Map.of(hp1, Set.of()), Set.of("a"), 1, 1, 1);
- runTest(Map.of(hp1, Set.of()), Set.of("a", "b"), 2, 2, 1);
+ runTest(pm, Map.of(pm, Set.of()), Set.of("a"), 1, 1, 1);
+ runTest(pm, Map.of(pm, Set.of()), Set.of("a", "b"), 2, 2, 1);
Map<HostAndPort,Set<String>> threeEmptyHost =
- Map.of(hp1, Set.of(), hp2, Set.of(), hp3, Set.of());
- runTest(threeEmptyHost, Set.of("a"), 0, 1, 1);
- runTest(threeEmptyHost, Set.of("a", "b"), 0, 1, 2);
- runTest(threeEmptyHost, Set.of("a", "b", "c"), 1, 1, 3);
- runTest(threeEmptyHost, Set.of("a", "b", "c", "d"), 1, 2, 1);
- runTest(threeEmptyHost, Set.of("a", "b", "c", "d", "e"), 1, 2, 2);
- runTest(threeEmptyHost, Set.of("a", "b", "c", "d", "e", "f"), 2, 2, 3);
- runTest(threeEmptyHost, Set.of("a", "b", "c", "d", "e", "f", "g"), 2, 3,
1);
+ Map.of(pm, Set.of(), hp1, Set.of(), hp2, Set.of(), hp3, Set.of());
+ runTest(pm, threeEmptyHost, Set.of("a"), 0, 1, 1);
+ runTest(pm, threeEmptyHost, Set.of("a", "b"), 0, 1, 2);
+ runTest(pm, threeEmptyHost, Set.of("a", "b", "c"), 1, 1, 3);
+ runTest(pm, threeEmptyHost, Set.of("a", "b", "c", "d"), 1, 2, 1);
+ runTest(pm, threeEmptyHost, Set.of("a", "b", "c", "d", "e"), 1, 2, 2);
+ runTest(pm, threeEmptyHost, Set.of("a", "b", "c", "d", "e", "f"), 2, 2, 3);
+ runTest(pm, threeEmptyHost, Set.of("a", "b", "c", "d", "e", "f", "g"), 2,
3, 1);
Map<HostAndPort,Set<String>> fourEmptyHost =
- Map.of(hp1, Set.of(), hp2, Set.of(), hp3, Set.of(), hp4, Set.of());
- runTest(fourEmptyHost, Set.of("a"), 0, 1, 1);
- runTest(fourEmptyHost, Set.of("a", "b"), 0, 1, 2);
- runTest(fourEmptyHost, Set.of("a", "b", "c"), 0, 1, 3);
- runTest(fourEmptyHost, Set.of("a", "b", "c", "d"), 1, 1, 4);
- runTest(fourEmptyHost, Set.of("a", "b", "c", "d", "e"), 1, 2, 1);
+ Map.of(pm, Set.of(), hp1, Set.of(), hp2, Set.of(), hp3, Set.of(), hp4,
Set.of());
+ runTest(pm, fourEmptyHost, Set.of("a"), 0, 1, 1);
+ runTest(pm, fourEmptyHost, Set.of("a", "b"), 0, 1, 2);
+ runTest(pm, fourEmptyHost, Set.of("a", "b", "c"), 0, 1, 3);
+ runTest(pm, fourEmptyHost, Set.of("a", "b", "c", "d"), 1, 1, 4);
+ runTest(pm, fourEmptyHost, Set.of("a", "b", "c", "d", "e"), 1, 2, 1);
var assignments =
- runTest(Map.of(hp1, Set.of("a", "z"), hp2, Set.of("b", "c", "x"), hp3,
Set.of("d", "e")),
- Set.of("a", "b", "c", "d", "e", "f"), 2, 2, 3);
- assertEquals(Map.of(hp1, Set.of("a", "f"), hp2, Set.of("b", "c"), hp3,
Set.of("d", "e")),
+ runTest(pm, Map.of(pm, Set.of(), hp1, Set.of("a", "z"), hp2,
Set.of("b", "c", "x"), hp3,
+ Set.of("d", "e")), Set.of("a", "b", "c", "d", "e", "f"), 2, 2, 3);
+ assertEquals(
+ Map.of(pm, Set.of(), hp1, Set.of("a", "f"), hp2, Set.of("b", "c"),
hp3, Set.of("d", "e")),
assignments);
- assignments =
- runTest(Map.of(hp1, Set.of("a", "b", "c"), hp2, Set.of("d", "x"), hp3,
Set.of("e")),
- Set.of("a", "b", "c", "d", "e", "f"), 2, 2, 3);
+ assignments = runTest(pm,
+ Map.of(pm, Set.of(), hp1, Set.of("a", "b", "c"), hp2, Set.of("d",
"x"), hp3, Set.of("e")),
+ Set.of("a", "b", "c", "d", "e", "f"), 2, 2, 3);
assertEquals(2, Sets.intersection(assignments.get(hp1), Set.of("a", "b",
"c")).size());
assertTrue(assignments.get(hp2).contains("d"));
assertTrue(assignments.get(hp3).contains("e"));
- assignments =
- runTest(Map.of(hp1, Set.of("a", "b", "c"), hp2, Set.of("d", "e", "f",
"g"), hp3, Set.of()),
- Set.of("a", "b", "c", "d", "e", "f", "g"), 2, 3, 1);
+ assignments = runTest(pm, Map.of(pm, Set.of(), hp1, Set.of("a", "b", "c"),
hp2,
+ Set.of("d", "e", "f", "g"), hp3, Set.of()), Set.of("a", "b", "c", "d",
"e", "f", "g"), 2, 3,
+ 1);
int iss1 = Sets.intersection(assignments.get(hp1), Set.of("a", "b",
"c")).size();
int iss2 = Sets.intersection(assignments.get(hp2), Set.of("d", "e", "f",
"g")).size();
assertTrue((iss1 == 2 && iss2 == 3) || (iss1 == 3 && iss2 == 2));
@@ -85,34 +86,73 @@ public class ManagerAssignmentTest {
@Test
public void testBug() {
+ var pm = HostAndPort.fromParts("127.0.0.1", 4999);
var hp1 = HostAndPort.fromParts("127.0.0.1", 5000);
var hp2 = HostAndPort.fromParts("127.0.0.1", 5001);
var hp3 = HostAndPort.fromParts("127.0.0.1", 5002);
var hp4 = HostAndPort.fromParts("127.0.0.1", 5003);
var hp5 = HostAndPort.fromParts("127.0.0.1", 5004);
- var assignments = runTest(
- Map.of(hp1, Set.of("a", "b", "c"), hp2, Set.of("d", "e", "f"), hp3,
Set.of("g", "h", "i"),
- hp4, Set.of(), hp5, Set.of()),
+ var assignments = runTest(pm,
+ Map.of(pm, Set.of(), hp1, Set.of("a", "b", "c"), hp2, Set.of("d", "e",
"f"), hp3,
+ Set.of("g", "h", "i"), hp4, Set.of(), hp5, Set.of()),
Set.of("a", "b", "c", "d", "e", "f", "g", "h", "i"), 1, 2, 4);
assertEquals(2, Sets.intersection(assignments.get(hp1), Set.of("a", "b",
"c")).size());
assertEquals(2, Sets.intersection(assignments.get(hp2), Set.of("d", "e",
"f")).size());
assertEquals(2, Sets.intersection(assignments.get(hp3), Set.of("g", "h",
"i")).size());
}
- private Map<HostAndPort,Set<String>> runTest(Map<HostAndPort,Set<String>>
currentAssignments,
- Set<String> parts, int expectedMin, int expectedMax, int
expectedHostWithMax) {
- var assignments = computeAssignments(currentAssignments, parts);
+ @Test
+ public void testPrimary() {
+ var pm = HostAndPort.fromParts("127.0.0.1", 4999);
+ var hp1 = HostAndPort.fromParts("127.0.0.1", 5000);
+ var hp2 = HostAndPort.fromParts("127.0.0.1", 5001);
+
+ // Simulate only having a primary manager, should assign everything to it
+ Map<HostAndPort,Set<String>> assignments =
+ runTest(pm, Map.of(pm, Set.of()), Set.of("a", "b", "c", "d"), 4, 4, 1);
+ assertEquals(Map.of(pm, Set.of("a", "b", "c", "d")), assignments);
+
+ // Simulate transition from only a primary manager to a primary and a
assistant manager. Should
+ // move everything off the primary and onto the assistant.
+ assignments = runTest(pm, Map.of(pm, Set.of("a", "b", "c", "d"), hp1,
Set.of()),
+ Set.of("a", "b", "c", "d"), 4, 4, 1);
+ assertEquals(Map.of(pm, Set.of(), hp1, Set.of("a", "b", "c", "d")),
assignments);
+
+ // Simulate transition from only a primary manager to a primary and two
assistant managers.
+ // Should move everything off the primary and onto the assistants.
+ assignments = runTest(pm, Map.of(pm, Set.of("a", "b", "c", "d"), hp1,
Set.of(), hp2, Set.of()),
+ Set.of("a", "b", "c", "d"), 2, 2, 2);
+ assertEquals(3, assignments.size());
+ assertEquals(Set.of(), assignments.get(pm));
+ assertEquals(2, assignments.get(hp1).size());
+ assertEquals(2, assignments.get(hp2).size());
+
+ // Test when current assignments does not contain the primary
+ assertThrows(IllegalStateException.class,
+ () -> computeAssignments(pm, Map.of(hp1, Set.of(), hp2, Set.of()),
Set.of("a", "b")));
+ }
+
+ private Map<HostAndPort,Set<String>> runTest(HostAndPort primary,
+ Map<HostAndPort,Set<String>> currentAssignments, Set<String> parts, int
expectedMin,
+ int expectedMax, int expectedHostWithMax) {
+ var assignments = computeAssignments(primary, currentAssignments, parts);
assertEquals(currentAssignments.keySet(), assignments.keySet());
HashSet<String> partsCopy = new HashSet<>(parts);
// ensure every partition is assigned and only assigned once
- assignments.values().forEach(hostAssignments -> {
+ assignments.forEach((host, hostAssignments) -> {
assertTrue(partsCopy.containsAll(hostAssignments), () -> partsCopy + " "
+ hostAssignments);
partsCopy.removeAll(hostAssignments);
- assertTrue(hostAssignments.size() == expectedMin ||
hostAssignments.size() == expectedMax);
+ if (currentAssignments.size() > 1 && host.equals(primary)) {
+ assertEquals(Set.of(), hostAssignments);
+ } else {
+ assertTrue(hostAssignments.size() == expectedMin ||
hostAssignments.size() == expectedMax);
+ }
});
+ assertEquals(Set.of(), partsCopy);
+
assertEquals(expectedHostWithMax,
assignments.values().stream().mapToInt(Set::size).filter(s -> s ==
expectedMax).count());
diff --git
a/test/src/main/java/org/apache/accumulo/test/ComprehensiveMultiManagerIT.java
b/test/src/main/java/org/apache/accumulo/test/ComprehensiveMultiManagerIT.java
index f3dc6edffb..011bcba30f 100644
---
a/test/src/main/java/org/apache/accumulo/test/ComprehensiveMultiManagerIT.java
+++
b/test/src/main/java/org/apache/accumulo/test/ComprehensiveMultiManagerIT.java
@@ -61,14 +61,17 @@ public class ComprehensiveMultiManagerIT extends
ComprehensiveITBase {
Wait.waitFor(() -> {
Map<HostAndPort,FateManager.CurrentPartitions> fateAssignments =
FateManager.getCurrentAssignments(srvCtx);
- boolean allAssigned = fateAssignments.size() == 3 &&
fateAssignments.values().stream()
- .noneMatch(currentPartitions ->
currentPartitions.partitions().isEmpty());
- if (allAssigned) {
+ long emptyCount = fateAssignments.values().stream()
+ .filter(currentPartitions ->
currentPartitions.partitions().isEmpty()).count();
+ long notEmptyCount = fateAssignments.values().stream()
+ .filter(currentPartitions ->
!currentPartitions.partitions().isEmpty()).count();
+ if (fateAssignments.size() == 3 && emptyCount == 1 && notEmptyCount ==
2) {
fateAssignments.forEach((hostPort, partitions) -> {
log.debug("Fate assignment {} {}", hostPort,
partitions.partitions());
});
+ return true;
}
- return allAssigned;
+ return false;
});
}
diff --git
a/test/src/main/java/org/apache/accumulo/test/MultipleManagerCompactionIT.java
b/test/src/main/java/org/apache/accumulo/test/MultipleManagerCompactionIT.java
index 9077d771b6..260e34e0e4 100644
---
a/test/src/main/java/org/apache/accumulo/test/MultipleManagerCompactionIT.java
+++
b/test/src/main/java/org/apache/accumulo/test/MultipleManagerCompactionIT.java
@@ -66,9 +66,10 @@ public class MultipleManagerCompactionIT extends
ConfigurableMacBase {
try (AccumuloClient client =
Accumulo.newClient().from(getCluster().getClientProperties()).build())
{
- // wait for three coordinator locations to show up in zookeeper
+ // wait for two coordinator locations to show up in zookeeper, the
primary manager will not be
+ // assigned anything
Wait.waitFor(
- () ->
getServerContext().getCoordinatorLocations().sortedUniqueHost().size() == 3);
+ () ->
getServerContext().getCoordinatorLocations().sortedUniqueHost().size() == 2);
assertEquals(getExpectedGroups(),
getServerContext().getCoordinatorLocations().locations().keySet());
@@ -94,9 +95,10 @@ public class MultipleManagerCompactionIT extends
ConfigurableMacBase {
getCluster().getConfig().getClusterServerConfiguration().setNumManagers(5);
getCluster().getClusterControl().start(ServerType.MANAGER);
- // wait for five coordinator locations to show up in zookeeper
+ // wait for four coordinator locations to show up in zookeeper, the
primary manager will not
+ // be assigned anything
Wait.waitFor(
- () ->
getServerContext().getCoordinatorLocations().sortedUniqueHost().size() == 5);
+ () ->
getServerContext().getCoordinatorLocations().sortedUniqueHost().size() == 4);
assertEquals(getExpectedGroups(),
getServerContext().getCoordinatorLocations().locations().keySet());
@@ -112,9 +114,9 @@ public class MultipleManagerCompactionIT extends
ConfigurableMacBase {
getCluster().getClusterControl().killProcess(ServerType.MANAGER, proc);
}
- // wait for two coordinator locations to show up in zookeeper
+ // wait for one coordinator location to show up in zookeeper
Wait.waitFor(
- () ->
getServerContext().getCoordinatorLocations().sortedUniqueHost().size() == 2,
+ () ->
getServerContext().getCoordinatorLocations().sortedUniqueHost().size() == 1,
120_000);
assertEquals(getExpectedGroups(),
getServerContext().getCoordinatorLocations().locations().keySet());
@@ -124,8 +126,6 @@ public class MultipleManagerCompactionIT extends
ConfigurableMacBase {
compact(client, table2, 2, GROUP2, true);
verify(client, table2, 30);
-
}
}
-
}
diff --git
a/test/src/main/java/org/apache/accumulo/test/MultipleManagerFateIT.java
b/test/src/main/java/org/apache/accumulo/test/MultipleManagerFateIT.java
index a15b1777f6..69621a9ede 100644
--- a/test/src/main/java/org/apache/accumulo/test/MultipleManagerFateIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/MultipleManagerFateIT.java
@@ -53,6 +53,7 @@ import org.apache.accumulo.core.lock.ServiceLock;
import org.apache.accumulo.core.lock.ServiceLockPaths;
import org.apache.accumulo.core.lock.ServiceLockPaths.ServiceLockPath;
import org.apache.accumulo.core.metadata.SystemTables;
+import org.apache.accumulo.core.rpc.clients.ManagerClient;
import org.apache.accumulo.core.util.UtilWaitThread;
import org.apache.accumulo.manager.Manager;
import org.apache.accumulo.manager.tableOps.FateEnv;
@@ -62,9 +63,11 @@ import org.apache.accumulo.miniclusterImpl.ProcessReference;
import org.apache.accumulo.server.ServerContext;
import org.apache.accumulo.test.fate.FastFate;
import org.apache.accumulo.test.functional.ConfigurableMacBase;
+import org.apache.accumulo.test.util.Wait;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.collect.Sets;
@@ -84,6 +87,9 @@ import com.google.common.net.HostAndPort;
*
*/
public class MultipleManagerFateIT extends ConfigurableMacBase {
+
+ private static final Logger log =
LoggerFactory.getLogger(MultipleManagerFateIT.class);
+
// A manager that will quickly clean up fate reservations held by dead
managers
public static class FastFateCleanupManager extends Manager {
protected FastFateCleanupManager(ServerOpts opts, String[] args) throws
IOException {
@@ -149,7 +155,7 @@ public class MultipleManagerFateIT extends
ConfigurableMacBase {
int loops = 0;
while (!stop.get() || loops == 0) {
client.tableOperations().create(table);
- log.info("Created table {}", table);
+ // log.info("Created table {}", table);
if (stop.get() && loops > 0) {
break;
}
@@ -254,6 +260,10 @@ public class MultipleManagerFateIT extends
ConfigurableMacBase {
private static void waitToSeeManagers(ClientContext context, int
expectedManagers,
UserFateStore<FateEnv> store, boolean managersKilled) {
+ Wait.waitFor(() -> ManagerClient.getPrimaryManagerLocation(context) !=
null);
+ var primaryManager =
HostAndPort.fromString(ManagerClient.getPrimaryManagerLocation(context));
+ log.debug("primary manager : {}", primaryManager);
+
// Track what reservations exist when entering, want to see new
reservations created during this
// function call.
var existingReservationUUIDs =
@@ -274,6 +284,9 @@ public class MultipleManagerFateIT extends
ConfigurableMacBase {
var expectedServers = assistants.stream().map(ServiceLockPath::getServer)
.map(HostAndPort::fromString).collect(toSet());
log.debug("managers seen in zookeeper :{}", expectedServers);
+ // Eventually the primary manager should be assigned no fate partitions,
so remove it from the
+ // expected severs.
+ assertTrue(expectedServers.remove(primaryManager));
Set<HostAndPort> reservationsSeen = new HashSet<>();
Set<HostAndPort> extraSeen = new HashSet<>();
@@ -285,7 +298,8 @@ public class MultipleManagerFateIT extends
ConfigurableMacBase {
// reassigned.
Set<Character> seenPrefixes = new HashSet<>();
- while (reservationsSeen.size() < expectedManagers ||
!seenPrefixes.equals(expectedPrefixes)) {
+ while (reservationsSeen.size() < (expectedManagers - 1)
+ || !seenPrefixes.equals(expectedPrefixes)) {
var reservations =
store.getActiveReservations(Set.of(FatePartition.all(FateInstanceType.USER)));
reservations.forEach((fateId, reservation) -> {
@@ -301,7 +315,7 @@ public class MultipleManagerFateIT extends
ConfigurableMacBase {
Sets.difference(expectedPrefixes, seenPrefixes));
}
}
- } else if (!managersKilled) {
+ } else if (!managersKilled && !hostPort.equals(primaryManager)) {
fail("Saw unexpected extra manager " + slp);
} else {
extraSeen.add(hostPort);
@@ -313,8 +327,8 @@ public class MultipleManagerFateIT extends
ConfigurableMacBase {
log.debug("managers seen in fate reservations :{}", reservationsSeen);
if (managersKilled) {
- log.debug("killed managers seen in fate reservations : {}", extraSeen);
+ log.debug("extra managers seen in fate reservations : {}", extraSeen);
}
- assertEquals(expectedManagers, reservationsSeen.size());
+ assertEquals(expectedManagers - 1, reservationsSeen.size());
}
}