Search in sources :

Example 1 with AbstractLSMIOOperationCallback

use of org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback in project asterixdb by apache.

the class TransactionContext method registerIndexAndCallback.

@Override
public void registerIndexAndCallback(long resourceId, ILSMIndex index, AbstractOperationCallback callback, boolean isPrimaryIndex) {
    synchronized (indexMap) {
        if (isPrimaryIndex && primaryIndex == null) {
            primaryIndex = index;
            primaryIndexCallback = callback;
            primaryIndexOpTracker = (PrimaryIndexOperationTracker) index.getOperationTracker();
        }
        tempResourceIdForRegister.set(resourceId);
        if (!indexMap.containsKey(tempResourceIdForRegister)) {
            indexMap.put(new MutableLong(resourceId), ((AbstractLSMIOOperationCallback) index.getIOOperationCallback()));
        }
    }
}
Also used : AbstractLSMIOOperationCallback(org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback) MutableLong(org.apache.asterix.common.transactions.MutableLong)

Example 2 with AbstractLSMIOOperationCallback

use of org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback in project asterixdb by apache.

the class DatasetLifecycleManager method flushDatasetOpenIndexes.

/*
     * This method can only be called asynchronously safely if we're sure no modify operation will take place until the flush is scheduled
     */
private void flushDatasetOpenIndexes(DatasetInfo dsInfo, boolean asyncFlush) throws HyracksDataException {
    if (!dsInfo.isExternal() && dsInfo.isDurable()) {
        synchronized (logRecord) {
            TransactionUtil.formFlushLogRecord(logRecord, dsInfo.getDatasetID(), null, logManager.getNodeId(), dsInfo.getIndexes().size());
            try {
                logManager.log(logRecord);
            } catch (ACIDException e) {
                throw new HyracksDataException("could not write flush log while closing dataset", e);
            }
            try {
                //notification will come from LogPage class (notifyFlushTerminator)
                logRecord.wait();
            } catch (InterruptedException e) {
                throw new HyracksDataException(e);
            }
        }
        for (IndexInfo iInfo : dsInfo.getIndexes().values()) {
            //update resource lsn
            AbstractLSMIOOperationCallback ioOpCallback = (AbstractLSMIOOperationCallback) iInfo.getIndex().getIOOperationCallback();
            ioOpCallback.updateLastLSN(logRecord.getLSN());
        }
    }
    if (asyncFlush) {
        for (IndexInfo iInfo : dsInfo.getIndexes().values()) {
            ILSMIndexAccessor accessor = iInfo.getIndex().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
            accessor.scheduleFlush(iInfo.getIndex().getIOOperationCallback());
        }
    } else {
        for (IndexInfo iInfo : dsInfo.getIndexes().values()) {
            // TODO: This is not efficient since we flush the indexes sequentially.
            // Think of a way to allow submitting the flush requests concurrently. We don't do them concurrently because this
            // may lead to a deadlock scenario between the DatasetLifeCycleManager and the PrimaryIndexOperationTracker.
            flushAndWaitForIO(dsInfo, iInfo);
        }
    }
}
Also used : AbstractLSMIOOperationCallback(org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 3 with AbstractLSMIOOperationCallback

use of org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback in project asterixdb by apache.

the class PrimaryIndexOperationTracker method triggerScheduleFlush.

//This method is called sequentially by LogPage.notifyFlushTerminator in the sequence flushes were scheduled.
public synchronized void triggerScheduleFlush(LogRecord logRecord) throws HyracksDataException {
    for (ILSMIndex lsmIndex : dsInfo.getDatasetIndexes()) {
        //get resource
        ILSMIndexAccessor accessor = lsmIndex.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
        //update resource lsn
        AbstractLSMIOOperationCallback ioOpCallback = (AbstractLSMIOOperationCallback) lsmIndex.getIOOperationCallback();
        ioOpCallback.updateLastLSN(logRecord.getLSN());
        //schedule flush after update
        accessor.scheduleFlush(lsmIndex.getIOOperationCallback());
    }
    flushLogCreated = false;
}
Also used : AbstractLSMIOOperationCallback(org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)

Example 4 with AbstractLSMIOOperationCallback

use of org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback 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 5 with AbstractLSMIOOperationCallback

use of org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback in project asterixdb by apache.

the class LSMIndexUtil method checkAndSetFirstLSN.

public static void checkAndSetFirstLSN(AbstractLSMIndex lsmIndex, ILogManager logManager) throws HyracksDataException {
    // If the index has an empty memory component, we need to set its first LSN (For soft checkpoint)
    if (lsmIndex.isCurrentMutableComponentEmpty()) {
        //prevent transactions from incorrectly setting the first LSN on a modified component by checking the index is still empty
        synchronized (lsmIndex.getOperationTracker()) {
            if (lsmIndex.isCurrentMutableComponentEmpty()) {
                AbstractLSMIOOperationCallback ioOpCallback = (AbstractLSMIOOperationCallback) lsmIndex.getIOOperationCallback();
                ioOpCallback.setFirstLSN(logManager.getAppendLSN());
            }
        }
    }
}
Also used : AbstractLSMIOOperationCallback(org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback)

Aggregations

AbstractLSMIOOperationCallback (org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback)5 ILSMIndexAccessor (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)2 IDatasetLifecycleManager (org.apache.asterix.common.api.IDatasetLifecycleManager)1 ACIDException (org.apache.asterix.common.exceptions.ACIDException)1 MutableLong (org.apache.asterix.common.transactions.MutableLong)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)1 AbstractLSMIndex (org.apache.hyracks.storage.am.lsm.common.impls.AbstractLSMIndex)1 IIndex (org.apache.hyracks.storage.common.IIndex)1