-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
MSQ: Allow for worker gaps. #17277
Merged
Merged
MSQ: Allow for worker gaps. #17277
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
142 changes: 142 additions & 0 deletions
142
...query/src/main/java/org/apache/druid/msq/input/stage/SparseStripedReadablePartitions.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,142 @@ | ||
/* | ||
* 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.msq.input.stage; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.collect.Iterators; | ||
import it.unimi.dsi.fastutil.ints.IntAVLTreeSet; | ||
import it.unimi.dsi.fastutil.ints.IntSortedSet; | ||
import org.apache.druid.msq.input.SlicerUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
/** | ||
* Set of partitions striped across a sparse set of {@code workers}. Each worker contains a "stripe" of each partition. | ||
* | ||
* @see StripedReadablePartitions dense version, where workers from [0..N) are all used. | ||
*/ | ||
public class SparseStripedReadablePartitions implements ReadablePartitions | ||
{ | ||
private final int stageNumber; | ||
private final IntSortedSet workers; | ||
private final IntSortedSet partitionNumbers; | ||
|
||
/** | ||
* Constructor. Most callers should use {@link ReadablePartitions#striped(int, int, int)} instead, which takes | ||
* a partition count rather than a set of partition numbers. | ||
*/ | ||
public SparseStripedReadablePartitions( | ||
final int stageNumber, | ||
final IntSortedSet workers, | ||
final IntSortedSet partitionNumbers | ||
) | ||
{ | ||
this.stageNumber = stageNumber; | ||
this.workers = workers; | ||
this.partitionNumbers = partitionNumbers; | ||
} | ||
|
||
@JsonCreator | ||
private SparseStripedReadablePartitions( | ||
@JsonProperty("stageNumber") final int stageNumber, | ||
@JsonProperty("workers") final Set<Integer> workers, | ||
@JsonProperty("partitionNumbers") final Set<Integer> partitionNumbers | ||
) | ||
{ | ||
this(stageNumber, new IntAVLTreeSet(workers), new IntAVLTreeSet(partitionNumbers)); | ||
} | ||
|
||
@Override | ||
public Iterator<ReadablePartition> iterator() | ||
{ | ||
return Iterators.transform( | ||
partitionNumbers.iterator(), | ||
partitionNumber -> ReadablePartition.striped(stageNumber, workers, partitionNumber) | ||
); | ||
} | ||
|
||
@Override | ||
public List<ReadablePartitions> split(final int maxNumSplits) | ||
{ | ||
final List<ReadablePartitions> retVal = new ArrayList<>(); | ||
|
||
for (List<Integer> entries : SlicerUtils.makeSlicesStatic(partitionNumbers.iterator(), maxNumSplits)) { | ||
if (!entries.isEmpty()) { | ||
retVal.add(new SparseStripedReadablePartitions(stageNumber, workers, new IntAVLTreeSet(entries))); | ||
} | ||
} | ||
|
||
return retVal; | ||
} | ||
|
||
@JsonProperty | ||
int getStageNumber() | ||
{ | ||
return stageNumber; | ||
} | ||
|
||
@JsonProperty | ||
IntSortedSet getWorkers() | ||
{ | ||
return workers; | ||
} | ||
|
||
@JsonProperty | ||
IntSortedSet getPartitionNumbers() | ||
{ | ||
return partitionNumbers; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) | ||
{ | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
SparseStripedReadablePartitions that = (SparseStripedReadablePartitions) o; | ||
return stageNumber == that.stageNumber | ||
&& Objects.equals(workers, that.workers) | ||
&& Objects.equals(partitionNumbers, that.partitionNumbers); | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return Objects.hash(stageNumber, workers, partitionNumbers); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "StripedReadablePartitions{" + | ||
"stageNumber=" + stageNumber + | ||
", workers=" + workers + | ||
", partitionNumbers=" + partitionNumbers + | ||
'}'; | ||
} | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
minor nit: Naming
Per my understanding, sparse means that there are pieces missing from the middle. Something like 2..10 would not be sparse, however, would be created as a "sparse" striped partitions. Maybe something like
SpecificStripedReadablePartitions
which clarifies that the workers are explicitly specified? This is not a blocker.