private void remove( NavigableMap<Interval, TimelineEntry> timeline, Interval interval, TimelineEntry entry, boolean incompleteOk ) { List<Interval> intervalsToRemove = new ArrayList<>(); TimelineEntry removed = timeline.get(interval); if (removed == null) { Iterator<Map.Entry<Interval, TimelineEntry>> iter = timeline.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<Interval, TimelineEntry> timelineEntry = iter.next(); if (timelineEntry.getValue() == entry) { intervalsToRemove.add(timelineEntry.getKey()); } } } else { intervalsToRemove.add(interval); } for (Interval i : intervalsToRemove) { remove(timeline, i, incompleteOk); } }
public PartitionChunk<ObjectType> remove(Interval interval, VersionType version, PartitionChunk<ObjectType> chunk) { try { lock.writeLock().lock(); Map<VersionType, TimelineEntry> versionEntries = allTimelineEntries.get(interval); if (versionEntries == null) { return null; } TimelineEntry entry = versionEntries.get(version); if (entry == null) { return null; } PartitionChunk<ObjectType> retVal = entry.getPartitionHolder().remove(chunk); if (entry.getPartitionHolder().isEmpty()) { versionEntries.remove(version); if (versionEntries.isEmpty()) { allTimelineEntries.remove(interval); } remove(incompletePartitionsTimeline, interval, entry, true); } remove(completePartitionsTimeline, interval, entry, false); return retVal; } finally { lock.writeLock().unlock(); } }
@Test public void testRemoveSomethingDontHave() { Assert.assertNull( "Don't have it, should be null", timeline.remove(Intervals.of("1970-01-01/2025-04-20"), "1", makeSingle(1)) ); Assert.assertNull( "Don't have it, should be null", timeline.remove(Intervals.of("2011-04-01/2011-04-09"), "version does not exist", makeSingle(1)) ); }
segmentLoadInfos.remove(segmentId); final PartitionChunk<SegmentLoadInfo> removedPartition = timeline.remove( segment.getInterval(), segment.getVersion(), segment.getShardSpec().createChunk( new SegmentLoadInfo(
selectors.remove(segmentId); final PartitionChunk<ServerSelector> removedPartition = timeline.remove( segment.getInterval(), segment.getVersion(), segment.getShardSpec().createChunk(selector) );
@Test public void testRemove() { for (TimelineObjectHolder<String, Integer> holder : timeline.findOvershadowed()) { for (PartitionChunk<Integer> chunk : holder.getObject()) { timeline.remove(holder.getInterval(), holder.getVersion(), chunk); } } Assert.assertTrue(timeline.findOvershadowed().isEmpty()); }
sinks.remove(truncatedTime); metrics.setSinkCount(sinks.size()); sinkTimeline.remove( sink.getInterval(), sink.getVersion(),
@Test public void testRemovePartitionMakesIncomplete() { testIncompletePartitionDoesNotOvershadow(); final IntegerPartitionChunk<Integer> chunk = IntegerPartitionChunk.make(null, 10, 0, 60); Assert.assertEquals(chunk, timeline.remove(Intervals.of("2011-10-05/2011-10-07"), "6", chunk)); assertValues( ImmutableList.of(createExpected("2011-10-05/2011-10-06", "5", 5)), timeline.lookup(Intervals.of("2011-10-05/2011-10-07")) ); Assert.assertTrue("Expected no overshadowed entries", timeline.findOvershadowed().isEmpty()); }
@Test public void testOverlapAndRemove3() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-20", "1", 1); add("2011-01-02/2011-01-03", "2", 2); add("2011-01-10/2011-01-14", "2", 3); timeline.remove(Intervals.of("2011-01-02/2011-01-03"), "2", makeSingle(2)); timeline.remove(Intervals.of("2011-01-10/2011-01-14"), "2", makeSingle(3)); assertValues( Collections.singletonList( createExpected("2011-01-01/2011-01-20", "1", 1) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-20")) ); }
@Test public void testMay3() { Assert.assertEquals( makeSingle(9), timeline.remove(Intervals.of("2011-05-01/2011-05-10"), "4", makeSingle(9)) ); Assert.assertEquals( makeSingle(7), timeline.remove(Intervals.of("2011-05-01/2011-05-05"), "2", makeSingle(7)) ); assertValues( Arrays.asList( createExpected("2011-05-01/2011-05-02", "1", 6), createExpected("2011-05-03/2011-05-04", "3", 8) ), timeline.lookup(Intervals.of("2011-05-01/2011-05-09")) ); }
@Test public void testMay2() { Assert.assertNotNull(timeline.remove(Intervals.of("2011-05-01/2011-05-10"), "4", makeSingle(1))); assertValues( Arrays.asList( createExpected("2011-05-01/2011-05-03", "2", 7), createExpected("2011-05-03/2011-05-04", "3", 8), createExpected("2011-05-04/2011-05-05", "2", 7) ), timeline.lookup(Intervals.of("2011-05-01/2011-05-09")) ); }
@Test public void testOverlapAndRemove() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-20", "1", 1); add("2011-01-10/2011-01-15", "2", 2); timeline.remove(Intervals.of("2011-01-10/2011-01-15"), "2", makeSingle(2)); assertValues( Collections.singletonList( createExpected("2011-01-01/2011-01-20", "1", 1) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-20")) ); }
@Test public void testOverlapAndRemove5() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-20", "1", 1); add("2011-01-10/2011-01-15", "2", 2); timeline.remove(Intervals.of("2011-01-10/2011-01-15"), "2", makeSingle(2)); add("2011-01-01/2011-01-20", "1", 1); assertValues( Collections.singletonList( createExpected("2011-01-01/2011-01-20", "1", 1) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-20")) ); }
@Test public void testApril3() { Assert.assertEquals( makeSingle(1), timeline.remove(Intervals.of("2011-04-01/2011-04-09"), "2", makeSingle(1)) ); Assert.assertEquals( makeSingle(2), timeline.remove(Intervals.of("2011-04-01/2011-04-03"), "1", makeSingle(2)) ); assertValues( Arrays.asList( createExpected("2011-04-01/2011-04-02", "3", 5), createExpected("2011-04-03/2011-04-06", "1", 3), createExpected("2011-04-06/2011-04-09", "3", 4) ), timeline.lookup(Intervals.of("2011-04-01/2011-04-09")) ); }
@Test public void testOverlapAndRemove2() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-20", "1", 1); add("2011-01-10/2011-01-20", "2", 2); add("2011-01-20/2011-01-30", "3", 4); timeline.remove(Intervals.of("2011-01-10/2011-01-20"), "2", makeSingle(2)); assertValues( Arrays.asList( createExpected("2011-01-01/2011-01-20", "1", 1), createExpected("2011-01-20/2011-01-30", "3", 4) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-30")) ); }
@Test public void testApril2() { Assert.assertEquals( makeSingle(1), timeline.remove(Intervals.of("2011-04-01/2011-04-09"), "2", makeSingle(1)) ); assertValues( Arrays.asList( createExpected("2011-04-01/2011-04-02", "3", 5), createExpected("2011-04-02/2011-04-03", "1", 2), createExpected("2011-04-03/2011-04-06", "1", 3), createExpected("2011-04-06/2011-04-09", "3", 4) ), timeline.lookup(Intervals.of("2011-04-01/2011-04-09")) ); }
@Test public void testOverlapAndRemove4() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-20", "1", 1); add("2011-01-10/2011-01-15", "2", 2); add("2011-01-15/2011-01-20", "2", 3); timeline.remove(Intervals.of("2011-01-15/2011-01-20"), "2", makeSingle(3)); assertValues( Arrays.asList( createExpected("2011-01-01/2011-01-10", "1", 1), createExpected("2011-01-10/2011-01-15", "2", 2), createExpected("2011-01-15/2011-01-20", "1", 1) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-20")) ); }
@Test public void testApril4() { Assert.assertEquals( makeSingle(1), timeline.remove(Intervals.of("2011-04-01/2011-04-09"), "2", makeSingle(1)) ); assertValues( Arrays.asList( createExpected("2011-04-01/2011-04-02", "3", 5), createExpected("2011-04-02/2011-04-03", "1", 2), createExpected("2011-04-03/2011-04-05", "1", 3) ), timeline.lookup(Intervals.of("2011-04-01/2011-04-05")) ); assertValues( Arrays.asList( createExpected("2011-04-02T18/2011-04-03", "1", 2), createExpected("2011-04-03/2011-04-04T01", "1", 3) ), timeline.lookup(Intervals.of("2011-04-02T18/2011-04-04T01")) ); }
@Test public void testRemoveNothingBacking() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-05", "1", 1); add("2011-01-05/2011-01-10", "2", 2); add("2011-01-10/2011-01-15", "3", 3); add("2011-01-15/2011-01-20", "4", 4); timeline.remove(Intervals.of("2011-01-15/2011-01-20"), "4", makeSingle(4)); assertValues( Arrays.asList( createExpected("2011-01-01/2011-01-05", "1", 1), createExpected("2011-01-05/2011-01-10", "2", 2), createExpected("2011-01-10/2011-01-15", "3", 3) ), timeline.lookup(new Interval(DateTimes.EPOCH, DateTimes.MAX)) ); }