Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-30846][runtime] Fix the getSchedulerType when test with flink.tests.enable-adaptive-scheduler #21814

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,6 @@ public static DefaultSlotPoolServiceSchedulerFactory fromConfiguration(

JobManagerOptions.SchedulerType schedulerType =
getSchedulerType(configuration, jobType, isDynamicGraph);
if (schedulerType == JobManagerOptions.SchedulerType.Adaptive && jobType == JobType.BATCH) {
LOG.info(
"Adaptive Scheduler configured, but Batch job detected. Changing scheduler type to 'Default'.");
// overwrite
schedulerType = JobManagerOptions.SchedulerType.Default;
} else if (schedulerType == JobManagerOptions.SchedulerType.Ng) {
LOG.warn(
"Config value '{}' for option '{}' is deprecated, use '{}' instead.",
JobManagerOptions.SchedulerType.Ng,
JobManagerOptions.SCHEDULER.key(),
JobManagerOptions.SchedulerType.Default);
// overwrite
schedulerType = JobManagerOptions.SchedulerType.Default;
}

if (configuration
.getOptional(JobManagerOptions.HYBRID_PARTITION_DATA_CONSUME_CONSTRAINT)
Expand Down Expand Up @@ -224,20 +210,48 @@ public static DefaultSlotPoolServiceSchedulerFactory fromConfiguration(

private static JobManagerOptions.SchedulerType getSchedulerType(
Configuration configuration, JobType jobType, boolean isDynamicGraph) {
if (configuration.get(JobManagerOptions.SCHEDULER_MODE)
== SchedulerExecutionMode.REACTIVE) {
return JobManagerOptions.SchedulerType.Adaptive;
} else {
return configuration
.getOptional(JobManagerOptions.SCHEDULER)
.orElse(
System.getProperties()
.containsKey("flink.tests.enable-adaptive-scheduler")
? JobManagerOptions.SchedulerType.Adaptive
: (jobType == JobType.BATCH && isDynamicGraph
JobManagerOptions.SchedulerType schedulerType;
if (jobType == JobType.BATCH) {
schedulerType =
configuration
.getOptional(JobManagerOptions.SCHEDULER)
.orElse(
isDynamicGraph
? JobManagerOptions.SchedulerType.AdaptiveBatch
: JobManagerOptions.SchedulerType.Default));
: JobManagerOptions.SchedulerType.Default);

if (schedulerType == JobManagerOptions.SchedulerType.Adaptive) {
LOG.info(
"Adaptive Scheduler configured, but Batch job detected. Changing scheduler type to 'AdaptiveBatch'.");
schedulerType = JobManagerOptions.SchedulerType.AdaptiveBatch;
}
} else {
if (configuration.get(JobManagerOptions.SCHEDULER_MODE)
== SchedulerExecutionMode.REACTIVE) {
schedulerType = JobManagerOptions.SchedulerType.Adaptive;
} else {
schedulerType =
configuration
.getOptional(JobManagerOptions.SCHEDULER)
.orElse(
System.getProperties()
.containsKey(
"flink.tests.enable-adaptive-scheduler")
? JobManagerOptions.SchedulerType.Adaptive
: JobManagerOptions.SchedulerType.Default);
}
}

if (schedulerType == JobManagerOptions.SchedulerType.Ng) {
LOG.warn(
"Config value '{}' for option '{}' is deprecated, use '{}' instead.",
JobManagerOptions.SchedulerType.Ng,
JobManagerOptions.SCHEDULER.key(),
JobManagerOptions.SchedulerType.Default);
// overwrite
schedulerType = JobManagerOptions.SchedulerType.Default;
}
return schedulerType;
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.flink.runtime.jobmaster.slotpool.SimpleRequestSlotMatchingStrategy;
import org.apache.flink.runtime.scheduler.DefaultSchedulerFactory;
import org.apache.flink.runtime.scheduler.adaptive.AdaptiveSchedulerFactory;
import org.apache.flink.runtime.scheduler.adaptivebatch.AdaptiveBatchSchedulerFactory;
import org.apache.flink.util.TestLoggerExtension;

import org.junit.jupiter.api.Test;
Expand All @@ -45,7 +46,7 @@
public class DefaultSlotPoolServiceSchedulerFactoryTest {

@Test
public void testFallsBackToDefaultSchedulerIfBatchJob() {
public void testFallsBackToAdaptiveBatchSchedulerIfBatchJob() {
final Configuration configuration = new Configuration();
configuration.set(JobManagerOptions.SCHEDULER, JobManagerOptions.SchedulerType.Adaptive);

Expand All @@ -54,9 +55,9 @@ public void testFallsBackToDefaultSchedulerIfBatchJob() {
configuration, JobType.BATCH, true);

assertThat(defaultSlotPoolServiceSchedulerFactory.getSchedulerNGFactory())
.isInstanceOf(DefaultSchedulerFactory.class);
.isInstanceOf(AdaptiveBatchSchedulerFactory.class);
assertThat(defaultSlotPoolServiceSchedulerFactory.getSchedulerType())
.isEqualTo(JobManagerOptions.SchedulerType.Default);
.isEqualTo(JobManagerOptions.SchedulerType.AdaptiveBatch);
}

@Test
Expand All @@ -74,6 +75,58 @@ public void testAdaptiveSchedulerForReactiveMode() {
.isEqualTo(JobManagerOptions.SchedulerType.Adaptive);
}

@Test
public void testFallBackSchedulerWithAdaptiveSchedulerTestProperty() {
String propertyValue = saveAdaptiveSchedulerTestPropertyValue();
System.setProperty("flink.tests.enable-adaptive-scheduler", "true");

DefaultSlotPoolServiceSchedulerFactory defaultSlotPoolServiceSchedulerFactory =
DefaultSlotPoolServiceSchedulerFactory.fromConfiguration(
new Configuration(), JobType.BATCH, true);

assertThat(defaultSlotPoolServiceSchedulerFactory.getSchedulerNGFactory())
.isInstanceOf(AdaptiveBatchSchedulerFactory.class);
assertThat(defaultSlotPoolServiceSchedulerFactory.getSchedulerType())
.isEqualTo(JobManagerOptions.SchedulerType.AdaptiveBatch);

defaultSlotPoolServiceSchedulerFactory =
DefaultSlotPoolServiceSchedulerFactory.fromConfiguration(
new Configuration(), JobType.STREAMING, false);

assertThat(defaultSlotPoolServiceSchedulerFactory.getSchedulerNGFactory())
.isInstanceOf(AdaptiveSchedulerFactory.class);
assertThat(defaultSlotPoolServiceSchedulerFactory.getSchedulerType())
.isEqualTo(JobManagerOptions.SchedulerType.Adaptive);

restoreAdaptiveSchedulerTestPropertiesValue(propertyValue);
}

@Test
public void testFallBackSchedulerWithoutAdaptiveSchedulerTestProperty() {
String propertyValue = saveAdaptiveSchedulerTestPropertyValue();
System.clearProperty("flink.tests.enable-adaptive-scheduler");

DefaultSlotPoolServiceSchedulerFactory defaultSlotPoolServiceSchedulerFactory =
DefaultSlotPoolServiceSchedulerFactory.fromConfiguration(
new Configuration(), JobType.BATCH, true);

assertThat(defaultSlotPoolServiceSchedulerFactory.getSchedulerNGFactory())
.isInstanceOf(AdaptiveBatchSchedulerFactory.class);
assertThat(defaultSlotPoolServiceSchedulerFactory.getSchedulerType())
.isEqualTo(JobManagerOptions.SchedulerType.AdaptiveBatch);

defaultSlotPoolServiceSchedulerFactory =
DefaultSlotPoolServiceSchedulerFactory.fromConfiguration(
new Configuration(), JobType.STREAMING, false);

assertThat(defaultSlotPoolServiceSchedulerFactory.getSchedulerNGFactory())
.isInstanceOf(DefaultSchedulerFactory.class);
assertThat(defaultSlotPoolServiceSchedulerFactory.getSchedulerType())
.isEqualTo(JobManagerOptions.SchedulerType.Default);

restoreAdaptiveSchedulerTestPropertiesValue(propertyValue);
}

@ParameterizedTest
@MethodSource("testGetRequestSlotMatchingStrategy")
public void testGetRequestSlotMatchingStrategy(
Expand All @@ -96,4 +149,16 @@ private static Stream<Arguments> testGetRequestSlotMatchingStrategy() {
JobType.STREAMING,
PreferredAllocationRequestSlotMatchingStrategy.INSTANCE));
}

private String saveAdaptiveSchedulerTestPropertyValue() {
return (String) System.getProperty("flink.tests.enable-adaptive-scheduler");
}

private void restoreAdaptiveSchedulerTestPropertiesValue(String savedPropertyValue) {
if (savedPropertyValue == null) {
System.clearProperty("flink.tests.enable-adaptive-scheduler");
} else {
System.setProperty("flink.tests.enable-adaptive-scheduler", savedPropertyValue);
}
}
}