@Override public synchronized void refresh() { final long nextId = ++lastUsedId; componentId = new LSMComponentId(nextId, nextId); currentComponentIndex = (currentComponentIndex + 1) % numComponents; }
public static ILSMComponentId readFrom(IComponentMetadata metadata, ArrayBackedValueStorage buffer) throws HyracksDataException { long minId = ComponentUtils.getLong(metadata, COMPONENT_ID_MIN_KEY, LSMComponentId.NOT_FOUND, buffer); long maxId = ComponentUtils.getLong(metadata, COMPONENT_ID_MAX_KEY, LSMComponentId.NOT_FOUND, buffer); if (minId == LSMComponentId.NOT_FOUND || maxId == LSMComponentId.NOT_FOUND) { LOGGER.warn("Invalid component id {} was persisted to a component metadata", LSMComponentId.EMPTY_INDEX_LAST_COMPONENT_ID); return LSMComponentId.EMPTY_INDEX_LAST_COMPONENT_ID; } else { return new LSMComponentId(minId, maxId); } }
@Test public void testSecondaryMissing() { try { List<ILSMComponentId> primaryComponentIDs = Arrays.asList(new LSMComponentId(40, 50), new LSMComponentId(30, 35), new LSMComponentId(25, 29), new LSMComponentId(20, 24), new LSMComponentId(10, 19)); List<ILSMComponentId> resultPrimaryIDs = new ArrayList<>(); IndexInfo primary = mockIndex(true, primaryComponentIDs, resultPrimaryIDs, 0); List<ILSMComponentId> secondaryComponentIDs = Arrays.asList(new LSMComponentId(30, 35), new LSMComponentId(25, 29), new LSMComponentId(20, 24)); List<ILSMComponentId> 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 LSMComponentId(30, 35), new LSMComponentId(25, 29), new LSMComponentId(20, 24), new LSMComponentId(10, 19)), resultPrimaryIDs); Assert.assertEquals( Arrays.asList(new LSMComponentId(30, 35), new LSMComponentId(25, 29), new LSMComponentId(20, 24)), resultSecondaryIDs); } catch (HyracksDataException e) { Assert.fail(e.getMessage()); } }
@Test public void testIDIntervals() { try { List<ILSMComponentId> componentIDs = Arrays.asList(new LSMComponentId(40, 50), new LSMComponentId(30, 35), new LSMComponentId(25, 29), new LSMComponentId(20, 24), new LSMComponentId(10, 19)); List<ILSMComponentId> resultPrimaryIDs = new ArrayList<>(); IndexInfo primary = mockIndex(true, componentIDs, resultPrimaryIDs, 0); List<ILSMComponentId> 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 LSMComponentId(30, 35), new LSMComponentId(25, 29), new LSMComponentId(20, 24), new LSMComponentId(10, 19)), resultPrimaryIDs); Assert.assertEquals(Arrays.asList(new LSMComponentId(30, 35), new LSMComponentId(25, 29), new LSMComponentId(20, 24), new LSMComponentId(10, 19)), resultSecondaryIDs); } catch (HyracksDataException e) { Assert.fail(e.getMessage()); } }
@Test public void testBasic() { try { List<ILSMComponentId> componentIDs = Arrays.asList(new LSMComponentId(5, 5), new LSMComponentId(4, 4), new LSMComponentId(3, 3), new LSMComponentId(2, 2), new LSMComponentId(1, 1)); List<ILSMComponentId> resultPrimaryIDs = new ArrayList<>(); IndexInfo primary = mockIndex(true, componentIDs, resultPrimaryIDs, 0); List<ILSMComponentId> 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 LSMComponentId(4, 4), new LSMComponentId(3, 3), new LSMComponentId(2, 2), new LSMComponentId(1, 1)), resultPrimaryIDs); Assert.assertEquals(Arrays.asList(new LSMComponentId(4, 4), new LSMComponentId(3, 3), new LSMComponentId(2, 2), new LSMComponentId(1, 1)), resultSecondaryIDs); } catch (HyracksDataException e) { Assert.fail(e.getMessage()); } }
@Test public void testMultiPartition() { try { List<ILSMComponentId> componentIDs = Arrays.asList(new LSMComponentId(40, 50), new LSMComponentId(30, 35), new LSMComponentId(25, 29), new LSMComponentId(20, 24), new LSMComponentId(10, 19)); List<ILSMComponentId> resultPrimaryIDs = new ArrayList<>(); IndexInfo primary = mockIndex(true, componentIDs, resultPrimaryIDs, 0); List<ILSMComponentId> resultSecondaryIDs = new ArrayList<>(); IndexInfo secondary = mockIndex(false, componentIDs, resultSecondaryIDs, 0); List<ILSMComponentId> 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 LSMComponentId(30, 35), new LSMComponentId(25, 29), new LSMComponentId(20, 24), new LSMComponentId(10, 19)), resultPrimaryIDs); Assert.assertEquals(Arrays.asList(new LSMComponentId(30, 35), new LSMComponentId(25, 29), new LSMComponentId(20, 24), new LSMComponentId(10, 19)), resultSecondaryIDs); Assert.assertTrue(resultSecondaryIDs1.isEmpty()); } catch (HyracksDataException e) { Assert.fail(e.getMessage()); } }
public static ILSMComponentId union(ILSMComponentId id1, ILSMComponentId id2) { long minId = Long.min(((LSMComponentId) id1).getMinId(), ((LSMComponentId) id2).getMinId()); long maxId = Long.max(((LSMComponentId) id1).getMaxId(), ((LSMComponentId) id2).getMaxId()); return new LSMComponentId(minId, maxId); }
long minId = logRecord.getFlushingComponentMinId(); long maxId = logRecord.getFlushingComponentMaxId(); ILSMComponentId id = new LSMComponentId(minId, maxId); flushMap.put(LSMIOOperationCallback.KEY_NEXT_COMPONENT_ID, index.getCurrentMemoryComponent().getId()); if (!index.getDiskComponents().isEmpty()) {
LSMComponentFileReferences files = new LSMComponentFileReferences(target, target, target); FlushOperation flush = new TestFlushOperation(accessor, target, callback, indexId, files, new LSMComponentId(0, 0)); callback.scheduled(flush); callback.beforeOperation(flush);
LSMComponentFileReferences firstFiles = new LSMComponentFileReferences(firstTarget, firstTarget, firstTarget); FlushOperation firstFlush = new TestFlushOperation(firstAccessor, firstTarget, callback, indexId, firstFiles, new LSMComponentId(0, 0)); callback.scheduled(firstFlush); callback.beforeOperation(firstFlush); new LSMComponentFileReferences(secondTarget, secondTarget, secondTarget); FlushOperation secondFlush = new TestFlushOperation(secondAccessor, secondTarget, callback, indexId, secondFiles, new LSMComponentId(1, 1)); callback.scheduled(secondFlush); callback.beforeOperation(secondFlush);