From e7ac644071604c79f50ad90e8acf83aff03ee6c1 Mon Sep 17 00:00:00 2001 From: sershe Date: Thu, 30 May 2013 17:55:04 +0000 Subject: [PATCH] HBASE-8638 add logging to compaction policy git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1487948 13f79535-47bb-0310-9956-ffa450edef68 --- .../regionserver/CompactSplitThread.java | 16 +++++++++++++- .../ExploringCompactionPolicy.java | 21 ++++++++++++++----- .../RatioBasedCompactionPolicy.java | 4 ++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java index 41e99d59669..11cc5ff5001 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java @@ -19,6 +19,8 @@ package org.apache.hadoop.hbase.regionserver; import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -395,7 +397,11 @@ public class CompactSplitThread implements CompactionRequestor { } } } catch (IOException ex) { - LOG.error("Compaction failed " + this, RemoteExceptionHandler.checkIOException(ex)); + IOException remoteEx = RemoteExceptionHandler.checkIOException(ex); + LOG.error("Compaction failed " + this, remoteEx); + if (remoteEx != ex) { + LOG.info("Compaction failed at original callstack: " + formatStackTrace(ex)); + } server.checkFileSystem(); } catch (Exception ex) { LOG.error("Compaction failed " + this, ex); @@ -406,6 +412,14 @@ public class CompactSplitThread implements CompactionRequestor { this.compaction.getRequest().afterExecute(); } + private String formatStackTrace(Exception ex) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + ex.printStackTrace(pw); + pw.flush(); + return sw.toString(); + } + @Override public int compareTo(CompactionRunner o) { // Only compare the underlying request, for queue sorting purposes. diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/ExploringCompactionPolicy.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/ExploringCompactionPolicy.java index 567dfa4dc58..2af46b08b29 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/ExploringCompactionPolicy.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/ExploringCompactionPolicy.java @@ -23,6 +23,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.regionserver.StoreConfigInformation; @@ -36,7 +38,7 @@ import org.apache.hadoop.hbase.regionserver.StoreFile; */ @InterfaceAudience.Private public class ExploringCompactionPolicy extends RatioBasedCompactionPolicy { - + private static final Log LOG = LogFactory.getLog(ExploringCompactionPolicy.class); /** * Constructor for ExploringCompactionPolicy. @@ -57,6 +59,7 @@ public class ExploringCompactionPolicy extends RatioBasedCompactionPolicy { long bestSize = 0; long smallestSize = Long.MAX_VALUE; + int opts = 0, optsInRatio = 0, bestStart = -1; // for debug logging // Consider every starting place. for (int start = 0; start < candidates.size(); start++) { // Consider every different sub list permutation in between start and end with min files. @@ -83,26 +86,34 @@ public class ExploringCompactionPolicy extends RatioBasedCompactionPolicy { smallestSize = size; } + if (size > comConf.getMaxCompactSize()) { + continue; + } + + ++opts; if (size >= comConf.getMinCompactSize() && !filesInRatio(potentialMatchFiles, mayUseOffPeak)) { continue; } - if (size > comConf.getMaxCompactSize()) { - continue; - } - + ++optsInRatio; // Keep if this gets rid of more files. Or the same number of files for less io. if (potentialMatchFiles.size() > bestSelection.size() || (potentialMatchFiles.size() == bestSelection.size() && size < bestSize)) { bestSelection = potentialMatchFiles; bestSize = size; + bestStart = start; } } } if (bestSelection.size() == 0 && mightBeStuck) { + LOG.debug("Exploring compaction algorithm has selected " + smallest.size() + + " files of size "+ smallestSize + " because the store might be stuck"); return new ArrayList(smallest); } + LOG.debug("Exploring compaction algorithm has selected " + bestSelection.size() + + " files of size " + bestSize + " starting at candidate #" + bestStart + + " after considering " + opts + " permutations with " + optsInRatio + " in ratio"); return new ArrayList(bestSelection); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/RatioBasedCompactionPolicy.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/RatioBasedCompactionPolicy.java index 9e2d1d13160..4e9cbc19bae 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/RatioBasedCompactionPolicy.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/RatioBasedCompactionPolicy.java @@ -89,6 +89,10 @@ public class RatioBasedCompactionPolicy extends CompactionPolicy { boolean mayBeStuck = (candidateFiles.size() - filesCompacting.size() + futureFiles) >= storeConfigInfo.getBlockingFileCount(); candidateSelection = getCurrentEligibleFiles(candidateSelection, filesCompacting); + LOG.debug("Selecting compaction from " + candidateFiles.size() + " store files, " + + filesCompacting.size() + " compacting, " + candidateSelection.size() + + " eligible, " + storeConfigInfo.getBlockingFileCount() + " blocking"); + long cfTtl = this.storeConfigInfo.getStoreFileTtl(); if (!forceMajor) { // If there are expired files, only select them so that compaction deletes them