You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2010/08/20 08:54:49 UTC
svn commit: r987389 - in /cassandra/trunk: ./
src/java/org/apache/cassandra/io/util/ src/java/org/apache/cassandra/utils/
test/unit/org/apache/cassandra/service/
Author: jbellis
Date: Fri Aug 20 06:54:49 2010
New Revision: 987389
URL: http://svn.apache.org/viewvc?rev=987389&view=rev
Log:
use JNA to call link w/o spawning a separate process during snapshot.
patch by jbellis; reviewed by jhermes for CASSANDRA-1371
Modified:
cassandra/trunk/CHANGES.txt
cassandra/trunk/src/java/org/apache/cassandra/io/util/FileUtils.java
cassandra/trunk/src/java/org/apache/cassandra/utils/CLibrary.java
cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java
cassandra/trunk/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java
Modified: cassandra/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=987389&r1=987388&r2=987389&view=diff
==============================================================================
--- cassandra/trunk/CHANGES.txt (original)
+++ cassandra/trunk/CHANGES.txt Fri Aug 20 06:54:49 2010
@@ -21,6 +21,7 @@ dev
(CASSANDRA-1385)
* disallow invalid keyspace and column family names. This includes name that
matches a '^\w+' regex. (CASSANDRA-1377)
+ * use JNA, if present, to take snapshots (CASSANDRA-1371)
0.7-beta1
Modified: cassandra/trunk/src/java/org/apache/cassandra/io/util/FileUtils.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/io/util/FileUtils.java?rev=987389&r1=987388&r2=987389&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/io/util/FileUtils.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/io/util/FileUtils.java Fri Aug 20 06:54:49 2010
@@ -25,6 +25,9 @@ import java.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.sun.jna.Native;
+import org.apache.cassandra.utils.CLibrary;
+
public class FileUtils
{
@@ -206,6 +209,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/trunk/src/java/org/apache/cassandra/utils/CLibrary.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/utils/CLibrary.java?rev=987389&r1=987388&r2=987389&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/utils/CLibrary.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/utils/CLibrary.java Fri Aug 20 06:54:49 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/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java?rev=987389&r1=987388&r2=987389&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java Fri Aug 20 06:54:49 2010
@@ -616,21 +616,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/trunk/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java?rev=987389&r1=987388&r2=987389&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java Fri Aug 20 06:54:49 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);
+ }
+}