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 5ed97dfaaa fixes coordinator location advertisements (#6665)
5ed97dfaaa is described below
commit 5ed97dfaaa5e1c0c7f46ad7a934184c6a324408f
Author: Keith Turner <[email protected]>
AuthorDate: Mon Nov 23 11:04:09 2026 -0500
fixes coordinator location advertisements (#6665)
Only compaction coordinators that had resource groups assigned to them
were advertised in zookeeper. That meant potentially less coordinators
were available to compactors for operations that can be done on any
coordinator. For example if there were 5 coordinators and 2 compactor
resource groups, then only 2 coordinators would have been advertised.
After this change all 5 coordinators would be advertised.
The core of this change is modifying what is stored in ZK from :
```
Map<ResourceGroup, HostAndPort>
```
to
```
Map<HostAndPort, Set<ResourceGroup>>
```
---
.../compaction/CoordinatorLocationsFactory.java | 75 +++++++++++++++++-----
.../org/apache/accumulo/compactor/Compactor.java | 6 +-
.../manager/compaction/CompactionJobClient.java | 2 +-
.../compaction/coordinator/CoordinatorManager.java | 25 ++++----
.../accumulo/test/MultipleManagerCompactionIT.java | 6 +-
5 files changed, 79 insertions(+), 35 deletions(-)
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/compaction/CoordinatorLocationsFactory.java
b/server/base/src/main/java/org/apache/accumulo/server/compaction/CoordinatorLocationsFactory.java
index 528ecba251..bd2dd94283 100644
---
a/server/base/src/main/java/org/apache/accumulo/server/compaction/CoordinatorLocationsFactory.java
+++
b/server/base/src/main/java/org/apache/accumulo/server/compaction/CoordinatorLocationsFactory.java
@@ -22,18 +22,23 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.accumulo.core.util.LazySingletons.GSON;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.data.AbstractId;
import org.apache.accumulo.core.data.ResourceGroupId;
import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy;
import org.apache.accumulo.server.ServerContext;
import org.apache.zookeeper.KeeperException;
+import com.google.common.base.Preconditions;
import com.google.common.net.HostAndPort;
import com.google.common.reflect.TypeToken;
@@ -52,46 +57,82 @@ public class CoordinatorLocationsFactory {
}
public static final class CoordinatorLocations {
- private final Map<ResourceGroupId,HostAndPort> locations;
+ private final Map<HostAndPort,Set<ResourceGroupId>> hostAssignments;
+ private final Map<ResourceGroupId,HostAndPort> groupAssignments;
private final List<HostAndPort> sortedUniqueHost;
- private CoordinatorLocations(Map<ResourceGroupId,HostAndPort> locations) {
- this.locations = Map.copyOf(locations);
- this.sortedUniqueHost = locations.values().stream().distinct()
- .sorted(Comparator.comparing(HostAndPort::toString)).toList();
+ private CoordinatorLocations(Map<HostAndPort,List<ResourceGroupId>>
assignments) {
+ final HashSet<ResourceGroupId> seenGroups = new HashSet<>();
+ final Map<HostAndPort,Set<ResourceGroupId>> hostAssignments = new
HashMap<>();
+ final Map<ResourceGroupId,HostAndPort> groupAssignments = new
HashMap<>();
+ final List<HostAndPort> sortedUniqueHost = new
ArrayList<>(assignments.size());
+
+ assignments.entrySet().forEach(e -> {
+ var hostAndPort = e.getKey();
+ var resourceGroups = e.getValue();
+ resourceGroups.forEach(rgid -> {
+ Preconditions.checkArgument(seenGroups.add(rgid), "Duplicated
resource group %s %s", rgid,
+ assignments);
+ groupAssignments.put(rgid, hostAndPort);
+ });
+ hostAssignments.put(hostAndPort, Set.copyOf(resourceGroups));
+ sortedUniqueHost.add(hostAndPort);
+ });
+
+ this.hostAssignments = Map.copyOf(hostAssignments);
+ this.groupAssignments = Map.copyOf(groupAssignments);
+ sortedUniqueHost.sort(Comparator.comparing(HostAndPort::toString));
+ this.sortedUniqueHost = List.copyOf(sortedUniqueHost);
+ }
+
+ /**
+ * @return the compactor resource groups assigned to each coordinator. If
a coordinator has no
+ * assigned resource groups, then it should have an empty set as
the value.
+ */
+ public Map<HostAndPort,Set<ResourceGroupId>> hostAssignments() {
+ return hostAssignments;
}
- public Map<ResourceGroupId,HostAndPort> locations() {
- return locations;
+ /**
+ * @return mapping of the coordinator that each resource group is assigned
to, if a coordinator
+ * has no assigned resource groups then it will not show up in
this map.
+ */
+ public Map<ResourceGroupId,HostAndPort> groupAssignments() {
+ return groupAssignments;
}
+ /**
+ * @return all coordinators, even coordinators with no assigned resource
groups, in sorted
+ * order.
+ */
public List<HostAndPort> sortedUniqueHost() {
return sortedUniqueHost;
}
}
- private static final Type MAP_TYPE = new TypeToken<Map<String,String>>()
{}.getType();
+ private static final Type MAP_TYPE = new
TypeToken<Map<String,List<String>>>() {}.getType();
public synchronized CoordinatorLocations getLocations() {
var zooCache = context.getZooCache();
if (lastLocations == null || lastUpdateCount != zooCache.getUpdateCount())
{
lastUpdateCount = zooCache.getUpdateCount();
byte[] serializedMap = zooCache.get(Constants.ZMANAGER_COORDINATOR);
- Map<String,String> stringMap =
+ Map<String,List<String>> stringMap =
GSON.get().fromJson(new String(serializedMap, UTF_8), MAP_TYPE);
- Map<ResourceGroupId,HostAndPort> locations = new
HashMap<>(stringMap.size());
- stringMap
- .forEach((rg, hp) -> locations.put(ResourceGroupId.of(rg),
HostAndPort.fromString(hp)));
+ Map<HostAndPort,List<ResourceGroupId>> locations = new
HashMap<>(stringMap.size());
+ stringMap.forEach((hp, rgids) ->
locations.put(HostAndPort.fromString(hp),
+ rgids.stream().map(ResourceGroupId::of).toList()));
lastLocations = new CoordinatorLocations(locations);
}
return lastLocations;
}
- public static void setLocations(ZooReaderWriter zk,
Map<ResourceGroupId,HostAndPort> locations,
- NodeExistsPolicy nodeExistsPolicy) throws InterruptedException,
KeeperException {
- Map<String,String> stringMap = new HashMap<>(locations.size());
- locations.forEach((rg, hp) -> {
- stringMap.put(rg.canonical(), hp.toString());
+ public static void setLocations(ZooReaderWriter zk,
+ Map<HostAndPort,Set<ResourceGroupId>> locations, NodeExistsPolicy
nodeExistsPolicy)
+ throws InterruptedException, KeeperException {
+ Map<String,List<String>> stringMap = new HashMap<>(locations.size());
+ locations.forEach((hp, rgids) -> {
+ stringMap.put(hp.toString(),
rgids.stream().map(AbstractId::canonical).toList());
});
byte[] serializedMap = GSON.get().toJson(stringMap).getBytes(UTF_8);
zk.putPersistentData(Constants.ZMANAGER_COORDINATOR, serializedMap,
nodeExistsPolicy);
diff --git
a/server/compactor/src/main/java/org/apache/accumulo/compactor/Compactor.java
b/server/compactor/src/main/java/org/apache/accumulo/compactor/Compactor.java
index da8330adaf..75fe538a23 100644
---
a/server/compactor/src/main/java/org/apache/accumulo/compactor/Compactor.java
+++
b/server/compactor/src/main/java/org/apache/accumulo/compactor/Compactor.java
@@ -604,7 +604,7 @@ public class Compactor extends AbstractServer implements
MetricsProducer, Compac
var coordinatorHost = switch (locationType) {
case GROUP -> {
- var allCoordinatorLocations =
getContext().getCoordinatorLocations().locations();
+ var allCoordinatorLocations =
getContext().getCoordinatorLocations().groupAssignments();
var host = allCoordinatorLocations.get(getResourceGroup());
if (host == null) {
throw new TTransportException("Did not find group " +
getResourceGroup()
@@ -617,8 +617,8 @@ public class Compactor extends AbstractServer implements
MetricsProducer, Compac
if (hosts.isEmpty()) {
throw new TTransportException("There are no coordinators in
zookeeper.");
}
- int hashedClientAddr = Math
-
.abs(Hashing.murmur3_128().hashString(getAdvertiseAddress().toString(),
UTF_8).asInt());
+ int hashedClientAddr =
+
Math.abs(Hashing.sha256().hashString(getAdvertiseAddress().toString(),
UTF_8).asInt());
// Hashing compactors to coordinators will spread them evenly across
coordinators, however
// each coordinator will only have connections for
#compactors/#coordinators. If compactors
// randomly choose a coordinator, then each coordinator would have a
lot more connections.
diff --git
a/server/manager/src/main/java/org/apache/accumulo/manager/compaction/CompactionJobClient.java
b/server/manager/src/main/java/org/apache/accumulo/manager/compaction/CompactionJobClient.java
index a6b5c6f8d1..c3a22d979c 100644
---
a/server/manager/src/main/java/org/apache/accumulo/manager/compaction/CompactionJobClient.java
+++
b/server/manager/src/main/java/org/apache/accumulo/manager/compaction/CompactionJobClient.java
@@ -71,7 +71,7 @@ public class CompactionJobClient implements AutoCloseable {
this.dataLevel = dataLevel;
this.fullScan = fullScan;
- this.coordinatorLocations = context.getCoordinatorLocations().locations();
+ this.coordinatorLocations =
context.getCoordinatorLocations().groupAssignments();
log.trace("Using coordinator locations {}", coordinatorLocations);
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 e8c8bdd78e..cb2da222d5 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
@@ -107,9 +107,9 @@ public class CoordinatorManager {
// This code is running in the primary manager, so should find
ourselves.
throw new IllegalStateException("No primary manager found");
}
+ var primary = HostAndPort.fromString(primaryManager);
- var desired =
- computeAssignments(HostAndPort.fromString(primaryManager),
current, configuredGroups);
+ var desired = computeAssignments(primary, current, configuredGroups);
log.trace("Desired assignments {}", desired);
if (!current.equals(desired)) {
@@ -127,7 +127,15 @@ public class CoordinatorManager {
.getTimeInMillis(Property.COMPACTION_COORDINATOR_ASSIGNMENT_MAX));
}
- advertiseAssignments(desired);
+ if (desired.size() > 1 && desired.getOrDefault(primary,
Set.of()).isEmpty()) {
+ // Do not advertise the primary as a coordinator when nothing is
assigned to it and there
+ // is more that one manager.
+ var copy = new HashMap<>(desired);
+ copy.remove(primary);
+ advertiseAssignments(copy);
+ } else {
+ advertiseAssignments(desired);
+ }
} catch (Exception e) {
log.warn("Failed to set compaction coordinator assignments", e);
sleepTime = context.getConfiguration()
@@ -142,15 +150,10 @@ public class CoordinatorManager {
private void advertiseAssignments(Map<HostAndPort,Set<ResourceGroupId>>
desired)
throws InterruptedException, KeeperException {
- // transform desired set to look like what is in zookeeper
- HashMap<ResourceGroupId,HostAndPort> locations = new HashMap<>();
- desired.forEach((hp, rgs) -> {
- rgs.forEach(rg -> locations.put(rg, hp));
- });
- var assignmentsInZk = context.getCoordinatorLocations().locations();
- if (!locations.equals(assignmentsInZk)) {
-
CoordinatorLocationsFactory.setLocations(context.getZooSession().asReaderWriter(),
locations,
+ var assignmentsInZk = context.getCoordinatorLocations().hostAssignments();
+ if (!desired.equals(assignmentsInZk)) {
+
CoordinatorLocationsFactory.setLocations(context.getZooSession().asReaderWriter(),
desired,
NodeExistsPolicy.OVERWRITE);
log.debug("Set new coordinator locations {}", desired);
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 260e34e0e4..12378cf831 100644
---
a/test/src/main/java/org/apache/accumulo/test/MultipleManagerCompactionIT.java
+++
b/test/src/main/java/org/apache/accumulo/test/MultipleManagerCompactionIT.java
@@ -71,7 +71,7 @@ public class MultipleManagerCompactionIT extends
ConfigurableMacBase {
Wait.waitFor(
() ->
getServerContext().getCoordinatorLocations().sortedUniqueHost().size() == 2);
assertEquals(getExpectedGroups(),
- getServerContext().getCoordinatorLocations().locations().keySet());
+
getServerContext().getCoordinatorLocations().groupAssignments().keySet());
String table1 = names[0];
createTable(client, table1, "cs1");
@@ -100,7 +100,7 @@ public class MultipleManagerCompactionIT extends
ConfigurableMacBase {
Wait.waitFor(
() ->
getServerContext().getCoordinatorLocations().sortedUniqueHost().size() == 4);
assertEquals(getExpectedGroups(),
- getServerContext().getCoordinatorLocations().locations().keySet());
+
getServerContext().getCoordinatorLocations().groupAssignments().keySet());
compact(client, table1, 3, GROUP1, true);
verify(client, table1, 6);
@@ -119,7 +119,7 @@ public class MultipleManagerCompactionIT extends
ConfigurableMacBase {
() ->
getServerContext().getCoordinatorLocations().sortedUniqueHost().size() == 1,
120_000);
assertEquals(getExpectedGroups(),
- getServerContext().getCoordinatorLocations().locations().keySet());
+
getServerContext().getCoordinatorLocations().groupAssignments().keySet());
compact(client, table1, 5, GROUP1, true);
verify(client, table1, 30);