Skip to content

Commit 8f87758

Browse files
author
Tom McCormick
committed
HDFS-16791 WIP - client protocol and Filesystem apis implemented and building.
Tests for Distributed Filesystem, view filesystem and RBF
1 parent 4891bf5 commit 8f87758

19 files changed

Lines changed: 709 additions & 371 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4876,6 +4876,16 @@ public CompletableFuture<FSDataInputStream> build() throws IOException {
48764876

48774877
}
48784878

4879+
/**
4880+
* Return root path
4881+
* @param path
4882+
* @return
4883+
* @throws IOException
4884+
*/
4885+
public Path getEnclosingRoot(Path path) throws IOException {
4886+
return this.makeQualified(new Path("/"));
4887+
}
4888+
48794889
/**
48804890
* Create a multipart uploader.
48814891
* @param basePath file path under which all files are uploaded

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

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@
6161
@InterfaceAudience.Public
6262
@InterfaceStability.Stable
6363
public class FilterFileSystem extends FileSystem {
64-
64+
6565
protected FileSystem fs;
6666
protected String swapScheme;
67-
67+
6868
/*
6969
* so that extending classes can define it
7070
*/
7171
public FilterFileSystem() {
7272
}
73-
73+
7474
public FilterFileSystem(FileSystem fs) {
7575
this.fs = fs;
7676
this.statistics = fs.statistics;
7777
}
7878

