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