/** * A wrapper around {@link FileSystem#rename(Path, Path)} which throws {@link IOException} if * {@link FileSystem#rename(Path, Path)} returns False. */ public static void renamePath(FileSystem fs, Path oldName, Path newName) throws IOException { renamePath(fs, oldName, newName, false); }
private void createNewLogFileIfNeeded() throws IOException { if (LogCopier.this.destFs.exists(this.destLogFile) && (this.watch.elapsed(TimeUnit.MINUTES) > LogCopier.this.maxMinutesPerLogFile || LogCopier.this.destFs.getFileStatus(this.destLogFile).getLen() > LogCopier.this.maxBytesPerLogFile)) { HadoopUtils.renamePath(LogCopier.this.destFs, this.destLogFile, new Path(this.destLogFile.toString() + "." + System.currentTimeMillis())); this.watch.reset(); this.watch.start(); } }
/** * Moves a src {@link Path} from a srcFs {@link FileSystem} to a dst {@link Path} on a dstFs {@link FileSystem}. If * the srcFs and the dstFs have the same scheme, and neither of them or S3 schemes, then the {@link Path} is simply * renamed. Otherwise, the data is from the src {@link Path} to the dst {@link Path}. So this method can handle copying * data between different {@link FileSystem} implementations. * * @param srcFs the source {@link FileSystem} where the src {@link Path} exists * @param src the source {@link Path} which will me moved * @param dstFs the destination {@link FileSystem} where the dst {@link Path} should be created * @param dst the {@link Path} to move data to * @param overwrite true if the destination should be overwritten; otherwise, false */ public static void movePath(FileSystem srcFs, Path src, FileSystem dstFs, Path dst, boolean overwrite, Configuration conf) throws IOException { if (srcFs.getUri().getScheme().equals(dstFs.getUri().getScheme()) && !FS_SCHEMES_NON_ATOMIC.contains(srcFs.getUri().getScheme()) && !FS_SCHEMES_NON_ATOMIC.contains(dstFs.getUri().getScheme())) { renamePath(srcFs, src, dst); } else { copyPath(srcFs, src, dstFs, dst, true, overwrite, conf); } }
@Override public Void call() throws Exception { Lock lock = ParallelRunner.this.locks.get(src.toString()); lock.lock(); try { if (ParallelRunner.this.fs.exists(src)) { HadoopUtils.renamePath(ParallelRunner.this.fs, src, dst); if (group.isPresent()) { HadoopUtils.setGroup(ParallelRunner.this.fs, dst, group.get()); } } return null; } catch (FileAlreadyExistsException e) { LOGGER.warn(String.format("Failed to rename %s to %s: dst already exists", src, dst), e); return null; } finally { lock.unlock(); } } }), "Rename " + src + " to " + dst));
/** * Writes the <code>config</code> to {@link #storeMetadataFilePath}. Creates a backup file at * <code>storeMetadataFilePath + ".bkp"</code> to recover old metadata in case of unexpected deployment failures * * @param config to be serialized * @throws IOException if there was any problem writing the <code>config</code> to the store metadata file. */ void writeMetadata(Config config) throws IOException { Path storeMetadataFileBkpPath = new Path(this.storeMetadataFilePath.getParent(), this.storeMetadataFilePath.getName() + ".bkp"); // Delete old backup file if exists HadoopUtils.deleteIfExists(this.fs, storeMetadataFileBkpPath, true); // Move current storeMetadataFile to backup if (this.fs.exists(this.storeMetadataFilePath)) { HadoopUtils.renamePath(this.fs, this.storeMetadataFilePath, storeMetadataFileBkpPath); } // Write new storeMetadataFile try (FSDataOutputStream outputStream = FileSystem.create(this.fs, this.storeMetadataFilePath, FsDeploymentConfig.DEFAULT_STORE_PERMISSIONS);) { outputStream.write(config.root().render(ConfigRenderOptions.concise()).getBytes(Charsets.UTF_8)); } catch (Exception e) { // Restore from backup HadoopUtils.deleteIfExists(this.fs, this.storeMetadataFilePath, true); HadoopUtils.renamePath(this.fs, storeMetadataFileBkpPath, this.storeMetadataFilePath); throw new IOException( String.format("Failed to write store metadata at %s. Restored existing store metadata file from backup", this.storeMetadataFilePath), e); } }
HadoopUtils.renamePath(this.fs, tmpTablePath, tablePath);
deletePath(dstFs, dst, true); } finally { renamePath(dstFs, tmp, dst); renamed = true; renamePath(dstFs, tmp, dst);
HadoopUtils.renamePath(this.fs, tmpTablePath, tablePath);