You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2015/03/19 09:44:55 UTC

svn commit: r1667679 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/ test/java/org/apache/jackrabbit/oak/plugins/document/

Author: mreutegg
Date: Thu Mar 19 08:44:55 2015
New Revision: 1667679

URL: http://svn.apache.org/r1667679
Log:
OAK-2597: expose mongo's clusterNodes info more prominently

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1667679&r1=1667678&r2=1667679&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java Thu Mar 19 08:44:55 2015
@@ -197,6 +197,13 @@ public final class DocumentNodeStore
             = new ConcurrentHashMap<Integer, Long>();
 
     /**
+     * Map of active cluster nodes and when the cluster node's lease ends.
+     * Key: clusterId, value: leaseEndTimeInMillis
+     */
+    private final ConcurrentMap<Integer, Long> activeClusterNodes
+            = new ConcurrentHashMap<Integer, Long>();
+
+    /**
      * The comparator for revisions.
      */
     private final Revision.RevisionComparator revisionComparator;
@@ -1567,8 +1574,8 @@ public final class DocumentNodeStore
     }
 
     /**
-     * Updates the info about inactive cluster nodes in
-     * {@link #inactiveClusterNodes}.
+     * Updates the state about cluster nodes in {@link #activeClusterNodes}
+     * and {@link #inactiveClusterNodes}.
      */
     void updateClusterState() {
         long now = clock.getTime();
@@ -1577,8 +1584,11 @@ public final class DocumentNodeStore
             int cId = doc.getClusterId();
             if (cId != this.clusterId && !doc.isActive()) {
                 inactive.add(cId);
+            } else {
+                activeClusterNodes.put(cId, doc.getLeaseEndTime());
             }
         }
+        activeClusterNodes.keySet().removeAll(inactive);
         inactiveClusterNodes.keySet().retainAll(inactive);
         for (Integer clusterId : inactive) {
             inactiveClusterNodes.putIfAbsent(clusterId, now);
@@ -1596,6 +1606,16 @@ public final class DocumentNodeStore
     }
 
     /**
+     * Returns the cluster nodes currently known as active.
+     *
+     * @return a map with the cluster id as key and the time in millis when the
+     *          lease ends.
+     */
+    Map<Integer, Long> getActiveClusterNodes() {
+        return new HashMap<Integer, Long>(activeClusterNodes);
+    }
+
+    /**
      * Perform a background read and make external changes visible.
      *
      * @param dispatchChange whether to dispatch external changes
@@ -2206,6 +2226,17 @@ public final class DocumentNodeStore
                     new Function<Map.Entry<Integer, Long>, String>() {
                         @Override
                         public String apply(Map.Entry<Integer, Long> input) {
+                            return input.toString();
+                        }
+                    }), String.class);
+        }
+
+        @Override
+        public String[] getActiveClusterNodes() {
+            return toArray(transform(activeClusterNodes.entrySet(),
+                    new Function<Map.Entry<Integer, Long>, String>() {
+                        @Override
+                        public String apply(Map.Entry<Integer, Long> input) {
                             return input.toString();
                         }
                     }), String.class);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java?rev=1667679&r1=1667678&r2=1667679&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java Thu Mar 19 08:44:55 2015
@@ -35,6 +35,8 @@ public interface DocumentNodeStoreMBean
 
     String[] getInactiveClusterNodes();
 
+    String[] getActiveClusterNodes();
+
     String[] getLastKnownRevisions();
 
     String formatRevision(@Name("revision") String rev, @Name("UTC")boolean utc);

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java?rev=1667679&r1=1667678&r2=1667679&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java Thu Mar 19 08:44:55 2015
@@ -615,16 +615,24 @@ public class DocumentNodeStoreTest {
         DocumentNodeStore ns2 = new DocumentMK.Builder().setAsyncDelay(0)
                 .setDocumentStore(docStore).getNodeStore();
 
+        ns1.updateClusterState();
+        ns2.updateClusterState();
+
         assertEquals(0, ns1.getInactiveClusterNodes().size());
         assertEquals(0, ns2.getInactiveClusterNodes().size());
+        assertEquals(2, ns1.getActiveClusterNodes().size());
+        assertEquals(2, ns2.getActiveClusterNodes().size());
 
         ns1.dispose();
 
         ns2.updateClusterState();
 
         Map<Integer, Long> inactive = ns2.getInactiveClusterNodes();
+        Map<Integer, Long> active = ns2.getActiveClusterNodes();
         assertEquals(1, inactive.size());
         assertEquals(1, (int) inactive.keySet().iterator().next());
+        assertEquals(1, active.size());
+        assertEquals(2, (int) active.keySet().iterator().next());
 
         ns2.dispose();
     }