kfaraz commented on code in PR #17653: URL: https://github.com/apache/druid/pull/17653#discussion_r1944967221
########## server/src/main/java/org/apache/druid/metadata/segment/cache/HeapMemoryDatasourceSegmentCache.java: ########## @@ -0,0 +1,621 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.metadata.segment.cache; + +import org.apache.druid.error.DruidException; +import org.apache.druid.metadata.PendingSegmentRecord; +import org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec; +import org.apache.druid.server.http.DataSegmentPlus; +import org.apache.druid.timeline.DataSegment; +import org.apache.druid.timeline.SegmentId; +import org.apache.druid.timeline.SegmentTimeline; +import org.joda.time.DateTime; +import org.joda.time.Interval; + +import javax.annotation.Nullable; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +/** + * In-memory cache for segments and pending segments of a single datasource. + */ +class HeapMemoryDatasourceSegmentCache extends ReadWriteCache +{ + private final String dataSource; + private final Map<String, DataSegmentPlus> idToUsedSegment = new HashMap<>(); + private final Map<SegmentId, DateTime> unusedSegmentIdToUpdatedTime = new HashMap<>(); + + /** + * Not being used right now. Could allow lookup of visible segments for a given interval. + */ + private final SegmentTimeline usedSegmentTimeline = SegmentTimeline.forSegments(Set.of()); Review Comment: > Is there a reason we aren't using a TreeMap: Interval -> (DataSegment / SegmentId) and use it instead? > I believe the perf impact would be significant when there are several intervals and segments. Hmm, let me evaluate this once. I had decided against it originally since most segment searches are for overlapping intervals rather than exact matches. But I guess we can have some additional logic to prune out intervals which are disjoint, thus benefiting perf as you point out. Other searches are by segment ID, so keeping an `id -> segment` map helped. Eventually, we would most likely end up keeping a timeline itself. That timeline could also be used to replace the timeline maintained in `SqlSegmentsMetadataManager` used by `CompactionScheduler` (and also the coordinator). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
