1 /** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20 package org.apache.hadoop.hbase.regionserver.compactions; 21 22 import org.apache.hadoop.classification.InterfaceAudience; 23 24 /** 25 * This class holds information relevant for tracking the progress of a 26 * compaction. 27 * 28 * <p>The metrics tracked allow one to calculate the percent completion of the 29 * compaction based on the number of Key/Value pairs already compacted vs. 30 * total amount scheduled to be compacted. 31 * 32 */ 33 @InterfaceAudience.Private 34 public class CompactionProgress { 35 36 /** the total compacting key values in currently running compaction */ 37 public long totalCompactingKVs; 38 /** the completed count of key values in currently running compaction */ 39 public long currentCompactedKVs = 0; 40 41 /** Constructor 42 * @param totalCompactingKVs the total Key/Value pairs to be compacted 43 */ 44 public CompactionProgress(long totalCompactingKVs) { 45 this.totalCompactingKVs = totalCompactingKVs; 46 } 47 48 /** getter for calculated percent complete 49 * @return float 50 */ 51 public float getProgressPct() { 52 return (float)currentCompactedKVs / totalCompactingKVs; 53 } 54 55 /** 56 * Cancels the compaction progress, setting things to 0. 57 */ 58 public void cancel() { 59 this.currentCompactedKVs = this.totalCompactingKVs = 0; 60 } 61 62 /** 63 * Marks the compaction as complete by setting total to current KV count; 64 * Total KV count is an estimate, so there might be a discrepancy otherwise. 65 */ 66 public void complete() { 67 this.totalCompactingKVs = this.currentCompactedKVs; 68 } 69 }