Search in sources :

Example 11 with ILSMDiskComponent

use of org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent in project asterixdb by apache.

the class CorrelatedPrefixMergePolicy method triggerScheduledMerge.

/**
     * Submit merge requests for all disk components within [minID, maxID]
     * of all indexes of a given dataset in the given partition
     *
     * @param minID
     * @param maxID
     * @param partition
     * @param indexInfos
     * @throws HyracksDataException
     */
private void triggerScheduledMerge(long minID, long maxID, Set<IndexInfo> indexInfos) throws HyracksDataException {
    for (IndexInfo info : indexInfos) {
        ILSMIndex lsmIndex = info.getIndex();
        List<ILSMDiskComponent> immutableComponents = new ArrayList<>(lsmIndex.getImmutableComponents());
        if (isMergeOngoing(immutableComponents)) {
            continue;
        }
        List<ILSMDiskComponent> mergableComponents = new ArrayList<>();
        for (ILSMDiskComponent component : immutableComponents) {
            ILSMDiskComponentId id = component.getComponentId();
            if (!id.notFound()) {
                if (id.getMinId() >= minID && id.getMaxId() <= maxID) {
                    mergableComponents.add(component);
                }
                if (id.getMaxId() < minID) {
                    //if the component.maxID < minID, we can safely skip the rest disk components in the list
                    break;
                }
            }
        }
        ILSMIndexAccessor accessor = lsmIndex.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
        accessor.scheduleMerge(lsmIndex.getIOOperationCallback(), mergableComponents);
    }
}
Also used : ILSMDiskComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent) ILSMDiskComponentId(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId) ArrayList(java.util.ArrayList) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)

Example 12 with ILSMDiskComponent

use of org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent in project asterixdb by apache.

the class AbstractLSMIOOperationCallback method getComponentId.

private ILSMDiskComponentId getComponentId(List<ILSMComponent> oldComponents) throws HyracksDataException {
    if (oldComponents == null) {
        //if oldComponents == null, then getComponentLSN would treat it as a flush operation,
        //and return the LSN for the flushed component
        long id = getComponentLSN(null);
        if (id == 0) {
            logger.log(Level.WARNING, "Flushing a memory component without setting the LSN");
            id = ILSMDiskComponentId.NOT_FOUND;
        }
        return new LSMDiskComponentId(id, id);
    } else {
        long minId = Long.MAX_VALUE;
        long maxId = Long.MIN_VALUE;
        for (ILSMComponent oldComponent : oldComponents) {
            ILSMDiskComponentId oldComponentId = ((ILSMDiskComponent) oldComponent).getComponentId();
            if (oldComponentId.getMinId() < minId) {
                minId = oldComponentId.getMinId();
            }
            if (oldComponentId.getMaxId() > maxId) {
                maxId = oldComponentId.getMaxId();
            }
        }
        return new LSMDiskComponentId(minId, maxId);
    }
}
Also used : ILSMDiskComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent) LSMDiskComponentId(org.apache.hyracks.storage.am.lsm.common.impls.LSMDiskComponentId) ILSMDiskComponentId(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId) ILSMDiskComponentId(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId) ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent)

Example 13 with ILSMDiskComponent

use of org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent in project asterixdb by apache.

the class AbstractLSMIOOperationCallback method getComponentLSN.

public long getComponentLSN(List<? extends ILSMComponent> diskComponents) throws HyracksDataException {
    if (diskComponents == null) {
        // Flush operation of an LSM index are executed sequentially.
        synchronized (this) {
            long lsn = mutableLastLSNs[readIndex];
            return lsn;
        }
    }
    // Get max LSN from the diskComponents. Implies a merge IO operation or Recovery operation.
    long maxLSN = -1L;
    for (ILSMComponent c : diskComponents) {
        DiskComponentMetadata md = ((ILSMDiskComponent) c).getMetadata();
        maxLSN = Math.max(getTreeIndexLSN(md), maxLSN);
    }
    return maxLSN;
}
Also used : ILSMDiskComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent) ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent) DiskComponentMetadata(org.apache.hyracks.storage.am.lsm.common.impls.DiskComponentMetadata)

Example 14 with ILSMDiskComponent

use of org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent in project asterixdb by apache.

the class ExternalBTreeWithBuddy method clear.

@Override
public void clear() throws HyracksDataException {
    if (!isActive) {
        throw new HyracksDataException("Failed to clear the index since it is not activated.");
    }
    ((ExternalIndexHarness) getLsmHarness()).indexClear();
    for (ILSMDiskComponent c : diskComponents) {
        clearDiskComponent(c);
        // Remove from second list to avoid destroying twice
        secondDiskComponents.remove(c);
    }
    for (ILSMDiskComponent c : secondDiskComponents) {
        clearDiskComponent(c);
    }
    diskComponents.clear();
    secondDiskComponents.clear();
    version = 0;
}
Also used : ILSMDiskComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent) ExternalIndexHarness(org.apache.hyracks.storage.am.lsm.common.impls.ExternalIndexHarness) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 15 with ILSMDiskComponent

use of org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent in project asterixdb by apache.

the class ExternalIndexHarness method addTransactionComponents.

// Three differences from  addBulkLoadedComponent
// 1. this needs synchronization since others might be accessing the index (specifically merge operations that might change the lists of components)
// 2. the actions taken by the index itself are different
// 3. the component has already been marked valid by the bulk update operation
public void addTransactionComponents(ILSMDiskComponent newComponent) throws HyracksDataException {
    ITwoPCIndex index = (ITwoPCIndex) lsmIndex;
    synchronized (opTracker) {
        List<ILSMDiskComponent> newerList;
        List<ILSMDiskComponent> olderList;
        if (index.getCurrentVersion() == 0) {
            newerList = index.getFirstComponentList();
            olderList = index.getSecondComponentList();
        } else {
            newerList = index.getSecondComponentList();
            olderList = index.getFirstComponentList();
        }
        // deleted if they are not needed anymore
        for (ILSMDiskComponent c : olderList) {
            exitComponent(c);
        }
        // Enter components in the newer list
        for (ILSMDiskComponent c : newerList) {
            enterComponent(c);
        }
        if (newComponent != null) {
            // Enter new component
            enterComponent(newComponent);
        }
        index.commitTransactionDiskComponent(newComponent);
        mergePolicy.diskComponentAdded(lsmIndex, fullMergeIsRequested.get());
    }
}
Also used : ILSMDiskComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent) ITwoPCIndex(org.apache.hyracks.storage.am.lsm.common.api.ITwoPCIndex)

Aggregations

ILSMDiskComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent)25 ILSMComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent)10 ILSMIndexAccessor (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)8 ArrayList (java.util.ArrayList)6 ILSMDiskComponentId (org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId)4 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)2 LSMDiskComponentId (org.apache.hyracks.storage.am.lsm.common.impls.LSMDiskComponentId)2 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 ByteBuffer (java.nio.ByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1