You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ja...@apache.org on 2013/05/29 18:32:50 UTC
git commit: CASSANDRA-3734: native link via java7 (no jna)
Updated Branches:
refs/heads/trunk 34407424b -> 01e79f5df
CASSANDRA-3734: native link via java7 (no jna)
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/01e79f5d
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/01e79f5d
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/01e79f5d
Branch: refs/heads/trunk
Commit: 01e79f5df870c2c98c4725cce50caecb3f6cbb27
Parents: 3440742
Author: Jason Brown <ja...@gmail.com>
Authored: Mon Mar 4 06:31:00 2013 -0800
Committer: Jason Brown <ja...@gmail.com>
Committed: Wed May 29 09:19:57 2013 -0700
----------------------------------------------------------------------
.../org/apache/cassandra/io/util/FileUtils.java | 7 +-
src/java/org/apache/cassandra/utils/CLibrary.java | 65 ---------------
2 files changed, 5 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/01e79f5d/src/java/org/apache/cassandra/io/util/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/util/FileUtils.java b/src/java/org/apache/cassandra/io/util/FileUtils.java
index 69038fa..005d3bb 100644
--- a/src/java/org/apache/cassandra/io/util/FileUtils.java
+++ b/src/java/org/apache/cassandra/io/util/FileUtils.java
@@ -21,6 +21,8 @@ import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.MappedByteBuffer;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.util.Arrays;
@@ -34,7 +36,6 @@ import org.apache.cassandra.io.FSError;
import org.apache.cassandra.io.FSReadError;
import org.apache.cassandra.io.FSWriteError;
import org.apache.cassandra.service.StorageService;
-import org.apache.cassandra.utils.CLibrary;
public class FileUtils
{
@@ -73,7 +74,9 @@ public class FileUtils
try
{
- CLibrary.createHardLink(from, to);
+ // Avoiding getAbsolutePath() in case there is ever a difference between that and the the
+ // behavior of nio2.
+ Files.createLink(Paths.get(to.getPath()), Paths.get(from.getPath()));
}
catch (IOException e)
{
http://git-wip-us.apache.org/repos/asf/cassandra/blob/01e79f5d/src/java/org/apache/cassandra/utils/CLibrary.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/CLibrary.java b/src/java/org/apache/cassandra/utils/CLibrary.java
index 2f6e088..09c7ac0 100644
--- a/src/java/org/apache/cassandra/utils/CLibrary.java
+++ b/src/java/org/apache/cassandra/utils/CLibrary.java
@@ -131,71 +131,6 @@ public final class CLibrary
}
}
- /**
- * Create a hard link for a given file.
- *
- * @param sourceFile The name of the source file.
- * @param destinationFile The name of the destination file.
- *
- * @throws java.io.IOException if an error has occurred while creating the link.
- */
- public static void createHardLink(File sourceFile, File destinationFile) throws IOException
- {
- try
- {
- link(sourceFile.getAbsolutePath(), destinationFile.getAbsolutePath());
- }
- catch (UnsatisfiedLinkError e)
- {
- createHardLinkWithExec(sourceFile, destinationFile);
- }
- catch (RuntimeException e)
- {
- logger.error("Unable to create hard link", e);
- if (!(e instanceof LastErrorException))
- throw e;
- // there are 17 different error codes listed on the man page. punt until/unless we find which
- // ones actually turn up in practice.
- throw new IOException(String.format("Unable to create hard link from %s to %s (errno %d)",
- sourceFile, destinationFile, errno(e)));
- }
- }
-
- public static void createHardLinkWithExec(File sourceFile, File destinationFile) throws IOException
- {
- String osname = System.getProperty("os.name");
- ProcessBuilder pb;
- if (osname.startsWith("Windows"))
- {
- float osversion = Float.parseFloat(System.getProperty("os.version"));
- if (osversion >= 6.0f)
- {
- pb = new ProcessBuilder("cmd", "/c", "mklink", "/H", destinationFile.getAbsolutePath(), sourceFile.getAbsolutePath());
- }
- else
- {
- pb = new ProcessBuilder("fsutil", "hardlink", "create", destinationFile.getAbsolutePath(), sourceFile.getAbsolutePath());
- }
- }
- else
- {
- pb = new ProcessBuilder("ln", sourceFile.getAbsolutePath(), destinationFile.getAbsolutePath());
- pb.redirectErrorStream(true);
- }
- try
- {
- FBUtilities.exec(pb);
- }
- catch (IOException ex)
- {
- String st = osname.startsWith("Windows")
- ? "Unable to create hard link. This probably means your data directory path is too long. Exception follows:"
- : "Unable to create hard link with exec. Suggest installing JNA to avoid the need to exec entirely. Exception follows: ";
- logger.error(st, ex);
- throw ex;
- }
- }
-
public static void trySkipCache(int fd, long offset, int len)
{
if (fd < 0)