jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1559963 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: Oak.java api/jmx/IndexStatsMBean.java plugins/index/AsyncIndexUpdate.java
Date Tue, 21 Jan 2014 10:20:06 GMT
Author: alexparvulescu
Date: Tue Jan 21 10:20:06 2014
New Revision: 1559963

URL: http://svn.apache.org/r1559963
Log:
OAK-982 Expose indexing status and information via JMX


Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/IndexStatsMBean.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java?rev=1559963&r1=1559962&r2=1559963&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java Tue Jan
21 10:20:06 2014
@@ -50,6 +50,7 @@ import org.apache.jackrabbit.mk.core.Mic
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean;
 import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
 import org.apache.jackrabbit.oak.plugins.commit.ConflictHook;
@@ -476,8 +477,12 @@ public class Oak {
                 .compose(editorProviders)));
 
         if (asyncIndexing) {
-            Runnable task = new AsyncIndexUpdate("async", store, indexEditors);
+            String name = "async";
+            AsyncIndexUpdate task = new AsyncIndexUpdate(name, store,
+                    indexEditors);
             WhiteboardUtils.scheduleWithFixedDelay(whiteboard, task, 5, true);
+            WhiteboardUtils.registerMBean(whiteboard, IndexStatsMBean.class,
+                    task.getIndexStats(), IndexStatsMBean.TYPE, name);
         }
 
         // FIXME: OAK-810 move to proper workspace initialization

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/IndexStatsMBean.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/IndexStatsMBean.java?rev=1559963&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/IndexStatsMBean.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/IndexStatsMBean.java
Tue Jan 21 10:20:06 2014
@@ -0,0 +1,50 @@
+/*
+ * 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.api.jmx;
+
+public interface IndexStatsMBean {
+
+    String TYPE = "IndexStats";
+
+    String STATUS_INIT = "init";
+
+    String STATUS_RUNNING = "running";
+
+    String STATUS_DONE = "done";
+
+    /**
+     * @return The time the indexing job stared at, or <code>""</code> if it
is
+     *         not currently running.
+     */
+    public String getStart();
+
+    /**
+     * @return The time the indexing job finished at, or <code>""</code> if it
+     *         is still running.
+     */
+    public String getDone();
+
+    /**
+     * Returns the current status of the indexing job
+     * 
+     * @return the current status of the indexing job: {@value #STATUS_INIT},
+     *         {@value #STATUS_RUNNING} or {@value #STATUS_DONE}
+     */
+    public String getStatus();
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/IndexStatsMBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/IndexStatsMBean.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java?rev=1559963&r1=1559962&r2=1559963&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java
Tue Jan 21 10:20:06 2014
@@ -21,6 +21,9 @@ package org.apache.jackrabbit.oak.plugin
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.jackrabbit.oak.api.Type.STRING;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
+import static org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean.STATUS_DONE;
+import static org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean.STATUS_INIT;
+import static org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean.STATUS_RUNNING;
 
 import java.util.Calendar;
 import java.util.concurrent.TimeUnit;
@@ -32,6 +35,7 @@ import com.google.common.base.Objects;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.EditorDiff;
@@ -76,6 +80,8 @@ public class AsyncIndexUpdate implements
     /** Flag to avoid repeatedly logging failure warnings */
     private boolean failing = false;
 
+    private final AsyncIndexStats indexStats = new AsyncIndexStats();
+
     public AsyncIndexUpdate(@Nonnull String name, @Nonnull NodeStore store,
             @Nonnull IndexEditorProvider provider) {
         this.name = checkNotNull(name);
@@ -97,7 +103,7 @@ public class AsyncIndexUpdate implements
         public void indexUpdate() throws CommitFailedException {
             if (!dirty) {
                 dirty = true;
-                preAsyncRun(store, name);
+                preAsyncRun(store, name, indexStats);
             }
         }
 
@@ -147,7 +153,7 @@ public class AsyncIndexUpdate implements
                         PropertyState stateAfterRebase = before
                                 .getChildNode(ASYNC).getProperty(name);
                         if (Objects.equal(state, stateAfterRebase)) {
-                            return postAsyncRunStatus(after.builder())
+                            return postAsyncRunStatus(after.builder(), indexStats)
                                     .getNodeState();
                         } else {
                             throw CONCURRENT_UPDATE;
@@ -174,10 +180,10 @@ public class AsyncIndexUpdate implements
         }
     }
 
-    private static void preAsyncRun(NodeStore store, String name)
-            throws CommitFailedException {
+    private static void preAsyncRun(NodeStore store, String name,
+            AsyncIndexStats stats) throws CommitFailedException {
         NodeBuilder builder = store.getRoot().builder();
-        preAsyncRunStatus(builder);
+        preAsyncRunStatus(builder, stats);
         store.merge(builder, EmptyHook.INSTANCE, null);
     }
 
@@ -190,7 +196,7 @@ public class AsyncIndexUpdate implements
         }
 
         //Check if already running or timed out
-        if ("running".equals(indexState.getString("async-status"))) {
+        if (STATUS_RUNNING.equals(indexState.getString("async-status"))) {
             PropertyState startTime = indexState.getProperty("async-start");
             Calendar start = Conversions.convert(startTime.getValue(Type.DATE)).toCalendar();
             Calendar now = Calendar.getInstance();
@@ -209,17 +215,23 @@ public class AsyncIndexUpdate implements
         return false;
     }
 
-    private static void preAsyncRunStatus(NodeBuilder builder) {
+    private static void preAsyncRunStatus(NodeBuilder builder,
+            AsyncIndexStats stats) {
+        String now = now();
+        stats.start(now);
         builder.getChildNode(IndexConstants.INDEX_DEFINITIONS_NAME)
-                .setProperty("async-status", "running")
-                .setProperty("async-start", now(), Type.DATE)
+                .setProperty("async-status", STATUS_RUNNING)
+                .setProperty("async-start", now, Type.DATE)
                 .removeProperty("async-done");
     }
 
-    private static NodeBuilder postAsyncRunStatus(NodeBuilder builder) {
+    private static NodeBuilder postAsyncRunStatus(NodeBuilder builder,
+            AsyncIndexStats stats) {
+        String now = now();
+        stats.done(now);
         builder.getChildNode(IndexConstants.INDEX_DEFINITIONS_NAME)
-                .setProperty("async-status", "done")
-                .setProperty("async-done", now(), Type.DATE)
+                .setProperty("async-status", STATUS_DONE)
+                .setProperty("async-done", now, Type.DATE)
                 .removeProperty("async-start");
         return builder;
     }
@@ -228,4 +240,42 @@ public class AsyncIndexUpdate implements
         return ISO8601.format(Calendar.getInstance());
     }
 
+    public AsyncIndexStats getIndexStats() {
+        return indexStats;
+    }
+
+    private static final class AsyncIndexStats implements IndexStatsMBean {
+
+        private String start = "";
+        private String done = "";
+        private String status = STATUS_INIT;
+
+        public void start(String now) {
+            status = STATUS_RUNNING;
+            start = now;
+            done = "";
+        }
+
+        public void done(String now) {
+            status = STATUS_DONE;
+            start = "";
+            done = now;
+        }
+
+        @Override
+        public String getStart() {
+            return start;
+        }
+
+        @Override
+        public String getDone() {
+            return done;
+        }
+
+        @Override
+        public String getStatus() {
+            return status;
+        }
+    }
+
 }



Mime
View raw message