Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public List<String> getManagerLocations() {
if (managers == null || managers.isEmpty()) {
return List.of();
} else {
return List.of(managers.iterator().next().toHostPortString());
return managers.stream().map(ServerId::toHostPortString).toList();
}
}

Expand Down Expand Up @@ -561,18 +561,8 @@ private Set<ServerId> getServers(ServerId.Type type,
.forEach(c -> results.add(createServerId(type, c)));
break;
case MANAGER:
ServiceLockPath m = context.getServerPaths().getManager(true);
if (m != null) {
Optional<ServiceLockData> sld = context.getZooCache().getLockData(m);
String location = null;
if (sld.isPresent()) {
location = sld.orElseThrow().getAddressString(ThriftService.MANAGER);
if (location != null && addressSelector.getPredicate().test(location)) {
HostAndPort hp = HostAndPort.fromString(location);
results.add(new ServerId(type, ResourceGroupId.DEFAULT, hp.getHost(), hp.getPort()));
}
}
}
context.getServerPaths().getAssistantManagers(addressSelector, true)
.forEach(s -> results.add(createServerId(type, s)));
break;
case MONITOR:
ServiceLockPath mon = context.getServerPaths().getMonitor(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
import static com.google.common.base.Preconditions.checkArgument;

import java.net.UnknownHostException;
import java.util.Set;
import java.util.Optional;

import org.apache.accumulo.core.client.admin.servers.ServerId;
import org.apache.accumulo.core.clientImpl.ClientContext;
import org.apache.accumulo.core.lock.ServiceLockData;
import org.apache.accumulo.core.lock.ServiceLockPaths;
import org.apache.accumulo.core.rpc.ThriftUtil;
import org.apache.thrift.TServiceClient;
import org.apache.thrift.transport.TTransportException;
Expand All @@ -37,14 +38,21 @@ public interface ManagerClient<C extends TServiceClient> {
default C getManagerConnection(Logger log, ThriftClientTypes<C> type, ClientContext context) {
checkArgument(context != null, "context is null");

Set<ServerId> managers = context.instanceOperations().getServers(ServerId.Type.MANAGER);
// obtain the primary manager location
String managerLocation = null;
ServiceLockPaths.ServiceLockPath m = context.getServerPaths().getManager(true);
if (m != null) {
Optional<ServiceLockData> sld = context.getZooCache().getLockData(m);
if (sld.isPresent()) {
managerLocation = sld.orElseThrow().getAddressString(ServiceLockData.ThriftService.MANAGER);
}
}

if (managers == null || managers.isEmpty()) {
if (managerLocation == null) {
log.debug("No managers...");
return null;
}

final String managerLocation = managers.iterator().next().toHostPortString();
if (managerLocation.equals("0.0.0.0:0")) {
// The Manager creates the lock with an initial address of 0.0.0.0:0, then
// later updates the lock contents with the actual address after everything
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,9 @@ public String description() {
public void execute(JCommander cl, ServerOpts options) throws Exception {
ServerContext context = getServerContext();
Set<ServerId> managers = context.instanceOperations().getServers(ServerId.Type.MANAGER);
String manager = null;
if (managers != null && !managers.isEmpty()) {
manager = managers.iterator().next().getHost();
}

System.out.println("monitor: " + MonitorUtil.getLocation(context));
System.out.println("managers: " + manager);
System.out.println("managers: " + managers);
System.out.println("zookeepers: " + context.getZooKeepers());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ private static boolean checkZKLocks(ServerContext context) throws Exception {
var servers = context.instanceOperations().getServers(serverType);

switch (serverType) {
case MANAGER:
// essential process
case GARBAGE_COLLECTOR:
// essential process
if (servers.size() != 1) {
Expand All @@ -101,6 +99,8 @@ private static boolean checkZKLocks(ServerContext context) throws Exception {
log.trace("Verified ZooKeeper lock for {}", servers);
}
break;
case MANAGER:
// essential process(es)
case TABLET_SERVER:
// essential process(es)
case COMPACTOR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
import org.apache.accumulo.core.client.Accumulo;
import org.apache.accumulo.core.client.AccumuloClient;
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.admin.InstanceOperations;
import org.apache.accumulo.core.client.admin.servers.ServerId;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.data.ResourceGroupId;
import org.apache.accumulo.harness.AccumuloClusterHarness;
import org.apache.accumulo.minicluster.ServerType;
import org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl;
import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
import org.apache.accumulo.test.util.Wait;
import org.apache.hadoop.conf.Configuration;
Expand All @@ -60,7 +61,7 @@ public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration hadoo
* Verify that we get the same servers from getServers() and getServer()
*/
@Test
public void testGetServer() {
public void testGetServer() throws Exception {
try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
final InstanceOperations iops = client.instanceOperations();

Expand Down Expand Up @@ -108,6 +109,20 @@ public void testGetServer() {
assertEquals(expectedServerId, actualServerId);
});

var cluster = (MiniAccumuloClusterImpl) getCluster();
cluster.getConfig().getClusterServerConfiguration().setNumManagers(3);
cluster.getClusterControl().start(ServerType.MANAGER);
Wait.waitFor(() -> iops.getServers(ServerId.Type.MANAGER).size() == 3);
final Set<ServerId> managers3 = iops.getServers(ServerId.Type.MANAGER);
assertEquals(3, managers3.size());
managers3.forEach(expectedServerId -> {
ServerId actualServerId =
iops.getServer(expectedServerId.getType(), expectedServerId.getResourceGroup(),
expectedServerId.getHost(), expectedServerId.getPort());
assertNotNull(actualServerId, "Expected to find manager " + expectedServerId);
assertEquals(expectedServerId, actualServerId);
});

// verify GC
final Set<ServerId> gcs = iops.getServers(ServerId.Type.GARBAGE_COLLECTOR);
assertEquals(1, gcs.size()); // Assuming there is only one garbage collector
Expand All @@ -128,7 +143,7 @@ public void testGetServer() {

@SuppressWarnings("deprecation")
@Test
public void testGetServers() throws AccumuloException, AccumuloSecurityException {
public void testGetServers() throws Exception {
try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
InstanceOperations iops = client.instanceOperations();

Expand All @@ -147,6 +162,13 @@ public void testGetServers() throws AccumuloException, AccumuloSecurityException
assertEquals(1, iops.getServers(ServerId.Type.MANAGER).size());
assertEquals(1, iops.getManagerLocations().size());
validateAddresses(iops.getManagerLocations(), iops.getServers(ServerId.Type.MANAGER));
var cluster = (MiniAccumuloClusterImpl) getCluster();
cluster.getConfig().getClusterServerConfiguration().setNumManagers(3);
cluster.getClusterControl().start(ServerType.MANAGER);
Wait.waitFor(() -> iops.getServers(ServerId.Type.MANAGER).size() == 3);
assertEquals(3, iops.getServers(ServerId.Type.MANAGER).size());
assertEquals(3, iops.getManagerLocations().size());
validateAddresses(iops.getManagerLocations(), iops.getServers(ServerId.Type.MANAGER));

assertEquals(1, iops.getServers(ServerId.Type.GARBAGE_COLLECTOR).size());

Expand Down