-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add test framework to simulate segment loading and balancing #13074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fa248fa
61c71ec
63bf325
b9db352
b4c83dd
4dc210f
76024b4
32c9f14
c8c344e
3a3d2c4
2479e4e
2bf2985
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,6 +92,7 @@ private void balanceTier( | |
| ) | ||
| { | ||
|
|
||
| log.info("Balancing segments in tier [%s]", tier); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any more information that can be added to this? Having just the fact that the balancing occurred is useful, but if we can like add sizes or anything else that might be nice to have when trying to understand what happened, that can make it even more useful.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I intend to clean up the logs and add some more useful metrics around balancing/loading as a follow up to these changes. |
||
| if (params.getUsedSegments().size() == 0) { | ||
| log.info("Metadata segments are not available. Cannot balance."); | ||
| // suppress emit zero stats | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| /* | ||
| * 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.server.coordinator; | ||
|
|
||
| import org.apache.druid.java.util.common.DateTimes; | ||
| import org.apache.druid.java.util.common.granularity.Granularity; | ||
| import org.apache.druid.segment.IndexIO; | ||
| import org.apache.druid.timeline.DataSegment; | ||
| import org.apache.druid.timeline.partition.NumberedShardSpec; | ||
| import org.joda.time.DateTime; | ||
| import org.joda.time.Interval; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Test utility to create {@link DataSegment}s for a given datasource. | ||
| */ | ||
| public class CreateDataSegments | ||
| { | ||
| private final String datasource; | ||
|
|
||
| private DateTime startTime; | ||
| private Granularity granularity; | ||
| private int numPartitions; | ||
| private int numIntervals; | ||
|
|
||
| public static CreateDataSegments ofDatasource(String datasource) | ||
| { | ||
| return new CreateDataSegments(datasource); | ||
| } | ||
|
|
||
| private CreateDataSegments(String datasource) | ||
| { | ||
| this.datasource = datasource; | ||
| } | ||
|
|
||
| public CreateDataSegments forIntervals(int numIntervals, Granularity intervalSize) | ||
| { | ||
| this.numIntervals = numIntervals; | ||
| this.granularity = intervalSize; | ||
| return this; | ||
| } | ||
|
|
||
| public CreateDataSegments startingAt(String startOfFirstInterval) | ||
| { | ||
| this.startTime = DateTimes.of(startOfFirstInterval); | ||
| return this; | ||
| } | ||
|
|
||
| public CreateDataSegments withNumPartitions(int numPartitions) | ||
| { | ||
| this.numPartitions = numPartitions; | ||
| return this; | ||
| } | ||
|
|
||
| public List<DataSegment> eachOfSizeInMb(long sizeMb) | ||
| { | ||
| final List<DataSegment> segments = new ArrayList<>(); | ||
|
|
||
| int uniqueIdInInterval = 0; | ||
| DateTime nextStart = startTime; | ||
| for (int numInterval = 0; numInterval < numIntervals; ++numInterval) { | ||
| Interval nextInterval = new Interval(nextStart, granularity.increment(nextStart)); | ||
| for (int numPartition = 0; numPartition < numPartitions; ++numPartition) { | ||
| segments.add( | ||
| new NumberedDataSegment( | ||
| datasource, | ||
| nextInterval, | ||
| new NumberedShardSpec(numPartition, numPartitions), | ||
| ++uniqueIdInInterval, | ||
| sizeMb | ||
| ) | ||
| ); | ||
| } | ||
| nextStart = granularity.increment(nextStart); | ||
| } | ||
|
|
||
| return Collections.unmodifiableList(segments); | ||
| } | ||
|
|
||
| /** | ||
| * Simple implementation of DataSegment with a unique integer id to make debugging easier. | ||
| */ | ||
| private static class NumberedDataSegment extends DataSegment | ||
| { | ||
| private final int uniqueId; | ||
|
|
||
| private NumberedDataSegment( | ||
| String datasource, | ||
| Interval interval, | ||
| NumberedShardSpec shardSpec, | ||
| int uinqueId, | ||
| long size | ||
| ) | ||
| { | ||
| super( | ||
| datasource, | ||
| interval, | ||
| "1", | ||
| Collections.emptyMap(), | ||
| Collections.emptyList(), | ||
| Collections.emptyList(), | ||
| shardSpec, | ||
| IndexIO.CURRENT_VERSION_ID, | ||
| size | ||
| ); | ||
| this.uniqueId = uinqueId; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() | ||
| { | ||
| return "{" + getDataSource() + "::" + uniqueId + "}"; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this comment isn't about your code, but your addition of the
toStringhere made me wonder whyDruidCoordinator'stoStringreads as "DutiesRunnable". The class is probably large enough (and already depended upon, see@VisibleForTestingannotation peppering this code) that maybe it's just time to promote it to its own class.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yeah, the
VisibleForTestingis ubiquitous 😅It would be good to pull out
DutiesRunnable. Right now, it seems to be directly using pretty much all the fields thatDruidCoordinatorcontains. That's probably why it is still hanging around here and why it is not a static inner class either.The preferable way to do this would be for
DruidCoordinatorto expose a bunch of methods that update the state of segmentManager and other fields thatDutiesRunnableneeds to access. And theDutiesRunnableconstructor just gets theDruidCoordinatorinstance.DruidCoordinatoralready exposes other such utility methods such asmoveSegment()ormarkSegmentAsUnused()which are used by the actual duties themselves.Let me know if this approach makes sense. We can get it done in a follow-up PR.