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 md...@apache.org on 2014/11/20 22:02:30 UTC

svn commit: r1640810 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document: Checkpoints.java DocumentCheckpointMBean.java DocumentNodeStoreService.java

Author: mduerig
Date: Thu Nov 20 21:02:29 2014
New Revision: 1640810

URL: http://svn.apache.org/r1640810
Log:
OAK-2267: Expose checkpoints through JMX
Checkpoints MBean for the DocumentMK, Marcel's patch

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentCheckpointMBean.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java?rev=1640810&r1=1640809&r2=1640810&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java Thu Nov 20 21:02:29 2014
@@ -124,7 +124,7 @@ class Checkpoints {
 
     @SuppressWarnings("unchecked")
     @CheckForNull
-    private SortedMap<Revision, String> getCheckpoints() {
+    SortedMap<Revision, String> getCheckpoints() {
         Document cdoc = store.find(Collection.SETTINGS, ID, 0);
         return (SortedMap<Revision, String>) cdoc.get(PROP_CHECKPOINT);
     }

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentCheckpointMBean.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentCheckpointMBean.java?rev=1640810&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentCheckpointMBean.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentCheckpointMBean.java Thu Nov 20 21:02:29 2014
@@ -0,0 +1,106 @@
+/*
+ * 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.jackrabbit.oak.plugins.document;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenDataException;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
+import javax.management.openmbean.TabularType;
+
+import org.apache.jackrabbit.oak.api.jmx.CheckpointMBean;
+
+/**
+ * {@code CheckpointMBean} implementation for the {@code DocumentNodeStore}.
+ */
+public class DocumentCheckpointMBean implements CheckpointMBean {
+    private static final String[] FIELD_NAMES = new String[] { "id", "created", "expires"};
+    private static final String[] FIELD_DESCRIPTIONS = FIELD_NAMES;
+
+    @SuppressWarnings("rawtypes")
+    private static final OpenType[] FIELD_TYPES = new OpenType[] {
+            SimpleType.STRING, SimpleType.STRING, SimpleType.STRING };
+
+    private static final CompositeType TYPE = createCompositeType();
+
+    private static CompositeType createCompositeType() {
+        try {
+            return new CompositeType(DocumentCheckpointMBean.class.getName(),
+                    "Checkpoints", FIELD_NAMES, FIELD_DESCRIPTIONS, FIELD_TYPES);
+        } catch (OpenDataException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private final DocumentNodeStore store;
+
+    public DocumentCheckpointMBean(DocumentNodeStore store) {
+        this.store = store;
+    }
+
+    @Override
+    public TabularData listCheckpoints() {
+        Map<Revision, String> checkpoints = store.getCheckpoints().getCheckpoints();
+        if (checkpoints == null) {
+            checkpoints = Collections.emptyMap();
+        }
+
+        try {
+            TabularDataSupport tab = new TabularDataSupport(
+                    new TabularType(DocumentCheckpointMBean.class.getName(),
+                            "Checkpoints", TYPE, new String[] { "id" }));
+
+            for (Entry<Revision, String> checkpoint : checkpoints.entrySet()) {
+                String id = checkpoint.getKey().toString();
+                Date created = new Date(checkpoint.getKey().getTimestamp());
+                Date expires = new Date(Long.parseLong(checkpoint.getValue()));
+                tab.put(id, toCompositeData(id, created.toString(), expires.toString()));
+            }
+
+            return tab;
+        } catch (OpenDataException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private static CompositeDataSupport toCompositeData(String id, String created, String expires)
+            throws OpenDataException {
+        return new CompositeDataSupport(TYPE, FIELD_NAMES, new String[] { id, created, expires });
+    }
+
+    @Override
+    public String createCheckpoint(long lifetime) {
+        return store.checkpoint(lifetime);
+    }
+
+    @Override
+    public boolean releaseCheckpoint(String checkpoint) {
+        return store.release(checkpoint);
+    }
+
+}

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java?rev=1640810&r1=1640809&r2=1640810&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java Thu Nov 20 21:02:29 2014
@@ -18,6 +18,12 @@
  */
 package org.apache.jackrabbit.oak.plugins.document;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.commons.PropertiesUtil.toBoolean;
+import static org.apache.jackrabbit.oak.commons.PropertiesUtil.toInteger;
+import static org.apache.jackrabbit.oak.commons.PropertiesUtil.toLong;
+import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Dictionary;
@@ -42,6 +48,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.ReferencePolicy;
 import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean;
+import org.apache.jackrabbit.oak.api.jmx.CheckpointMBean;
 import org.apache.jackrabbit.oak.commons.PropertiesUtil;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
 import org.apache.jackrabbit.oak.osgi.ObserverTracker;
@@ -66,12 +73,6 @@ import org.osgi.service.component.Compon
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.oak.commons.PropertiesUtil.toBoolean;
-import static org.apache.jackrabbit.oak.commons.PropertiesUtil.toInteger;
-import static org.apache.jackrabbit.oak.commons.PropertiesUtil.toLong;
-import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean;
-
 /**
  * The OSGi service to start/stop a DocumentNodeStore instance.
  */
@@ -414,6 +415,13 @@ public class DocumentNodeStoreService {
                         CacheStatsMBean.TYPE,
                         store.getDocChildrenCacheStats().getName())
         );
+        registrations.add(
+                registerMBean(whiteboard,
+                        CheckpointMBean.class,
+                        new DocumentCheckpointMBean(store),
+                        CheckpointMBean.TYPE,
+                        "Document node store checkpoint management")
+        );
         DiffCache cl = store.getDiffCache();
         if (cl instanceof MemoryDiffCache) {
             MemoryDiffCache mcl = (MemoryDiffCache) cl;