Skip to content

Commit bf0581f

Browse files
committed
HADOOP-17542. IPV6 support in Netutils#createSocketAddress, review comments
1 parent 328577e commit bf0581f

File tree

3 files changed

+23
-28
lines changed

3 files changed

+23
-28
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFileSystem.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.concurrent.CompletableFuture;
3131

3232
import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions;
33-
import org.apache.commons.lang3.StringUtils;
3433
import org.apache.hadoop.classification.InterfaceAudience;
3534
import org.apache.hadoop.classification.InterfaceStability;
3635
import org.apache.hadoop.conf.Configuration;
@@ -105,18 +104,12 @@ public FileSystem getRawFileSystem() {
105104

106105
/** Return the name of the checksum file associated with a file.*/
107106
public Path getChecksumFile(Path file) {
108-
if (StringUtils.countMatches(file.toString(), ":") > 2) {
109-
return new Path(file.getParent(), "./" + file.getName() + ".crc");
110-
}
111107
return new Path(file.getParent(), "." + file.getName() + ".crc");
112108
}
113109

114110
/** Return true iff file is a checksum file name.*/
115111
public static boolean isChecksumFile(Path file) {
116112
String name = file.getName();
117-
if (StringUtils.countMatches(file.toString(), ":") > 2) {
118-
return name.startsWith("./") && name.endsWith(".crc");
119-
}
120113
return name.startsWith(".") && name.endsWith(".crc");
121114
}
122115

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,14 @@ public Path(String pathString) throws IllegalArgumentException {
200200

201201
// parse uri scheme, if any
202202
int colon = -1;
203-
int slash = -1;
203+
int slash = pathString.indexOf('/');
204204
if (StringUtils.countMatches(pathString, ":") > 2) {
205+
//In case of IPv6 address, we should be able to parse the scheme
206+
// correctly (This will ensure to parse path with & without scheme
207+
// correctly in IPv6).
205208
colon = pathString.indexOf(":/");
206-
slash = pathString.indexOf('/');
207209
} else {
208210
colon = pathString.indexOf(':');
209-
slash = pathString.indexOf('/');
210211
}
211212
if ((colon != -1) &&
212213
((slash == -1) || (colon < slash))) { // has a scheme

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestNetUtils.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -820,37 +820,38 @@ private <T> void assertBetterArrayEquals(T[] expect, T[]got) {
820820

821821
@Test
822822
public void testCreateSocketAddressWithIPV6() throws Throwable {
823-
String IPV6_SAMPLE_ADDRESS = "2a03:2880:2130:cf05:face:b00c:0:1";
824-
String IPV6_SAMPLE_WITH_PORT = IPV6_SAMPLE_ADDRESS + ":12345";
823+
String ipv6Address = "2a03:2880:2130:cf05:face:b00c:0:1";
824+
String ipv6WithPort = ipv6Address + ":12345";
825825

826-
InetSocketAddress addr = NetUtils.createSocketAddr(IPV6_SAMPLE_WITH_PORT,
826+
InetSocketAddress addr = NetUtils.createSocketAddr(ipv6WithPort,
827827
1000, "myconfig");
828-
assertEquals("[" + IPV6_SAMPLE_ADDRESS + "]", addr.getHostName());
828+
assertEquals("[" + ipv6Address + "]", addr.getHostName());
829829
assertEquals(12345, addr.getPort());
830830

831-
String IPV6_SAMPLE_ADDRESS_WITHSCOPE = IPV6_SAMPLE_ADDRESS + "%2";
832-
IPV6_SAMPLE_WITH_PORT = IPV6_SAMPLE_ADDRESS_WITHSCOPE + ":12345";
833-
addr = NetUtils.createSocketAddr(IPV6_SAMPLE_WITH_PORT, 1000, "myconfig");
834-
assertEquals("[" + IPV6_SAMPLE_ADDRESS + "]", addr.getHostName());
831+
String ipv6SampleAddressWithScope = ipv6Address + "%2";
832+
ipv6WithPort = ipv6SampleAddressWithScope + ":12345";
833+
addr = NetUtils.createSocketAddr(ipv6WithPort, 1000, "myconfig");
834+
assertEquals("[" + ipv6Address + "]", addr.getHostName());
835835
assertEquals(12345, addr.getPort());
836836

837-
IPV6_SAMPLE_ADDRESS = "[2a03:2880:2130:cf05:face:b00c:0:1]";
838-
IPV6_SAMPLE_WITH_PORT = IPV6_SAMPLE_ADDRESS + ":12345";
837+
ipv6Address = "[2a03:2880:2130:cf05:face:b00c:0:1]";
838+
ipv6WithPort = ipv6Address + ":12345";
839839

840-
addr = NetUtils.createSocketAddr(IPV6_SAMPLE_WITH_PORT, 1000, "myconfig");
841-
assertEquals(IPV6_SAMPLE_ADDRESS, addr.getHostName());
840+
addr = NetUtils.createSocketAddr(ipv6WithPort, 1000, "myconfig");
841+
assertEquals(ipv6Address, addr.getHostName());
842842
assertEquals(12345, addr.getPort());
843843

844-
String IPV6_ADDRESS_WITH_SCHEME = "https://2a03:2880:2130:cf05:face:b00c:0:1:12345";
845-
addr = NetUtils.createSocketAddr(IPV6_ADDRESS_WITH_SCHEME, 1000,
844+
String ipv6AddressWithScheme =
845+
"https://2a03:2880:2130:cf05:face:b00c:0:1:12345";
846+
addr = NetUtils.createSocketAddr(ipv6AddressWithScheme, 1000,
846847
"myconfig");
847-
assertEquals(IPV6_SAMPLE_ADDRESS, addr.getHostName());
848+
assertEquals(ipv6Address, addr.getHostName());
848849
assertEquals(12345, addr.getPort());
849850

850-
IPV6_ADDRESS_WITH_SCHEME = "https://[2a03:2880:2130:cf05:face:b00c:0:1]:12345";
851-
addr = NetUtils.createSocketAddr(IPV6_ADDRESS_WITH_SCHEME, 1000,
851+
ipv6AddressWithScheme = "https://[2a03:2880:2130:cf05:face:b00c:0:1]:12345";
852+
addr = NetUtils.createSocketAddr(ipv6AddressWithScheme, 1000,
852853
"myconfig");
853-
assertEquals(IPV6_SAMPLE_ADDRESS, addr.getHostName());
854+
assertEquals(ipv6Address, addr.getHostName());
854855
assertEquals(12345, addr.getPort());
855856
}
856857
}

0 commit comments

Comments
 (0)