-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve run time of coordinator duty MarkAsUnusedOvershadowedSegments (…
…#13287) In clusters with a large number of segments, the duty `MarkAsUnusedOvershadowedSegments` can take a long very long time to finish. This is because of the costly invocation of `timeline.isOvershadowed` which is done for every used segment in every coordinator run. Changes - Use `DataSourceSnapshot.getOvershadowedSegments` to get all overshadowed segments - Iterate over this set instead of all used segments to identify segments that can be marked as unused - Mark segments as unused in the DB in batches rather than one at a time - Refactor: Add class `SegmentTimeline` for ease of use and readability while using a `VersionedIntervalTimeline` of segments.
- Loading branch information
Showing
34 changed files
with
281 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
core/src/main/java/org/apache/druid/timeline/SegmentTimeline.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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.timeline; | ||
|
||
import java.util.Comparator; | ||
import java.util.Iterator; | ||
|
||
/** | ||
* {@link VersionedIntervalTimeline} for {@link DataSegment} objects. | ||
*/ | ||
public class SegmentTimeline extends VersionedIntervalTimeline<String, DataSegment> | ||
{ | ||
public static SegmentTimeline forSegments(Iterable<DataSegment> segments) | ||
{ | ||
return forSegments(segments.iterator()); | ||
} | ||
|
||
public static SegmentTimeline forSegments(Iterator<DataSegment> segments) | ||
{ | ||
final SegmentTimeline timeline = new SegmentTimeline(); | ||
VersionedIntervalTimeline.addSegments(timeline, segments); | ||
return timeline; | ||
} | ||
|
||
public SegmentTimeline() | ||
{ | ||
super(Comparator.naturalOrder()); | ||
} | ||
|
||
public boolean isOvershadowed(DataSegment segment) | ||
{ | ||
return isOvershadowed(segment.getInterval(), segment.getVersion(), segment); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
core/src/test/java/org/apache/druid/timeline/SegmentTimelineTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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.timeline; | ||
|
||
import org.apache.druid.java.util.common.Intervals; | ||
import org.apache.druid.timeline.partition.NumberedShardSpec; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
public class SegmentTimelineTest | ||
{ | ||
|
||
@Test | ||
public void testIsOvershadowed() | ||
{ | ||
final SegmentTimeline timeline = SegmentTimeline.forSegments( | ||
Arrays.asList( | ||
createSegment("2022-01-01/2022-01-02", "v1", 0, 3), | ||
createSegment("2022-01-01/2022-01-02", "v1", 1, 3), | ||
createSegment("2022-01-01/2022-01-02", "v1", 2, 3), | ||
createSegment("2022-01-02/2022-01-03", "v2", 0, 2), | ||
createSegment("2022-01-02/2022-01-03", "v2", 1, 2) | ||
) | ||
); | ||
|
||
Assert.assertFalse( | ||
timeline.isOvershadowed(createSegment("2022-01-01/2022-01-02", "v1", 1, 3)) | ||
); | ||
Assert.assertFalse( | ||
timeline.isOvershadowed(createSegment("2022-01-01/2022-01-02", "v1", 2, 3)) | ||
); | ||
Assert.assertFalse( | ||
timeline.isOvershadowed(createSegment("2022-01-01/2022-01-02", "v1", 1, 4)) | ||
); | ||
Assert.assertFalse( | ||
timeline.isOvershadowed(createSegment("2022-01-01T00:00:00/2022-01-01T06:00:00", "v1", 1, 4)) | ||
); | ||
|
||
Assert.assertTrue( | ||
timeline.isOvershadowed(createSegment("2022-01-02/2022-01-03", "v1", 2, 4)) | ||
); | ||
Assert.assertTrue( | ||
timeline.isOvershadowed(createSegment("2022-01-02/2022-01-03", "v1", 0, 1)) | ||
); | ||
} | ||
|
||
private DataSegment createSegment(String interval, String version, int partitionNum, int totalNumPartitions) | ||
{ | ||
return new DataSegment( | ||
"wiki", | ||
Intervals.of(interval), | ||
version, | ||
Collections.emptyMap(), | ||
Collections.emptyList(), | ||
Collections.emptyList(), | ||
new NumberedShardSpec(partitionNum, totalNumPartitions), | ||
0x9, | ||
1L | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.