Java Code Examples for org.apache.hadoop.fs.HardLink#createHardLink()
The following examples show how to use
org.apache.hadoop.fs.HardLink#createHardLink() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NativeIO.java From hadoop with Apache License 2.0 | 5 votes |
public static void link(File src, File dst) throws IOException { if (!nativeLoaded) { HardLink.createHardLink(src, dst); } else { link0(src.getAbsolutePath(), dst.getAbsolutePath()); } }
Example 2
Source File: NativeIO.java From big-c with Apache License 2.0 | 5 votes |
public static void link(File src, File dst) throws IOException { if (!nativeLoaded) { HardLink.createHardLink(src, dst); } else { link0(src.getAbsolutePath(), dst.getAbsolutePath()); } }
Example 3
Source File: NativeIO.java From yuzhouwan with Apache License 2.0 | 5 votes |
public static void link(File src, File dst) throws IOException { if (!nativeLoaded) { HardLink.createHardLink(src, dst); } else { link0(src.getAbsolutePath(), dst.getAbsolutePath()); } }
Example 4
Source File: FSDataset.java From RDFS with Apache License 2.0 | 4 votes |
/** * Copies a file as fast as possible. Tries to do a hardlink instead of a copy * if the hardlink parameter is specified. * * @param src * the source file for copying * @param dst * the destination file for copying * @param hardlink * whether or not to attempt a hardlink * @throws IOException */ public void copyFile(File src, File dst, boolean hardlink) throws IOException { if (src == null || dst == null) { throw new IOException("src/dst file is null"); } try { if (hardlink && shouldHardLinkBlockCopy) { // Remove destination before hard linking, since this file might already // exist and a hardlink would fail as a result. if (dst.exists()) { if(!dst.delete()) { throw new IOException("Deletion of file : " + dst + " failed"); } } HardLink.createHardLink(src, dst); DataNode.LOG.info("Hard Link Created from : " + src + " to " + dst); return; } } catch (IOException e) { DataNode.LOG.warn("Hard link failed from : " + src + " to " + dst + " continuing with regular file copy"); } FileChannel input = null; FileChannel output = null; try { // This improves copying performance a lot, it uses native buffers // for copying. input = new FileInputStream(src).getChannel(); output = new FileOutputStream(dst).getChannel(); if (input == null || output == null) { throw new IOException("Could not create file channels for src : " + src + " dst : " + dst); } long bytesLeft = input.size(); long position = 0; while (bytesLeft > 0) { long bytesWritten = output.transferFrom(input, position, bytesLeft); bytesLeft -= bytesWritten; position += bytesWritten; } if (datanode.syncOnClose) { output.force(true); } } finally { if (input != null) { input.close(); } if (output != null) { output.close(); } } }