com.bazaarvoice.emodb.sor.DataStoreModule Maven / Gradle / Ivy
package com.bazaarvoice.emodb.sor;
import com.bazaarvoice.emodb.cachemgr.api.CacheRegistry;
import com.bazaarvoice.emodb.common.cassandra.CassandraConfiguration;
import com.bazaarvoice.emodb.common.cassandra.CassandraFactory;
import com.bazaarvoice.emodb.common.cassandra.CassandraKeyspace;
import com.bazaarvoice.emodb.common.cassandra.CqlDriverConfiguration;
import com.bazaarvoice.emodb.common.cassandra.cqldriver.HintsPollerCQLSession;
import com.bazaarvoice.emodb.common.dropwizard.guice.SystemTablePlacement;
import com.bazaarvoice.emodb.common.dropwizard.healthcheck.HealthCheckRegistry;
import com.bazaarvoice.emodb.common.dropwizard.leader.LeaderServiceTask;
import com.bazaarvoice.emodb.common.dropwizard.lifecycle.LifeCycleRegistry;
import com.bazaarvoice.emodb.common.dropwizard.log.DefaultRateLimitedLogFactory;
import com.bazaarvoice.emodb.common.dropwizard.log.RateLimitedLogFactory;
import com.bazaarvoice.emodb.common.dropwizard.service.EmoServiceMode;
import com.bazaarvoice.emodb.common.dropwizard.task.TaskRegistry;
import com.bazaarvoice.emodb.common.zookeeper.store.MapStore;
import com.bazaarvoice.emodb.common.zookeeper.store.ValueStore;
import com.bazaarvoice.emodb.common.zookeeper.store.ZkBooleanSerializer;
import com.bazaarvoice.emodb.common.zookeeper.store.ZkDoubleSerializer;
import com.bazaarvoice.emodb.common.zookeeper.store.ZkDurationSerializer;
import com.bazaarvoice.emodb.common.zookeeper.store.ZkMapStore;
import com.bazaarvoice.emodb.common.zookeeper.store.ZkTimestampSerializer;
import com.bazaarvoice.emodb.common.zookeeper.store.ZkValueStore;
import com.bazaarvoice.emodb.datacenter.DataCenterConfiguration;
import com.bazaarvoice.emodb.datacenter.api.DataCenters;
import com.bazaarvoice.emodb.datacenter.api.KeyspaceDiscovery;
import com.bazaarvoice.emodb.sor.admin.RowKeyTask;
import com.bazaarvoice.emodb.sor.api.CompactionControlSource;
import com.bazaarvoice.emodb.sor.api.DataStore;
import com.bazaarvoice.emodb.sor.audit.AuditFlusher;
import com.bazaarvoice.emodb.sor.audit.AuditStore;
import com.bazaarvoice.emodb.sor.audit.AuditWriter;
import com.bazaarvoice.emodb.sor.audit.DiscardingAuditWriter;
import com.bazaarvoice.emodb.sor.audit.s3.AthenaAuditWriter;
import com.bazaarvoice.emodb.sor.condition.Condition;
import com.bazaarvoice.emodb.sor.condition.Conditions;
import com.bazaarvoice.emodb.sor.core.DataProvider;
import com.bazaarvoice.emodb.sor.core.DataStoreMinSplitSize;
import com.bazaarvoice.emodb.sor.core.DataStoreProviderProxy;
import com.bazaarvoice.emodb.sor.core.DataTools;
import com.bazaarvoice.emodb.sor.core.DataWriteCloser;
import com.bazaarvoice.emodb.sor.core.DatabusEventWriterRegistry;
import com.bazaarvoice.emodb.sor.core.DefaultDataStore;
import com.bazaarvoice.emodb.sor.core.DefaultHistoryStore;
import com.bazaarvoice.emodb.sor.core.DeltaHistoryTtl;
import com.bazaarvoice.emodb.sor.core.GracefulShutdownManager;
import com.bazaarvoice.emodb.sor.core.HistoryStore;
import com.bazaarvoice.emodb.sor.core.LocalDataStore;
import com.bazaarvoice.emodb.sor.core.ManagedDataStoreDelegate;
import com.bazaarvoice.emodb.sor.core.ManagedTableBackingStoreDelegate;
import com.bazaarvoice.emodb.sor.core.MinSplitSizeCleanupMonitor;
import com.bazaarvoice.emodb.sor.core.MinSplitSizeMap;
import com.bazaarvoice.emodb.sor.core.StashRoot;
import com.bazaarvoice.emodb.sor.core.SystemDataStore;
import com.bazaarvoice.emodb.sor.core.WriteCloseableDataStore;
import com.bazaarvoice.emodb.sor.core.ZKDataStoreMinSplitSizeSerializer;
import com.bazaarvoice.emodb.sor.db.astyanax.DAOModule;
import com.bazaarvoice.emodb.sor.db.astyanax.DeltaPlacementFactory;
import com.bazaarvoice.emodb.sor.db.cql.CqlForMultiGets;
import com.bazaarvoice.emodb.sor.db.cql.CqlForScans;
import com.bazaarvoice.emodb.sor.db.cql.SorCqlSettingsTask;
import com.bazaarvoice.emodb.sor.log.LogbackSlowQueryLogProvider;
import com.bazaarvoice.emodb.sor.log.SlowQueryLog;
import com.bazaarvoice.emodb.sor.log.SlowQueryLogConfiguration;
import com.bazaarvoice.emodb.table.db.ClusterInfo;
import com.bazaarvoice.emodb.table.db.Placements;
import com.bazaarvoice.emodb.table.db.ShardsPerTable;
import com.bazaarvoice.emodb.table.db.StashBlackListTableCondition;
import com.bazaarvoice.emodb.table.db.StashTableDAO;
import com.bazaarvoice.emodb.table.db.TableBackingStore;
import com.bazaarvoice.emodb.table.db.TableChangesEnabled;
import com.bazaarvoice.emodb.table.db.TableDAO;
import com.bazaarvoice.emodb.table.db.astyanax.AstyanaxKeyspaceDiscovery;
import com.bazaarvoice.emodb.table.db.astyanax.AstyanaxTableDAO;
import com.bazaarvoice.emodb.table.db.astyanax.BootstrapTables;
import com.bazaarvoice.emodb.table.db.astyanax.CQLSessionForHintsPollerMap;
import com.bazaarvoice.emodb.table.db.astyanax.CQLStashTableDAO;
import com.bazaarvoice.emodb.table.db.astyanax.CurrentDataCenter;
import com.bazaarvoice.emodb.table.db.astyanax.FullConsistencyTimeProvider;
import com.bazaarvoice.emodb.table.db.astyanax.KeyspaceMap;
import com.bazaarvoice.emodb.table.db.astyanax.Maintenance;
import com.bazaarvoice.emodb.table.db.astyanax.MaintenanceDAO;
import com.bazaarvoice.emodb.table.db.astyanax.MaintenanceRateLimitTask;
import com.bazaarvoice.emodb.table.db.astyanax.MaintenanceSchedulerManager;
import com.bazaarvoice.emodb.table.db.astyanax.MoveTableTask;
import com.bazaarvoice.emodb.table.db.astyanax.PlacementCache;
import com.bazaarvoice.emodb.table.db.astyanax.PlacementFactory;
import com.bazaarvoice.emodb.table.db.astyanax.PlacementsUnderMove;
import com.bazaarvoice.emodb.table.db.astyanax.RateLimiterCache;
import com.bazaarvoice.emodb.table.db.astyanax.SystemTableNamespace;
import com.bazaarvoice.emodb.table.db.astyanax.TableChangesEnabledTask;
import com.bazaarvoice.emodb.table.db.astyanax.ValidTablePlacements;
import com.bazaarvoice.emodb.table.db.consistency.CassandraClusters;
import com.bazaarvoice.emodb.table.db.consistency.ClusterHintsPoller;
import com.bazaarvoice.emodb.table.db.consistency.CompositeConsistencyTimeProvider;
import com.bazaarvoice.emodb.table.db.consistency.DatabusClusterInfo;
import com.bazaarvoice.emodb.table.db.consistency.GlobalFullConsistencyZooKeeper;
import com.bazaarvoice.emodb.table.db.consistency.HintsConsistencyTimeProvider;
import com.bazaarvoice.emodb.table.db.consistency.HintsConsistencyTimeTask;
import com.bazaarvoice.emodb.table.db.consistency.HintsConsistencyTimeValues;
import com.bazaarvoice.emodb.table.db.consistency.HintsPollerManager;
import com.bazaarvoice.emodb.table.db.consistency.MinLagConsistencyTimeProvider;
import com.bazaarvoice.emodb.table.db.consistency.MinLagDurationTask;
import com.bazaarvoice.emodb.table.db.consistency.MinLagDurationValues;
import com.bazaarvoice.emodb.table.db.curator.TableMutexManager;
import com.bazaarvoice.emodb.table.db.eventregistry.TableEventRegistry;
import com.bazaarvoice.emodb.table.db.eventregistry.TableEventTools;
import com.bazaarvoice.emodb.table.db.generic.CachingTableDAO;
import com.bazaarvoice.emodb.table.db.generic.CachingTableDAODelegate;
import com.bazaarvoice.emodb.table.db.generic.CachingTableDAORegistry;
import com.bazaarvoice.emodb.table.db.generic.MutexTableDAO;
import com.bazaarvoice.emodb.table.db.generic.MutexTableDAODelegate;
import com.codahale.metrics.MetricRegistry;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.inject.Exposed;
import com.google.inject.Key;
import com.google.inject.PrivateModule;
import com.google.inject.Provider;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import com.sun.jersey.api.client.Client;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.utils.ZKPaths;
import java.net.URI;
import java.time.Clock;
import java.time.Duration;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
/**
* Guice module for constructing a {@link DataStore}.
*
* Requires the following external references:
*
* - {@link DataStoreConfiguration}
*
- {@link DataCenterConfiguration}
*
- {@link DataCenters}
*
- {@link CacheRegistry}
*
- {@link HealthCheckRegistry}
*
- {@link LeaderServiceTask}
*
- {@link LifeCycleRegistry}
*
- {@link TaskRegistry}
*
- Curator {@link CuratorFramework}
*
- Jersey {@link Client}
*
- @{@link CqlForMultiGets} Supplier<Boolean>
*
- @{@link CqlForScans} Supplier<Boolean>
*
- {@link CqlDriverConfiguration}
*
- {@link Clock}
*
- {@link CompactionControlSource}
*
* Exports the following:
*
* - {@link DataStore}
*
- {@link DataProvider}
*
- {@link DataTools}
*
*/
public class DataStoreModule extends PrivateModule {
private final EmoServiceMode _serviceMode;
public DataStoreModule(EmoServiceMode serviceMode) {
_serviceMode = serviceMode;
}
@Override
protected void configure() {
requireBinding(Key.get(String.class, SystemTablePlacement.class));
// Note: we only use ZooKeeper if this is the data center that is allowed to edit table metadata (create/drop table)
// Chain TableDAO -> MutexTableDAO -> CachingTableDAO -> AstyanaxTableDAO.
bind(TableDAO.class).to(MutexTableDAO.class).asEagerSingleton();
bind(TableDAO.class).annotatedWith(MutexTableDAODelegate.class).to(CachingTableDAO.class).asEagerSingleton();
bind(TableDAO.class).annotatedWith(CachingTableDAODelegate.class).to(AstyanaxTableDAO.class).asEagerSingleton();
bind(String.class).annotatedWith(SystemTableNamespace.class).toInstance("__system_sor");
bind(PlacementFactory.class).to(DeltaPlacementFactory.class).asEagerSingleton();
bind(DeltaPlacementFactory.class).asEagerSingleton();
bind(PlacementCache.class).asEagerSingleton();
bind(AstyanaxTableDAO.class).asEagerSingleton();
bind(CassandraFactory.class).asEagerSingleton();
bind(SlowQueryLog.class).toProvider(LogbackSlowQueryLogProvider.class);
bind(HintsConsistencyTimeProvider.class).asEagerSingleton();
bind(MinLagConsistencyTimeProvider.class).asEagerSingleton();
// The web servers are responsible for updating the ZooKeeper full consistency data. CLI tools don't need to.
// Enable updating the ZooKeeper full consistency data if specified
if (_serviceMode.specifies(EmoServiceMode.Aspect.sor_zookeeper_full_consistency)) {
bind(HintsPollerManager.class).asEagerSingleton();
bind(HintsConsistencyTimeTask.class).asEagerSingleton();
bind(MinLagDurationTask.class).asEagerSingleton();
bind(ClusterHintsPoller.class).asEagerSingleton();
}
if (_serviceMode.specifies(EmoServiceMode.Aspect.dataStore_web)) {
bind(MinSplitSizeCleanupMonitor.class).asEagerSingleton();
}
// The web servers are responsible for performing background table background_table_maintenance.
// Enable background table background_table_maintenance if specified.
if (_serviceMode.specifies(EmoServiceMode.Aspect.background_table_maintenance)) {
bind(MaintenanceSchedulerManager.class).asEagerSingleton();
bind(MaintenanceDAO.class).to(AstyanaxTableDAO.class).asEagerSingleton();
bind(CuratorFramework.class).annotatedWith(Maintenance.class)
.to(Key.get(CuratorFramework.class, DataStoreZooKeeper.class)).asEagerSingleton();
bind(String.class).annotatedWith(Maintenance.class).toInstance("sor");
bind(TableChangesEnabledTask.class).asEagerSingleton();
bind(MaintenanceRateLimitTask.class).asEagerSingleton();
bind(MoveTableTask.class).asEagerSingleton();
}
if (_serviceMode.specifies(EmoServiceMode.Aspect.megabus)) {
bind(TableEventTools.class).to(AstyanaxTableDAO.class).asEagerSingleton();
bind(TableEventRegistry.class).to(AstyanaxTableDAO.class).asEagerSingleton();
expose(TableEventTools.class);
expose(TableEventRegistry.class);
}
// Stash requires an additional DAO for storing Stash artifacts and provides a custom interface for access.
if (_serviceMode.specifies(EmoServiceMode.Aspect.scanner) || _serviceMode.specifies(EmoServiceMode.Aspect.megabus)) {
bind(CQLStashTableDAO.class).asEagerSingleton();
bind(StashTableDAO.class).to(AstyanaxTableDAO.class).asEagerSingleton();
expose(StashTableDAO.class);
}
// The system of record requires two bootstrap tables in which it stores its metadata about tables.
// The 64-bit UUID values were chosen at random.
bind(new TypeLiteral
© 2015 - 2024 Weber Informatics LLC | Privacy Policy