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:
Gian Merlino 2024-11-27 00:01:00 -08:00 committed by GitHub
parent 5333c53d71
commit 80d6763e39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 12 deletions

View File

@ -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;
}