-
Notifications
You must be signed in to change notification settings - Fork 19
/
DefaultSlotPoolServiceSchedulerFactory.java
283 lines (258 loc) · 12.8 KB
/
DefaultSlotPoolServiceSchedulerFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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 org.apache.flink.runtime.jobmaster;
import org.apache.flink.annotation.VisibleForTesting;
import org.apache.flink.api.common.JobID;
import org.apache.flink.api.common.time.Time;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.JobManagerOptions;
import org.apache.flink.configuration.RpcOptions;
import org.apache.flink.configuration.SchedulerExecutionMode;
import org.apache.flink.configuration.StateRecoveryOptions;
import org.apache.flink.core.failure.FailureEnricher;
import org.apache.flink.runtime.blob.BlobWriter;
import org.apache.flink.runtime.blocklist.BlocklistOperations;
import org.apache.flink.runtime.checkpoint.CheckpointRecoveryFactory;
import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
import org.apache.flink.runtime.executiongraph.JobStatusListener;
import org.apache.flink.runtime.io.network.partition.JobMasterPartitionTracker;
import org.apache.flink.runtime.jobgraph.JobGraph;
import org.apache.flink.runtime.jobgraph.JobType;
import org.apache.flink.runtime.jobmaster.slotpool.DeclarativeSlotPoolBridgeServiceFactory;
import org.apache.flink.runtime.jobmaster.slotpool.DeclarativeSlotPoolFactory;
import org.apache.flink.runtime.jobmaster.slotpool.DeclarativeSlotPoolServiceFactory;
import org.apache.flink.runtime.jobmaster.slotpool.PreferredAllocationRequestSlotMatchingStrategy;
import org.apache.flink.runtime.jobmaster.slotpool.RequestSlotMatchingStrategy;
import org.apache.flink.runtime.jobmaster.slotpool.SimpleRequestSlotMatchingStrategy;
import org.apache.flink.runtime.jobmaster.slotpool.SlotPoolService;
import org.apache.flink.runtime.jobmaster.slotpool.SlotPoolServiceFactory;
import org.apache.flink.runtime.metrics.groups.JobManagerJobMetricGroup;
import org.apache.flink.runtime.rpc.FatalErrorHandler;
import org.apache.flink.runtime.scheduler.DefaultSchedulerFactory;
import org.apache.flink.runtime.scheduler.SchedulerNG;
import org.apache.flink.runtime.scheduler.SchedulerNGFactory;
import org.apache.flink.runtime.scheduler.adaptive.AdaptiveSchedulerFactory;
import org.apache.flink.runtime.scheduler.adaptivebatch.AdaptiveBatchSchedulerFactory;
import org.apache.flink.runtime.shuffle.ShuffleMaster;
import org.apache.flink.util.Preconditions;
import org.apache.flink.util.clock.SystemClock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
/** Default {@link SlotPoolServiceSchedulerFactory} implementation. */
public final class DefaultSlotPoolServiceSchedulerFactory
implements SlotPoolServiceSchedulerFactory {
private static final Logger LOG =
LoggerFactory.getLogger(DefaultSlotPoolServiceSchedulerFactory.class);
private final SlotPoolServiceFactory slotPoolServiceFactory;
private final SchedulerNGFactory schedulerNGFactory;
private DefaultSlotPoolServiceSchedulerFactory(
SlotPoolServiceFactory slotPoolServiceFactory, SchedulerNGFactory schedulerNGFactory) {
this.slotPoolServiceFactory = slotPoolServiceFactory;
this.schedulerNGFactory = schedulerNGFactory;
}
@VisibleForTesting
SchedulerNGFactory getSchedulerNGFactory() {
return schedulerNGFactory;
}
@Override
public SlotPoolService createSlotPoolService(
JobID jid, DeclarativeSlotPoolFactory declarativeSlotPoolFactory) {
return slotPoolServiceFactory.createSlotPoolService(jid, declarativeSlotPoolFactory);
}
@Override
public JobManagerOptions.SchedulerType getSchedulerType() {
return schedulerNGFactory.getSchedulerType();
}
@Override
public SchedulerNG createScheduler(
Logger log,
JobGraph jobGraph,
Executor ioExecutor,
Configuration configuration,
SlotPoolService slotPoolService,
ScheduledExecutorService futureExecutor,
ClassLoader userCodeLoader,
CheckpointRecoveryFactory checkpointRecoveryFactory,
Time rpcTimeout,
BlobWriter blobWriter,
JobManagerJobMetricGroup jobManagerJobMetricGroup,
Time slotRequestTimeout,
ShuffleMaster<?> shuffleMaster,
JobMasterPartitionTracker partitionTracker,
ExecutionDeploymentTracker executionDeploymentTracker,
long initializationTimestamp,
ComponentMainThreadExecutor mainThreadExecutor,
FatalErrorHandler fatalErrorHandler,
JobStatusListener jobStatusListener,
Collection<FailureEnricher> failureEnrichers,
BlocklistOperations blocklistOperations)
throws Exception {
return schedulerNGFactory.createInstance(
log,
jobGraph,
ioExecutor,
configuration,
slotPoolService,
futureExecutor,
userCodeLoader,
checkpointRecoveryFactory,
rpcTimeout,
blobWriter,
jobManagerJobMetricGroup,
slotRequestTimeout,
shuffleMaster,
partitionTracker,
executionDeploymentTracker,
initializationTimestamp,
mainThreadExecutor,
fatalErrorHandler,
jobStatusListener,
failureEnrichers,
blocklistOperations);
}
public static DefaultSlotPoolServiceSchedulerFactory create(
SlotPoolServiceFactory slotPoolServiceFactory, SchedulerNGFactory schedulerNGFactory) {
return new DefaultSlotPoolServiceSchedulerFactory(
slotPoolServiceFactory, schedulerNGFactory);
}
public static DefaultSlotPoolServiceSchedulerFactory fromConfiguration(
Configuration configuration, JobType jobType, boolean isDynamicGraph) {
final Time rpcTimeout =
Time.fromDuration(configuration.get(RpcOptions.ASK_TIMEOUT_DURATION));
final Time slotIdleTimeout =
Time.milliseconds(configuration.get(JobManagerOptions.SLOT_IDLE_TIMEOUT));
final Time batchSlotTimeout =
Time.milliseconds(configuration.get(JobManagerOptions.SLOT_REQUEST_TIMEOUT));
final SlotPoolServiceFactory slotPoolServiceFactory;
final SchedulerNGFactory schedulerNGFactory;
JobManagerOptions.SchedulerType schedulerType =
getSchedulerType(configuration, jobType, isDynamicGraph);
if (configuration
.getOptional(JobManagerOptions.HYBRID_PARTITION_DATA_CONSUME_CONSTRAINT)
.isPresent()) {
Preconditions.checkState(
schedulerType == JobManagerOptions.SchedulerType.AdaptiveBatch,
"Only adaptive batch scheduler supports setting "
+ JobManagerOptions.HYBRID_PARTITION_DATA_CONSUME_CONSTRAINT.key());
}
switch (schedulerType) {
case Default:
schedulerNGFactory = new DefaultSchedulerFactory();
slotPoolServiceFactory =
new DeclarativeSlotPoolBridgeServiceFactory(
SystemClock.getInstance(),
rpcTimeout,
slotIdleTimeout,
batchSlotTimeout,
getRequestSlotMatchingStrategy(configuration, jobType));
break;
case Adaptive:
schedulerNGFactory = new AdaptiveSchedulerFactory();
slotPoolServiceFactory =
new DeclarativeSlotPoolServiceFactory(
SystemClock.getInstance(), slotIdleTimeout, rpcTimeout);
break;
case AdaptiveBatch:
schedulerNGFactory = new AdaptiveBatchSchedulerFactory();
slotPoolServiceFactory =
new DeclarativeSlotPoolBridgeServiceFactory(
SystemClock.getInstance(),
rpcTimeout,
slotIdleTimeout,
batchSlotTimeout,
getRequestSlotMatchingStrategy(configuration, jobType));
break;
default:
throw new IllegalArgumentException(
String.format(
"Illegal value [%s] for config option [%s]",
schedulerType, JobManagerOptions.SCHEDULER.key()));
}
return new DefaultSlotPoolServiceSchedulerFactory(
slotPoolServiceFactory, schedulerNGFactory);
}
private static JobManagerOptions.SchedulerType getSchedulerType(
Configuration configuration, JobType jobType, boolean isDynamicGraph) {
JobManagerOptions.SchedulerType schedulerType;
if (jobType == JobType.BATCH) {
if (configuration.get(JobManagerOptions.SCHEDULER_MODE)
== SchedulerExecutionMode.REACTIVE
|| configuration.get(JobManagerOptions.SCHEDULER)
== JobManagerOptions.SchedulerType.Adaptive) {
LOG.info(
"Adaptive Scheduler configured, but Batch job detected. Changing scheduler type to 'AdaptiveBatch'.");
// overwrite
schedulerType = JobManagerOptions.SchedulerType.AdaptiveBatch;
} else {
schedulerType =
configuration
.getOptional(JobManagerOptions.SCHEDULER)
.orElse(
isDynamicGraph
? JobManagerOptions.SchedulerType.AdaptiveBatch
: JobManagerOptions.SchedulerType.Default);
}
} 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
static RequestSlotMatchingStrategy getRequestSlotMatchingStrategy(
Configuration configuration, JobType jobType) {
final boolean isLocalRecoveryEnabled =
configuration.get(StateRecoveryOptions.LOCAL_RECOVERY);
if (isLocalRecoveryEnabled) {
if (jobType == JobType.STREAMING) {
return PreferredAllocationRequestSlotMatchingStrategy.INSTANCE;
} else {
LOG.warn(
"Batch jobs do not support local recovery. Falling back for request slot matching strategy to {}.",
SimpleRequestSlotMatchingStrategy.class.getSimpleName());
return SimpleRequestSlotMatchingStrategy.INSTANCE;
}
} else {
return SimpleRequestSlotMatchingStrategy.INSTANCE;
}
}
}