-
Notifications
You must be signed in to change notification settings - Fork 156
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
Update with external checkpoints #199
base: master
Are you sure you want to change the base?
Changes from all commits
d92696a
0552fe9
c108c8e
0969f49
5c15785
84e650e
7b4e12d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,9 @@ type ControllerInterface interface { | |
// able to savepoint for some reason. | ||
FindExternalizedCheckpoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) | ||
|
||
// Ensures that application is configured to externalize and *not* delete checkpoints on cancel. | ||
FindExternalizedCheckpointForSavepoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) | ||
|
||
// Logs an event to the FlinkApplication resource and to the operator log | ||
LogEvent(ctx context.Context, app *v1beta1.FlinkApplication, eventType string, reason string, message string) | ||
|
||
|
@@ -468,8 +471,8 @@ func (f *Controller) DeleteOldResourcesForApp(ctx context.Context, app *v1beta1. | |
return nil | ||
} | ||
|
||
func (f *Controller) FindExternalizedCheckpoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) { | ||
checkpoint, err := f.flinkClient.GetLatestCheckpoint(ctx, f.getURLFromApp(application, hash), f.GetLatestJobID(ctx, application)) | ||
func (f *Controller) findExternalizedCheckpoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string, checkpointMaxAge int32) (string, error) { | ||
checkpoint, err := f.flinkClient.GetLatestCheckpoint(ctx, f.getURLFromApp(application, hash), application.Status.JobStatus.JobID) | ||
var checkpointPath string | ||
var checkpointTime int64 | ||
if err != nil { | ||
|
@@ -490,12 +493,28 @@ func (f *Controller) FindExternalizedCheckpoint(ctx context.Context, application | |
return "", nil | ||
} | ||
|
||
if isCheckpointOldToRecover(checkpointTime, getMaxCheckpointRestoreAgeSeconds(application)) { | ||
if isCheckpointOldToRecover(checkpointTime, checkpointMaxAge) { | ||
logger.Info(ctx, "Found checkpoint to restore from, but was too old") | ||
return "", nil | ||
} | ||
|
||
return checkpointPath, nil | ||
|
||
} | ||
|
||
func (f *Controller) FindExternalizedCheckpoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) { | ||
return f.findExternalizedCheckpoint(ctx, application, hash, getMaxCheckpointRestoreAgeSeconds(application)) | ||
} | ||
|
||
func (f *Controller) FindExternalizedCheckpointForSavepoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) { | ||
checkpointConfig, err := f.flinkClient.GetCheckpointConfig(ctx, f.getURLFromApp(application, hash), application.Status.JobStatus.JobID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there opportunity to combine |
||
if err != nil { | ||
return "", err | ||
} | ||
if checkpointConfig.Externalization.Enabled && !checkpointConfig.Externalization.DeleteOnCancellation { | ||
return "", fmt.Errorf("Checkpoint configuration not compatable for starting from checkpoints") | ||
} | ||
return f.findExternalizedCheckpoint(ctx, application, hash, getMaxCheckpointRestoreAgeSeconds(application)) | ||
} | ||
|
||
func isCheckpointOldToRecover(checkpointTime int64, maxCheckpointRecoveryAgeSec int32) bool { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,6 +233,7 @@ func (s *FlinkStateMachine) IsTimeToHandlePhase(application *v1beta1.FlinkApplic | |
|
||
// In this state we create a new cluster, either due to an entirely new FlinkApplication or due to an update. | ||
func (s *FlinkStateMachine) handleNewOrUpdating(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { | ||
|
||
// TODO: add up-front validation on the FlinkApplication resource | ||
if rollback, reason := s.shouldRollback(ctx, application); rollback { | ||
// we've failed to make progress; move to deploy failed | ||
|
@@ -305,16 +306,34 @@ func (s *FlinkStateMachine) handleClusterStarting(ctx context.Context, applicati | |
|
||
logger.Infof(ctx, "Flink cluster has started successfully") | ||
// TODO: in single mode move to submitting job | ||
if application.Spec.SavepointDisabled && !v1beta1.IsBlueGreenDeploymentMode(application.Status.DeploymentMode) { | ||
if application.Spec.SavepointingDisabled() && !v1beta1.IsBlueGreenDeploymentMode(application.Status.DeploymentMode) { | ||
s.updateApplicationPhase(application, v1beta1.FlinkApplicationCancelling) | ||
} else if application.Spec.SavepointDisabled && v1beta1.IsBlueGreenDeploymentMode(application.Status.DeploymentMode) { | ||
} else if application.Spec.SavepointingDisabled() && v1beta1.IsBlueGreenDeploymentMode(application.Status.DeploymentMode) { | ||
// Blue Green deployment and no savepoint required implies, we directly transition to submitting job | ||
s.updateApplicationPhase(application, v1beta1.FlinkApplicationSubmittingJob) | ||
} else { | ||
s.updateApplicationPhase(application, v1beta1.FlinkApplicationSavepointing) | ||
} | ||
return statusChanged, nil | ||
} | ||
func (s *FlinkStateMachine) handleApplicationSavepointingWithCheckpoint(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's scope to abstract out some common code between this method and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also minor suggestion: Could we rename this method to not include the term |
||
checkpointPath, err := s.flinkController.FindExternalizedCheckpointForSavepoint(ctx, application, application.Status.DeployHash) | ||
davidbirdsong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return statusUnchanged, err | ||
} | ||
|
||
jobID := s.flinkController.GetLatestJobID(ctx, application) | ||
if err := s.flinkController.ForceCancel(ctx, application, application.Status.DeployHash, jobID); err != nil { | ||
return statusUnchanged, err | ||
} | ||
|
||
s.flinkController.LogEvent(ctx, application, corev1.EventTypeNormal, "CancellingJob", | ||
fmt.Sprintf("Cancelling job job %s with a final checkpoint", jobID)) | ||
application.Status.JobStatus.JobID = "" | ||
application.Status.SavepointPath = checkpointPath | ||
s.updateApplicationPhase(application, v1beta1.FlinkApplicationSubmittingJob) | ||
return statusChanged, nil | ||
} | ||
|
||
func (s *FlinkStateMachine) initializeAppStatusIfEmpty(application *v1beta1.FlinkApplication) { | ||
if v1beta1.IsBlueGreenDeploymentMode(application.Status.DeploymentMode) { | ||
|
@@ -331,6 +350,7 @@ func (s *FlinkStateMachine) initializeAppStatusIfEmpty(application *v1beta1.Flin | |
func (s *FlinkStateMachine) handleApplicationSavepointing(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { | ||
// we've already savepointed (or this is our first deploy), continue on | ||
if application.Status.SavepointPath != "" || application.Status.DeployHash == "" { | ||
logger.Debugf(ctx, "Using SavepointPath: %s", application.Status.SavepointPath) | ||
s.updateApplicationPhase(application, v1beta1.FlinkApplicationSubmittingJob) | ||
return statusChanged, nil | ||
} | ||
|
@@ -342,6 +362,11 @@ func (s *FlinkStateMachine) handleApplicationSavepointing(ctx context.Context, a | |
s.updateApplicationPhase(application, v1beta1.FlinkApplicationRecovering) | ||
return statusChanged, nil | ||
} | ||
// use of checkpoints in the place of savepoints | ||
if application.Spec.UpdateMode == v1beta1.UpdateModeCheckpoint { | ||
return s.handleApplicationSavepointingWithCheckpoint(ctx, application) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think it would make sense to make the restoration from a checkpoint an explicit state in the state machine? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, my gut was that it doesn't warrant it, but I suppose that since there's a max-age and a window where the controller is polling to find the next, fresher checkpoint that the controller might do well to expose that state and have a clearer exit condition. I can prototype it, if you'd like. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I agree that it would be clearer to expose it as a state. Happy to help review the prototype! |
||
} | ||
|
||
cancelFlag := getCancelFlag(application) | ||
// we haven't started savepointing yet; do so now | ||
// TODO: figure out the idempotence of this | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love
go fmt
, but it can also be disruptive causing PR's to bloat changes and hides the actual diff.I could add some line breaks to separate out the new, longer struct member and minimize the line change count on things like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Not a problem, ok to leave as is :)