Hey fellow Flinkers, Quick operator question. I’m...
# troubleshooting
r
Hey fellow Flinkers, Quick operator question. I’m in the process of trying to make the migration from a previously running Flink job (using Ververica Platform) to the official Flink Operator and am trying to reduce as much friction as possible. Currently - I’ve added a hook prior to the deployment of the
FlinkDeployment
to handle suspending the previous job, taking a savepoint, and copying it over to the target savepoint directory for the new deployment (via the operator). Using the
upgradeMode: savepoint
is the expectation that when the job runs that it use the savepoint in the savepoints directory? Or should I copy the savepoint to the checkpoints directory or another location to allow it to “automatically” pick up the savepoint? I’m trying to avoid a bunch of complicated post-rendering hooks to set things like the
initialSavepointPath
if possible. So I’m asking - is it possible to use the configured directories to restore a job from a savepoint (without explicitly setting the
initialSavepointPath
on the deployment?
t
I recently used the flink services to migrate the workloads using the savepoint approach. What I did was to kind of use a predetermined directory where I would copy the artifacts while pausing the existing jobs and then resume the job in the new cluster with the appropriate timestamp. I can share the sequence of steps and you can possibly adapt those for your use-case.
r
Hi @Taruj Goyal , that’s similar to the approach I’ve adopted. It basically goes: • stop previous job with a savepoint • copy previous savepoint to a predetermined directory (same directory used for savepoints for the new deployment, e.g. state.savepoints.dir) • run the new job (hoping it would pick them up) I wasn’t sure if copying the savepoint over to the checkpoints directory would make any difference. I’m currently using the
upgrade mode: savepoint
in this case.
t
1. Ensure the k8s operator that you use has the following two fields set.
Copy code
<flink-job-alias>.flink.job.upgradeMode: savepoint
		<flink-job-alias>.flink.job.initialSavepointPath: s3 directory to savepoint
2. Assuming that you restore your jobs and use s3 for the savepoints and checkpointing. Go to S3 and confirm that the bucket and the directory exists ahead of time.
Copy code
aws s3 ls path_to_savepoint/savepoints/
	aws s3api put-object --bucket savepoint_bucket --key ac-path_to_savepoint/savepoints/savepoint-restore-startpoint/
3. Ensure that the folder is created and then run the following script
Copy code
#!/bin/bash
		set -ex

		JOB_NAME="flink-job-name"
		NAMESPACE="namespace-of-cluster"

		# Patch the existing Job to go to suspended mode to create savepoint
		kubectl -n "$NAMESPACE" patch flinkdeployments "$JOB_NAME" --type=merge -p '{"spec": {"job": {"upgradeMode": "savepoint"}}}'

		kubectl -n "$NAMESPACE" patch flinkdeployments "$JOB_NAME" --type=merge -p '{"spec": {"job": {"state": "suspended"}}}'

		# Loop until the job is finished
		while [ "$(kubectl get flinkdeployment "$JOB_NAME" -n "$NAMESPACE" -o jsonpath='{.status.jobStatus.state}')" != "FINISHED" ]; do
		    echo "Waiting for the job to finish..."
		    sleep 5
		done

		savepointPath=$(kubectl -n "$NAMESPACE" get flinkdeployments "$JOB_NAME" -o=jsonpath='{.status.jobStatus.savepointInfo.lastSavepoint.location}')
		aws s3 sync $savepointPath ${savepointPath%/*}/savepoint-restore-startpoint
4. Delete the deployment for flink in the older environment and communicate ahead of time for the same to the team mates.
r
It sounds similar to your approach but maybe there’s some differences (I’m not currently setting the initialSavepointPath, which would be quite involved in this case and likely require some post-rendering of the deployments since it would rely on the dynamic savepoint location).
t
Once you are done with 3. you would need to sync your new application with the manifests that you see.
You can use the script that I shared to copy the artifact from the savepoint created with the older job. If you patch the existing deployment to have upgradeMode set to savepoint. On shutting or suspending you get the savepoint path in the jobStatus
r
Okay, that sounds similar to what I was thinking. Basically running a post-render/patch to update the deployment and point to the new savepoint.
It is worth mentioning that the current job I’m migrating from is not using the operator.
But I’d assume it shouldn’t matter as they generate the same artifact.
t
Aaah. That was an assumption that I made. But would you be able to create a savepoint from that? And copy it to a pre-determined directory?
r
Yes, so that’s what’s I’m currently doing. I have a pre-upgrade helm hook that picks up that a given job is being migrated and it suspends it and takes a savepoint. It currently stores the savepoint path along with a boolean flag indicating if the job had been migrated successfully. Initially I thought I could just copy the savepoint to the same directory that the operator-run job uses for savepoints (I.e. state.savepoints.dir) and it would “just pick it up” but it didn’t seem that was the case.
So I think what I’ll have to do is: • stop the previous job, taking a savepoint and retaining the path • set up a post-render step to update the FlinkDeployment based on the path (set initialSavepointPath and savepointRedeployNonce) • update the configmap storing the migration to ensure future deployments don’t try to repeat these steps
Unless - there’s some way I’m not aware of to force the deployment to recognize/read a savepoint in its savepoint directory.
So I’ll experiment with that tomorrow unless some others know of some workaround to get it to automatically pick up the latest savepoint from the directory or another approach.
g
The operator does not scan your savepoint or checkpoint directories . It doesn’t even have access to it in 99% of the cases. You must use the initialSavepointPath when you create the deployment first
After that savepoint info during upgrades is received through the JM rest API and is stored in the FlinkDeployment CR status
p
When upgradeMode is set to `savepoint,`JM maintains location of last
savepoint
after you suspend a job and upon restart ignores the
initialSavepointPath
and restores from the last successful savepoint. You will have to specify the
initialSavepointPath
if you are starting a new job or if you are starting a job after
deleting
the last one.
➕ 1
Something to keep in mind with
upgradeMode:savepoint
https://apache-flink.slack.com/archives/C03G7LJTS2G/p1706622931936909
r
Okay, I managed to work around the migration using the predetermined migration path with a pre-upgrade hook. However, if I am deploying in a new environment (where the previous job did not exist), it looks like the deployment will fail on account of:
Copy code
job:
  initialSavepointPath: {{ $storage.baseUri }}/my-predetermined-path/
  savepointRedeployNonce: 0
Is there any way to ignore this? Basically if the savepoint exists, use it, otherwise just continue sans state?
Without doing something (which I’m not even sure is possible) like prepopulating the directory with empty state
p
The job should start from an empty state if
initialSavepointPath
is not set, correct?