cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1030157 - in /cassandra/branches/cassandra-0.6: CHANGES.txt src/java/org/apache/cassandra/io/util/FileUtils.java src/java/org/apache/cassandra/utils/CLibrary.java src/java/org/apache/cassandra/utils/FBUtilities.java
Date Tue, 02 Nov 2010 18:24:38 GMT
Author: jbellis
Date: Tue Nov  2 18:24:37 2010
New Revision: 1030157

URL: http://svn.apache.org/viewvc?rev=1030157&view=rev
Log:
fix jna errno reporting, take 2

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

Modified: cassandra/branches/cassandra-0.6/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/CHANGES.txt?rev=1030157&r1=1030156&r2=1030157&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.6/CHANGES.txt Tue Nov  2 18:24:37 2010
@@ -6,6 +6,7 @@ dev
  * initMetadata wasn't loading saved partitioner from disk (CASSANDRA-1638)
  * log tpstats when dropping messages (CASSANDRA-1660)
  * Avoid dropping messages off the client request path (CASSANDRA-1676)
+ * fix jna errno reporting (CASSANDRA-1694)
  * add friendlier error for UnknownHostException on startup (CASSANDRA-1697)
 
 

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=1030157&r1=1030156&r2=1030157&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
Tue Nov  2 18:24:37 2010
@@ -23,6 +23,7 @@ import java.text.DecimalFormat;
 import java.util.*;
 import java.util.concurrent.ExecutorService;
 
+import com.sun.jna.LastErrorException;
 import org.apache.cassandra.concurrent.JMXEnabledThreadPoolExecutor;
 
 import org.apache.log4j.Logger;
@@ -202,25 +203,25 @@ 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();
+            assert result == 0; // success is always zero
         }
         catch (UnsatisfiedLinkError e)
         {
             createHardLinkWithExec(sourceFile, destinationFile);
-            return;
         }
-
-        if (errno != Integer.MIN_VALUE)
+        catch (RuntimeException 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));
+            if (e instanceof LastErrorException)
+            {
+                // 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, CLibrary.errno(e)));
+            }
+            throw e;
         }
     }
 

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=1030157&r1=1030156&r2=1030157&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 Tue
Nov  2 18:24:37 2010
@@ -21,6 +21,7 @@ package org.apache.cassandra.utils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.sun.jna.LastErrorException;
 import com.sun.jna.Native;
 
 public final class CLibrary
@@ -48,10 +49,24 @@ public final class CLibrary
         }
     }
 
-    public static native int mlockall(int flags);
-    public static native int munlockall();
+    public static native int mlockall(int flags) throws LastErrorException;
+    public static native int munlockall() throws LastErrorException;
 
-    public static native int link(String from, String to);
+    public static native int link(String from, String to) throws LastErrorException;
+
+    public static int errno(RuntimeException e)
+    {
+        assert e instanceof LastErrorException;
+        try
+        {
+            return ((LastErrorException) e).getErrorCode();
+        }
+        catch (NoSuchMethodError x)
+        {
+            logger.warn("Obsolete version of JNA present; unable to read errno. Upgrade to
JNA 3.2.7 or later");
+            return 0;
+        }
+    }
 
     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=1030157&r1=1030156&r2=1030157&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
Tue Nov  2 18:24:37 2010
@@ -37,6 +37,7 @@ import org.apache.log4j.Logger;
 
 import org.apache.commons.collections.iterators.CollatingIterator;
 
+import com.sun.jna.LastErrorException;
 import com.sun.jna.Native;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.db.DecoratedKey;
@@ -553,32 +554,32 @@ public class FBUtilities
 
     public static void tryMlockall()
     {
-        int errno = Integer.MIN_VALUE;
         try
         {
             int result = CLibrary.mlockall(CLibrary.MCL_CURRENT);
-            if (result != 0)
-                errno = Native.getLastError();
+            assert result == 0; // mlockall should always be zero on success
         }
         catch (UnsatisfiedLinkError e)
         {
             // this will have already been logged by CLibrary, no need to repeat it
-            return;
         }
-
-        if (errno != Integer.MIN_VALUE)
+        catch (RuntimeException e)
         {
-            if (errno == CLibrary.ENOMEM && System.getProperty("os.name").toLowerCase().contains("linux"))
-            {
-                logger_.warn("Unable to lock JVM memory (ENOMEM)."
-                             + " This can result in part of the JVM being swapped out, especially
with mmapped I/O enabled."
-                             + " Increase RLIMIT_MEMLOCK or run Cassandra as root.");
-            }
-            else if (!System.getProperty("os.name").toLowerCase().contains("mac"))
+            if (e instanceof LastErrorException)
             {
-                // OS X allows mlockall to be called, but always returns an error
-                logger_.warn("Unknown mlockall error " + errno);
+                if (CLibrary.errno(e) == CLibrary.ENOMEM && System.getProperty("os.name").toLowerCase().contains("linux"))
+                {
+                    logger_.warn("Unable to lock JVM memory (ENOMEM)."
+                                 + " This can result in part of the JVM being swapped out,
especially with mmapped I/O enabled."
+                                 + " Increase RLIMIT_MEMLOCK or run Cassandra as root.");
+                }
+                else if (!System.getProperty("os.name").toLowerCase().contains("mac"))
+                {
+                    // OS X allows mlockall to be called, but always returns an error
+                    logger_.warn("Unknown mlockall error " + CLibrary.errno(e));
+                }
             }
+            throw e;
         }
     }
 }



Mime
View raw message