public void add(final Interval interval, VersionType version, PartitionChunk<ObjectType> object) { try { lock.writeLock().lock(); Map<VersionType, TimelineEntry> exists = allTimelineEntries.get(interval); TimelineEntry entry = null; if (exists == null) { entry = new TimelineEntry(interval, version, new PartitionHolder<ObjectType>(object)); TreeMap<VersionType, TimelineEntry> versionEntry = new TreeMap<VersionType, TimelineEntry>(versionComparator); versionEntry.put(version, entry); allTimelineEntries.put(interval, versionEntry); } else { entry = exists.get(version); if (entry == null) { entry = new TimelineEntry(interval, version, new PartitionHolder<ObjectType>(object)); exists.put(version, entry); } else { PartitionHolder<ObjectType> partitionHolder = entry.getPartitionHolder(); partitionHolder.add(object); } } if (entry.getPartitionHolder().isComplete()) { add(completePartitionsTimeline, interval, entry); } add(incompletePartitionsTimeline, interval, entry); } finally { lock.writeLock().unlock(); } }
private void serverAddedSegment(final DruidServerMetadata server, final DataSegment segment) { String segmentId = segment.getIdentifier(); synchronized (lock) { log.debug("Adding segment[%s] for server[%s]", segment, server); ServerSelector selector = selectors.get(segmentId); if (selector == null) { selector = new ServerSelector(segment, tierSelectorStrategy); VersionedIntervalTimeline<String, ServerSelector> timeline = timelines.get(segment.getDataSource()); if (timeline == null) { timeline = new VersionedIntervalTimeline<>(Ordering.natural()); timelines.put(segment.getDataSource(), timeline); } timeline.add( segment.getInterval(), segment.getVersion(), segment.getShardSpec().createChunk(selector)); selectors.put(segmentId, selector); } QueryableDruidServer queryableDruidServer = clients.get(server.getName()); if (queryableDruidServer == null) { queryableDruidServer = addServer(baseView.getInventoryValue(server.getName())); } selector.addServerAndUpdateSegment(queryableDruidServer, segment); } }
@Override public Set<DataSegment> findUsedSegments(Set<SegmentIdentifier> identifiers) throws IOException { final VersionedIntervalTimeline<String, DataSegment> timeline = new VersionedIntervalTimeline<>(Ordering.natural()); for (DataSegment dataSegment : appenderatorTester.getPushedSegments()) { timeline.add( dataSegment.getInterval(), dataSegment.getVersion(), dataSegment.getShardSpec().createChunk(dataSegment)); } final Set<DataSegment> retVal = Sets.newHashSet(); for (SegmentIdentifier identifier : identifiers) { for (TimelineObjectHolder<String, DataSegment> holder : timeline.lookup(identifier.getInterval())) { for (PartitionChunk<DataSegment> chunk : holder.getObject()) { if (identifiers.contains(SegmentIdentifier.fromDataSegment(chunk.getObject()))) { retVal.add(chunk.getObject()); } } } } return retVal; }
private void remove( NavigableMap<Interval, TimelineEntry> timeline, Interval interval, boolean incompleteOk) { timeline.remove(interval); for (Map.Entry<Interval, TreeMap<VersionType, TimelineEntry>> versionEntry : allTimelineEntries.entrySet()) { if (versionEntry.getKey().overlap(interval) != null) { if (incompleteOk) { add(timeline, versionEntry.getKey(), versionEntry.getValue().lastEntry().getValue()); } else { for (VersionType ver : versionEntry.getValue().descendingKeySet()) { TimelineEntry timelineEntry = versionEntry.getValue().get(ver); if (timelineEntry.getPartitionHolder().isComplete()) { add(timeline, versionEntry.getKey(), timelineEntry); break; } } } } } }