Repository: hbase
Updated Branches:
  refs/heads/master 3434e99e6 -> 8afa49f5d


HBASE-19767 Fix for Master web UI shows negative values for Remaining KVs

Negative Remaining KVs and progress percent greater than 100 is because 
CompactionProgress#totalCompactingKVs is sometimes less than 
CompactionProgress#currentCompactedKVs.
Changes add a getter to CompactionProgress#totalCompactingKVs and from inside 
getter warning is logged. currentCompactedKVs are return when 
totalCompactingKVs are less than current.

Signed-off-by: Michael Stack <st...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/8afa49f5
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/8afa49f5
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/8afa49f5

Branch: refs/heads/master
Commit: 8afa49f5d0e28e96c6e1b6c88c6ac976ac0da2b2
Parents: 3434e99
Author: Umesh Agashe <uaga...@cloudera.com>
Authored: Wed Feb 21 13:59:59 2018 -0800
Committer: Michael Stack <st...@apache.org>
Committed: Thu Feb 22 10:10:21 2018 -0800

----------------------------------------------------------------------
 .../hadoop/hbase/regionserver/HRegionServer.java    |  2 +-
 .../apache/hadoop/hbase/regionserver/HStore.java    |  4 ++--
 .../compactions/CompactionProgress.java             | 16 ++++++++++++----
 .../hbase/regionserver/TestMajorCompaction.java     |  2 +-
 4 files changed, 16 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/8afa49f5/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
index 49b7b80..a76dec2 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
@@ -1623,7 +1623,7 @@ public class HRegionServer extends HasThread implements
       storefileIndexSizeKB += store.getStorefilesRootLevelIndexSize() / 1024;
       CompactionProgress progress = store.getCompactionProgress();
       if (progress != null) {
-        totalCompactingKVs += progress.totalCompactingKVs;
+        totalCompactingKVs += progress.getTotalCompactingKVs();
         currentCompactedKVs += progress.currentCompactedKVs;
       }
       rootLevelIndexSizeKB += (int) (store.getStorefilesRootLevelIndexSize() / 
1024);

http://git-wip-us.apache.org/repos/asf/hbase/blob/8afa49f5/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java
index bef50b4..c0ef3ef 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java
@@ -1373,10 +1373,10 @@ public class HStore implements Store, HeapSize, 
StoreConfigInformation, Propagat
     writeCompactionWalRecord(filesToCompact, sfs);
     replaceStoreFiles(filesToCompact, sfs);
     if (cr.isMajor()) {
-      majorCompactedCellsCount += getCompactionProgress().totalCompactingKVs;
+      majorCompactedCellsCount += 
getCompactionProgress().getTotalCompactingKVs();
       majorCompactedCellsSize += getCompactionProgress().totalCompactedSize;
     } else {
-      compactedCellsCount += getCompactionProgress().totalCompactingKVs;
+      compactedCellsCount += getCompactionProgress().getTotalCompactingKVs();
       compactedCellsSize += getCompactionProgress().totalCompactedSize;
     }
     long outputBytes = getTotalSize(sfs);

http://git-wip-us.apache.org/repos/asf/hbase/blob/8afa49f5/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/CompactionProgress.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/CompactionProgress.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/CompactionProgress.java
index d40651a..577276e 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/CompactionProgress.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/CompactionProgress.java
@@ -20,6 +20,8 @@
 package org.apache.hadoop.hbase.regionserver.compactions;
 
 import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * This class holds information relevant for tracking the progress of a
@@ -32,9 +34,10 @@ import org.apache.yetus.audience.InterfaceAudience;
  */
 @InterfaceAudience.Private
 public class CompactionProgress {
+  private static final Logger LOG = 
LoggerFactory.getLogger(CompactionProgress.class);
 
   /** the total compacting key values in currently running compaction */
-  public long totalCompactingKVs;
+  private long totalCompactingKVs;
   /** the completed count of key values in currently running compaction */
   public long currentCompactedKVs = 0;
   /** the total size of data processed by the currently running compaction, in 
bytes */
@@ -51,7 +54,7 @@ public class CompactionProgress {
    * @return float
    */
   public float getProgressPct() {
-    return (float)currentCompactedKVs / totalCompactingKVs;
+    return (float)currentCompactedKVs / getTotalCompactingKVs();
   }
 
   /**
@@ -72,7 +75,12 @@ public class CompactionProgress {
   /**
    * @return the total compacting key values in currently running compaction
    */
-  public long getTotalCompactingKvs() {
+  public long getTotalCompactingKVs() {
+    if (totalCompactingKVs < currentCompactedKVs) {
+      LOG.warn("totalCompactingKVs={} less than currentCompactedKVs={}",
+          totalCompactingKVs, currentCompactedKVs);
+      return currentCompactedKVs;
+    }
     return totalCompactingKVs;
   }
 
@@ -92,7 +100,7 @@ public class CompactionProgress {
 
   @Override
   public String toString() {
-    return String.format("%d/%d (%.2f%%)", currentCompactedKVs, 
totalCompactingKVs,
+    return String.format("%d/%d (%.2f%%)", currentCompactedKVs, 
getTotalCompactingKVs(),
       100 * getProgressPct());
   }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/8afa49f5/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMajorCompaction.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMajorCompaction.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMajorCompaction.java
index ee717f9..4fdd6b3 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMajorCompaction.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMajorCompaction.java
@@ -221,7 +221,7 @@ public class TestMajorCompaction {
       if( progress != null ) {
         ++storeCount;
         assertTrue(progress.currentCompactedKVs > 0);
-        assertTrue(progress.totalCompactingKVs > 0);
+        assertTrue(progress.getTotalCompactingKVs() > 0);
       }
       assertTrue(storeCount > 0);
     }

Reply via email to