You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by sk...@apache.org on 2019/07/19 16:30:38 UTC

[phoenix] branch master updated: PHOENIX-5358: Metrics for the GlobalIndexChecker coprocessor

This is an automated email from the ASF dual-hosted git repository.

skadam pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
     new 93b58e1  PHOENIX-5358: Metrics for the GlobalIndexChecker coprocessor
93b58e1 is described below

commit 93b58e14478e58822b05af4fc4a0afb15ad5fcb2
Author: Priyank Porwal <pp...@salesforce.com>
AuthorDate: Mon Jul 8 16:20:10 2019 -0700

    PHOENIX-5358: Metrics for the GlobalIndexChecker coprocessor
    
    Signed-off-by: s.kadam <sk...@apache.org>
---
 .../index/metrics/GlobalIndexCheckerSource.java    | 67 ++++++++++++++++++
 .../metrics/GlobalIndexCheckerSourceImpl.java      | 82 ++++++++++++++++++++++
 .../index/metrics/MetricsIndexerSourceFactory.java |  8 +++
 .../apache/phoenix/index/GlobalIndexChecker.java   | 37 ++++++++--
 4 files changed, 187 insertions(+), 7 deletions(-)

diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/metrics/GlobalIndexCheckerSource.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/metrics/GlobalIndexCheckerSource.java
new file mode 100644
index 0000000..84b03d1
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/metrics/GlobalIndexCheckerSource.java
@@ -0,0 +1,67 @@
+/*
+ * 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.phoenix.hbase.index.metrics;
+
+import org.apache.hadoop.hbase.metrics.BaseSource;
+
+/**
+ * Interface for metrics from GlobalIndexChecker
+ */
+public interface GlobalIndexCheckerSource extends BaseSource {
+    // Metrics2 and JMX constants
+    String METRICS_NAME = "GlobalIndexChecker";
+    String METRICS_CONTEXT = "phoenix";
+    String METRICS_DESCRIPTION = "Metrics about the Phoenix Global Index Checker";
+    String METRICS_JMX_CONTEXT = "RegionServer,sub=" + METRICS_NAME;
+
+    String INDEX_REPAIR = "indexRepairs";
+    String INDEX_REPAIR_DESC = "The number of index row repairs";
+
+    String INDEX_REPAIR_FAILURE = "indexRepairFailures";
+    String INDEX_REPAIR_FAILURE_DESC = "The number of index row repair failures";
+
+    String INDEX_REPAIR_TIME = "indexRepairTime";
+    String INDEX_REPAIR_TIME_DESC = "Histogram for the time in milliseconds for index row repairs";
+
+    String INDEX_REPAIR_FAILURE_TIME = "indexRepairFailureTime";
+    String INDEX_REPAIR_FAILURE_TIME_DESC = "Histogram for the time in milliseconds for index row repair failures";
+
+    /**
+     * Increments the number of index repairs
+     */
+    void incrementIndexRepairs();
+
+    /**
+     * Increments the number of index repair failures
+     */
+    void incrementIndexRepairFailures();
+
+    /**
+     * Updates the index repair time histogram
+     *
+     * @param t time taken in milliseconds
+     */
+    void updateIndexRepairTime(long t);
+
+    /**
+     * Updates the index repair failure time histogram
+     *
+     * @param t time taken in milliseconds
+     */
+    void updateIndexRepairFailureTime(long t);
+}
\ No newline at end of file
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/metrics/GlobalIndexCheckerSourceImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/metrics/GlobalIndexCheckerSourceImpl.java
new file mode 100644
index 0000000..f59851a
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/metrics/GlobalIndexCheckerSourceImpl.java
@@ -0,0 +1,82 @@
+/*
+ * 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.phoenix.hbase.index.metrics;
+
+import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
+import org.apache.hadoop.metrics2.MetricHistogram;
+import org.apache.hadoop.metrics2.lib.MutableFastCounter;
+
+/**
+ * Implementation for tracking Phoenix Index Checker metrics.
+ */
+public class GlobalIndexCheckerSourceImpl extends BaseSourceImpl implements GlobalIndexCheckerSource {
+
+    private final MutableFastCounter indexRepairs;
+    private final MutableFastCounter indexRepairFailures;
+
+    private final MetricHistogram indexRepairTimeHisto;
+    private final MetricHistogram indexRepairFailureTimeHisto;
+
+    public GlobalIndexCheckerSourceImpl() {
+        this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT);
+    }
+
+    public GlobalIndexCheckerSourceImpl(String metricsName,
+                                        String metricsDescription,
+                                        String metricsContext,
+                                        String metricsJmxContext) {
+        super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
+
+        indexRepairs = getMetricsRegistry().newCounter(INDEX_REPAIR, INDEX_REPAIR_DESC, 0L);
+        indexRepairFailures = getMetricsRegistry().newCounter(INDEX_REPAIR_FAILURE, INDEX_REPAIR_FAILURE_DESC, 0L);
+
+        indexRepairTimeHisto = getMetricsRegistry().newHistogram(INDEX_REPAIR_TIME, INDEX_REPAIR_TIME_DESC);
+        indexRepairFailureTimeHisto = getMetricsRegistry().newHistogram(INDEX_REPAIR_FAILURE_TIME, INDEX_REPAIR_FAILURE_TIME_DESC);
+    }
+
+    /**
+     * Increments the number of index repairs
+     */
+    public void incrementIndexRepairs() {
+        indexRepairs.incr();
+    }
+
+    /**
+     * Increments the number of index repair failures
+     */
+    public void incrementIndexRepairFailures() {
+        indexRepairFailures.incr();
+    }
+
+    /**
+     * Updates the index repair time histogram
+     *
+     * @param t time taken in milliseconds
+     */
+    public void updateIndexRepairTime(long t) {
+        indexRepairTimeHisto.add(t);
+    }
+
+    /**
+     * Updates the index repair failure time histogram
+     *
+     * @param t time taken in milliseconds
+     */
+    public void updateIndexRepairFailureTime(long t) {
+        indexRepairFailureTimeHisto.add(t);
+    }
+}
\ No newline at end of file
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/metrics/MetricsIndexerSourceFactory.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/metrics/MetricsIndexerSourceFactory.java
index e373e2f..b105290 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/metrics/MetricsIndexerSourceFactory.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/metrics/MetricsIndexerSourceFactory.java
@@ -22,6 +22,7 @@ package org.apache.phoenix.hbase.index.metrics;
 public class MetricsIndexerSourceFactory {
   private static final MetricsIndexerSourceFactory INSTANCE = new MetricsIndexerSourceFactory();
   private MetricsIndexerSource indexerSource;
+  private GlobalIndexCheckerSource globalIndexCheckerSource;
 
   private MetricsIndexerSourceFactory() {}
 
@@ -35,4 +36,11 @@ public class MetricsIndexerSourceFactory {
     }
     return INSTANCE.indexerSource;
   }
