mirror of https://github.com/apache/druid.git
ServerSelector: Synchronize getAllServers(). (#17499)
This method was missing some required synchronization. This patch also adds GuardedBy annotations to historicalServers and realtimeServers, which would have caught it.
This commit is contained in:
parent
5333c53d71
commit
80d6763e39
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.apache.druid.client.selector;
|
||||
|
||||
import com.google.errorprone.annotations.concurrent.GuardedBy;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
|
||||
import org.apache.druid.client.DataSegmentInterner;
|
||||
import org.apache.druid.query.Query;
|
||||
|
@ -40,9 +41,10 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
*/
|
||||
public class ServerSelector implements Overshadowable<ServerSelector>
|
||||
{
|
||||
|
||||
@GuardedBy("this")
|
||||
private final Int2ObjectRBTreeMap<Set<QueryableDruidServer>> historicalServers;
|
||||
|
||||
@GuardedBy("this")
|
||||
private final Int2ObjectRBTreeMap<Set<QueryableDruidServer>> realtimeServers;
|
||||
|
||||
private final TierSelectorStrategy strategy;
|
||||
|
@ -145,18 +147,21 @@ public class ServerSelector implements Overshadowable<ServerSelector>
|
|||
|
||||
public List<DruidServerMetadata> getAllServers()
|
||||
{
|
||||
List<DruidServerMetadata> servers = new ArrayList<>();
|
||||
historicalServers.values()
|
||||
.stream()
|
||||
.flatMap(Collection::stream)
|
||||
.map(server -> server.getServer().getMetadata())
|
||||
.forEach(servers::add);
|
||||
final List<DruidServerMetadata> servers = new ArrayList<>();
|
||||
|
||||
realtimeServers.values()
|
||||
.stream()
|
||||
.flatMap(Collection::stream)
|
||||
.map(server -> server.getServer().getMetadata())
|
||||
.forEach(servers::add);
|
||||
synchronized (this) {
|
||||
historicalServers.values()
|
||||
.stream()
|
||||
.flatMap(Collection::stream)
|
||||
.map(server -> server.getServer().getMetadata())
|
||||
.forEach(servers::add);
|
||||
|
||||
realtimeServers.values()
|
||||
.stream()
|
||||
.flatMap(Collection::stream)
|
||||
.map(server -> server.getServer().getMetadata())
|
||||
.forEach(servers::add);
|
||||
}
|
||||
|
||||
return servers;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue