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.ArrayList;
23 import java.util.List;
24
25 import org.apache.hadoop.classification.InterfaceAudience;
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.fs.Path;
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.CompactionPolicy;
31 import org.apache.hadoop.hbase.regionserver.compactions.Compactor;
32 import org.apache.hadoop.hbase.regionserver.compactions.DefaultCompactionPolicy;
33 import org.apache.hadoop.hbase.regionserver.compactions.DefaultCompactor;
34 import org.apache.hadoop.hbase.util.ReflectionUtils;
35
36
37
38
39
40 @InterfaceAudience.Private
41 public class DefaultStoreEngine extends StoreEngine<
42 DefaultCompactionPolicy, DefaultCompactor, DefaultStoreFileManager> {
43
44 public static final String DEFAULT_COMPACTOR_CLASS_KEY =
45 "hbase.hstore.defaultengine.compactor.class";
46 public static final String DEFAULT_COMPACTION_POLICY_CLASS_KEY =
47 "hbase.hstore.defaultengine.compactionpolicy.class";
48
49 private static final Class<? extends DefaultCompactor>
50 DEFAULT_COMPACTOR_CLASS = DefaultCompactor.class;
51 private static final Class<? extends DefaultCompactionPolicy>
52 DEFAULT_COMPACTION_POLICY_CLASS = DefaultCompactionPolicy.class;
53
54 @Override
55 protected void createComponents(
56 Configuration conf, Store store, KVComparator kvComparator) throws IOException {
57 storeFileManager = new DefaultStoreFileManager(kvComparator, conf);
58 String className = conf.get(DEFAULT_COMPACTOR_CLASS_KEY, DEFAULT_COMPACTOR_CLASS.getName());
59 try {
60 compactor = ReflectionUtils.instantiateWithCustomCtor(className,
61 new Class[] { Configuration.class, Store.class }, new Object[] { conf, store });
62 } catch (Exception e) {
63 throw new IOException("Unable to load configured compactor '" + className + "'", e);
64 }
65 className = conf.get(
66 DEFAULT_COMPACTION_POLICY_CLASS_KEY, DEFAULT_COMPACTION_POLICY_CLASS.getName());
67 try {
68 compactionPolicy = ReflectionUtils.instantiateWithCustomCtor(className,
69 new Class[] { Configuration.class, StoreConfigInformation.class },
70 new Object[] { conf, store });
71 } catch (Exception e) {
72 throw new IOException("Unable to load configured compaction policy '" + className + "'", e);
73 }
74 }
75
76 @Override
77 public CompactionContext createCompaction() {
78 return new DefaultCompactionContext();
79 }
80
81 private class DefaultCompactionContext extends CompactionContext {
82 @Override
83 public boolean select(List<StoreFile> filesCompacting, boolean isUserCompaction,
84 boolean mayUseOffPeak, boolean forceMajor) throws IOException {
85 request = compactionPolicy.selectCompaction(storeFileManager.getStorefiles(),
86 filesCompacting, isUserCompaction, mayUseOffPeak, forceMajor);
87 return request != null;
88 }
89
90 @Override
91 public List<Path> compact() throws IOException {
92 return compactor.compact(request);
93 }
94
95 @Override
96 public List<StoreFile> preSelect(List<StoreFile> filesCompacting) {
97 return compactionPolicy.preSelectCompactionForCoprocessor(
98 storeFileManager.getStorefiles(), filesCompacting);
99 }
100 }
101 }