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.LowWatermarkWriter;
33  import org.apache.omid.tso.LowWatermarkWriterImpl;
34  import org.apache.omid.tso.MockPanicker;
35  import org.apache.omid.tso.NetworkInterfaceUtils;
36  import org.apache.omid.tso.Panicker;
37  import org.apache.omid.tso.PersistenceProcessorHandler;
38  import org.apache.omid.tso.TSOChannelHandler;
39  import org.apache.omid.tso.TSOServerConfig;
40  import org.apache.omid.tso.TSOStateManager;
41  import org.apache.omid.tso.TSOStateManagerImpl;
42  import org.apache.omid.tso.TimestampOracle;
43  import org.apache.omid.tso.TimestampOracleImpl;
44  import org.apache.omid.tso.VoidLeaseManager;
45  
46  import org.apache.commons.io.FileUtils;
47  import org.apache.hadoop.conf.Configuration;
48  import org.apache.hadoop.hbase.HBaseConfiguration;
49  
50  import javax.inject.Named;
51  import javax.inject.Singleton;
52  
53  import java.io.File;
54  import java.io.IOException;
55  import java.net.SocketException;
56  import java.net.UnknownHostException;
57  
58  import static org.apache.omid.tso.TSOServer.TSO_HOST_AND_PORT_KEY;
59  
60  class TSOForHBaseCompactorTestModule extends AbstractModule {
61  
62      private final TSOServerConfig config;
63  
64      TSOForHBaseCompactorTestModule(TSOServerConfig config) {
65          this.config = config;
66      }
67  
68      @Override
69      protected void configure() {
70  
71          bind(TSOChannelHandler.class).in(Singleton.class);
72  
73          bind(TSOStateManager.class).to(TSOStateManagerImpl.class).in(Singleton.class);
74  
75          bind(Panicker.class).to(MockPanicker.class);
76          // HBase commit table creation
77          bind(CommitTable.class).to(HBaseCommitTable.class).in(Singleton.class);
78          // Timestamp storage creation
79          bind(TimestampStorage.class).to(HBaseTimestampStorage.class).in(Singleton.class);
80          bind(TimestampOracle.class).to(TimestampOracleImpl.class).in(Singleton.class);
81          bind(LowWatermarkWriter.class).to(LowWatermarkWriterImpl.class).in(Singleton.class);
82          install(new BatchPoolModule(config));
83          // DisruptorConfig
84          install(new DisruptorModule(config));
85  
86      }
87  
88      @Provides
89      @Singleton
90      Configuration provideHBaseConfig() throws IOException {
91          Configuration hbaseConf = HBaseConfiguration.create();
92          hbaseConf.setBoolean("hbase.localcluster.assign.random.ports",true);
93          hbaseConf.setInt("hbase.hregion.memstore.flush.size", 10_000 * 1024);
94          hbaseConf.setInt("hbase.regionserver.nbreservationblocks", 1);
95          hbaseConf.set("tso.host", "localhost");
96          hbaseConf.setInt("tso.port", 1234);
97          hbaseConf.set("hbase.coprocessor.region.classes", "org.apache.omid.transaction.OmidCompactor");
98          final String rootdir = "/tmp/hbase.test.dir/";
99          File rootdirFile = new File(rootdir);
100         FileUtils.deleteDirectory(rootdirFile);
101         hbaseConf.set("hbase.rootdir", rootdir);
102         return hbaseConf;
103     }
104 
105     @Provides
106     TSOServerConfig provideTSOServerConfig() {
107         return config;
108     }
109 
110     @Provides
111     @Singleton
112     MetricsRegistry provideMetricsRegistry() {
113         return new NullMetricsProvider();
114     }
115 
116     @Provides
117     @Singleton
118     LeaseManagement provideLeaseManager(TSOChannelHandler tsoChannelHandler,
119                                         TSOStateManager stateManager) throws IOException {
120         return new VoidLeaseManager(tsoChannelHandler, stateManager);
121     }
122 
123     @Provides
124     @Named(TSO_HOST_AND_PORT_KEY)
125     String provideTSOHostAndPort() throws SocketException, UnknownHostException {
126         return NetworkInterfaceUtils.getTSOHostAndPort(config);
127     }
128 
129     @Provides
130     PersistenceProcessorHandler[] getPersistenceProcessorHandler(Provider<PersistenceProcessorHandler> provider) {
131         PersistenceProcessorHandler[] persistenceProcessorHandlers = new PersistenceProcessorHandler[config.getNumConcurrentCTWriters()];
132         for (int i = 0; i < persistenceProcessorHandlers.length; i++) {
133             persistenceProcessorHandlers[i] = provider.get();
134         }
135         return persistenceProcessorHandlers;
136     }
137 }