From 5c33a8afa7289e768fcd2f3150f3d094688edb69 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Mon, 2 May 2016 12:54:20 +0300 Subject: [PATCH] ColumnFamilyStore: Preparation for removing the pull mode This expose the ColumnFamilyStore registration via static method. It would allow an external object (ie. MBeanServer) to update the registration on demand. Signed-off-by: Amnon Heiman --- .../cassandra/db/ColumnFamilyStore.java | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/main/java/org/apache/cassandra/db/ColumnFamilyStore.java index 44d4d1a..ad62dad 100644 --- a/src/main/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/main/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -50,6 +50,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean { private String keyspace; private String name; private String mbeanName; + private static APIClient s_c = new APIClient(); static final int INTERVAL = 1000; // update every 1second public final ColumnFamilyMetrics metric; @@ -102,8 +103,35 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean { + ",columnfamily=" + name; } + public static boolean checkRegistration() { + try { + JsonArray mbeans = s_c.getJsonArray("/column_family/"); + Set all_cf = new HashSet(); + for (int i = 0; i < mbeans.size(); i++) { + JsonObject mbean = mbeans.getJsonObject(i); + String name = getName(mbean.getString("type"), + mbean.getString("ks"), mbean.getString("cf")); + if (!cf.containsKey(name)) { + ColumnFamilyStore cfs = new ColumnFamilyStore( + mbean.getString("type"), mbean.getString("ks"), + mbean.getString("cf")); + cf.put(name, cfs); + } + all_cf.add(name); + } + // removing deleted column family + for (String n : cf.keySet()) { + if (!all_cf.contains(n)) { + cf.remove(n); + } + } + } catch (IllegalStateException e) { + return false; + } + return true; + } + private static final class CheckRegistration extends TimerTask { - private APIClient c = new APIClient(); private int missed_response = 0; // After MAX_RETRY retry we assume the API is not available // and the jmx will shutdown @@ -111,31 +139,13 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean { @Override public void run() { try { - JsonArray mbeans = c.getJsonArray("/column_family/"); - Set all_cf = new HashSet(); - for (int i = 0; i < mbeans.size(); i++) { - JsonObject mbean = mbeans.getJsonObject(i); - String name = getName(mbean.getString("type"), - mbean.getString("ks"), mbean.getString("cf")); - if (!cf.containsKey(name)) { - ColumnFamilyStore cfs = new ColumnFamilyStore( - mbean.getString("type"), mbean.getString("ks"), - mbean.getString("cf")); - cf.put(name, cfs); + if (checkRegistration()) { + missed_response = 0; + } else { + if (missed_response++ > MAX_RETRY) { + System.err.println("API is not available, JMX is shuting down"); + System.exit(-1); } - all_cf.add(name); - } - // removing deleted column family - for (String n : cf.keySet()) { - if (!all_cf.contains(n)) { - cf.remove(n); - } - } - missed_response = 0; - } catch (IllegalStateException e) { - if (missed_response++ > MAX_RETRY) { - System.err.println("API is not available, JMX is shuting down"); - System.exit(-1); } } catch (Exception e) { // ignoring exceptions, will retry on the next interval