Skip to content

Commit 15a5ea2

Browse files
authored
HADOOP-18169. getDelegationTokens in ViewFs should also fetch the token from fallback FS (#4094)
HADOOP-18169. getDelegationTokens in ViewFs should also fetch the token from the fallback FS
1 parent 94031b7 commit 15a5ea2

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,17 @@ public List<Token<?>> getDelegationTokens(String renewer) throws IOException {
746746
result.addAll(tokens);
747747
}
748748
}
749+
750+
// Add tokens from fallback FS
751+
if (this.fsState.getRootFallbackLink() != null) {
752+
AbstractFileSystem rootFallbackFs =
753+
this.fsState.getRootFallbackLink().getTargetFileSystem();
754+
List<Token<?>> tokens = rootFallbackFs.getDelegationTokens(renewer);
755+
if (tokens != null) {
756+
result.addAll(tokens);
757+
}
758+
}
759+
749760
return result;
750761
}
751762

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFsLinkFallback.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.net.URISyntaxException;
3030
import java.util.EnumSet;
3131

32+
import java.util.List;
3233
import org.apache.hadoop.conf.Configuration;
3334
import org.apache.hadoop.fs.AbstractFileSystem;
3435
import org.apache.hadoop.fs.FileAlreadyExistsException;
@@ -45,6 +46,7 @@
4546
import org.apache.hadoop.hdfs.DistributedFileSystem;
4647
import org.apache.hadoop.hdfs.MiniDFSCluster;
4748
import org.apache.hadoop.hdfs.MiniDFSNNTopology;
49+
import org.apache.hadoop.security.token.Token;
4850
import org.apache.hadoop.test.LambdaTestUtils;
4951
import org.junit.AfterClass;
5052
import org.junit.Assert;
@@ -182,6 +184,26 @@ public void testMkdirOfNewDirWithOutMatchingToMountOrFallbackDirTree()
182184
assertTrue(fsTarget.exists(test));
183185
}
184186

187+
/**
188+
* Test getDelegationToken when fallback is configured.
189+
*/
190+
@Test
191+
public void testGetDelegationToken() throws IOException {
192+
Configuration conf = new Configuration();
193+
conf.setBoolean(Constants.CONFIG_VIEWFS_MOUNT_LINKS_AS_SYMLINKS, false);
194+
ConfigUtil.addLink(conf, "/user",
195+
new Path(targetTestRoot.toString(), "user").toUri());
196+
ConfigUtil.addLink(conf, "/data",
197+
new Path(targetTestRoot.toString(), "data").toUri());
198+
ConfigUtil.addLinkFallback(conf, targetTestRoot.toUri());
199+
200+
FileContext fcView =
201+
FileContext.getFileContext(FsConstants.VIEWFS_URI, conf);
202+
List<Token<?>> tokens = fcView.getDelegationTokens(new Path("/"), "tester");
203+
// Two tokens from the two mount points and one token from fallback
204+
assertEquals(3, tokens.size());
205+
}
206+
185207
/**
186208
* Tests that when the parent dirs does not exist in fallback but the parent
187209
* dir is same as mount internal directory, then we create parent structure

0 commit comments

Comments
 (0)