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 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.fs.Path;
29 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
30 import org.apache.hadoop.hbase.KeyValue.KVComparator;
31 import org.apache.hadoop.hbase.regionserver.compactions.CompactionContext;
32 import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequest;
33 import org.apache.hadoop.hbase.regionserver.compactions.StripeCompactionPolicy;
34 import org.apache.hadoop.hbase.regionserver.compactions.StripeCompactor;
35
36 import com.google.common.base.Preconditions;
37
38
39
40
41 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
42 public class StripeStoreEngine extends StoreEngine<StripeStoreFlusher,
43 StripeCompactionPolicy, StripeCompactor, StripeStoreFileManager> {
44 static final Log LOG = LogFactory.getLog(StripeStoreEngine.class);
45 private StripeStoreConfig config;
46
47 @Override
48 public boolean needsCompaction(List<StoreFile> filesCompacting) {
49 return this.compactionPolicy.needsCompactions(this.storeFileManager, filesCompacting);
50 }
51
52 @Override
53 public CompactionContext createCompaction() {
54 return new StripeCompaction();
55 }
56
57 @Override
58 protected void createComponents(
59 Configuration conf, Store store, KVComparator comparator) throws IOException {
60 this.config = new StripeStoreConfig(conf, store);
61 this.compactionPolicy = new StripeCompactionPolicy(conf, store, config);
62 this.storeFileManager = new StripeStoreFileManager(comparator, conf, this.config);
63 this.storeFlusher = new StripeStoreFlusher(
64 conf, store, this.compactionPolicy, this.storeFileManager);
65 this.compactor = new StripeCompactor(conf, store);
66 }
67
68
69
70
71 private class StripeCompaction extends CompactionContext {
72 private StripeCompactionPolicy.StripeCompactionRequest stripeRequest = null;
73
74 @Override
75 public List<StoreFile> preSelect(List<StoreFile> filesCompacting) {
76 return compactionPolicy.preSelectFilesForCoprocessor(storeFileManager, filesCompacting);
77 }
78
79 @Override
80 public boolean select(List<StoreFile> filesCompacting, boolean isUserCompaction,
81 boolean mayUseOffPeak, boolean forceMajor) throws IOException {
82 this.stripeRequest = compactionPolicy.selectCompaction(
83 storeFileManager, filesCompacting, mayUseOffPeak);
84 this.request = (this.stripeRequest == null)
85 ? new CompactionRequest(new ArrayList<StoreFile>()) : this.stripeRequest.getRequest();
86 return this.stripeRequest != null;
87 }
88
89 @Override
90 public void forceSelect(CompactionRequest request) {
91 super.forceSelect(request);
92 if (this.stripeRequest != null) {
93 this.stripeRequest.setRequest(this.request);
94 } else {
95 LOG.warn("Stripe store is forced to take an arbitrary file list and compact it.");
96 this.stripeRequest = compactionPolicy.createEmptyRequest(storeFileManager, this.request);
97 }
98 }
99
100 @Override
101 public List<Path> compact() throws IOException {
102 Preconditions.checkArgument(this.stripeRequest != null, "Cannot compact without selection");
103 return this.stripeRequest.execute(compactor);
104 }
105 }
106 }