1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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 }