View Javadoc

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.wal;
21  
22  import java.io.IOException;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.apache.hadoop.fs.Path;
27  import org.apache.hadoop.hbase.classification.InterfaceAudience;
28  import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
29  import org.apache.hadoop.hbase.HRegionInfo;
30  import org.apache.hadoop.hbase.HTableDescriptor;
31  import org.apache.hadoop.util.StringUtils;
32  
33  import com.google.common.annotations.VisibleForTesting;
34  
35  
36  /**
37   * Class used to push numbers about the WAL into the metrics subsystem.  This will take a
38   * single function call and turn it into multiple manipulations of the hadoop metrics system.
39   */
40  @InterfaceAudience.Private
41  public class MetricsWAL implements WALActionsListener {
42    static final Log LOG = LogFactory.getLog(MetricsWAL.class);
43  
44    private final MetricsWALSource source;
45  
46    public MetricsWAL() {
47      this(CompatibilitySingletonFactory.getInstance(MetricsWALSource.class));
48    }
49  
50    @VisibleForTesting
51    MetricsWAL(MetricsWALSource s) {
52      this.source = s;
53    }
54  
55    public void finishSync(long time) {
56      source.incrementSyncTime(time);
57    }
58  
59    public void finishAppend(long time, long size) {
60  
61      source.incrementAppendCount();
62      source.incrementAppendTime(time);
63      source.incrementAppendSize(size);
64  
65      if (time > 1000) {
66        source.incrementSlowAppendCount();
67        LOG.warn(String.format("%s took %d ms appending an edit to hlog; len~=%s",
68            Thread.currentThread().getName(),
69            time,
70            StringUtils.humanReadableInt(size)));
71      }
72    }
73  
74    @Override
75    public void logRollRequested(boolean underReplicated) {
76      source.incrementLogRollRequested();
77      if (underReplicated) {
78        source.incrementLowReplicationLogRoll();
79      }
80    }
81  
82    @Override
83    public void preLogRoll(Path oldPath, Path newPath) throws IOException {
84    }
85  
86    @Override
87    public void postLogRoll(Path oldPath, Path newPath) throws IOException {
88    }
89  
90    @Override
91    public void preLogArchive(Path oldPath, Path newPath) throws IOException {
92    }
93  
94    @Override
95    public void postLogArchive(Path oldPath, Path newPath) throws IOException {
96    }
97  
98    @Override
99    public void logCloseRequested() {
100   }
101 
102   @Override
103   public void visitLogEntryBeforeWrite(HRegionInfo info, HLogKey logKey, WALEdit logEdit) {
104   }
105 
106   @Override
107   public void visitLogEntryBeforeWrite(HTableDescriptor htd, HLogKey logKey, WALEdit logEdit) {
108   }
109 }