You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ya...@apache.org on 2021/03/12 06:06:26 UTC

[phoenix] 04/07: PHOENIX-6388 Add sampled logging for read repairs

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

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

commit d1cd37fd87ce30edb7f9d22faa0aec00df07ef1f
Author: Xinyi Yan <ya...@apache.org>
AuthorDate: Tue Feb 23 10:41:51 2021 -0800

    PHOENIX-6388 Add sampled logging for read repairs
---
 .../apache/phoenix/index/GlobalIndexChecker.java   | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)

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 7720ae6..374c292 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
@@ -34,6 +34,7 @@ import java.io.IOException;
 import java.sql.SQLException;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Random;
 
 import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.CellUtil;
@@ -101,6 +102,9 @@ import org.slf4j.LoggerFactory;
  */
 public class GlobalIndexChecker extends BaseScannerRegionObserver {
     private static final Logger LOG = LoggerFactory.getLogger(GlobalIndexChecker.class);
+    private static final String REPAIR_LOGGING_PERCENT_ATTRIB = "phoenix.index.repair.logging.percent";
+    private static final double DEFAULT_REPAIR_LOGGING_PERCENT = 1;
+
     private HTableFactory hTableFactory;
     private GlobalIndexCheckerSource metricsSource;
 
@@ -145,6 +149,8 @@ public class GlobalIndexChecker extends BaseScannerRegionObserver {
         private long pageSize = Long.MAX_VALUE;
         private boolean restartScanDueToPageFilterRemoval = false;
         private boolean hasMore;
+        private double loggingPercent;
+        private Random random;
         private String indexName;
         private long pageSizeMs;
 
@@ -176,6 +182,9 @@ public class GlobalIndexChecker extends BaseScannerRegionObserver {
                         "repairIndexRows: IndexMaintainer is not included in scan attributes for " +
                                 region.getRegionInfo().getTable().getNameAsString());
             }
+            loggingPercent = env.getConfiguration().getDouble(REPAIR_LOGGING_PERCENT_ATTRIB,
+                    DEFAULT_REPAIR_LOGGING_PERCENT);
+            random = new Random(EnvironmentEdgeManager.currentTimeMillis());
             pageSizeMs = getPageSizeMsForRegionScanner(scan);
         }
 
@@ -586,17 +595,28 @@ public class GlobalIndexChecker extends BaseScannerRegionObserver {
                 long ts = cellList.get(0).getTimestamp();
                 cellList.clear();
 
+                long repairTime;
                 try {
                     repairIndexRows(rowKey, ts, cellList);
+                    repairTime = EnvironmentEdgeManager.currentTimeMillis() - repairStart;
                     metricsSource.incrementIndexRepairs(indexName);
                     metricsSource.updateUnverifiedIndexRowAge(indexName,
                         EnvironmentEdgeManager.currentTimeMillis() - ts);
                     metricsSource.updateIndexRepairTime(indexName,
                         EnvironmentEdgeManager.currentTimeMillis() - repairStart);
+                    if (shouldLog()) {
+                        LOG.info("Index row repair on region {} took {} ms.",
+                                env.getRegionInfo().getRegionNameAsString(), repairTime);
+                    }
                 } catch (IOException e) {
+                    repairTime = EnvironmentEdgeManager.currentTimeMillis() - repairStart;
                     metricsSource.incrementIndexRepairFailures(indexName);
                     metricsSource.updateIndexRepairFailureTime(indexName,
                         EnvironmentEdgeManager.currentTimeMillis() - repairStart);
+                    if (shouldLog()) {
+                        LOG.warn("Index row repair failure on region {} took {} ms.",
+                                env.getRegionInfo().getRegionNameAsString(), repairTime);
+                    }
                     throw e;
                 }
 
@@ -607,6 +627,13 @@ public class GlobalIndexChecker extends BaseScannerRegionObserver {
                 return true;
             }
         }
+
+        private boolean shouldLog() {
+            if (loggingPercent == 0) {
+                return false;
+            }
+            return (random.nextDouble() <= (loggingPercent / 100.0d));
+        }
     }
 
     @Override