Author: brandonwilliams Date: Wed Sep 15 17:29:26 2010 New Revision: 997408
URL: http://svn.apache.org/viewvc?rev=997408&view=rev Log: use JNA, if present, to take snapshots. Patch by jbellis, reviewed by brandonwilliams for CASSANDRA-1371 Modified: cassandra/branches/cassandra-0.6/CHANGES.txt cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/util/FileUtils.java cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/CLibrary.java cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/FBUtilities.java cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java Modified: cassandra/branches/cassandra-0.6/CHANGES.txt URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/CHANGES.txt?rev=997408&r1=997407&r2=997408&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/CHANGES.txt (original) +++ cassandra/branches/cassandra-0.6/CHANGES.txt Wed Sep 15 17:29:26 2010 @@ -20,6 +20,7 @@ avoid synchronization bottleneck (CASSANDRA-1481) * nodes that coordinated a loadbalance in the past could not be seen by newly added nodes (CASSANDRA-1467) + * use JNA, if present, to take snapshots (CASSANDRA-1371) 0.6.5 Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/util/FileUtils.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/util/FileUtils.java?rev=997408&r1=997407&r2=997408&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/util/FileUtils.java (original) +++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/util/FileUtils.java Wed Sep 15 17:29:26 2010 @@ -27,6 +27,9 @@ import org.apache.cassandra.concurrent.J import org.apache.log4j.Logger; +import com.sun.jna.Native; +import org.apache.cassandra.utils.CLibrary; + public class FileUtils { @@ -199,6 +202,30 @@ public class FileUtils */ public static void createHardLink(File sourceFile, File destinationFile) throws IOException { + int errno = Integer.MIN_VALUE; + try + { + int result = CLibrary.link(sourceFile.getAbsolutePath(), destinationFile.getAbsolutePath()); + if (result != 0) + errno = Native.getLastError(); + } + catch (UnsatisfiedLinkError e) + { + createHardLinkWithExec(sourceFile, destinationFile); + return; + } + + if (errno != Integer.MIN_VALUE) + { + // 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)); + } + } + + private static void createHardLinkWithExec(File sourceFile, File destinationFile) throws IOException + { String osname = System.getProperty("os.name"); ProcessBuilder pb; if (osname.startsWith("Windows")) Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/CLibrary.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/CLibrary.java?rev=997408&r1=997407&r2=997408&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/CLibrary.java (original) +++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/CLibrary.java Wed Sep 15 17:29:26 2010 @@ -49,8 +49,9 @@ public final class CLibrary } public static native int mlockall(int flags); - public static native int munlockall(); + public static native int link(String from, String to); + private CLibrary() {} } Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/FBUtilities.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/FBUtilities.java?rev=997408&r1=997407&r2=997408&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/FBUtilities.java (original) +++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/FBUtilities.java Wed Sep 15 17:29:26 2010 @@ -565,21 +565,6 @@ public class FBUtilities // this will have already been logged by CLibrary, no need to repeat it return; } - catch (Exception e) - { - logger_.debug("Unable to mlockall", e); - // skipping mlockall doesn't seem to be a Big Deal except on Linux. See CASSANDRA-1214 - if (System.getProperty("os.name").toLowerCase().contains("linux")) - { - logger_.warn("Unable to lock JVM memory (" + e.getMessage() + ")." - + " This can result in part of the JVM being swapped out, especially with mmapped I/O enabled."); - } - else if (!System.getProperty("os.name").toLowerCase().contains("windows")) - { - logger_.info("Unable to lock JVM memory: " + e.getMessage()); - } - return; - } if (errno != Integer.MIN_VALUE) { Modified: cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java?rev=997408&r1=997407&r2=997408&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java (original) +++ cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java Wed Sep 15 17:29:26 2010 @@ -60,5 +60,11 @@ public class StorageServiceServerTest List<Token> toks = Collections.emptyList(); assertEquals(Collections.emptyList(), StorageService.instance.getAllRanges(toks)); } -} + @Test + public void testSnapshot() throws IOException + { + // no need to insert extra data, even an "empty" database will have a little information in the system keyspace + StorageService.instance.takeAllSnapshot(null); + } +}
