51
51
import java .util .Set ;
52
52
import java .util .stream .Collectors ;
53
53
54
- /** Rescale event. */
54
+ /**
55
+ * The rescale to record the related vertices and slots change during the rescaling process.
56
+ *
57
+ * <p>This rescale begins when the scheduler initiates a rescaling operation and ends when the
58
+ * rescaling succeeds.
59
+ *
60
+ * <pre>
61
+ * The structure of the rescale as follows:
62
+ * - rescale id information:
63
+ * +--> rescale uuid
64
+ * +--> resource requirements id
65
+ * +--> rescale attempt id
66
+ * +--> vertices:
67
+ * + +--> job vertex id-1 -> vertex-1 parallelism rescale:
68
+ * + + +--> vertex id
69
+ * + + +--> vertex name
70
+ * + + +--> slot sharing group id
71
+ * + + +--> slot sharing group name
72
+ * + + +--> desired parallelism
73
+ * + + +--> sufficient parallelism
74
+ * + +--> job vertex id-2 -> vertex-2 parallelism rescale:
75
+ * + + +--> ...
76
+ * + + ...
77
+ * + ...
78
+ * +--> slots:
79
+ * + +--> slot sharing group id-1 -> slot-1 sharing group rescale:
80
+ * + + +--> slot sharing group id
81
+ * + + +--> slot sharing group name
82
+ * + + +--> required resource profile
83
+ * + + +--> minimal required slots
84
+ * + + +--> pre-rescale slots
85
+ * + + +--> post-rescale slots
86
+ * + + +--> acquired resource profile
87
+ * + +--> slot sharing group id-2 -> slot-2 sharing group rescale:
88
+ * + + +--> ...
89
+ * + + ...
90
+ * + ...
91
+ * +--> scheduler states:
92
+ * + +--> scheduler state span:
93
+ * + + +--> state
94
+ * + + +--> in timestamp
95
+ * + + +--> out timestamp
96
+ * + + +--> duration
97
+ * + + +--> exception information
98
+ * + +--> ...
99
+ * + ...
100
+ * +--> start timestamp
101
+ * +--> end timestamp
102
+ * +--> trigger cause
103
+ * +--> terminal state
104
+ * +--> terminated reason
105
+ * </pre>
106
+ *
107
+ * <p>The more design details about the rescale could be viewed in <a
108
+ * href="https://cwiki.apache.org/confluence/x/TQr0Ew">FLIP-495</a>.
109
+ */
55
110
public class Rescale implements Serializable {
56
111
57
112
private static final long serialVersionUID = 1L ;
@@ -186,10 +241,10 @@ public Rescale setDesiredSlots(JobInformation jobInformation) {
186
241
.getParallelism ())
187
242
.max (Integer ::compare )
188
243
.orElse (0 );
189
- SlotSharingGroupId sharingGroupId = sharingGroup .getSlotSharingGroupId ();
190
244
SlotSharingGroupRescale sharingGroupRescaleInfo =
191
- slots .computeIfAbsent (sharingGroupId , SlotSharingGroupRescale ::new );
192
- sharingGroupRescaleInfo .setSlotSharingGroupMetaInfo (sharingGroup );
245
+ slots .computeIfAbsent (
246
+ sharingGroup .getSlotSharingGroupId (),
247
+ ignored -> new SlotSharingGroupRescale (sharingGroup ));
193
248
sharingGroupRescaleInfo .setDesiredSlots (desiredSlot );
194
249
}
195
250
return this ;
@@ -201,15 +256,16 @@ public Rescale setDesiredVertexParallelism(JobInformation jobInformation) {
201
256
for (Map .Entry <JobVertexID , VertexParallelismInformation > entry :
202
257
allParallelismInfo .entrySet ()) {
203
258
JobVertexID jvId = entry .getKey ();
204
- VertexParallelismInformation vertexParallelInfo = entry .getValue ();
205
- VertexParallelismRescale vertexParallelismRescale =
206
- this .vertices .computeIfAbsent (
207
- jvId , jobVertexID -> new VertexParallelismRescale (jvId ));
208
259
SlotSharingGroup slotSharingGroup =
209
260
jobInformation .getVertexInformation (jvId ).getSlotSharingGroup ();
210
- vertexParallelismRescale .setSlotSharingGroupMetaInfo (slotSharingGroup );
211
- vertexParallelismRescale .setJobVertexName (jobInformation .getVertexName (jvId ));
212
- vertexParallelismRescale .setRequiredParallelisms (vertexParallelInfo );
261
+ String vertexName = jobInformation .getVertexInformation (jvId ).getVertexName ();
262
+ VertexParallelismRescale vertexParallelismRescale =
263
+ this .vertices .computeIfAbsent (
264
+ jvId ,
265
+ jobVertexID ->
266
+ new VertexParallelismRescale (
267
+ jvId , vertexName , slotSharingGroup ));
268
+ vertexParallelismRescale .setRequiredParallelisms (entry .getValue ());
213
269
}
214
270
return this ;
215
271
}
@@ -219,43 +275,69 @@ public Rescale setMinimalRequiredSlots(JobInformation jobInformation) {
219
275
SlotSharingGroupMetaInfo .from (jobInformation .getVertices ());
220
276
for (Map .Entry <SlotSharingGroup , SlotSharingGroupMetaInfo > entry :
221
277
slotSharingGroupMetaInfo .entrySet ()) {
222
- SlotSharingGroupId groupId = entry .getKey (). getSlotSharingGroupId ();
278
+ SlotSharingGroup sharingGroup = entry .getKey ();
223
279
SlotSharingGroupRescale slotSharingGroupRescale =
224
- slots .computeIfAbsent (groupId , SlotSharingGroupRescale ::new );
280
+ slots .computeIfAbsent (
281
+ sharingGroup .getSlotSharingGroupId (),
282
+ ignored -> new SlotSharingGroupRescale (sharingGroup ));
225
283
slotSharingGroupRescale .setMinimalRequiredSlots (entry .getValue ().getMaxLowerBound ());
226
284
}
227
285
return this ;
228
286
}
229
287
230
- public Rescale setPreRescaleSlotsAndParallelisms (@ Nullable Rescale lastCompletedRescale ) {
288
+ public Rescale setPreRescaleSlotsAndParallelisms (
289
+ JobInformation jobInformation , @ Nullable Rescale lastCompletedRescale ) {
231
290
if (lastCompletedRescale == null ) {
232
291
LOG .info ("No available previous parallelism to set." );
233
292
return this ;
234
293
}
235
294
for (JobVertexID jobVertexID : lastCompletedRescale .getVertices ().keySet ()) {
236
295
Integer preRescaleParallelism =
237
296
lastCompletedRescale .vertices .get (jobVertexID ).getPostRescaleParallelism ();
297
+ JobInformation .VertexInformation vertexInformation =
298
+ jobInformation .getVertexInformation (jobVertexID );
238
299
VertexParallelismRescale vertexParallelismRescale =
239
- vertices .computeIfAbsent (jobVertexID , VertexParallelismRescale ::new );
300
+ vertices .computeIfAbsent (
301
+ jobVertexID ,
302
+ jobVertexId ->
303
+ new VertexParallelismRescale (
304
+ jobVertexId ,
305
+ vertexInformation .getVertexName (),
306
+ vertexInformation .getSlotSharingGroup ()));
240
307
vertexParallelismRescale .setPreRescaleParallelism (preRescaleParallelism );
241
308
}
242
309
243
- for (SlotSharingGroupId sharingGroupId : lastCompletedRescale .getSlots ().keySet ()) {
244
- Integer preRescaleSlot =
245
- lastCompletedRescale .slots .get (sharingGroupId ).getPostRescaleSlots ();
310
+ Map <SlotSharingGroupId , SlotSharingGroupRescale > slotsRescales =
311
+ lastCompletedRescale .getSlots ();
312
+ for (SlotSharingGroup sharingGroup : jobInformation .getSlotSharingGroups ()) {
313
+ SlotSharingGroupId slotSharingGroupId = sharingGroup .getSlotSharingGroupId ();
314
+ Integer preRescaleSlot = slotsRescales .get (slotSharingGroupId ).getPostRescaleSlots ();
246
315
SlotSharingGroupRescale slotSharingGroupRescale =
247
- slots .computeIfAbsent (sharingGroupId , SlotSharingGroupRescale ::new );
316
+ slots .computeIfAbsent (
317
+ slotSharingGroupId ,
318
+ ignored -> new SlotSharingGroupRescale (sharingGroup ));
248
319
slotSharingGroupRescale .setPreRescaleSlots (preRescaleSlot );
249
320
}
250
321
251
322
return this ;
252
323
}
253
324
254
- public Rescale setPostRescaleVertexParallelism (VertexParallelism postRescaleVertexParallelism ) {
325
+ public Rescale setPostRescaleVertexParallelism (
326
+ JobInformation jobInformation , VertexParallelism postRescaleVertexParallelism ) {
327
+
255
328
Set <JobVertexID > vertices = postRescaleVertexParallelism .getVertices ();
256
329
for (JobVertexID vertexID : vertices ) {
330
+ JobInformation .VertexInformation vertexInformation =
331
+ jobInformation .getVertexInformation (vertexID );
257
332
VertexParallelismRescale vertexParallelismRescale =
258
- this .vertices .computeIfAbsent (vertexID , VertexParallelismRescale ::new );
333
+ this .vertices .computeIfAbsent (
334
+ vertexID ,
335
+ jobVertexId ->
336
+ new VertexParallelismRescale (
337
+ jobVertexId ,
338
+ vertexInformation .getVertexName (),
339
+ vertexInformation .getSlotSharingGroup ()));
340
+
259
341
vertexParallelismRescale .setPostRescaleParallelism (
260
342
postRescaleVertexParallelism .getParallelism (vertexID ));
261
343
}
@@ -264,27 +346,28 @@ public Rescale setPostRescaleVertexParallelism(VertexParallelism postRescaleVert
264
346
265
347
public Rescale setPostRescaleSlots (
266
348
Collection <JobSchedulingPlan .SlotAssignment > postRescaleSlotAssignments ) {
267
- Map <SlotSharingGroupId , Set <JobSchedulingPlan .SlotAssignment >> assignmentsPerSharingGroup =
349
+ Map <SlotSharingGroup , Set <JobSchedulingPlan .SlotAssignment >> assignmentsPerSharingGroup =
268
350
postRescaleSlotAssignments .stream ()
269
351
.collect (
270
352
Collectors .groupingBy (
271
353
slotAssignment ->
272
354
slotAssignment
273
355
.getTargetAs (
274
356
ExecutionSlotSharingGroup .class )
275
- .getSlotSharingGroup ()
276
- .getSlotSharingGroupId (),
357
+ .getSlotSharingGroup (),
277
358
Collectors .toSet ()));
278
- for (Map .Entry <SlotSharingGroupId , Set <JobSchedulingPlan .SlotAssignment >> entry :
359
+ for (Map .Entry <SlotSharingGroup , Set <JobSchedulingPlan .SlotAssignment >> entry :
279
360
assignmentsPerSharingGroup .entrySet ()) {
280
- SlotSharingGroupId sharingGroupId = entry .getKey ();
361
+ SlotSharingGroup sharingGroup = entry .getKey ();
281
362
Set <JobSchedulingPlan .SlotAssignment > assignments =
282
- assignmentsPerSharingGroup .get (sharingGroupId );
363
+ assignmentsPerSharingGroup .get (sharingGroup );
283
364
int postRescaleSlot = assignments .size ();
284
365
ResourceProfile acquiredResource =
285
366
assignments .iterator ().next ().getSlotInfo ().getResourceProfile ();
286
367
SlotSharingGroupRescale slotSharingGroupRescale =
287
- slots .computeIfAbsent (sharingGroupId , SlotSharingGroupRescale ::new );
368
+ slots .computeIfAbsent (
369
+ sharingGroup .getSlotSharingGroupId (),
370
+ ignored -> new SlotSharingGroupRescale (sharingGroup ));
288
371
slotSharingGroupRescale .setPostRescaleSlots (postRescaleSlot );
289
372
slotSharingGroupRescale .setAcquiredResourceProfile (acquiredResource );
290
373
}
0 commit comments