Skip to content

Commit dd1634e

Browse files
aajisakajojochuang
authored andcommitted
HADOOP-17255. JavaKeyStoreProvider fails to create a new key if the keystore is HDFS. (#2291)
Reviewed-by: Steve Loughran <[email protected]> Reviewed-by: Wei-Chiu Chuang <[email protected]> (cherry picked from commit 7f5caca)
1 parent 2473e8b commit dd1634e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/JavaKeyStoreProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.hadoop.conf.Configuration;
2424
import org.apache.hadoop.fs.FSDataInputStream;
2525
import org.apache.hadoop.fs.FSDataOutputStream;
26+
import org.apache.hadoop.fs.FileContext;
2627
import org.apache.hadoop.fs.FileStatus;
2728
import org.apache.hadoop.fs.FileSystem;
2829
import org.apache.hadoop.fs.Path;
@@ -104,6 +105,7 @@ public class JavaKeyStoreProvider extends KeyProvider {
104105
private final Path path;
105106
private final FileSystem fs;
106107
private FsPermission permissions;
108+
private FileContext context;
107109
private KeyStore keyStore;
108110
private char[] password;
109111
private boolean changed = false;
@@ -131,6 +133,7 @@ private JavaKeyStoreProvider(URI uri, Configuration conf) throws IOException {
131133
this.uri = uri;
132134
path = ProviderUtils.unnestUri(uri);
133135
fs = path.getFileSystem(conf);
136+
context = FileContext.getFileContext(conf);
134137
locateKeystore();
135138
ReadWriteLock lock = new ReentrantReadWriteLock(true);
136139
readLock = lock.readLock();
@@ -639,10 +642,7 @@ private void revertFromOld(Path oldPath, boolean fileExisted)
639642

640643
private void renameOrFail(Path src, Path dest)
641644
throws IOException {
642-
if (!fs.rename(src, dest)) {
643-
throw new IOException("Rename unsuccessful : "
644-
+ String.format("'%s' to '%s'", src, dest));
645-
}
645+
context.rename(src, dest, org.apache.hadoop.fs.Options.Rename.NONE);
646646
}
647647

648648
@Override

0 commit comments

Comments
 (0)