jihoonson commented on a change in pull request #7653: Refactor
SQLMetadataSegmentManager; Change contract of REST methods in
DataSourcesResource
URL: https://github.com/apache/incubator-druid/pull/7653#discussion_r304696814
##########
File path:
core/src/main/java/org/apache/druid/timeline/partition/PartitionHolder.java
##########
@@ -22,72 +22,62 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
+import javax.annotation.Nullable;
import java.util.Iterator;
import java.util.List;
-import java.util.SortedSet;
import java.util.Spliterator;
-import java.util.TreeSet;
+import java.util.TreeMap;
/**
* An object that clumps together multiple other objects which each represent
a shard of some space.
*/
public class PartitionHolder<T> implements Iterable<PartitionChunk<T>>
{
- private final TreeSet<PartitionChunk<T>> holderSet;
+ private final TreeMap<PartitionChunk<T>, PartitionChunk<T>> holderMap;
public PartitionHolder(PartitionChunk<T> initialChunk)
{
- this.holderSet = new TreeSet<>();
+ this.holderMap = new TreeMap<>();
add(initialChunk);
}
public PartitionHolder(List<PartitionChunk<T>> initialChunks)
{
- this.holderSet = new TreeSet<>();
+ this.holderMap = new TreeMap<>();
for (PartitionChunk<T> chunk : initialChunks) {
add(chunk);
}
}
- public PartitionHolder(PartitionHolder partitionHolder)
+ public PartitionHolder(PartitionHolder<T> partitionHolder)
{
- this.holderSet = new TreeSet<>();
- this.holderSet.addAll(partitionHolder.holderSet);
+ this.holderMap = new TreeMap<>();
+ this.holderMap.putAll(partitionHolder.holderMap);
}
- public void add(PartitionChunk<T> chunk)
+ public boolean add(PartitionChunk<T> chunk)
{
- holderSet.add(chunk);
+ return holderMap.putIfAbsent(chunk, chunk) == null;
Review comment:
I believe this is a bug. `PartitionChunk` is one of most wacky things in
Druid when it comes to equals() and hashCode() implementations. It considers
only the partitionId and ignores the object in the `PartitionChunk`. So, the
`add` should always overwrite the existing chunk with the given one. I think
this behavior is to swap realtime segments with published and available ones in
historicals. I know this is confusing and must be addressed in the future.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]