Updated Branches:
  refs/heads/trunk 992d31f41 -> 880ce10bf

Expose whether jna is enabled and memory is locked via JMX
patch by dbrosius reviewed by jbellis for cassandra-5508


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/880ce10b
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/880ce10b
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/880ce10b

Branch: refs/heads/trunk
Commit: 880ce10bf16c96f8b5ceb419890948223d174c6c
Parents: 992d31f
Author: Dave Brosius <dbros...@apache.org>
Authored: Sun Jun 2 01:27:23 2013 -0400
Committer: Dave Brosius <dbros...@apache.org>
Committed: Sun Jun 2 01:27:23 2013 -0400

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../apache/cassandra/service/CassandraDaemon.java  |   33 ++++++++++++++-
 src/java/org/apache/cassandra/utils/CLibrary.java  |   17 +++++++-
 3 files changed, 48 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/880ce10b/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 8ab9b3e..47cc712 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -27,6 +27,7 @@
  * replace supercolumns internally by composites (CASSANDRA-3237, 5123)
  * upgrade thrift to 0.9.0 (CASSANDRA-3719)
  * drop unnecessary keyspace parameter from user-defined compaction API 
+ * Expose whether jna is enabled and memory is locked via JMX (CASSANDRA-5508)
    (CASSANDRA-5139)
  * more robust solution to incomplete compactions + counters (CASSANDRA-5151)
  * Change order of directory searching for c*.in.sh (CASSANDRA-3983)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/880ce10b/src/java/org/apache/cassandra/service/CassandraDaemon.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/CassandraDaemon.java 
b/src/java/org/apache/cassandra/service/CassandraDaemon.java
index 5e62107..7d22840 100644
--- a/src/java/org/apache/cassandra/service/CassandraDaemon.java
+++ b/src/java/org/apache/cassandra/service/CassandraDaemon.java
@@ -19,6 +19,7 @@ package org.apache.cassandra.service;
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.management.ManagementFactory;
 import java.net.InetAddress;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -26,6 +27,10 @@ import java.util.Arrays;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.StandardMBean;
+
 import com.google.common.collect.Iterables;
 import com.google.common.collect.SetMultimap;
 
@@ -34,13 +39,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.cassandra.config.CFMetaData;
-import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.db.*;
 import org.apache.cassandra.db.commitlog.CommitLog;
 import org.apache.cassandra.db.compaction.CompactionManager;
 import org.apache.cassandra.db.compaction.LegacyLeveledManifest;
+import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.io.FSError;
 import org.apache.cassandra.io.util.FileUtils;
 import org.apache.cassandra.thrift.ThriftServer;
@@ -57,6 +62,8 @@ import org.apache.cassandra.utils.Pair;
  */
 public class CassandraDaemon
 {
+    public static final String MBEAN_NAME = 
"org.apache.cassandra.db:type=NativeAccess";
+    
     static
     {
         initLog4j();
@@ -432,6 +439,17 @@ public class CassandraDaemon
 
         try
         {
+            try
+            {
+                MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+                mbs.registerMBean(new StandardMBean(new NativeAccess(), 
NativeAccessMBean.class), new ObjectName(MBEAN_NAME));
+            }
+            catch (Exception e)
+            {
+                logger.error("error registering MBean " + MBEAN_NAME, e);
+                //Allow the server to start even if the bean can't be 
registered
+            }
+            
             setup();
 
             if (pidFile != null)
@@ -477,6 +495,19 @@ public class CassandraDaemon
     {
         instance.activate();
     }
+    
+    static class NativeAccess implements NativeAccessMBean
+    {
+        public boolean isAvailable()
+        {
+            return CLibrary.jnaAvailable();
+        }
+        
+        public boolean isMemoryLockable() 
+        {
+            return CLibrary.jnaMemoryLockable();
+        }
+    }
 
     public interface Server
     {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/880ce10b/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 09c7ac0..e6efbbd 100644
--- a/src/java/org/apache/cassandra/utils/CLibrary.java
+++ b/src/java/org/apache/cassandra/utils/CLibrary.java
@@ -17,9 +17,7 @@
  */
 package org.apache.cassandra.utils;
 
-import java.io.File;
 import java.io.FileDescriptor;
-import java.io.IOException;
 import java.lang.reflect.Field;
 
 import org.slf4j.Logger;
@@ -49,12 +47,16 @@ public final class CLibrary
     private static final int POSIX_FADV_WILLNEED   = 3; /* fadvise.h */
     private static final int POSIX_FADV_DONTNEED   = 4; /* fadvise.h */
     private static final int POSIX_FADV_NOREUSE    = 5; /* fadvise.h */
+    
+    static boolean jnaAvailable = false;
+    static boolean jnaLockable = false;
 
     static
     {
         try
         {
             Native.register("c");
+            jnaAvailable = true;
         }
         catch (NoClassDefFoundError e)
         {
@@ -101,12 +103,23 @@ public final class CLibrary
     }
 
     private CLibrary() {}
+    
+    public static boolean jnaAvailable()
+    {
+        return jnaAvailable;
+    }
+    
+    public static boolean jnaMemoryLockable()
+    {
+        return jnaLockable;
+    }
 
     public static void tryMlockall()
     {
         try
         {
             mlockall(MCL_CURRENT);
+            jnaLockable = true;
             logger.info("JNA mlockall successful");
         }
         catch (UnsatisfiedLinkError e)

Reply via email to