This is an automated email from the ASF dual-hosted git repository. domgarguilo 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 ef824fdb00 Fix bug in InstanceOperationsImpl.getServer() (#5056) ef824fdb00 is described below commit ef824fdb004891432182017d0bf984b96b216729 Author: Dom G. <domgargu...@apache.org> AuthorDate: Wed Nov 13 16:09:22 2024 -0500 Fix bug in InstanceOperationsImpl.getServer() (#5056) * Fix bug in InstanceOperationsImpl.getServer() where the code to gather tservers was mistakenly collecting scan servers * Added tests for each of the server types accepted by this method --- .../core/clientImpl/InstanceOperationsImpl.java | 2 +- .../apache/accumulo/test/InstanceOperationsIT.java | 88 ++++++++++++++++++---- 2 files changed, 74 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/InstanceOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/InstanceOperationsImpl.java index 60ccc9145d..e111c6921f 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/InstanceOperationsImpl.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/InstanceOperationsImpl.java @@ -511,7 +511,7 @@ public class InstanceOperationsImpl implements InstanceOperations { throw new IllegalStateException("Multiple servers matching provided address"); } case TABLET_SERVER: - Set<ServiceLockPath> tservers = context.getServerPaths().getScanServer(rg, hp, true); + Set<ServiceLockPath> tservers = context.getServerPaths().getTabletServer(rg, hp, true); if (tservers.isEmpty()) { return null; } else if (tservers.size() == 1) { diff --git a/test/src/main/java/org/apache/accumulo/test/InstanceOperationsIT.java b/test/src/main/java/org/apache/accumulo/test/InstanceOperationsIT.java index 3fd18e353d..1aec21729f 100644 --- a/test/src/main/java/org/apache/accumulo/test/InstanceOperationsIT.java +++ b/test/src/main/java/org/apache/accumulo/test/InstanceOperationsIT.java @@ -44,12 +44,70 @@ import org.junit.jupiter.api.Test; public class InstanceOperationsIT extends AccumuloClusterHarness { + final int NUM_COMPACTORS = 3; + final int NUM_SCANSERVERS = 2; + final int NUM_TABLETSERVERS = 1; + @Override public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite) { cfg.setProperty(Property.INSTANCE_ZK_TIMEOUT, "10s"); - cfg.getClusterServerConfiguration().setNumDefaultCompactors(3); - cfg.getClusterServerConfiguration().setNumDefaultScanServers(2); - cfg.getClusterServerConfiguration().setNumDefaultTabletServers(1); + cfg.getClusterServerConfiguration().setNumDefaultCompactors(NUM_COMPACTORS); + cfg.getClusterServerConfiguration().setNumDefaultScanServers(NUM_SCANSERVERS); + cfg.getClusterServerConfiguration().setNumDefaultTabletServers(NUM_TABLETSERVERS); + } + + /** + * Verify that we get the same servers from getServers() and getServer() + */ + @Test + public void testGetServer() { + try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) { + final InstanceOperations iops = client.instanceOperations(); + + // Verify scan servers + final Set<ServerId> sservers = iops.getServers(ServerId.Type.SCAN_SERVER); + assertEquals(NUM_SCANSERVERS, sservers.size()); + sservers.forEach(expectedServerId -> { + ServerId actualServerId = + iops.getServer(expectedServerId.getType(), expectedServerId.getResourceGroup(), + expectedServerId.getHost(), expectedServerId.getPort()); + assertNotNull(actualServerId, "Expected to find scan server " + expectedServerId); + assertEquals(expectedServerId, actualServerId); + }); + + // Verify tablet servers + final Set<ServerId> tservers = iops.getServers(ServerId.Type.TABLET_SERVER); + assertEquals(NUM_TABLETSERVERS, tservers.size()); + tservers.forEach(expectedServerId -> { + ServerId actualServerId = + iops.getServer(expectedServerId.getType(), expectedServerId.getResourceGroup(), + expectedServerId.getHost(), expectedServerId.getPort()); + assertNotNull(actualServerId, "Expected to find tablet server " + expectedServerId); + assertEquals(expectedServerId, actualServerId); + }); + + // Verify compactors + final Set<ServerId> compactors = iops.getServers(ServerId.Type.COMPACTOR); + assertEquals(NUM_COMPACTORS, compactors.size()); + compactors.forEach(expectedServerId -> { + ServerId actualServerId = + iops.getServer(expectedServerId.getType(), expectedServerId.getResourceGroup(), + expectedServerId.getHost(), expectedServerId.getPort()); + assertNotNull(actualServerId, "Expected to find compactor " + expectedServerId); + assertEquals(expectedServerId, actualServerId); + }); + + // Verify managers + final Set<ServerId> managers = iops.getServers(ServerId.Type.MANAGER); + assertEquals(1, managers.size()); // Assuming there is only one manager + managers.forEach(expectedServerId -> { + ServerId actualServerId = + iops.getServer(expectedServerId.getType(), expectedServerId.getResourceGroup(), + expectedServerId.getHost(), expectedServerId.getPort()); + assertNotNull(actualServerId, "Expected to find manager " + expectedServerId); + assertEquals(expectedServerId, actualServerId); + }); + } } @SuppressWarnings("deprecation") @@ -58,16 +116,16 @@ public class InstanceOperationsIT extends AccumuloClusterHarness { try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) { InstanceOperations iops = client.instanceOperations(); - assertEquals(3, iops.getServers(ServerId.Type.COMPACTOR).size()); - assertEquals(3, iops.getCompactors().size()); + assertEquals(NUM_COMPACTORS, iops.getServers(ServerId.Type.COMPACTOR).size()); + assertEquals(NUM_COMPACTORS, iops.getCompactors().size()); validateAddresses(iops.getCompactors(), iops.getServers(ServerId.Type.COMPACTOR)); - assertEquals(2, iops.getServers(ServerId.Type.SCAN_SERVER).size()); - assertEquals(2, iops.getScanServers().size()); + assertEquals(NUM_SCANSERVERS, iops.getServers(ServerId.Type.SCAN_SERVER).size()); + assertEquals(NUM_SCANSERVERS, iops.getScanServers().size()); validateAddresses(iops.getScanServers(), iops.getServers(ServerId.Type.SCAN_SERVER)); - assertEquals(1, iops.getServers(ServerId.Type.TABLET_SERVER).size()); - assertEquals(1, iops.getTabletServers().size()); + assertEquals(NUM_TABLETSERVERS, iops.getServers(ServerId.Type.TABLET_SERVER).size()); + assertEquals(NUM_TABLETSERVERS, iops.getTabletServers().size()); validateAddresses(iops.getTabletServers(), iops.getServers(ServerId.Type.TABLET_SERVER)); assertEquals(1, iops.getServers(ServerId.Type.MANAGER).size()); @@ -96,12 +154,12 @@ public class InstanceOperationsIT extends AccumuloClusterHarness { public void testPing() throws Exception { try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) { - Wait.waitFor( - () -> client.instanceOperations().getServers(ServerId.Type.COMPACTOR).size() == 3); - Wait.waitFor( - () -> client.instanceOperations().getServers(ServerId.Type.SCAN_SERVER).size() == 2); - Wait.waitFor( - () -> client.instanceOperations().getServers(ServerId.Type.TABLET_SERVER).size() == 1); + Wait.waitFor(() -> client.instanceOperations().getServers(ServerId.Type.COMPACTOR).size() + == NUM_COMPACTORS); + Wait.waitFor(() -> client.instanceOperations().getServers(ServerId.Type.SCAN_SERVER).size() + == NUM_SCANSERVERS); + Wait.waitFor(() -> client.instanceOperations().getServers(ServerId.Type.TABLET_SERVER).size() + == NUM_TABLETSERVERS); final InstanceOperations io = client.instanceOperations(); Set<ServerId> servers = io.getServers(ServerId.Type.COMPACTOR);