Search in sources :

Example 6 with IDatasetLifecycleManager

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

the class RecoveryManager method getLocalMinFirstLSN.

@Override
public long getLocalMinFirstLSN() throws HyracksDataException {
    IDatasetLifecycleManager datasetLifecycleManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getDatasetLifecycleManager();
    List<IIndex> openIndexList = datasetLifecycleManager.getOpenResources();
    long firstLSN;
    //the min first lsn can only be the current append or smaller
    long minFirstLSN = logMgr.getAppendLSN();
    if (!openIndexList.isEmpty()) {
        for (IIndex index : openIndexList) {
            AbstractLSMIOOperationCallback ioCallback = (AbstractLSMIOOperationCallback) ((ILSMIndex) index).getIOOperationCallback();
            if (!((AbstractLSMIndex) index).isCurrentMutableComponentEmpty() || ioCallback.hasPendingFlush()) {
                firstLSN = ioCallback.getFirstLSN();
                minFirstLSN = Math.min(minFirstLSN, firstLSN);
            }
        }
    }
    return minFirstLSN;
}
Also used : IDatasetLifecycleManager(org.apache.asterix.common.api.IDatasetLifecycleManager) IIndex(org.apache.hyracks.storage.common.IIndex) AbstractLSMIOOperationCallback(org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback) AbstractLSMIndex(org.apache.hyracks.storage.am.lsm.common.impls.AbstractLSMIndex)

Example 7 with IDatasetLifecycleManager

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

the class CheckpointManager method tryCheckpoint.

/***
     * Attempts to perform a soft checkpoint at the specified {@code checkpointTargetLSN}.
     * If a checkpoint cannot be captured due to datasets having LSN < {@code checkpointTargetLSN},
     * an asynchronous flush is triggered on them. When a checkpoint is successful, all transaction
     * log files that end with LSN < {@code checkpointTargetLSN} are deleted.
     */
@Override
public synchronized long tryCheckpoint(long checkpointTargetLSN) throws HyracksDataException {
    LOGGER.info("Attemping soft checkpoint...");
    final long minFirstLSN = txnSubsystem.getRecoveryManager().getMinFirstLSN();
    boolean checkpointSucceeded = minFirstLSN >= checkpointTargetLSN;
    if (!checkpointSucceeded) {
        // Flush datasets with indexes behind target checkpoint LSN
        IDatasetLifecycleManager datasetLifecycleManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getDatasetLifecycleManager();
        datasetLifecycleManager.scheduleAsyncFlushForLaggingDatasets(checkpointTargetLSN);
    }
    capture(minFirstLSN, false);
    if (checkpointSucceeded) {
        txnSubsystem.getLogManager().deleteOldLogFiles(minFirstLSN);
        LOGGER.info(String.format("soft checkpoint succeeded at LSN(%s)", minFirstLSN));
    }
    return minFirstLSN;
}
Also used : IDatasetLifecycleManager(org.apache.asterix.common.api.IDatasetLifecycleManager)

Example 8 with IDatasetLifecycleManager

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

the class CheckpointManager method doSharpCheckpoint.

/**
     * Performs a sharp checkpoint. All datasets are flushed and all transaction
     * log files are deleted.
     */
@Override
public synchronized void doSharpCheckpoint() throws HyracksDataException {
    LOGGER.info("Starting sharp checkpoint...");
    final IDatasetLifecycleManager datasetLifecycleManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getDatasetLifecycleManager();
    datasetLifecycleManager.flushAllDatasets();
    capture(SHARP_CHECKPOINT_LSN, true);
    txnSubsystem.getLogManager().renewLogFiles();
    LOGGER.info("Completed sharp checkpoint.");
}
Also used : IDatasetLifecycleManager(org.apache.asterix.common.api.IDatasetLifecycleManager)

Example 9 with IDatasetLifecycleManager

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

the class ReplicationCheckpointManager method tryCheckpoint.

