1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.regionserver;
19
20 import java.io.IOException;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
26 import org.apache.hadoop.hbase.HTableDescriptor;
27 import org.apache.hadoop.hbase.classification.InterfaceAudience;
28 import org.apache.hadoop.util.ReflectionUtils;
29
30
31
32
33
34
35
36 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
37 public class FlushPolicyFactory {
38
39 private static final Log LOG = LogFactory.getLog(FlushPolicyFactory.class);
40
41 public static final String HBASE_FLUSH_POLICY_KEY = "hbase.regionserver.flush.policy";
42
43 private static final Class<? extends FlushPolicy> DEFAULT_FLUSH_POLICY_CLASS =
44 FlushLargeStoresPolicy.class;
45
46
47
48
49 public static FlushPolicy create(HRegion region, Configuration conf) throws IOException {
50 Class<? extends FlushPolicy> clazz = getFlushPolicyClass(region.getTableDesc(), conf);
51 FlushPolicy policy = ReflectionUtils.newInstance(clazz, conf);
52 policy.configureForRegion(region);
53 return policy;
54 }
55
56
57
58
59 public static Class<? extends FlushPolicy> getFlushPolicyClass(HTableDescriptor htd,
60 Configuration conf) throws IOException {
61 String className = htd.getFlushPolicyClassName();
62 if (className == null) {
63 className = conf.get(HBASE_FLUSH_POLICY_KEY, DEFAULT_FLUSH_POLICY_CLASS.getName());
64 }
65 try {
66 Class<? extends FlushPolicy> clazz = Class.forName(className).asSubclass(FlushPolicy.class);
67 return clazz;
68 } catch (Exception e) {
69 LOG.warn(
70 "Unable to load configured flush policy '" + className + "' for table '"
71 + htd.getTableName() + "', load default flush policy "
72 + DEFAULT_FLUSH_POLICY_CLASS.getName() + " instead", e);
73 return DEFAULT_FLUSH_POLICY_CLASS;
74 }
75 }
76 }