cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbros...@apache.org
Subject [2/4] git commit: Expose black-listed directories via JMX patch by Kirk True reviewed by dbrosius for cassandra-4848
Date Tue, 13 Nov 2012 04:14:41 GMT
Expose black-listed directories via JMX
patch by Kirk True reviewed by dbrosius for cassandra-4848


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

Branch: refs/heads/trunk
Commit: de7aed52cf5c4f07839d953d498c6722c08bed92
Parents: 6677d07
Author: Dave Brosius <dbrosius@apache.org>
Authored: Mon Nov 12 23:04:20 2012 -0500
Committer: Dave Brosius <dbrosius@apache.org>
Committed: Mon Nov 12 23:04:20 2012 -0500

----------------------------------------------------------------------
 CHANGES.txt                                        |    2 +-
 .../cassandra/db/BlacklistedDirectories.java       |   46 ++++++++++++--
 .../cassandra/db/BlacklistedDirectoriesMBean.java  |   29 +++++++++
 3 files changed, 69 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/de7aed52/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index d7855af..4a1ba94 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,6 @@
 1.2.1
  * Add debug logging to list filenames processed by Directories.migrateFile method (CASSANDRA-4939)
-
+ * Expose black-listed directories via JMX (CASSANDRA-4848)
 
 1.2-rc1
  * fix cqlsh DESCRIBE command (CASSANDRA-4913)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/de7aed52/src/java/org/apache/cassandra/db/BlacklistedDirectories.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/BlacklistedDirectories.java b/src/java/org/apache/cassandra/db/BlacklistedDirectories.java
index 5ca7d1f..5e873c7 100644
--- a/src/java/org/apache/cassandra/db/BlacklistedDirectories.java
+++ b/src/java/org/apache/cassandra/db/BlacklistedDirectories.java
@@ -21,15 +21,47 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
+import java.lang.management.ManagementFactory;
+import java.util.Collections;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArraySet;
 
-public class BlacklistedDirectories
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+public class BlacklistedDirectories implements BlacklistedDirectoriesMBean
 {
+    public static final String MBEAN_NAME = "org.apache.cassandra.db:type=BlacklistedDirectories";
+    private static final BlacklistedDirectories instance = new BlacklistedDirectories();
     private static final Logger logger = LoggerFactory.getLogger(BlacklistedDirectories.class);
 
-    private static Set<File> unreadableDirectories = new CopyOnWriteArraySet<File>();
-    private static Set<File> unwritableDirectories = new CopyOnWriteArraySet<File>();
+    private final Set<File> unreadableDirectories = new CopyOnWriteArraySet<File>();
+    private final Set<File> unwritableDirectories = new CopyOnWriteArraySet<File>();
+
+    private BlacklistedDirectories()
+    {
+        // Register this instance with JMX
+        try
+        {
+            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+            mbs.registerMBean(this, 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
+        }
+    }
+
+    public Set<File> getUnreadableDirectories()
+    {
+        return Collections.unmodifiableSet(unreadableDirectories);
+    }
+
+    public Set<File> getUnwritableDirectories()
+    {
+        return Collections.unmodifiableSet(unwritableDirectories);
+    }
 
     /**
      * Adds parent directory of the file (or the file itself, if it is a directory)
@@ -40,7 +72,7 @@ public class BlacklistedDirectories
     public static File maybeMarkUnreadable(File path)
     {
         File directory = getDirectory(path);
-        if (unreadableDirectories.add(directory))
+        if (instance.unreadableDirectories.add(directory))
         {
             logger.warn("Blacklisting {} for reads", directory);
             return directory;
@@ -57,7 +89,7 @@ public class BlacklistedDirectories
     public static File maybeMarkUnwritable(File path)
     {
         File directory = getDirectory(path);
-        if (unwritableDirectories.add(directory))
+        if (instance.unwritableDirectories.add(directory))
         {
             logger.warn("Blacklisting {} for writes", directory);
             return directory;
@@ -71,7 +103,7 @@ public class BlacklistedDirectories
      */
     public static boolean isUnreadable(File directory)
     {
-        return unreadableDirectories.contains(directory);
+        return instance.unreadableDirectories.contains(directory);
     }
 
     /**
@@ -80,7 +112,7 @@ public class BlacklistedDirectories
      */
     public static boolean isUnwritable(File directory)
     {
-        return unwritableDirectories.contains(directory);
+        return instance.unwritableDirectories.contains(directory);
     }
 
     private static File getDirectory(File file)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/de7aed52/src/java/org/apache/cassandra/db/BlacklistedDirectoriesMBean.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/BlacklistedDirectoriesMBean.java b/src/java/org/apache/cassandra/db/BlacklistedDirectoriesMBean.java
new file mode 100644
index 0000000..3163b9a
--- /dev/null
+++ b/src/java/org/apache/cassandra/db/BlacklistedDirectoriesMBean.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.db;
+
+import java.io.File;
+import java.util.Set;
+
+public interface BlacklistedDirectoriesMBean {
+
+    public Set<File> getUnreadableDirectories();
+    
+    public Set<File> getUnwritableDirectories();
+    
+}


Mime
View raw message