/***
     * Attempts to perform a soft checkpoint at the specified {@code checkpointTargetLSN}.
     * If a checkpoint cannot be captured due to datasets having LSN < {@code checkpointTargetLSN},
     * an asynchronous flush is triggered on them. If the checkpoint fails due to a replica index,
     * a request is sent to the primary replica of the index to flush it.
     * When a checkpoint is successful, all transaction log files that end with
     * LSN < {@code checkpointTargetLSN} are deleted.
     */
@Override
public synchronized long tryCheckpoint(long checkpointTargetLSN) throws HyracksDataException {
    LOGGER.info("Attemping soft checkpoint...");
    final long minFirstLSN = txnSubsystem.getRecoveryManager().getMinFirstLSN();
    boolean checkpointSucceeded = minFirstLSN >= checkpointTargetLSN;
    if (!checkpointSucceeded) {
        // Flush datasets with indexes behind target checkpoint LSN
        final IDatasetLifecycleManager datasetLifecycleManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getDatasetLifecycleManager();
        datasetLifecycleManager.scheduleAsyncFlushForLaggingDatasets(checkpointTargetLSN);
        // Request remote replicas to flush lagging indexes
        final IReplicationManager replicationManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getAppContext().getReplicationManager();
        try {
            replicationManager.requestFlushLaggingReplicaIndexes(checkpointTargetLSN);
        } catch (IOException e) {
            throw new HyracksDataException(e);
        }
    }
    capture(minFirstLSN, false);
    if (checkpointSucceeded) {
        txnSubsystem.getLogManager().deleteOldLogFiles(minFirstLSN);
        LOGGER.info(String.format("soft checkpoint succeeded with at LSN(%s)", minFirstLSN));
    }
    return minFirstLSN;
}
Also used : IDatasetLifecycleManager(org.apache.asterix.common.api.IDatasetLifecycleManager) IReplicationManager(org.apache.asterix.common.replication.IReplicationManager) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 10 with IDatasetLifecycleManager

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

the class FlushDatasetOperatorDescriptor method createPushRuntime.

@Override
public IOperatorNodePushable createPushRuntime(final IHyracksTaskContext ctx, IRecordDescriptorProvider recordDescProvider, int partition, int nPartitions) throws HyracksDataException {
    return new AbstractUnaryInputSinkOperatorNodePushable() {

        @Override
        public void open() throws HyracksDataException {
        }

        @Override
        public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
        }

        @Override
        public void fail() throws HyracksDataException {
            this.close();
        }

        @Override
        public void close() throws HyracksDataException {
            try {
                INcApplicationContext appCtx = (INcApplicationContext) ctx.getJobletContext().getServiceContext().getApplicationContext();
                IDatasetLifecycleManager datasetLifeCycleManager = appCtx.getDatasetLifecycleManager();
                ILockManager lockManager = appCtx.getTransactionSubsystem().getLockManager();
                ITransactionManager txnManager = appCtx.getTransactionSubsystem().getTransactionManager();
                // get the local transaction
                ITransactionContext txnCtx = txnManager.getTransactionContext(jobId, false);
                // lock the dataset granule
                lockManager.lock(datasetId, -1, LockMode.S, txnCtx);
                // flush the dataset synchronously
                datasetLifeCycleManager.flushDataset(datasetId.getId(), false);
            } catch (ACIDException e) {
                throw new HyracksDataException(e);
            }
        }
    };
}
Also used : IDatasetLifecycleManager(org.apache.asterix.common.api.IDatasetLifecycleManager) AbstractUnaryInputSinkOperatorNodePushable(org.apache.hyracks.dataflow.std.base.AbstractUnaryInputSinkOperatorNodePushable) INcApplicationContext(org.apache.asterix.common.api.INcApplicationContext) ILockManager(org.apache.asterix.common.transactions.ILockManager) ITransactionManager(org.apache.asterix.common.transactions.ITransactionManager) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ByteBuffer(java.nio.ByteBuffer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

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