forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show candidate hosts for the given query (apache#2282)
* Show candidate hosts for the given query * Added test cases & minor changes to address comments * Changed path-param to query-pram for intervals/numCandidates
- Loading branch information
Showing
12 changed files
with
552 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets 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 io.druid.client; | ||
|
||
import com.google.common.collect.Lists; | ||
import io.druid.client.selector.ServerSelector; | ||
import io.druid.query.DataSource; | ||
import io.druid.query.LocatedSegmentDescriptor; | ||
import io.druid.query.SegmentDescriptor; | ||
import io.druid.query.TableDataSource; | ||
import io.druid.server.coordination.DruidServerMetadata; | ||
import io.druid.timeline.TimelineLookup; | ||
import io.druid.timeline.TimelineObjectHolder; | ||
import io.druid.timeline.partition.PartitionChunk; | ||
import org.joda.time.Interval; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
*/ | ||
public class ServerViewUtil | ||
{ | ||
public static List<LocatedSegmentDescriptor> getTargetLocations( | ||
TimelineServerView serverView, | ||
String datasource, | ||
List<Interval> intervals, | ||
int numCandidates | ||
) | ||
{ | ||
return getTargetLocations(serverView, new TableDataSource(datasource), intervals, numCandidates); | ||
} | ||
|
||
public static List<LocatedSegmentDescriptor> getTargetLocations( | ||
TimelineServerView serverView, | ||
DataSource datasource, | ||
List<Interval> intervals, | ||
int numCandidates | ||
) | ||
{ | ||
TimelineLookup<String, ServerSelector> timeline = serverView.getTimeline(datasource); | ||
if (timeline == null) { | ||
return Collections.emptyList(); | ||
} | ||
List<LocatedSegmentDescriptor> located = Lists.newArrayList(); | ||
for (Interval interval : intervals) { | ||
for (TimelineObjectHolder<String, ServerSelector> holder : timeline.lookup(interval)) { | ||
for (PartitionChunk<ServerSelector> chunk : holder.getObject()) { | ||
ServerSelector selector = chunk.getObject(); | ||
final SegmentDescriptor descriptor = new SegmentDescriptor( | ||
holder.getInterval(), holder.getVersion(), chunk.getChunkNumber() | ||
); | ||
long size = selector.getSegment().getSize(); | ||
List<DruidServerMetadata> candidates = selector.getCandidates(numCandidates); | ||
located.add(new LocatedSegmentDescriptor(descriptor, size, candidates)); | ||
} | ||
} | ||
} | ||
return located; | ||
} | ||
} |
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
134 changes: 134 additions & 0 deletions
134
server/src/main/java/io/druid/query/LocatedSegmentDescriptor.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,134 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets 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 io.druid.query; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.collect.ImmutableList; | ||
import io.druid.server.coordination.DruidServerMetadata; | ||
import org.joda.time.Interval; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* public, evolving | ||
* <p/> | ||
* extended version of SegmentDescriptor, which is internal class, with location and size information attached | ||
*/ | ||
public class LocatedSegmentDescriptor | ||
{ | ||
private final Interval interval; | ||
private final String version; | ||
private final int partitionNumber; | ||
private final long size; | ||
private final List<DruidServerMetadata> locations; | ||
|
||
@JsonCreator | ||
public LocatedSegmentDescriptor( | ||
@JsonProperty("interval") Interval interval, | ||
@JsonProperty("version") String version, | ||
@JsonProperty("partitionNumber") int partitionNumber, | ||
@JsonProperty("size") long size, | ||
@JsonProperty("locations") List<DruidServerMetadata> locations | ||
) | ||
{ | ||
this.interval = interval; | ||
this.version = version; | ||
this.partitionNumber = partitionNumber; | ||
this.size = size; | ||
this.locations = locations == null ? ImmutableList.<DruidServerMetadata>of() : locations; | ||
} | ||
|
||
public LocatedSegmentDescriptor(SegmentDescriptor descriptor, long size, List<DruidServerMetadata> candidates) | ||
{ | ||
this(descriptor.getInterval(), descriptor.getVersion(), descriptor.getPartitionNumber(), size, candidates); | ||
} | ||
|
||
@JsonProperty("interval") | ||
public Interval getInterval() | ||
{ | ||
return interval; | ||
} | ||
|
||
@JsonProperty("version") | ||
public String getVersion() | ||
{ | ||
return version; | ||
} | ||
|
||
@JsonProperty("partitionNumber") | ||
public int getPartitionNumber() | ||
{ | ||
return partitionNumber; | ||
} | ||
|
||
@JsonProperty("size") | ||
public long getSize() | ||
{ | ||
return size; | ||
} | ||
|
||
@JsonProperty("locations") | ||
public List<DruidServerMetadata> getLocations() | ||
{ | ||
return locations; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) | ||
{ | ||
if (!(o instanceof LocatedSegmentDescriptor)) { | ||
return false; | ||
} | ||
|
||
LocatedSegmentDescriptor other = (LocatedSegmentDescriptor) o; | ||
|
||
if (partitionNumber != other.partitionNumber) { | ||
return false; | ||
} | ||
if (!Objects.equals(interval, other.interval)) { | ||
return false; | ||
} | ||
if (!Objects.equals(version, other.version)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return Objects.hash(partitionNumber, interval, version); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "LocatedSegmentDescriptor{" + | ||
"interval=" + interval + | ||
", version='" + version + '\'' + | ||
", partitionNumber=" + partitionNumber + | ||
", size=" + size + | ||
", locations=" + locations + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.