/** Close/abort all files being written. */ public void closeAllFilesBeingWritten(final boolean abort) { for(;;) { final long inodeId; final DFSOutputStream out; synchronized(filesBeingWritten) { if (filesBeingWritten.isEmpty()) { return; } inodeId = filesBeingWritten.keySet().iterator().next(); out = filesBeingWritten.remove(inodeId); } if (out != null) { try { if (abort) { out.abort(); } else { out.close(); } } catch(IOException ie) { LOG.error("Failed to " + (abort ? "abort" : "close") + " file: " + out.getSrc() + " with inode: " + inodeId, ie); } } } }
/** * Wraps the stream in a CryptoOutputStream if the underlying file is * encrypted. */ public HdfsDataOutputStream createWrappedOutputStream(DFSOutputStream dfsos, FileSystem.Statistics statistics, long startPos) throws IOException { final FileEncryptionInfo feInfo = dfsos.getFileEncryptionInfo(); if (feInfo != null) { // File is encrypted, wrap the stream in a crypto stream. // Currently only one version, so no special logic based on the version # HdfsKMSUtil.getCryptoProtocolVersion(feInfo); final CryptoCodec codec = HdfsKMSUtil.getCryptoCodec(conf, feInfo); KeyVersion decrypted; try (TraceScope ignored = tracer.newScope("decryptEDEK")) { LOG.debug("Start decrypting EDEK for file: {}, output stream: 0x{}", dfsos.getSrc(), Integer.toHexString(dfsos.hashCode())); decrypted = HdfsKMSUtil.decryptEncryptedDataEncryptionKey(feInfo, getKeyProvider()); LOG.debug("Decrypted EDEK for file: {}, output stream: 0x{}", dfsos.getSrc(), Integer.toHexString(dfsos.hashCode())); } final CryptoOutputStream cryptoOut = new CryptoOutputStream(dfsos, codec, decrypted.getMaterial(), feInfo.getIV(), startPos); return new HdfsDataOutputStream(cryptoOut, statistics, startPos); } else { // No FileEncryptionInfo present so no encryption. return new HdfsDataOutputStream(dfsos, statistics, startPos); } }