7979
/**
80-
* Get the raw file system
80+
* Get the raw file system
8181
* @return FileSystem being filtered
8282
*/
8383
public FileSystem getRawFileSystem() {
@@ -108,8 +108,8 @@ public void initialize(URI name, Configuration conf) throws IOException {
108108
public URI getUri() {
109109
return fs.getUri();
110110
}
111-
112-
111+
112+
113113
@Override
114114
protected URI getCanonicalUri() {
115115
return fs.getCanonicalUri();
@@ -127,7 +127,7 @@ public Path makeQualified(Path path) {
127127
// swap in our scheme if the filtered fs is using a different scheme
128128
if (swapScheme != null) {
129129
try {
130-
// NOTE: should deal with authority, but too much other stuff is broken
130+
// NOTE: should deal with authority, but too much other stuff is broken
131131
fqPath = new Path(
132132
new URI(swapScheme, fqPath.toUri().getSchemeSpecificPart(), null)
133133
);
@@ -137,7 +137,7 @@ public Path makeQualified(Path path) {
137137
}
138138
return fqPath;
139139
}
140-
140+
141141
///////////////////////////////////////////////////////////////
142142
// FileSystem
143143
///////////////////////////////////////////////////////////////
@@ -223,14 +223,14 @@ protected RemoteIterator<LocatedFileStatus> listLocatedStatus(final Path f,
223223
public FSDataOutputStream createNonRecursive(Path f, FsPermission permission,
224224
EnumSet<CreateFlag> flags, int bufferSize, short replication, long blockSize,
225225
Progressable progress) throws IOException {
226-
226+
227227
return fs.createNonRecursive(f, permission, flags, bufferSize, replication, blockSize,
228228
progress);
229229
}
230230

231231
/**
232232
* Set replication for an existing file.
233-
*
233+
*
234234
* @param src file name
235235
* @param replication new replication
236236
* @throws IOException raised on errors performing I/O.
@@ -241,7 +241,7 @@ public FSDataOutputStream createNonRecursive(Path f, FsPermission permission,
241241
public boolean setReplication(Path src, short replication) throws IOException {
242242
return fs.setReplication(src, replication);
243243
}
244-
244+
245245
/**
246246
* Renames Path src to Path dst. Can take place on local fs
247247
* or remote DFS.
@@ -261,13 +261,13 @@ protected void rename(Path src, Path dst, Rename... options)
261261
public boolean truncate(Path f, final long newLength) throws IOException {
262262
return fs.truncate(f, newLength);
263263
}
264-
264+
265265
/** Delete a file */
266266
@Override
267267
public boolean delete(Path f, boolean recursive) throws IOException {
268268
return fs.delete(f, recursive);
269269
}
270-
270+
271271
/** List files in a directory. */
272272
@Override
273273
public FileStatus[] listStatus(Path f) throws IOException {
@@ -286,7 +286,7 @@ public RemoteIterator<LocatedFileStatus> listLocatedStatus(Path f)
286286
throws IOException {
287287
return fs.listLocatedStatus(f);
288288
}
289-
289+
290290
/** Return a remote iterator for listing in a directory */
291291
@Override
292292
public RemoteIterator<FileStatus> listStatusIterator(Path f)
@@ -303,34 +303,34 @@ public Path getHomeDirectory() {
303303
/**
304304
* Set the current working directory for the given file system. All relative
305305
* paths will be resolved relative to it.
306-
*
306+
*
307307
* @param newDir new dir.
308308
*/
309309
@Override
310310
public void setWorkingDirectory(Path newDir) {
311311
fs.setWorkingDirectory(newDir);
312312
}
313-
313+
314314
/**
315315
* Get the current working directory for the given file system
316-
*
316+
*
317317
* @return the directory pathname
318318
*/
319319
@Override
320320
public Path getWorkingDirectory() {
321321
return fs.getWorkingDirectory();
322322
}
323-
323+
324324
@Override
325325
protected Path getInitialWorkingDirectory() {
326326
return fs.getInitialWorkingDirectory();
327327
}
328-
328+
329329
@Override
330330
public FsStatus getStatus(Path p) throws IOException {
331331
return fs.getStatus(p);
332332
}
333-
333+
334334
@Override
335335
public boolean mkdirs(Path f, FsPermission permission) throws IOException {
336336
return fs.mkdirs(f, permission);
@@ -351,26 +351,26 @@ public void copyFromLocalFile(boolean delSrc, Path src, Path dst)
351351
throws IOException {
352352
fs.copyFromLocalFile(delSrc, src, dst);
353353
}
354-
354+
355355
/**
356356
* The src files are on the local disk. Add it to FS at
357357
* the given dst name.
358358
* delSrc indicates if the source should be removed
359359
*/
360360
@Override
361-
public void copyFromLocalFile(boolean delSrc, boolean overwrite,
361+
public void copyFromLocalFile(boolean delSrc, boolean overwrite,
362362
Path[] srcs, Path dst)
363363
throws IOException {
364364
fs.copyFromLocalFile(delSrc, overwrite, srcs, dst);
365365
}
366-
366+
367367
/**
368368
* The src file is on the local disk. Add it to FS at
369369
* the given dst name.
370370
* delSrc indicates if the source should be removed
371371
*/
372372
@Override
373-
public void copyFromLocalFile(boolean delSrc, boolean overwrite,
373+
public void copyFromLocalFile(boolean delSrc, boolean overwrite,
374374
Path src, Path dst)
375375
throws IOException {
376376
fs.copyFromLocalFile(delSrc, overwrite, src, dst);
@@ -380,13 +380,13 @@ public void copyFromLocalFile(boolean delSrc, boolean overwrite,
380380
* The src file is under FS, and the dst is on the local disk.
381381
* Copy it from FS control to the local dst name.
382382
* delSrc indicates if the src will be removed or not.
383-
*/
383+
*/
384384
@Override
385385
public void copyToLocalFile(boolean delSrc, Path src, Path dst)
386386
throws IOException {
387387
fs.copyToLocalFile(delSrc, src, dst);
388388
}
389-
389+
390390
/**
391391
* Returns a local File that the user can write output to. The caller
392392
* provides both the eventual FS target name and the local working
@@ -427,7 +427,7 @@ public long getUsed(Path path) throws IOException {
427427
public long getDefaultBlockSize() {
428428
return fs.getDefaultBlockSize();
429429
}
430-
430+
431431
@Override
432432
public short getDefaultReplication() {
433433
return fs.getDefaultReplication();
@@ -438,7 +438,7 @@ public FsServerDefaults getServerDefaults() throws IOException {
438438
return fs.getServerDefaults();
439439
}
440440

441-
// path variants delegate to underlying filesystem
441+
// path variants delegate to underlying filesystem
442442
@Override
443443
public long getDefaultBlockSize(Path f) {
444444
return fs.getDefaultBlockSize(f);
@@ -476,7 +476,7 @@ public void access(Path path, FsAction mode) throws AccessControlException,
476476
public void createSymlink(final Path target, final Path link,
477477
final boolean createParent) throws AccessControlException,
478478
FileAlreadyExistsException, FileNotFoundException,
479-
ParentNotDirectoryException, UnsupportedFileSystemException,
479+
ParentNotDirectoryException, UnsupportedFileSystemException,
480480
IOException {
481481
fs.createSymlink(target, link, createParent);
482482
}
@@ -513,7 +513,7 @@ public FileChecksum getFileChecksum(Path f, long length) throws IOException {
513513
public void setVerifyChecksum(boolean verifyChecksum) {
514514
fs.setVerifyChecksum(verifyChecksum);
515515
}
516-
516+
517517
@Override
518518
public void setWriteChecksum(boolean writeChecksum) {
519519
fs.setWriteChecksum(writeChecksum);
@@ -523,7 +523,7 @@ public void setWriteChecksum(boolean writeChecksum) {
523523
public Configuration getConf() {
524524
return fs.getConf();
525525
}
526-
526+
527527
@Override
528528
public void close() throws IOException {
529529
super.close();
@@ -564,7 +564,7 @@ protected boolean primitiveMkdir(Path f, FsPermission abdolutePermission)
564564
throws IOException {
565565
return fs.primitiveMkdir(f, abdolutePermission);
566566
}
567-
567+
568568
@Override // FileSystem
569569
public FileSystem[] getChildFileSystems() {
570570
return new FileSystem[]{fs};
@@ -575,13 +575,13 @@ public Path createSnapshot(Path path, String snapshotName)
575575
throws IOException {
576576
return fs.createSnapshot(path, snapshotName);
577577
}
578-
578+
579579
@Override // FileSystem
580580
public void renameSnapshot(Path path, String snapshotOldName,
581581
String snapshotNewName) throws IOException {
582582
fs.renameSnapshot(path, snapshotOldName, snapshotNewName);
583583
}
584-
584+
585585
@Override // FileSystem
586586
public void deleteSnapshot(Path path, String snapshotName)
587587
throws IOException {
@@ -732,6 +732,11 @@ protected CompletableFuture<FSDataInputStream> openFileWithOptions(
732732
return fs.openFileWithOptions(pathHandle, parameters);
733733
}
734734

735+
@Override
736+
public Path getEnclosingRoot(Path path) throws IOException {
737+
return fs.getEnclosingRoot(path);
738+
}
739+
735740
@Override
736741
public boolean hasPathCapability(final Path path, final String capability)
737742
throws IOException {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,14 @@ public boolean hasPathCapability(Path path, String capability)
13701370
}
13711371
}
13721372

1373+
@Override
1374+
public Path getEnclosingRoot(Path path) throws IOException {
1375+
InodeTree.ResolveResult<FileSystem> res = fsState.resolve(getUriPath(path), true);
1376+
Path fullPath = new Path(res.resolvedPath);
1377+
Path enclosingPath = res.targetFileSystem.getEnclosingRoot(path);
1378+
return enclosingPath.depth() > fullPath.depth() ? enclosingPath : fullPath;
1379+
}
1380+
13731381
/**
13741382
* An instance of this class represents an internal dir of the viewFs
13751383
* that is internal dir of the mount table.
@@ -1919,6 +1927,14 @@ public Collection<? extends BlockStoragePolicySpi> getAllStoragePolicies()
19191927
}
19201928
return allPolicies;
19211929
}
1930+
1931+
@Override
1932+
public Path getEnclosingRoot(Path path) throws IOException {
1933+
InodeTree.ResolveResult<FileSystem> res = fsState.resolve(path.toString(), true);
1934+
Path fullPath = new Path(res.resolvedPath);
1935+
Path enclosingPath = res.targetFileSystem.getEnclosingRoot(path);
1936+
return enclosingPath.depth() > fullPath.depth() ? enclosingPath : fullPath;
1937+
}
19221938
}
19231939

19241940
enum RenameStrategy {

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,4 +3528,14 @@ public DatanodeInfo[] slowDatanodeReport() throws IOException {
35283528
}
35293529
}
35303530

3531+
public Path getEnclosingRoot(String src) throws IOException {
3532+
checkOpen();
3533+
try (TraceScope ignored = newPathTraceScope("getEnclosingRoot", src)) {
3534+
return new Path(namenode.getEnclosingRoot(src));
3535+
} catch (RemoteException re) {
3536+
throw re.unwrapRemoteException(AccessControlException.class,
3537+
UnresolvedPathException.class);
3538+
}
3539+
}
3540+
35313541
}

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOpsCountStatistics.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public enum OpType {
6464
GET_EC_CODECS("op_get_ec_codecs"),
6565
GET_EC_POLICY("op_get_ec_policy"),
6666
GET_EC_POLICIES("op_get_ec_policies"),
67+
GET_ENCLOSING_ROOT("op_get_enclosing_root"),
6768
GET_ENCRYPTION_ZONE("op_get_encryption_zone"),
6869
GET_FILE_BLOCK_LOCATIONS("op_get_file_block_locations"),
6970
GET_FILE_CHECKSUM(CommonStatisticNames.OP_GET_FILE_CHECKSUM),

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3898,4 +3898,31 @@ public DatanodeInfo[] getSlowDatanodeStats() throws IOException {
38983898
return dfs.slowDatanodeReport();
38993899
}
39003900

3901+
/* HDFS only */
3902+
public Path getEnclosingRoot(final Path path) throws IOException {
3903+
statistics.incrementReadOps(1);
3904+
storageStatistics.incrementOpCounter(OpType.GET_ENCLOSING_ROOT);
3905+
Preconditions.checkNotNull(path);
3906+
Path absF = fixRelativePart(path);
3907+
return new FileSystemLinkResolver<Path>() {
3908+
@Override
3909+
public Path doCall(final Path p) throws IOException {
3910+
return dfs.getEnclosingRoot(getPathName(p));
3911+
}
3912+
3913+
@Override
3914+
public Path next(final FileSystem fs, final Path p)
3915+
throws IOException {
3916+
if (fs instanceof DistributedFileSystem) {
3917+
DistributedFileSystem myDfs = (DistributedFileSystem) fs;
3918+
return myDfs.getEnclosingRoot(p);
3919+
} else {
3920+
throw new UnsupportedOperationException(
3921+
"Cannot call getEZForPath"
3922+
+ " on a symlink to a non-DistributedFileSystem: " + path
3923+
+ " -> " + p);
3924+
}
3925+
}
3926+
}.resolve(this, absF);
3927+
}
39013928
}

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ClientProtocol.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.hadoop.classification.InterfaceStability;
2727
import org.apache.hadoop.crypto.CryptoProtocolVersion;
2828
import org.apache.hadoop.fs.BatchedRemoteIterator.BatchedEntries;
29+
import org.apache.hadoop.fs.Path;
2930
import org.apache.hadoop.fs.PathIsNotEmptyDirectoryException;
3031
import org.apache.hadoop.ha.HAServiceProtocol;
3132
import org.apache.hadoop.hdfs.AddBlockFlag;
@@ -1888,4 +1889,11 @@ BatchedEntries<OpenFileEntry> listOpenFiles(long prevId,
18881889
@ReadOnly
18891890
DatanodeInfo[] getSlowDatanodeReport() throws IOException;
18901891

1892+
/**
1893+
* Get the enclosing root for a path.
1894+
*/
1895+
@Idempotent
1896+
@ReadOnly(isCoordinated = true)
1897+
String getEnclosingRoot(String src) throws IOException;
1898+
18911899
}

0 commit comments

Comments
 (0)