This is an automated email from the ASF dual-hosted git repository. dlmarion pushed a commit to branch 2.1 in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.1 by this push: new a2ca2bc382 Created bind addr property (#5599) a2ca2bc382 is described below commit a2ca2bc382196f53ac1e096fa6d29d964d0ac756 Author: Dave Marion <dlmar...@apache.org> AuthorDate: Wed Jun 11 13:04:15 2025 -0400 Created bind addr property (#5599) This change includes a new property, rpc.bind.addr, which was included in 3.0 as general.process.bind.addr in #3192, backports ConfigOptsTest from #3192, and changes to AbstractServer to use either the '-a' or '-o rpc.bind.addr' bind address as the hostname. Closes #5430 Co-authored-by: Christopher Tubbs <ctubb...@apache.org> Co-authored-by: Daniel Roberts <ddani...@gmail.com> --- .../org/apache/accumulo/core/conf/Property.java | 3 +++ .../apache/accumulo/core/cli/ConfigOptsTest.java | 31 +++++++++++++++------- .../org/apache/accumulo/server/AbstractServer.java | 24 +++++++++++++++-- .../org/apache/accumulo/server/ServerOpts.java | 7 +++-- .../apache/accumulo/server/rpc/TServerUtils.java | 5 ++-- .../org/apache/accumulo/server/ServerOptsTest.java | 2 +- .../java/org/apache/accumulo/monitor/Monitor.java | 2 +- .../test/functional/GarbageCollectorIT.java | 3 ++- .../accumulo/test/functional/ZombieTServer.java | 3 ++- .../apache/accumulo/test/metrics/MetricsIT.java | 3 ++- .../accumulo/test/performance/NullTserver.java | 4 ++- 11 files changed, 65 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/org/apache/accumulo/core/conf/Property.java b/core/src/main/java/org/apache/accumulo/core/conf/Property.java index 5a938c1a3f..adfd95a66b 100644 --- a/core/src/main/java/org/apache/accumulo/core/conf/Property.java +++ b/core/src/main/java/org/apache/accumulo/core/conf/Property.java @@ -54,6 +54,9 @@ public enum Property { "Properties in this category related to the configuration of SSL keys for" + " RPC. See also `instance.ssl.enabled`.", "1.6.0"), + RPC_PROCESS_BIND_ADDRESS("rpc.bind.addr", "", PropertyType.STRING, + "The local IP address to which this server should bind for sending and receiving network traffic. If not set then the process binds to all addresses.", + "2.1.4"), RPC_MAX_MESSAGE_SIZE("rpc.message.size.max", Integer.toString(Integer.MAX_VALUE), PropertyType.BYTES, "The maximum size of a message that can be received by a server.", "2.1.3"), diff --git a/server/base/src/test/java/org/apache/accumulo/server/ServerOptsTest.java b/core/src/test/java/org/apache/accumulo/core/cli/ConfigOptsTest.java similarity index 60% copy from server/base/src/test/java/org/apache/accumulo/server/ServerOptsTest.java copy to core/src/test/java/org/apache/accumulo/core/cli/ConfigOptsTest.java index 1cde30e02e..e991bc74a3 100644 --- a/server/base/src/test/java/org/apache/accumulo/server/ServerOptsTest.java +++ b/core/src/test/java/org/apache/accumulo/core/cli/ConfigOptsTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.accumulo.server; +package org.apache.accumulo.core.cli; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -26,32 +26,43 @@ import org.apache.accumulo.core.conf.Property; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class ServerOptsTest { - private ServerOpts opts; +public class ConfigOptsTest { + private ConfigOpts opts; @BeforeEach public void setUp() { - opts = new ServerOpts(); + opts = new ConfigOpts(); } @Test public void testGetAddress() { - opts.parseArgs(ServerOptsTest.class.getName(), new String[] {"-a", "1.2.3.4"}); - assertEquals("1.2.3.4", opts.getAddress()); + opts.parseArgs(ConfigOptsTest.class.getName(), + new String[] {"-o", Property.RPC_PROCESS_BIND_ADDRESS.getKey() + "=1.2.3.4"}); + assertEquals("1.2.3.4", opts.getSiteConfiguration().get(Property.RPC_PROCESS_BIND_ADDRESS)); } @Test - public void testGetAddress_NOne() { - opts.parseArgs(ServerOptsTest.class.getName(), new String[] {}); - assertEquals("0.0.0.0", opts.getAddress()); + public void testGetAddress_None() { + opts.parseArgs(ConfigOptsTest.class.getName(), new String[] {}); + assertEquals("", opts.getSiteConfiguration().get(Property.RPC_PROCESS_BIND_ADDRESS)); } @Test public void testOverrideConfig() { AccumuloConfiguration defaults = DefaultConfiguration.getInstance(); assertEquals("localhost:2181", defaults.get(Property.INSTANCE_ZK_HOST)); - opts.parseArgs(ServerOptsTest.class.getName(), + opts.parseArgs(ConfigOptsTest.class.getName(), new String[] {"-o", "instance.zookeeper.host=test:123"}); assertEquals("test:123", opts.getSiteConfiguration().get(Property.INSTANCE_ZK_HOST)); } + + @Test + public void testOverrideMultiple() { + opts.parseArgs(ConfigOptsTest.class.getName(), + new String[] {"-o", Property.RPC_PROCESS_BIND_ADDRESS.getKey() + "=1.2.3.4", "-o", + Property.SSERV_CLIENTPORT.getKey() + "=8888"}); + assertEquals("1.2.3.4", opts.getSiteConfiguration().get(Property.RPC_PROCESS_BIND_ADDRESS)); + assertEquals("8888", opts.getSiteConfiguration().get(Property.SSERV_CLIENTPORT)); + } + } diff --git a/server/base/src/main/java/org/apache/accumulo/server/AbstractServer.java b/server/base/src/main/java/org/apache/accumulo/server/AbstractServer.java index 37cb9ee381..932eb0d078 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/AbstractServer.java +++ b/server/base/src/main/java/org/apache/accumulo/server/AbstractServer.java @@ -18,7 +18,6 @@ */ package org.apache.accumulo.server; -import java.util.Objects; import java.util.OptionalInt; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -65,8 +64,29 @@ public abstract class AbstractServer this.log = LoggerFactory.getLogger(getClass().getName()); this.applicationName = appName; opts.parseArgs(appName, args); - this.hostname = Objects.requireNonNull(opts.getAddress()); var siteConfig = opts.getSiteConfiguration(); + boolean oldBindParameterSpecifiedOnCmdLine = false; + boolean newBindParameterSpecified = false; + for (String arg : args) { + if (arg.equals("-a") || arg.equals("--address")) { + oldBindParameterSpecifiedOnCmdLine = true; + } else if (siteConfig.isPropertySet(Property.RPC_PROCESS_BIND_ADDRESS)) { + newBindParameterSpecified = true; + } + } + if (oldBindParameterSpecifiedOnCmdLine && newBindParameterSpecified) { + throw new IllegalStateException("Argument '-a' cannot be used with property 'rpc.bind.addr'"); + } + final String newBindParameter = siteConfig.get(Property.RPC_PROCESS_BIND_ADDRESS); + // If new bind parameter passed on command line or in file, then use it. + if (newBindParameterSpecified + || !newBindParameter.equals(Property.RPC_PROCESS_BIND_ADDRESS.getDefaultValue())) { + this.hostname = newBindParameter; + } else if (oldBindParameterSpecifiedOnCmdLine) { + this.hostname = opts.getAddress(); + } else { + this.hostname = ServerOpts.BIND_ALL_ADDRESSES; + } SecurityUtil.serverLogin(siteConfig); context = new ServerContext(siteConfig); final String upgradePrepNode = context.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE; diff --git a/server/base/src/main/java/org/apache/accumulo/server/ServerOpts.java b/server/base/src/main/java/org/apache/accumulo/server/ServerOpts.java index 3bde48f436..3e73d98127 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/ServerOpts.java +++ b/server/base/src/main/java/org/apache/accumulo/server/ServerOpts.java @@ -24,13 +24,16 @@ import com.beust.jcommander.Parameter; public class ServerOpts extends ConfigOpts { - @Parameter(names = {"-a", "--address"}, description = "address to bind to") + public static final String BIND_ALL_ADDRESSES = "0.0.0.0"; + + @Parameter(names = {"-a", "--address"}, + description = "address to bind to (deprecated, use `-o rpc.bind.addr=<address>` instead)") private String address = null; public String getAddress() { if (address != null) { return address; } - return "0.0.0.0"; + return BIND_ALL_ADDRESSES; } } diff --git a/server/base/src/main/java/org/apache/accumulo/server/rpc/TServerUtils.java b/server/base/src/main/java/org/apache/accumulo/server/rpc/TServerUtils.java index ea2572ffe7..7c34b6601d 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/rpc/TServerUtils.java +++ b/server/base/src/main/java/org/apache/accumulo/server/rpc/TServerUtils.java @@ -53,6 +53,7 @@ import org.apache.accumulo.core.util.UtilWaitThread; import org.apache.accumulo.core.util.threads.ThreadPools; import org.apache.accumulo.core.util.threads.Threads; import org.apache.accumulo.server.ServerContext; +import org.apache.accumulo.server.ServerOpts; import org.apache.hadoop.security.SaslRpcServer; import org.apache.hadoop.security.UserGroupInformation; import org.apache.thrift.TProcessor; @@ -498,7 +499,7 @@ public class TServerUtils { // If we can't get a real hostname from the provided host test, use the hostname from DNS for // localhost - if ("0.0.0.0".equals(hostname)) { + if (ServerOpts.BIND_ALL_ADDRESSES.equals(hostname)) { hostname = fqdn; } @@ -669,7 +670,7 @@ public class TServerUtils { } // check for the special "bind to everything address" - if (serverAddress.address.getHost().equals("0.0.0.0")) { + if (serverAddress.address.getHost().equals(ServerOpts.BIND_ALL_ADDRESSES)) { // can't get the address from the bind, so we'll do our best to invent our hostname try { serverAddress = new ServerAddress(finalServer, HostAndPort diff --git a/server/base/src/test/java/org/apache/accumulo/server/ServerOptsTest.java b/server/base/src/test/java/org/apache/accumulo/server/ServerOptsTest.java index 1cde30e02e..8314f43ad9 100644 --- a/server/base/src/test/java/org/apache/accumulo/server/ServerOptsTest.java +++ b/server/base/src/test/java/org/apache/accumulo/server/ServerOptsTest.java @@ -43,7 +43,7 @@ public class ServerOptsTest { @Test public void testGetAddress_NOne() { opts.parseArgs(ServerOptsTest.class.getName(), new String[] {}); - assertEquals("0.0.0.0", opts.getAddress()); + assertEquals(ServerOpts.BIND_ALL_ADDRESSES, opts.getAddress()); } @Test diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java index defa59dacd..369e725734 100644 --- a/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java +++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java @@ -482,7 +482,7 @@ public class Monitor extends AbstractServer implements HighlyAvailableService { } String advertiseHost = getHostname(); - if (advertiseHost.equals("0.0.0.0")) { + if (advertiseHost.equals(ServerOpts.BIND_ALL_ADDRESSES)) { try { advertiseHost = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { diff --git a/test/src/main/java/org/apache/accumulo/test/functional/GarbageCollectorIT.java b/test/src/main/java/org/apache/accumulo/test/functional/GarbageCollectorIT.java index d4b34debf4..25e89fbd60 100644 --- a/test/src/main/java/org/apache/accumulo/test/functional/GarbageCollectorIT.java +++ b/test/src/main/java/org/apache/accumulo/test/functional/GarbageCollectorIT.java @@ -71,6 +71,7 @@ import org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl.ProcessInfo; import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl; import org.apache.accumulo.miniclusterImpl.ProcessNotFoundException; import org.apache.accumulo.miniclusterImpl.ProcessReference; +import org.apache.accumulo.server.ServerOpts; import org.apache.accumulo.test.TestIngest; import org.apache.accumulo.test.VerifyIngest; import org.apache.accumulo.test.VerifyIngest.VerifyParams; @@ -436,7 +437,7 @@ public class GarbageCollectorIT extends ConfigurableMacBase { String host = addr.substring(0, addrSplit), port = addr.substring(addrSplit + 1); // We shouldn't have the "bindall" address in zk - assertNotEquals("0.0.0.0", host); + assertNotEquals(ServerOpts.BIND_ALL_ADDRESSES, host); // Nor should we have the "random port" in zk assertNotEquals(0, Integer.parseInt(port)); return; diff --git a/test/src/main/java/org/apache/accumulo/test/functional/ZombieTServer.java b/test/src/main/java/org/apache/accumulo/test/functional/ZombieTServer.java index 0b755ba0a1..3703b717a8 100644 --- a/test/src/main/java/org/apache/accumulo/test/functional/ZombieTServer.java +++ b/test/src/main/java/org/apache/accumulo/test/functional/ZombieTServer.java @@ -48,6 +48,7 @@ import org.apache.accumulo.core.util.ServerServices; import org.apache.accumulo.core.util.ServerServices.Service; import org.apache.accumulo.core.util.threads.ThreadPools; import org.apache.accumulo.server.ServerContext; +import org.apache.accumulo.server.ServerOpts; import org.apache.accumulo.server.client.ClientServiceHandler; import org.apache.accumulo.server.rpc.ServerAddress; import org.apache.accumulo.server.rpc.TServerUtils; @@ -126,7 +127,7 @@ public class ZombieTServer { ThriftServerType.CUSTOM_HS_HA, muxProcessor, "ZombieTServer", "walking dead", 2, ThreadPools.DEFAULT_TIMEOUT_MILLISECS, 1000, 10 * 1024 * 1024, null, null, -1, context.getConfiguration().getCount(Property.RPC_BACKLOG), context.getMetricsInfo(), false, - HostAndPort.fromParts("0.0.0.0", port)); + HostAndPort.fromParts(ServerOpts.BIND_ALL_ADDRESSES, port)); String addressString = serverPort.address.toString(); var zLockPath = diff --git a/test/src/main/java/org/apache/accumulo/test/metrics/MetricsIT.java b/test/src/main/java/org/apache/accumulo/test/metrics/MetricsIT.java index 77c76f41ad..b7cefe3c8b 100644 --- a/test/src/main/java/org/apache/accumulo/test/metrics/MetricsIT.java +++ b/test/src/main/java/org/apache/accumulo/test/metrics/MetricsIT.java @@ -45,6 +45,7 @@ import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.metrics.MetricsProducer; import org.apache.accumulo.core.spi.metrics.LoggingMeterRegistryFactory; import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl; +import org.apache.accumulo.server.ServerOpts; import org.apache.accumulo.test.functional.ConfigurableMacBase; import org.apache.accumulo.test.metrics.TestStatsDSink.Metric; import org.apache.hadoop.conf.Configuration; @@ -206,7 +207,7 @@ public class MetricsIT extends ConfigurableMacBase implements MetricsProducer { var t = a.getTags(); log.trace("METRICS, name: '{}' num tags: {}, tags: {}", a.getName(), t.size(), t); // check hostname is always set and is valid - assertNotEquals("0.0.0.0", a.getTags().get("host")); + assertNotEquals(ServerOpts.BIND_ALL_ADDRESSES, a.getTags().get("host")); assertNotNull(a.getTags().get("instance.name")); // check the length of the tag value is sane diff --git a/test/src/main/java/org/apache/accumulo/test/performance/NullTserver.java b/test/src/main/java/org/apache/accumulo/test/performance/NullTserver.java index e470d1ff48..d9625eaa21 100644 --- a/test/src/main/java/org/apache/accumulo/test/performance/NullTserver.java +++ b/test/src/main/java/org/apache/accumulo/test/performance/NullTserver.java @@ -74,6 +74,7 @@ import org.apache.accumulo.core.trace.thrift.TInfo; import org.apache.accumulo.core.util.HostAndPort; import org.apache.accumulo.core.util.threads.ThreadPools; import org.apache.accumulo.server.ServerContext; +import org.apache.accumulo.server.ServerOpts; import org.apache.accumulo.server.client.ClientServiceHandler; import org.apache.accumulo.server.manager.state.Assignment; import org.apache.accumulo.server.manager.state.MetaDataTableScanner; @@ -349,7 +350,8 @@ public class NullTserver { TServerUtils.startTServer(context.getConfiguration(), ThriftServerType.CUSTOM_HS_HA, muxProcessor, "NullTServer", "null tserver", 2, ThreadPools.DEFAULT_TIMEOUT_MILLISECS, 1000, 10 * 1024 * 1024, null, null, -1, context.getConfiguration().getCount(Property.RPC_BACKLOG), - context.getMetricsInfo(), false, HostAndPort.fromParts("0.0.0.0", opts.port)); + context.getMetricsInfo(), false, + HostAndPort.fromParts(ServerOpts.BIND_ALL_ADDRESSES, opts.port)); HostAndPort addr = HostAndPort.fromParts(InetAddress.getLocalHost().getHostName(), opts.port);