Search in sources :

Example 6 with IndexInfo

use of org.apache.asterix.common.context.IndexInfo in project asterixdb by apache.

the class CorrelatedPrefixMergePolicyTest method testMultiPartition.

@Test
public void testMultiPartition() {
    try {
        List<ILSMDiskComponentId> componentIDs = Arrays.asList(new LSMDiskComponentId(40, 50), new LSMDiskComponentId(30, 35), new LSMDiskComponentId(25, 29), new LSMDiskComponentId(20, 24), new LSMDiskComponentId(10, 19));
        List<ILSMDiskComponentId> resultPrimaryIDs = new ArrayList<>();
        IndexInfo primary = mockIndex(true, componentIDs, resultPrimaryIDs, 0);
        List<ILSMDiskComponentId> resultSecondaryIDs = new ArrayList<>();
        IndexInfo secondary = mockIndex(false, componentIDs, resultSecondaryIDs, 0);
        List<ILSMDiskComponentId> resultSecondaryIDs1 = new ArrayList<>();
        IndexInfo secondary1 = mockIndex(false, componentIDs, resultSecondaryIDs, 1);
        ILSMMergePolicy policy = mockMergePolicy(primary, secondary, secondary1);
        policy.diskComponentAdded(secondary.getIndex(), false);
        Assert.assertTrue(resultPrimaryIDs.isEmpty());
        Assert.assertTrue(resultSecondaryIDs.isEmpty());
        policy.diskComponentAdded(primary.getIndex(), false);
        Assert.assertEquals(Arrays.asList(new LSMDiskComponentId(30, 35), new LSMDiskComponentId(25, 29), new LSMDiskComponentId(20, 24), new LSMDiskComponentId(10, 19)), resultPrimaryIDs);
        Assert.assertEquals(Arrays.asList(new LSMDiskComponentId(30, 35), new LSMDiskComponentId(25, 29), new LSMDiskComponentId(20, 24), new LSMDiskComponentId(10, 19)), resultSecondaryIDs);
        Assert.assertTrue(resultSecondaryIDs1.isEmpty());
    } 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)

Example 7 with IndexInfo

use of org.apache.asterix.common.context.IndexInfo in project asterixdb by apache.

the class CorrelatedPrefixMergePolicyTest method testSecondaryNotFound.

@Test
public void testSecondaryNotFound() {
    try {
        List<ILSMDiskComponentId> primaryComponentIDs = Arrays.asList(new LSMDiskComponentId(40, 50), new LSMDiskComponentId(30, 35), new LSMDiskComponentId(25, 29), new LSMDiskComponentId(20, 24), new LSMDiskComponentId(10, 19));
        List<ILSMDiskComponentId> resultPrimaryIDs = new ArrayList<>();
        IndexInfo primary = mockIndex(true, primaryComponentIDs, resultPrimaryIDs, 0);
        List<ILSMDiskComponentId> secondaryComponentIDs = Arrays.asList(new LSMDiskComponentId(30, 35), new LSMDiskComponentId(ILSMDiskComponentId.NOT_FOUND, ILSMDiskComponentId.NOT_FOUND), new LSMDiskComponentId(20, 24));
        List<ILSMDiskComponentId> resultSecondaryIDs = new ArrayList<>();
        IndexInfo secondary = mockIndex(false, secondaryComponentIDs, 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(30, 35), new LSMDiskComponentId(25, 29), new LSMDiskComponentId(20, 24), new LSMDiskComponentId(10, 19)), resultPrimaryIDs);
        Assert.assertEquals(Arrays.asList(new LSMDiskComponentId(30, 35), new LSMDiskComponentId(20, 24)), 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)

Example 8 with IndexInfo

use of org.apache.asterix.common.context.IndexInfo in project asterixdb by apache.

the class CorrelatedPrefixMergePolicyTest method mockIndex.

private IndexInfo mockIndex(boolean isPrimary, List<ILSMDiskComponentId> componentIDs, List<ILSMDiskComponentId> resultComponentIDs, int partition) throws HyracksDataException {
    List<ILSMDiskComponent> components = new ArrayList<>();
    for (ILSMDiskComponentId id : componentIDs) {
        ILSMDiskComponent component = Mockito.mock(ILSMDiskComponent.class);
        Mockito.when(component.getComponentId()).thenReturn(id);
        Mockito.when(component.getComponentSize()).thenReturn(DEFAULT_COMPONENT_SIZE);
        Mockito.when(component.getState()).thenReturn(ComponentState.READABLE_UNWRITABLE);
        components.add(component);
    }
    ILSMIndex index = Mockito.mock(ILSMIndex.class);
    Mockito.when(index.getImmutableComponents()).thenReturn(components);
    ILSMIndexAccessor accessor = Mockito.mock(ILSMIndexAccessor.class);
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            List<ILSMDiskComponent> mergedComponents = invocation.getArgumentAt(1, List.class);
            mergedComponents.forEach(component -> {
                try {
                    resultComponentIDs.add(component.getComponentId());
                } catch (HyracksDataException e) {
                    e.printStackTrace();
                }
            });
            return null;
        }
    }).when(accessor).scheduleMerge(Mockito.any(ILSMIOOperationCallback.class), Mockito.anyListOf(ILSMDiskComponent.class));
    Mockito.when(index.createAccessor(Mockito.any(IModificationOperationCallback.class), Mockito.any(ISearchOperationCallback.class))).thenReturn(accessor);
    Mockito.when(index.isPrimaryIndex()).thenReturn(isPrimary);
    return new IndexInfo(index, DATASET_ID, 0, partition);
}
Also used : Arrays(java.util.Arrays) CorrelatedPrefixMergePolicyFactory(org.apache.asterix.common.context.CorrelatedPrefixMergePolicyFactory) ISearchOperationCallback(org.apache.hyracks.storage.common.ISearchOperationCallback) LSMDiskComponentId(org.apache.hyracks.storage.am.lsm.common.impls.LSMDiskComponentId) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ILSMDiskComponentId(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CorrelatedPrefixMergePolicy(org.apache.asterix.common.context.CorrelatedPrefixMergePolicy) Map(java.util.Map) TestCase(junit.framework.TestCase) DatasetInfo(org.apache.asterix.common.context.DatasetInfo) IndexInfo(org.apache.asterix.common.context.IndexInfo) IDatasetLifecycleManager(org.apache.asterix.common.api.IDatasetLifecycleManager) ILSMDiskComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent) ILSMIOOperationCallback(org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperationCallback) Set(java.util.Set) Test(org.junit.Test) ComponentState(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent.ComponentState) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) Mockito(org.mockito.Mockito) List(java.util.List) IModificationOperationCallback(org.apache.hyracks.storage.common.IModificationOperationCallback) ILSMMergePolicy(org.apache.hyracks.storage.am.lsm.common.api.ILSMMergePolicy) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) Assert(org.junit.Assert) 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) ISearchOperationCallback(org.apache.hyracks.storage.common.ISearchOperationCallback) IndexInfo(org.apache.asterix.common.context.IndexInfo) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IModificationOperationCallback(org.apache.hyracks.storage.common.IModificationOperationCallback) ILSMDiskComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ILSMIOOperationCallback(org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperationCallback) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

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