Search in sources :

Example 6 with PersistentLocalResourceRepository

use of org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepository in project asterixdb by apache.

the class RemoteRecoveryManager method takeoverPartitons.

@Override
public void takeoverPartitons(Integer[] partitions) throws IOException, ACIDException {
    /**
         * TODO even though the takeover is always expected to succeed,
         * in case of any failure during the takeover, the CC should be
         * notified that the takeover failed.
         */
    Set<Integer> partitionsToTakeover = new HashSet<>(Arrays.asList(partitions));
    replayReplicaPartitionLogs(partitionsToTakeover, false);
    //mark these partitions as active in this node
    PersistentLocalResourceRepository resourceRepository = (PersistentLocalResourceRepository) runtimeContext.getLocalResourceRepository();
    for (Integer patitionId : partitions) {
        resourceRepository.addActivePartition(patitionId);
    }
}
Also used : PersistentLocalResourceRepository(org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepository) HashSet(java.util.HashSet)

Example 7 with PersistentLocalResourceRepository

use of org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepository in project asterixdb by apache.

the class RemoteRecoveryManager method doRemoteRecoveryPlan.

//TODO refactor common code between remote recovery and failback process
@Override
public void doRemoteRecoveryPlan(Map<String, Set<Integer>> recoveryPlan) throws HyracksDataException {
    int maxRecoveryAttempts = replicationProperties.getMaxRemoteRecoveryAttempts();
    PersistentLocalResourceRepository resourceRepository = (PersistentLocalResourceRepository) runtimeContext.getLocalResourceRepository();
    IDatasetLifecycleManager datasetLifeCycleManager = runtimeContext.getDatasetLifecycleManager();
    ILogManager logManager = runtimeContext.getTransactionSubsystem().getLogManager();
    while (true) {
        //start recovery steps
        try {
            if (maxRecoveryAttempts <= 0) {
                //to avoid infinite loop in case of unexpected behavior.
                throw new IllegalStateException("Failed to perform remote recovery.");
            }
            /*** Prepare for Recovery ***/
            //1. clean any memory data that could've existed from previous failed recovery attempt
            datasetLifeCycleManager.closeAllDatasets();
            //2. remove any existing storage data and initialize storage metadata
            resourceRepository.deleteStorageData(true);
            resourceRepository.initializeNewUniverse(ClusterProperties.INSTANCE.getStorageDirectoryName());
            /*** Start Recovery Per Lost Replica ***/
            for (Entry<String, Set<Integer>> remoteReplica : recoveryPlan.entrySet()) {
                String replicaId = remoteReplica.getKey();
                Set<Integer> partitionsToRecover = remoteReplica.getValue();
                //Request indexes metadata and LSM components
                replicationManager.requestReplicaFiles(replicaId, partitionsToRecover, new HashSet<String>());
            }
            //get max LSN from selected remote replicas
            long maxRemoteLSN = replicationManager.getMaxRemoteLSN(recoveryPlan.keySet());
            //6. force LogManager to start from a partition > maxLSN in selected remote replicas
            logManager.renewLogFilesAndStartFromLSN(maxRemoteLSN);
            break;
        } catch (IOException e) {
            if (LOGGER.isLoggable(Level.WARNING)) {
                LOGGER.log(Level.WARNING, "Failed during remote recovery. Attempting again...", e);
            }
            maxRecoveryAttempts--;
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IOException(java.io.IOException) IDatasetLifecycleManager(org.apache.asterix.common.api.IDatasetLifecycleManager) PersistentLocalResourceRepository(org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepository) ILogManager(org.apache.asterix.common.transactions.ILogManager)

Aggregations

PersistentLocalResourceRepository (org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepository)7 HashSet (java.util.HashSet)4 IOException (java.io.IOException)2 Set (java.util.Set)2 IDatasetLifecycleManager (org.apache.asterix.common.api.IDatasetLifecycleManager)2 ClusterPartition (org.apache.asterix.common.cluster.ClusterPartition)2 MetadataProperties (org.apache.asterix.common.config.MetadataProperties)2 File (java.io.File)1 RemoteException (java.rmi.RemoteException)1 NCAppRuntimeContext (org.apache.asterix.app.nc.NCAppRuntimeContext)1 AsterixThreadFactory (org.apache.asterix.common.api.AsterixThreadFactory)1 IApplicationContext (org.apache.asterix.common.api.IApplicationContext)1 MessagingProperties (org.apache.asterix.common.config.MessagingProperties)1 INCMessageBroker (org.apache.asterix.common.messaging.api.INCMessageBroker)1 IReplicaResourcesManager (org.apache.asterix.common.replication.IReplicaResourcesManager)1 ILogManager (org.apache.asterix.common.transactions.ILogManager)1 IRecoveryManager (org.apache.asterix.common.transactions.IRecoveryManager)1 MessagingChannelInterfaceFactory (org.apache.asterix.messaging.MessagingChannelInterfaceFactory)1 NCMessageBroker (org.apache.asterix.messaging.NCMessageBroker)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1