Search in sources :

Example 1 with SyncReplicationWALProvider

use of org.apache.hadoop.hbase.wal.SyncReplicationWALProvider in project hbase by apache.

the class Replication method initialize.

@Override
public void initialize(Server server, FileSystem fs, Path logDir, Path oldLogDir, WALFactory walFactory) throws IOException {
    this.server = server;
    this.conf = this.server.getConfiguration();
    this.isReplicationForBulkLoadDataEnabled = ReplicationUtils.isReplicationForBulkLoadDataEnabled(this.conf);
    if (this.isReplicationForBulkLoadDataEnabled) {
        if (conf.get(HConstants.REPLICATION_CLUSTER_ID) == null || conf.get(HConstants.REPLICATION_CLUSTER_ID).isEmpty()) {
            throw new IllegalArgumentException(HConstants.REPLICATION_CLUSTER_ID + " cannot be null/empty when " + HConstants.REPLICATION_BULKLOAD_ENABLE_KEY + " is set to true.");
        }
    }
    try {
        this.queueStorage = ReplicationStorageFactory.getReplicationQueueStorage(server.getZooKeeper(), conf);
        this.replicationPeers = ReplicationFactory.getReplicationPeers(server.getZooKeeper(), this.conf);
        this.replicationPeers.init();
    } catch (Exception e) {
        throw new IOException("Failed replication handler create", e);
    }
    UUID clusterId = null;
    try {
        clusterId = ZKClusterId.getUUIDForCluster(this.server.getZooKeeper());
    } catch (KeeperException ke) {
        throw new IOException("Could not read cluster id", ke);
    }
    SyncReplicationPeerMappingManager mapping = new SyncReplicationPeerMappingManager();
    this.globalMetricsSource = CompatibilitySingletonFactory.getInstance(MetricsReplicationSourceFactory.class).getGlobalSource();
    this.replicationManager = new ReplicationSourceManager(queueStorage, replicationPeers, conf, this.server, fs, logDir, oldLogDir, clusterId, walFactory, mapping, globalMetricsSource);
    this.syncReplicationPeerInfoProvider = new SyncReplicationPeerInfoProviderImpl(replicationPeers, mapping);
    PeerActionListener peerActionListener = PeerActionListener.DUMMY;
    // Get the user-space WAL provider
    WALProvider walProvider = walFactory != null ? walFactory.getWALProvider() : null;
    if (walProvider != null) {
        walProvider.addWALActionsListener(new ReplicationSourceWALActionListener(conf, replicationManager));
        if (walProvider instanceof SyncReplicationWALProvider) {
            SyncReplicationWALProvider syncWALProvider = (SyncReplicationWALProvider) walProvider;
            peerActionListener = syncWALProvider;
            syncWALProvider.setPeerInfoProvider(syncReplicationPeerInfoProvider);
            // for sync replication state change, we need to reload the state twice, you can see the
            // code in PeerProcedureHandlerImpl, so here we need to go over the sync replication peers
            // to see if any of them are in the middle of the two refreshes, if so, we need to manually
            // repeat the action we have done in the first refresh, otherwise when the second refresh
            // comes we will be in trouble, such as NPE.
            replicationPeers.getAllPeerIds().stream().map(replicationPeers::getPeer).filter(p -> p.getPeerConfig().isSyncReplication()).filter(p -> p.getNewSyncReplicationState() != SyncReplicationState.NONE).forEach(p -> syncWALProvider.peerSyncReplicationStateChange(p.getId(), p.getSyncReplicationState(), p.getNewSyncReplicationState(), 0));
        }
    }
    this.statsPeriodInSecond = this.conf.getInt("replication.stats.thread.period.seconds", 5 * 60);
    this.replicationLoad = new ReplicationLoad();
    this.peerProcedureHandler = new PeerProcedureHandlerImpl(replicationManager, peerActionListener);
}
Also used : FileSystem(org.apache.hadoop.fs.FileSystem) ReplicationStorageFactory(org.apache.hadoop.hbase.replication.ReplicationStorageFactory) LoggerFactory(org.slf4j.LoggerFactory) ReplicationFactory(org.apache.hadoop.hbase.replication.ReplicationFactory) WALFactory(org.apache.hadoop.hbase.wal.WALFactory) ReplicationQueueStorage(org.apache.hadoop.hbase.replication.ReplicationQueueStorage) ArrayList(java.util.ArrayList) HConstants(org.apache.hadoop.hbase.HConstants) CompatibilitySingletonFactory(org.apache.hadoop.hbase.CompatibilitySingletonFactory) Configuration(org.apache.hadoop.conf.Configuration) Path(org.apache.hadoop.fs.Path) Server(org.apache.hadoop.hbase.Server) WALProvider(org.apache.hadoop.hbase.wal.WALProvider) ReplicationUtils(org.apache.hadoop.hbase.replication.ReplicationUtils) Pair(org.apache.hadoop.hbase.util.Pair) TableName(org.apache.hadoop.hbase.TableName) Logger(org.slf4j.Logger) ReplicationSourceService(org.apache.hadoop.hbase.regionserver.ReplicationSourceService) KeeperException(org.apache.zookeeper.KeeperException) SyncReplicationState(org.apache.hadoop.hbase.replication.SyncReplicationState) IOException(java.io.IOException) UUID(java.util.UUID) ReplicationPeers(org.apache.hadoop.hbase.replication.ReplicationPeers) Stoppable(org.apache.hadoop.hbase.Stoppable) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) SyncReplicationWALProvider(org.apache.hadoop.hbase.wal.SyncReplicationWALProvider) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) ZKClusterId(org.apache.hadoop.hbase.zookeeper.ZKClusterId) ScheduledChore(org.apache.hadoop.hbase.ScheduledChore) SyncReplicationWALProvider(org.apache.hadoop.hbase.wal.SyncReplicationWALProvider) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UUID(java.util.UUID) KeeperException(org.apache.zookeeper.KeeperException) WALProvider(org.apache.hadoop.hbase.wal.WALProvider) SyncReplicationWALProvider(org.apache.hadoop.hbase.wal.SyncReplicationWALProvider)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 TimeUnit (java.util.concurrent.TimeUnit)1 Configuration (org.apache.hadoop.conf.Configuration)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 CompatibilitySingletonFactory (org.apache.hadoop.hbase.CompatibilitySingletonFactory)1 HConstants (org.apache.hadoop.hbase.HConstants)1 ScheduledChore (org.apache.hadoop.hbase.ScheduledChore)1 Server (org.apache.hadoop.hbase.Server)1 Stoppable (org.apache.hadoop.hbase.Stoppable)1 TableName (org.apache.hadoop.hbase.TableName)1 ReplicationSourceService (org.apache.hadoop.hbase.regionserver.ReplicationSourceService)1 ReplicationFactory (org.apache.hadoop.hbase.replication.ReplicationFactory)1 ReplicationPeers (org.apache.hadoop.hbase.replication.ReplicationPeers)1 ReplicationQueueStorage (org.apache.hadoop.hbase.replication.ReplicationQueueStorage)1 ReplicationStorageFactory (org.apache.hadoop.hbase.replication.ReplicationStorageFactory)1 ReplicationUtils (org.apache.hadoop.hbase.replication.ReplicationUtils)1