jonmeredith commented on code in PR #2546:
URL: https://github.com/apache/cassandra/pull/2546#discussion_r1302225513
##########
test/distributed/org/apache/cassandra/distributed/impl/INodeProvisionStrategy.java:
##########
@@ -18,97 +18,174 @@
package org.apache.cassandra.distributed.impl;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+import org.apache.cassandra.net.SocketUtils;
import org.apache.cassandra.utils.Shared;
import static org.apache.cassandra.utils.Shared.Recursive.INTERFACES;
@Shared(inner = INTERFACES)
public interface INodeProvisionStrategy
{
- public enum Strategy
+ enum Strategy
{
OneNetworkInterface
{
- INodeProvisionStrategy create(int subnet) {
+ @Override
+ INodeProvisionStrategy create(int subnet, @Nullable Map<String,
Integer> portMap)
+ {
+ String ipAdress = "127.0." + subnet + ".1";
return new INodeProvisionStrategy()
{
+ @Override
public String seedIp()
{
- return "127.0." + subnet + ".1";
+ return ipAdress;
}
+ @Override
public int seedPort()
{
+ if (portMap != null)
+ {
+ return portMap.computeIfAbsent("seedPort", key ->
SocketUtils.findAvailablePort(seedIp(), 7012));
+ }
return 7012;
}
+ @Override
public String ipAddress(int nodeNum)
{
- return "127.0." + subnet + ".1";
+ return ipAdress;
}
+ @Override
public int storagePort(int nodeNum)
{
+ if (nodeNum == 1)
+ {
+ // for node 1 the storage port and seed ports are
the same
+ return seedPort();
+ }
+
+ if (portMap != null)
+ {
+ return portMap.computeIfAbsent("storagePort:" +
nodeNum, key -> SocketUtils.findAvailablePort(seedIp(), 7011 + nodeNum));
+ }
return 7011 + nodeNum;
}
+ @Override
public int nativeTransportPort(int nodeNum)
{
+ if (portMap != null)
+ {
+ return
portMap.computeIfAbsent("nativeTransportPort:" + nodeNum, key ->
SocketUtils.findAvailablePort(seedIp(), 9041 + nodeNum));
+ }
return 9041 + nodeNum;
}
+ @Override
public int jmxPort(int nodeNum)
{
+ if (portMap != null)
+ {
+ return portMap.computeIfAbsent("jmxPort:" +
nodeNum, key -> SocketUtils.findAvailablePort(seedIp(), 7199 + nodeNum));
+ }
return 7199 + nodeNum;
}
};
}
},
MultipleNetworkInterfaces
{
- INodeProvisionStrategy create(int subnet) {
- String ipPrefix = "127.0." + subnet + ".";
+ @Override
+ INodeProvisionStrategy create(int subnet, @Nullable Map<String,
Integer> portMap)
+ {
+ String ipPrefix = "127.0." + subnet + '.';
return new INodeProvisionStrategy()
{
+
+ @Override
public String seedIp()
{
- return ipPrefix + "1";
+ return ipPrefix + '1';
}
+ @Override
public int seedPort()
{
+ if (portMap != null)
+ {
+ return portMap.computeIfAbsent("seedPort", key ->
SocketUtils.findAvailablePort(seedIp(), 7012));
+ }
return 7012;
}
Review Comment:
Instead of checking for nodeNum == 1 in `storagePort`, you could just define
default methods on the interface for `seedIP()` and `seedPort()`, just calling
`ipAddress(1)` and `storagePort(1)` respectively and reduce the amount of
methods and make the portMap more regular with entries for `storagePort` for
all.
```portMap = {ConcurrentHashMap@16060} size = 6
"nativeTransportPort:2" -> {Integer@17131} 63721
"nativeTransportPort:1" -> {Integer@17107} 63719
"jmxPort:2" -> {Integer@17133} 63722
"jmxPort:1" -> {Integer@17109} 63720
"storagePort:2" -> {Integer@16549} 63709
"seedPort" -> {Integer@16550} 63708```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]