Skip to content

Commit 1c7043b

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) (cherry picked from commit dd1634e)
1 parent 31154fd commit 1c7043b

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;
@@ -103,6 +104,7 @@ public class JavaKeyStoreProvider extends KeyProvider {
103104
private final Path path;
104105
private final FileSystem fs;
105106
private FsPermission permissions;
107+
private FileContext context;
106108
private KeyStore keyStore;
107109
private char[] password;
108110
private boolean changed = false;
@@ -130,6 +132,7 @@ private JavaKeyStoreProvider(URI uri, Configuration conf) throws IOException {
130132
this.uri = uri;
131133
path = ProviderUtils.unnestUri(uri);
132134
fs = path.getFileSystem(conf);
135+
context = FileContext.getFileContext(conf);
133136
locateKeystore();
134137
ReadWriteLock lock = new ReentrantReadWriteLock(true);
135138
readLock = lock.readLock();
@@ -638,10 +641,7 @@ private void revertFromOld(Path oldPath, boolean fileExisted)
638641

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

647647
@Override

0 commit comments

Comments
 (0)