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.master.slowlog;
21  
22  import java.io.IOException;
23  
24  import org.apache.hadoop.conf.Configuration;
25  import org.apache.hadoop.hbase.HColumnDescriptor;
26  import org.apache.hadoop.hbase.HConstants;
27  import org.apache.hadoop.hbase.HTableDescriptor;
28  import org.apache.hadoop.hbase.MetaTableAccessor;
29  import org.apache.hadoop.hbase.classification.InterfaceAudience;
30  import org.apache.hadoop.hbase.master.MasterServices;
31  import org.apache.hadoop.hbase.slowlog.SlowLogTableAccessor;
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  
35  /**
36   * Slowlog Master services - Table creation to be used by HMaster
37   */
38  @InterfaceAudience.Private
39  public class SlowLogMasterService {
40  
41    private static final Logger LOG = LoggerFactory.getLogger(SlowLogMasterService.class);
42  
43    private final boolean slowlogTableEnabled;
44    private final MasterServices masterServices;
45  
46    private static final HTableDescriptor TABLE_DESCRIPTOR_BUILDER =
47      new HTableDescriptor(SlowLogTableAccessor.SLOW_LOG_TABLE_NAME).setRegionReplication(1);
48  
49    static {
50      TABLE_DESCRIPTOR_BUILDER.addFamily(new HColumnDescriptor(HConstants.SLOWLOG_INFO_FAMILY)
51        .setScope(HConstants.REPLICATION_SCOPE_LOCAL).setBlockCacheEnabled(false).setMaxVersions(1));
52    }
53  
54    public SlowLogMasterService(final Configuration configuration,
55      final MasterServices masterServices) {
56      slowlogTableEnabled = configuration.getBoolean(HConstants.SLOW_LOG_SYS_TABLE_ENABLED_KEY,
57        HConstants.DEFAULT_SLOW_LOG_SYS_TABLE_ENABLED_KEY);
58      this.masterServices = masterServices;
59    }
60  
61    public void init() throws IOException {
62      if (!slowlogTableEnabled) {
63        LOG.info("Slow/Large requests logging to system table hbase:slowlog is disabled. Quitting.");
64        return;
65      }
66      if (!MetaTableAccessor
67          .tableExists(masterServices.getConnection(), SlowLogTableAccessor.SLOW_LOG_TABLE_NAME)) {
68        LOG.info("slowlog table not found. Creating.");
69        this.masterServices.createSystemTable(TABLE_DESCRIPTOR_BUILDER);
70      }
71    }
72  
73  }