Skip to content

Commit 15982c4

Browse files
authored
Always advance generation when creating a new cluster in scheduling (ArroyoSystems#1065)
1 parent ceecf59 commit 15982c4

2 files changed

Lines changed: 23 additions & 36 deletions

File tree

crates/arroyo-controller/src/states/mod.rs

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,7 @@ impl TransitionTo<Compiling> for Stopped {}
194194

195195
impl TransitionTo<Compiling> for Scheduling {}
196196

197-
impl TransitionTo<Scheduling> for Compiling {
198-
fn update_status(&self) -> TransitionFn {
199-
Box::new(|ctx| {
200-
ctx.status.generation += 1;
201-
})
202-
}
203-
}
197+
impl TransitionTo<Scheduling> for Compiling {}
204198

205199
impl TransitionTo<Running> for Scheduling {
206200
fn update_status(&self) -> TransitionFn {
@@ -257,13 +251,7 @@ impl TransitionTo<Recovering> for Scheduling {
257251

258252
impl TransitionTo<Rescaling> for Running {}
259253

260-
impl TransitionTo<Scheduling> for Rescaling {
261-
fn update_status(&self) -> TransitionFn {
262-
Box::new(|ctx| {
263-
ctx.status.generation += 1;
264-
})
265-
}
266-
}
254+
impl TransitionTo<Scheduling> for Rescaling {}
267255

268256
impl TransitionTo<Compiling> for Recovering {}
269257
impl TransitionTo<Compiling> for Failed {
@@ -352,13 +340,7 @@ impl TransitionTo<Stopping> for LeaderFinishing {}
352340

353341
impl TransitionTo<LeaderCheckpointStopping> for LeaderRestarting {}
354342
impl TransitionTo<LeaderRestarting> for LeaderRestarting {}
355-
impl TransitionTo<Scheduling> for LeaderRestarting {
356-
fn update_status(&self) -> TransitionFn {
357-
Box::new(|ctx| {
358-
ctx.status.generation += 1;
359-
})
360-
}
361-
}
343+
impl TransitionTo<Scheduling> for LeaderRestarting {}
362344

363345
impl TransitionTo<Recovering> for LeaderRestarting {
364346
fn update_status(&self) -> TransitionFn {
@@ -369,13 +351,8 @@ impl TransitionTo<Recovering> for LeaderRestarting {
369351
}
370352
impl TransitionTo<LeaderStopping> for LeaderRestarting {}
371353

372-
impl TransitionTo<Scheduling> for LeaderRescaling {
373-
fn update_status(&self) -> TransitionFn {
374-
Box::new(|ctx| {
375-
ctx.status.generation += 1;
376-
})
377-
}
378-
}
354+
impl TransitionTo<Scheduling> for LeaderRescaling {}
355+
379356
impl TransitionTo<Recovering> for LeaderRescaling {
380357
fn update_status(&self) -> TransitionFn {
381358
Box::new(|ctx| {
@@ -406,13 +383,7 @@ impl TransitionTo<Restarting> for Running {
406383
}
407384
}
408385
impl TransitionTo<Restarting> for Restarting {}
409-
impl TransitionTo<Scheduling> for Restarting {
410-
fn update_status(&self) -> TransitionFn {
411-
Box::new(|ctx| {
412-
ctx.status.generation += 1;
413-
})
414-
}
415-
}
386+
impl TransitionTo<Scheduling> for Restarting {}
416387
impl TransitionTo<Stopping> for Restarting {}
417388
impl TransitionTo<CheckpointStopping> for Restarting {}
418389

crates/arroyo-controller/src/states/scheduling.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,17 @@ impl State for Scheduling {
608608
// to schedule
609609
stop_if_desired_non_running!(self, &ctx.config);
610610

611+
// update the generation for this scheduling attempt
612+
ctx.status.generation += 1;
613+
if let Err(e) = ctx.status.update_db(&ctx.db).await {
614+
return Err(ctx.retryable(
615+
self,
616+
"failed to advance generation for scheduling retry",
617+
anyhow!("{}", e),
618+
10,
619+
));
620+
}
621+
611622
// clear out any existing workers for this job
612623
if let Err(e) = ctx.scheduler.stop_workers(&ctx.config.id, None, true).await {
613624
warn!(
@@ -683,7 +694,12 @@ impl State for Scheduling {
683694

684695
for h in handles {
685696
if let Err(e) = h.await {
686-
return Err(fatal("Failed to start cluster for pipeline", e.into()));
697+
return Err(ctx.retryable(
698+
self,
699+
"Failed to start cluster for pipeline",
700+
e.into(),
701+
10,
702+
));
687703
}
688704
}
689705

0 commit comments

Comments
 (0)