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 org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.hadoop.classification.InterfaceAudience;
25  import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
26  import org.apache.hadoop.util.StringUtils;
27  
28  
29  /**
30   * Class used to push numbers about the WAL into the metrics subsystem.  This will take a
31   * single function call and turn it into multiple manipulations of the hadoop metrics system.
32   */
33  @InterfaceAudience.Private
34  public class MetricsWAL {
35    static final Log LOG = LogFactory.getLog(MetricsWAL.class);
36  
37    private final MetricsWALSource source;
38  
39    public MetricsWAL() {
40      source = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class);
41    }
42  
43    public void finishSync(long time) {
44      source.incrementSyncTime(time);
45    }
46  
47    public void finishAppend(long time, long size) {
48  
49      source.incrementAppendCount();
50      source.incrementAppendTime(time);
51      source.incrementAppendSize(size);
52  
53      if (time > 1000) {
54        source.incrementSlowAppendCount();
55        LOG.warn(String.format("%s took %d ms appending an edit to hlog; len~=%s",
56            Thread.currentThread().getName(),
57            time,
58            StringUtils.humanReadableInt(size)));
59      }
60    }
61  }