MSQ should load even if node roles are not set (#13318)

This commit is contained in:
Abhishek Agarwal 2022-11-07 21:11:16 +05:30 committed by GitHub
parent 47c32a9d92
commit b1eaf7a21f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 2 deletions

View File

@ -23,7 +23,10 @@ import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.google.common.collect.ImmutableList;
import com.google.inject.Binder;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import org.apache.druid.discovery.NodeRole;
import org.apache.druid.frame.processor.Bouncer;
import org.apache.druid.guice.LazySingleton;
@ -82,6 +85,8 @@ import org.apache.druid.msq.querykit.scan.ScanQueryFrameProcessorFactory;
import org.apache.druid.msq.util.PassthroughAggregatorFactory;
import org.apache.druid.query.DruidProcessingConfig;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@ -188,9 +193,10 @@ public class MSQIndexingModule implements DruidModule
@Provides
@LazySingleton
public Bouncer makeBouncer(final DruidProcessingConfig processingConfig, @Self final Set<NodeRole> nodeRoles)
public Bouncer makeBouncer(final DruidProcessingConfig processingConfig, Injector injector)
{
if (nodeRoles.contains(NodeRole.PEON) && !nodeRoles.contains(NodeRole.INDEXER)) {
Set<NodeRole> nodeRoles = getNodeRoles(injector);
if (null == nodeRoles || (nodeRoles.contains(NodeRole.PEON) && !nodeRoles.contains(NodeRole.INDEXER))) {
// CliPeon -> use only one thread regardless of configured # of processing threads. This matches the expected
// resource usage pattern for CliPeon-based tasks (one task / one working thread per JVM).
return new Bouncer(1);
@ -198,4 +204,22 @@ public class MSQIndexingModule implements DruidModule
return new Bouncer(processingConfig.getNumThreads());
}
}
@Nullable
private static Set<NodeRole> getNodeRoles(Injector injector)
{
try {
return injector.getInstance(
Key.get(
new TypeLiteral<Set<NodeRole>>()
{
},
Self.class
)
);
}
catch (Exception e) {
return null;
}
}
}