Search in sources :

Example 1 with ILSMDiskComponentId

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

the class CorrelatedPrefixMergePolicy method scheduleMerge.

private boolean scheduleMerge(ILSMIndex index) throws HyracksDataException {
    List<ILSMDiskComponent> immutableComponents = new ArrayList<>(index.getImmutableComponents());
    Collections.reverse(immutableComponents);
    long totalSize = 0;
    int startIndex = -1;
    int numComponents = immutableComponents.size();
    for (int i = 0; i < numComponents; i++) {
        ILSMComponent c = immutableComponents.get(i);
        long componentSize = ((ILSMDiskComponent) c).getComponentSize();
        if (componentSize > maxMergableComponentSize || ((ILSMDiskComponent) c).getComponentId().notFound()) {
            startIndex = i;
            totalSize = 0;
            continue;
        }
        totalSize += componentSize;
        boolean isLastComponent = i + 1 == numComponents ? true : false;
        if (totalSize > maxMergableComponentSize || (isLastComponent && i - startIndex >= maxToleranceComponentCount)) {
            //merge disk components from startIndex+1 to i
            long minID = Long.MAX_VALUE;
            long maxID = Long.MIN_VALUE;
            for (int j = startIndex + 1; j <= i; j++) {
                ILSMDiskComponentId id = immutableComponents.get(j).getComponentId();
                if (minID > id.getMinId()) {
                    minID = id.getMinId();
                }
                if (maxID < id.getMaxId()) {
                    maxID = id.getMaxId();
                }
            }
            Set<IndexInfo> indexInfos = datasetLifecycleManager.getDatasetInfo(datasetId).getDatsetIndexInfos();
            int partition = getIndexPartition(index, indexInfos);
            triggerScheduledMerge(minID, maxID, indexInfos.stream().filter(info -> info.getPartition() == partition).collect(Collectors.toSet()));
            return true;
        }
    }
    return false;
}
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) ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent)

Example 2 with ILSMDiskComponentId

use of org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId 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 3 with ILSMDiskComponentId

use of org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId 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 4 with ILSMDiskComponentId

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

the class AbstractLSMIOOperationCallback method putComponentIdIntoMetadata.

private void putComponentIdIntoMetadata(ILSMDiskComponent component, List<ILSMComponent> oldComponents) throws HyracksDataException {
    DiskComponentMetadata metadata = component.getMetadata();
    ILSMDiskComponentId componentId = getComponentId(oldComponents);
    metadata.put(ILSMDiskComponentId.COMPONENT_ID_MIN_KEY, LongPointable.FACTORY.createPointable(componentId.getMinId()));
    metadata.put(ILSMDiskComponentId.COMPONENT_ID_MAX_KEY, LongPointable.FACTORY.createPointable(componentId.getMaxId()));
}
Also used : ILSMDiskComponentId(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId) DiskComponentMetadata(org.apache.hyracks.storage.am.lsm.common.impls.DiskComponentMetadata)

Example 5 with ILSMDiskComponentId

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

the class CorrelatedPrefixMergePolicyTest method testBasic.

@Test
public void testBasic() {
    try {
        List<ILSMDiskComponentId> componentIDs = Arrays.asList(new LSMDiskComponentId(5, 5), new LSMDiskComponentId(4, 4), new LSMDiskComponentId(3, 3), new LSMDiskComponentId(2, 2), new LSMDiskComponentId(1, 1));
        List<ILSMDiskComponentId> resultPrimaryIDs = new ArrayList<>();
        IndexInfo primary = mockIndex(true, componentIDs, resultPrimaryIDs, 0);
        List<ILSMDiskComponentId> resultSecondaryIDs = new ArrayList<>();
        IndexInfo secondary = mockIndex(false, componentIDs, resultSecondaryIDs, 0);
        ILSMMergePolicy policy = mockMergePolicy(primary, secondary);
        policy.diskComponentAdded(secondary.getIndex(), false);
        Assert.assertTrue(resultPrimaryIDs.isEmpty());
        Assert.assertTrue(resultSecondaryIDs.isEmpty());
        policy.diskComponentAdded(primary.getIndex(), false);
        Assert.assertEquals(Arrays.asList(new LSMDiskComponentId(4, 4), new LSMDiskComponentId(3, 3), new LSMDiskComponentId(2, 2), new LSMDiskComponentId(1, 1)), resultPrimaryIDs);
        Assert.assertEquals(Arrays.asList(new LSMDiskComponentId(4, 4), new LSMDiskComponentId(3, 3), new LSMDiskComponentId(2, 2), new LSMDiskComponentId(1, 1)), resultSecondaryIDs);
    } catch (HyracksDataException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : 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) ArrayList(java.util.ArrayList) IndexInfo(org.apache.asterix.common.context.IndexInfo) ILSMMergePolicy(org.apache.hyracks.storage.am.lsm.common.api.ILSMMergePolicy) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) Test(org.junit.Test)

Aggregations

ILSMDiskComponentId (org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId)11 ArrayList (java.util.ArrayList)9 LSMDiskComponentId (org.apache.hyracks.storage.am.lsm.common.impls.LSMDiskComponentId)8 IndexInfo (org.apache.asterix.common.context.IndexInfo)7 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)7 ILSMMergePolicy (org.apache.hyracks.storage.am.lsm.common.api.ILSMMergePolicy)7 Test (org.junit.Test)7 ILSMDiskComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent)4 ILSMComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent)2 ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)2 ILSMIndexAccessor (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)2 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 TestCase (junit.framework.TestCase)1 IDatasetLifecycleManager (org.apache.asterix.common.api.IDatasetLifecycleManager)1 CorrelatedPrefixMergePolicy (org.apache.asterix.common.context.CorrelatedPrefixMergePolicy)1