+
+  public synchronized GlobalIndexCheckerSource getGlobalIndexCheckerSource() {
+    if (INSTANCE.globalIndexCheckerSource == null) {
+      INSTANCE.globalIndexCheckerSource = new GlobalIndexCheckerSourceImpl();
+    }
+    return INSTANCE.globalIndexCheckerSource;
+  }
 }
\ No newline at end of file
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/GlobalIndexChecker.java b/phoenix-core/src/main/java/org/apache/phoenix/index/GlobalIndexChecker.java
index f9056bd..d09e1ba 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/GlobalIndexChecker.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/GlobalIndexChecker.java
@@ -54,13 +54,12 @@ import org.apache.hadoop.hbase.regionserver.RegionScanner;
 import org.apache.hadoop.hbase.regionserver.ScannerContext;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
-import org.apache.phoenix.hbase.index.table.HTableFactory;
-import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.hbase.index.metrics.GlobalIndexCheckerSource;
+import org.apache.phoenix.hbase.index.metrics.MetricsIndexerSourceFactory;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.util.EnvironmentEdgeManager;
 import org.apache.phoenix.util.IndexUtil;
-import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.ServerUtil;
 
 /**
@@ -70,6 +69,7 @@ import org.apache.phoenix.util.ServerUtil;
  */
 public class GlobalIndexChecker implements RegionCoprocessor, RegionObserver {
     private static final Log LOG = LogFactory.getLog(GlobalIndexChecker.class);
+    private GlobalIndexCheckerSource metricsSource;
 
     /**
      * Class that verifies a given row of a non-transactional global index.
@@ -92,12 +92,18 @@ public class GlobalIndexChecker implements RegionCoprocessor, RegionObserver {
         private Region region;
         private long minTimestamp;
         private long maxTimestamp;
+        private GlobalIndexCheckerSource metricsSource;
 
-        public GlobalIndexScanner(RegionCoprocessorEnvironment env, Scan scan, RegionScanner scanner) throws IOException {
+        public GlobalIndexScanner(RegionCoprocessorEnvironment env,
+                                  Scan scan,
+                                  RegionScanner scanner,
+                                  GlobalIndexCheckerSource metricsSource) throws IOException {
             this.env = env;
             this.scan = scan;
-            region = env.getRegion();
             this.scanner = scanner;
+            this.metricsSource = metricsSource;
+
+            region = env.getRegion();
             emptyCF = scan.getAttribute(EMPTY_COLUMN_FAMILY_NAME);
             emptyCQ = scan.getAttribute(EMPTY_COLUMN_QUALIFIER_NAME);
             ageThreshold = env.getConfiguration().getLong(
@@ -356,11 +362,23 @@ public class GlobalIndexChecker implements RegionCoprocessor, RegionObserver {
             if (verifyRowAndRemoveEmptyColumn(cellList)) {
                 return true;
             } else {
+                long repairStart = EnvironmentEdgeManager.currentTimeMillis();
+
                 byte[] rowKey = new byte[cell.getRowLength()];
                 System.arraycopy(cell.getRowArray(), cell.getRowOffset(), rowKey, 0, cell.getRowLength());
                 long ts = getMaxTimestamp(cellList);
                 cellList.clear();
-                repairIndexRows(rowKey, ts, cellList);
+
+                try {
+                    repairIndexRows(rowKey, ts, cellList);
+                    metricsSource.incrementIndexRepairs();
+                    metricsSource.updateIndexRepairTime(EnvironmentEdgeManager.currentTimeMillis() - repairStart);
+                } catch (IOException e) {
+                    metricsSource.incrementIndexRepairFailures();
+                    metricsSource.updateIndexRepairFailureTime(EnvironmentEdgeManager.currentTimeMillis() - repairStart);
+                    throw e;
+                }
+
                 if (cellList.isEmpty()) {
                     // This means that the index row is invalid. Return false to tell the caller that this row should be skipped
                     return false;
@@ -381,6 +399,11 @@ public class GlobalIndexChecker implements RegionCoprocessor, RegionObserver {
         if (scan.getAttribute(CHECK_VERIFY_COLUMN) == null) {
             return s;
         }
-        return new GlobalIndexScanner(c.getEnvironment(), scan, s);
+        return new GlobalIndexScanner(c.getEnvironment(), scan, s, metricsSource);
+    }
+
+    @Override
+    public void start(CoprocessorEnvironment e) throws IOException {
+        this.metricsSource = MetricsIndexerSourceFactory.getInstance().getGlobalIndexCheckerSource();
     }
 }