Search in sources :

Example 11 with IDatasetLifecycleManager

use of org.apache.asterix.common.api.IDatasetLifecycleManager 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)

Example 12 with IDatasetLifecycleManager

use of org.apache.asterix.common.api.IDatasetLifecycleManager in project asterixdb by apache.

the class CorrelatedPrefixMergePolicyFactory method createMergePolicy.

@Override
public ILSMMergePolicy createMergePolicy(Map<String, String> configuration, INCServiceContext ctx) {
    IDatasetLifecycleManager dslcManager = ((INcApplicationContext) ctx.getApplicationContext()).getDatasetLifecycleManager();
    int datasetId = Integer.parseInt(configuration.get(KEY_DATASET_ID));
    ILSMMergePolicy policy = new CorrelatedPrefixMergePolicy(dslcManager, datasetId);
    policy.configure(configuration);
    return policy;
}
Also used : IDatasetLifecycleManager(org.apache.asterix.common.api.IDatasetLifecycleManager) INcApplicationContext(org.apache.asterix.common.api.INcApplicationContext) ILSMMergePolicy(org.apache.hyracks.storage.am.lsm.common.api.ILSMMergePolicy)

Aggregations

IDatasetLifecycleManager (org.apache.asterix.common.api.IDatasetLifecycleManager)12 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 ACIDException (org.apache.asterix.common.exceptions.ACIDException)3 Set (java.util.Set)2 INcApplicationContext (org.apache.asterix.common.api.INcApplicationContext)2 Checkpoint (org.apache.asterix.common.transactions.Checkpoint)2 ILogRecord (org.apache.asterix.common.transactions.ILogRecord)2 PersistentLocalResourceRepository (org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepository)2 TxnId (org.apache.asterix.transaction.management.service.recovery.TxnId)2 ILSMMergePolicy (org.apache.hyracks.storage.am.lsm.common.api.ILSMMergePolicy)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ClusterPartition (org.apache.asterix.common.cluster.ClusterPartition)1