1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver;
20
21 import java.io.IOException;
22 import java.util.List;
23
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.fs.Path;
27 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
28 import org.apache.hadoop.hbase.KeyValue.KVComparator;
29 import org.apache.hadoop.hbase.regionserver.compactions.CompactionContext;
30 import org.apache.hadoop.hbase.regionserver.compactions.ExploringCompactionPolicy;
31 import org.apache.hadoop.hbase.regionserver.compactions.RatioBasedCompactionPolicy;
32 import org.apache.hadoop.hbase.regionserver.compactions.DefaultCompactor;
33 import org.apache.hadoop.hbase.regionserver.compactions.CompactionThroughputController;
34 import org.apache.hadoop.hbase.security.User;
35 import org.apache.hadoop.hbase.util.ReflectionUtils;
36
37
38
39
40
41 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
42 public class DefaultStoreEngine extends StoreEngine<
43 DefaultStoreFlusher, RatioBasedCompactionPolicy, DefaultCompactor, DefaultStoreFileManager> {
44
45 public static final String DEFAULT_STORE_FLUSHER_CLASS_KEY =
46 "hbase.hstore.defaultengine.storeflusher.class";
47 public static final String DEFAULT_COMPACTOR_CLASS_KEY =
48 "hbase.hstore.defaultengine.compactor.class";
49 public static final String DEFAULT_COMPACTION_POLICY_CLASS_KEY =
50 "hbase.hstore.defaultengine.compactionpolicy.class";
51
52 private static final Class<? extends DefaultStoreFlusher>
53 DEFAULT_STORE_FLUSHER_CLASS = DefaultStoreFlusher.class;
54 private static final Class<? extends DefaultCompactor>
55 DEFAULT_COMPACTOR_CLASS = DefaultCompactor.class;
56 private static final Class<? extends RatioBasedCompactionPolicy>
57 DEFAULT_COMPACTION_POLICY_CLASS = ExploringCompactionPolicy.class;
58
59 @Override
60 public boolean needsCompaction(List<StoreFile> filesCompacting) {
61 return compactionPolicy.needsCompaction(
62 this.storeFileManager.getStorefiles(), filesCompacting);
63 }
64
65 @Override
66 protected void createComponents(
67 Configuration conf, Store store, KVComparator kvComparator) throws IOException {
68 createCompactor(conf, store);
69 createCompactionPolicy(conf, store);
70 createStoreFlusher(conf, store);
71 storeFileManager = new DefaultStoreFileManager(kvComparator, conf, compactionPolicy.getConf());
72 }
73
74 protected void createCompactor(Configuration conf, Store store) throws IOException {
75 String className = conf.get(DEFAULT_COMPACTOR_CLASS_KEY, DEFAULT_COMPACTOR_CLASS.getName());
76 try {
77 compactor = ReflectionUtils.instantiateWithCustomCtor(className,
78 new Class[] { Configuration.class, Store.class }, new Object[] { conf, store });
79 } catch (Exception e) {
80 throw new IOException("Unable to load configured compactor '" + className + "'", e);
81 }
82 }
83
84 protected void createCompactionPolicy(Configuration conf, Store store) throws IOException {
85 String className = conf.get(
86 DEFAULT_COMPACTION_POLICY_CLASS_KEY, DEFAULT_COMPACTION_POLICY_CLASS.getName());
87 try {
88 compactionPolicy = ReflectionUtils.instantiateWithCustomCtor(className,
89 new Class[] { Configuration.class, StoreConfigInformation.class },
90 new Object[] { conf, store });
91 } catch (Exception e) {
92 throw new IOException("Unable to load configured compaction policy '" + className + "'", e);
93 }
94 }
95
96 protected void createStoreFlusher(Configuration conf, Store store) throws IOException {
97 String className = conf.get(
98 DEFAULT_STORE_FLUSHER_CLASS_KEY, DEFAULT_STORE_FLUSHER_CLASS.getName());
99 try {
100 storeFlusher = ReflectionUtils.instantiateWithCustomCtor(className,
101 new Class[] { Configuration.class, Store.class }, new Object[] { conf, store });
102 } catch (Exception e) {
103 throw new IOException("Unable to load configured store flusher '" + className + "'", e);
104 }
105 }
106
107
108 @Override
109 public CompactionContext createCompaction() {
110 return new DefaultCompactionContext();
111 }
112
113 private class DefaultCompactionContext extends CompactionContext {
114 @Override
115 public boolean select(List<StoreFile> filesCompacting, boolean isUserCompaction,
116 boolean mayUseOffPeak, boolean forceMajor) throws IOException {
117 request = compactionPolicy.selectCompaction(storeFileManager.getStorefiles(),
118 filesCompacting, isUserCompaction, mayUseOffPeak, forceMajor);
119 return request != null;
120 }
121
122 @Override
123 public List<Path> compact(CompactionThroughputController throughputController)
124 throws IOException {
125 return compact(throughputController, null);
126 }
127
128 @Override
129 public List<Path> compact(CompactionThroughputController throughputController, User user)
130 throws IOException {
131 return compactor.compact(request, throughputController, user);
132 }
133
134 @Override
135 public List<StoreFile> preSelect(List<StoreFile> filesCompacting) {
136 return compactionPolicy.preSelectCompactionForCoprocessor(
137 storeFileManager.getStorefiles(), filesCompacting);
138 }
139 }
140
141 }