SegmentsForSequence build() { final NavigableMap<Long, SegmentsOfInterval> map = new TreeMap<>(); for (Entry<SegmentIdWithShardSpec, Pair<SegmentWithState, List<SegmentWithState>>> entry : intervalToSegments.entrySet()) { map.put( entry.getKey().getInterval().getStartMillis(), new SegmentsOfInterval(entry.getKey().getInterval(), entry.getValue().lhs, entry.getValue().rhs) ); } return new SegmentsForSequence(map, lastSegmentId); } }
private void addSegment(String sequenceName, SegmentIdWithShardSpec identifier) { synchronized (segments) { segments.computeIfAbsent(sequenceName, k -> new SegmentsForSequence()) .add(identifier); } }
private void checkSegmentStates(int expectedNumSegmentsInState, SegmentState expectedState) { final SegmentsForSequence segmentsForSequence = driver.getSegments().get("dummy"); Assert.assertNotNull(segmentsForSequence); final List<SegmentWithState> segmentWithStates = segmentsForSequence .allSegmentStateStream() .filter(segmentWithState -> segmentWithState.getState() == expectedState) .collect(Collectors.toList()); Assert.assertEquals(expectedNumSegmentsInState, segmentWithStates.size()); }
segmentsForSequence.getAllSegmentsOfInterval().forEach(segmentsOfInterval -> { final SegmentWithState appendingSegment = segmentsOfInterval.getAppendingSegment(); if (appendingSegment != null) {
/** * Find a segment in the {@link SegmentState#APPENDING} state for the given timestamp and sequenceName. */ private SegmentIdentifier getAppendableSegment(final DateTime timestamp, final String sequenceName) { synchronized (segments) { final SegmentsForSequence segmentsForSequence = segments.get(sequenceName); if (segmentsForSequence == null) { return null; } final Map.Entry<Long, SegmentsOfInterval> candidateEntry = segmentsForSequence.floor( timestamp.getMillis() ); if (candidateEntry != null) { final SegmentsOfInterval segmentsOfInterval = candidateEntry.getValue(); if (segmentsOfInterval.interval.contains(timestamp)) { return segmentsOfInterval.appendingSegment == null ? null : segmentsOfInterval.appendingSegment.getSegmentIdentifier(); } else { return null; } } else { return null; } } }
/** * Move a set of identifiers out from "active", making way for newer segments. * This method is to support KafkaIndexTask's legacy mode and will be removed in the future. * See KakfaIndexTask.runLegacy(). */ public void moveSegmentOut(final String sequenceName, final List<SegmentIdentifier> identifiers) { synchronized (segments) { final SegmentsForSequence activeSegmentsForSequence = segments.get(sequenceName); if (activeSegmentsForSequence == null) { throw new ISE("WTF?! Asked to remove segments for sequenceName[%s] which doesn't exist...", sequenceName); } for (final SegmentIdentifier identifier : identifiers) { log.info("Moving segment[%s] out of active list.", identifier); final long key = identifier.getInterval().getStartMillis(); final SegmentsOfInterval segmentsOfInterval = activeSegmentsForSequence.get(key); if (segmentsOfInterval == null || segmentsOfInterval.getAppendingSegment() == null || !segmentsOfInterval.getAppendingSegment().getSegmentIdentifier().equals(identifier)) { throw new ISE("WTF?! Asked to remove segment[%s] that didn't exist...", identifier); } segmentsOfInterval.finishAppendingToCurrentActiveSegment(SegmentWithState::finishAppending); } } }
SegmentsForSequence build() { final NavigableMap<Long, SegmentsOfInterval> map = new TreeMap<>(); for (Entry<SegmentIdentifier, Pair<SegmentWithState, List<SegmentWithState>>> entry : intervalToSegments.entrySet()) { map.put( entry.getKey().getInterval().getStartMillis(), new SegmentsOfInterval(entry.getKey().getInterval(), entry.getValue().lhs, entry.getValue().rhs) ); } return new SegmentsForSequence(map, lastSegmentId); } }
private void addSegment(String sequenceName, SegmentIdentifier identifier) { synchronized (segments) { segments.computeIfAbsent(sequenceName, k -> new SegmentsForSequence()) .add(identifier); } }
segmentsForSequence.getAllSegmentsOfInterval().forEach(segmentsOfInterval -> { final SegmentWithState appendingSegment = segmentsOfInterval.getAppendingSegment(); if (appendingSegment != null) {
/** * Find a segment in the {@link SegmentState#APPENDING} state for the given timestamp and sequenceName. */ private SegmentIdWithShardSpec getAppendableSegment(final DateTime timestamp, final String sequenceName) { synchronized (segments) { final SegmentsForSequence segmentsForSequence = segments.get(sequenceName); if (segmentsForSequence == null) { return null; } final Map.Entry<Long, SegmentsOfInterval> candidateEntry = segmentsForSequence.floor( timestamp.getMillis() ); if (candidateEntry != null) { final SegmentsOfInterval segmentsOfInterval = candidateEntry.getValue(); if (segmentsOfInterval.interval.contains(timestamp)) { return segmentsOfInterval.appendingSegment == null ? null : segmentsOfInterval.appendingSegment.getSegmentIdentifier(); } else { return null; } } else { return null; } } }
/** * Move a set of identifiers out from "active", making way for newer segments. * This method is to support KafkaIndexTask's legacy mode and will be removed in the future. * See KakfaIndexTask.runLegacy(). */ public void moveSegmentOut(final String sequenceName, final List<SegmentIdWithShardSpec> identifiers) { synchronized (segments) { final SegmentsForSequence activeSegmentsForSequence = segments.get(sequenceName); if (activeSegmentsForSequence == null) { throw new ISE("WTF?! Asked to remove segments for sequenceName[%s] which doesn't exist...", sequenceName); } for (final SegmentIdWithShardSpec identifier : identifiers) { log.info("Moving segment[%s] out of active list.", identifier); final long key = identifier.getInterval().getStartMillis(); final SegmentsOfInterval segmentsOfInterval = activeSegmentsForSequence.get(key); if (segmentsOfInterval == null || segmentsOfInterval.getAppendingSegment() == null || !segmentsOfInterval.getAppendingSegment().getSegmentIdentifier().equals(identifier)) { throw new ISE("WTF?! Asked to remove segment[%s] that didn't exist...", identifier); } segmentsOfInterval.finishAppendingToCurrentActiveSegment(SegmentWithState::finishAppending); } } }