View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.omid.transaction;
19  
20  import com.google.inject.AbstractModule;
21  import com.google.inject.Provider;
22  import com.google.inject.Provides;
23  import org.apache.omid.committable.CommitTable;
24  import org.apache.omid.committable.hbase.HBaseCommitTable;
25  import org.apache.omid.metrics.MetricsRegistry;
26  import org.apache.omid.metrics.NullMetricsProvider;
27  import org.apache.omid.timestamp.storage.HBaseTimestampStorage;
28  import org.apache.omid.timestamp.storage.TimestampStorage;
29  import org.apache.omid.tso.BatchPoolModule;
30  import org.apache.omid.tso.DisruptorModule;
31  import org.apache.omid.tso.LeaseManagement;
32  import org.apache.omid.tso.MockPanicker;
33  import org.apache.omid.tso.NetworkInterfaceUtils;
34  import org.apache.omid.tso.Panicker;
35  import org.apache.omid.tso.PersistenceProcessorHandler;
36  import org.apache.omid.tso.TSOChannelHandler;
37  import org.apache.omid.tso.TSOServerConfig;
38  import org.apache.omid.tso.TSOStateManager;
39  import org.apache.omid.tso.TSOStateManagerImpl;
40  import org.apache.omid.tso.TimestampOracle;
41  import org.apache.omid.tso.TimestampOracleImpl;
42  import org.apache.omid.tso.VoidLeaseManager;
43  
44  import org.apache.commons.io.FileUtils;
45  import org.apache.hadoop.conf.Configuration;
46  import org.apache.hadoop.hbase.HBaseConfiguration;
47  
48  import javax.inject.Named;
49  import javax.inject.Singleton;
50  
51  import java.io.File;
52  import java.io.IOException;
53  import java.net.SocketException;
54  import java.net.UnknownHostException;
55  
56  import static org.apache.omid.tso.TSOServer.TSO_HOST_AND_PORT_KEY;
57  
58  class TSOForHBaseCompactorTestModule extends AbstractModule {
59  
60      private final TSOServerConfig config;
61  
62      TSOForHBaseCompactorTestModule(TSOServerConfig config) {
63          this.config = config;
64      }
65  
66      @Override
67      protected void configure() {
68  
69          bind(TSOChannelHandler.class).in(Singleton.class);
70  
71          bind(TSOStateManager.class).to(TSOStateManagerImpl.class).in(Singleton.class);
72  
73          bind(Panicker.class).to(MockPanicker.class);
74          // HBase commit table creation
75          bind(CommitTable.class).to(HBaseCommitTable.class).in(Singleton.class);
76          // Timestamp storage creation
77          bind(TimestampStorage.class).to(HBaseTimestampStorage.class).in(Singleton.class);
78          bind(TimestampOracle.class).to(TimestampOracleImpl.class).in(Singleton.class);
79  
80          install(new BatchPoolModule(config));
81          // DisruptorConfig
82          install(new DisruptorModule());
83  
84      }
85  
86      @Provides
87      @Singleton
88      Configuration provideHBaseConfig() throws IOException {
89          Configuration hbaseConf = HBaseConfiguration.create();
90          hbaseConf.setInt("hbase.hregion.memstore.flush.size", 10_000 * 1024);
91          hbaseConf.setInt("hbase.regionserver.nbreservationblocks", 1);
92          hbaseConf.set("tso.host", "localhost");
93          hbaseConf.setInt("tso.port", 1234);
94          hbaseConf.set("hbase.coprocessor.region.classes", "org.apache.omid.transaction.OmidCompactor");
95          final String rootdir = "/tmp/hbase.test.dir/";
96          File rootdirFile = new File(rootdir);
97          FileUtils.deleteDirectory(rootdirFile);
98          hbaseConf.set("hbase.rootdir", rootdir);
99          return hbaseConf;
100     }
101 
102     @Provides
103     TSOServerConfig provideTSOServerConfig() {
104         return config;
105     }
106 
107     @Provides
108     @Singleton
109     MetricsRegistry provideMetricsRegistry() {
110         return new NullMetricsProvider();
111     }
112 
113     @Provides
114     @Singleton
115     LeaseManagement provideLeaseManager(TSOChannelHandler tsoChannelHandler,
116                                         TSOStateManager stateManager) throws IOException {
117         return new VoidLeaseManager(tsoChannelHandler, stateManager);
118     }
119 
120     @Provides
121     @Named(TSO_HOST_AND_PORT_KEY)
122     String provideTSOHostAndPort() throws SocketException, UnknownHostException {
123         return NetworkInterfaceUtils.getTSOHostAndPort(config);
124     }
125 
126     @Provides
127     PersistenceProcessorHandler[] getPersistenceProcessorHandler(Provider<PersistenceProcessorHandler> provider) {
128         PersistenceProcessorHandler[] persistenceProcessorHandlers = new PersistenceProcessorHandler[config.getNumConcurrentCTWriters()];
129         for (int i = 0; i < persistenceProcessorHandlers.length; i++) {
130             persistenceProcessorHandlers[i] = provider.get();
131         }
132         return persistenceProcessorHandlers;
133     }
134 }