mxm commented on code in PR #637:
URL:
https://github.com/apache/flink-kubernetes-operator/pull/637#discussion_r1273162749
##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/config/KubernetesOperatorConfigOptions.java:
##########
@@ -369,6 +395,13 @@ public static String operatorConfigKey(String key) {
.withDescription(
"Type of the binary format in which a savepoint
should be taken.");
+ @Documentation.Section(SECTION_DYNAMIC)
+ public static final ConfigOption<CheckpointType> OPERATOR_CHECKPOINT_TYPE =
+ operatorConfig("checkpoint.type")
+ .enumType(CheckpointType.class)
+ .defaultValue(CheckpointType.FULL)
+ .withDescription("Type of checkpoint.");
Review Comment:
Let's list the options here, i.e. full and incremental.
##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/observer/SnapshotObserver.java:
##########
@@ -74,8 +80,32 @@ public void observeSavepointStatus(FlinkResourceContext<CR>
ctx) {
cleanupSavepointHistory(ctx, savepointInfo);
}
+ public void observeCheckpointStatus(FlinkResourceContext<CR> ctx) {
+ if (!isCheckpointsTriggeringSupported(ctx.getObserveConfig())) {
+ return;
+ }
+ var resource = ctx.getResource();
+ var jobStatus = resource.getStatus().getJobStatus();
+ var checkpointInfo = jobStatus.getSavepointInfo();
+ var jobId = jobStatus.getJobId();
+
+ // If any manual or periodic savepoint is in progress, observe it
+ if (SnapshotUtils.checkpointInProgress(jobStatus)) {
+ observeTriggeredCheckpoint(ctx, jobId);
+ }
+
+ // REVIEW: clarify if this is relevant for checkpoints.
+ /*
+ // If job is in globally terminal state, observe last savepoint
+ if (ReconciliationUtils.isJobInTerminalState(resource.getStatus())) {
+ observeLatestCheckpoint(
+ ctx.getFlinkService(), checkpointInfo, jobId,
ctx.getObserveConfig());
+ }
+ */
Review Comment:
I think it is relevant. When the job terminates, we might still have
completed the externally triggered checkpoint.
##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/observer/SnapshotObserver.java:
##########
@@ -74,8 +80,32 @@ public void observeSavepointStatus(FlinkResourceContext<CR>
ctx) {
cleanupSavepointHistory(ctx, savepointInfo);
}
+ public void observeCheckpointStatus(FlinkResourceContext<CR> ctx) {
+ if (!isCheckpointsTriggeringSupported(ctx.getObserveConfig())) {
+ return;
+ }
+ var resource = ctx.getResource();
+ var jobStatus = resource.getStatus().getJobStatus();
+ var checkpointInfo = jobStatus.getSavepointInfo();
Review Comment:
This is pointing to the savepointInfo.
##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/observer/SnapshotObserver.java:
##########
@@ -74,8 +80,32 @@ public void observeSavepointStatus(FlinkResourceContext<CR>
ctx) {
cleanupSavepointHistory(ctx, savepointInfo);
}
+ public void observeCheckpointStatus(FlinkResourceContext<CR> ctx) {
+ if (!isCheckpointsTriggeringSupported(ctx.getObserveConfig())) {
+ return;
+ }
+ var resource = ctx.getResource();
+ var jobStatus = resource.getStatus().getJobStatus();
+ var checkpointInfo = jobStatus.getSavepointInfo();
+ var jobId = jobStatus.getJobId();
+
+ // If any manual or periodic savepoint is in progress, observe it
+ if (SnapshotUtils.checkpointInProgress(jobStatus)) {
Review Comment:
```suggestion
// If any manual or periodic checkpoint is in progress, observe it
if (SnapshotUtils.checkpointInProgress(jobStatus)) {
```
##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/service/AbstractFlinkService.java:
##########
@@ -496,6 +505,41 @@ public void triggerSavepoint(
}
}
+ @Override
+ public void triggerCheckpoint(
+ String jobId,
+ SnapshotTriggerType triggerType,
+ org.apache.flink.kubernetes.operator.api.status.CheckpointInfo
checkpointInfo,
+ Configuration conf)
+ throws Exception {
+ LOG.info("Triggering new checkpoint");
+ try (var clusterClient = getClusterClient(conf)) {
+ var checkpointTriggerHeaders =
CheckpointTriggerHeaders.getInstance();
+ var checkpointTriggerMessageParameters =
+ checkpointTriggerHeaders.getUnresolvedMessageParameters();
+
checkpointTriggerMessageParameters.jobID.resolve(JobID.fromHexString(jobId));
+
+ var timeout = operatorConfig.getFlinkClientTimeout().getSeconds();
+
+ // var checkpointFormatType =
SavepointUtils.getCheckpointFormatType(conf);
+ var checkpointFormatType =
org.apache.flink.core.execution.CheckpointType.FULL;
Review Comment:
Left over comment
##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/observer/SnapshotObserver.java:
##########
@@ -124,14 +159,78 @@ private void
observeTriggeredSavepoint(FlinkResourceContext<CR> ctx, String jobI
savepointFetchResult.getLocation(),
savepointInfo.getTriggerType(),
savepointInfo.getFormatType(),
- SavepointTriggerType.MANUAL ==
savepointInfo.getTriggerType()
+ SnapshotTriggerType.MANUAL ==
savepointInfo.getTriggerType()
?
resource.getSpec().getJob().getSavepointTriggerNonce()
: null);
-
ReconciliationUtils.updateLastReconciledSavepointTriggerNonce(savepointInfo,
resource);
+ ReconciliationUtils.updateLastReconciledSnapshotTriggerNonce(
+ savepointInfo, resource, SAVEPOINT);
savepointInfo.updateLastSavepoint(savepoint);
}
+ /**
+ * Observe the status of triggered checkpoints.
+ *
+ * @param ctx Resource context.
+ * @param jobID the jobID of the observed job.
+ */
+ private void observeTriggeredCheckpoint(FlinkResourceContext<CR> ctx,
String jobID) {
Review Comment:
There is nothing in this JavaDoc which would not be obvious by looking at
the method signature. I would remove the entire JavaDoc. It's verbose and will
get stale during refactors.
##########
flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/reconciler/sessionjob/SessionJobReconcilerTest.java:
##########
@@ -409,24 +417,143 @@ public void testTriggerSavepoint() throws Exception {
sp1SessionJob, JobState.RUNNING, RECONCILING.name(), null,
flinkService.listJobs());
sp1SessionJob.getStatus().getJobStatus().getSavepointInfo().resetTrigger();
- ReconciliationUtils.updateLastReconciledSavepointTriggerNonce(
- sp1SessionJob.getStatus().getJobStatus().getSavepointInfo(),
sp1SessionJob);
+ ReconciliationUtils.updateLastReconciledSnapshotTriggerNonce(
+ sp1SessionJob.getStatus().getJobStatus().getSavepointInfo(),
+ sp1SessionJob,
+ SAVEPOINT);
// trigger when new nonce is defined
sp1SessionJob.getSpec().getJob().setSavepointTriggerNonce(4L);
reconciler.reconcile(sp1SessionJob, readyContext);
assertEquals(
- "trigger_1",
+ "savepoint_trigger_1",
sp1SessionJob.getStatus().getJobStatus().getSavepointInfo().getTriggerId());
sp1SessionJob.getStatus().getJobStatus().getSavepointInfo().resetTrigger();
- ReconciliationUtils.updateLastReconciledSavepointTriggerNonce(
- sp1SessionJob.getStatus().getJobStatus().getSavepointInfo(),
sp1SessionJob);
+ ReconciliationUtils.updateLastReconciledSnapshotTriggerNonce(
+ sp1SessionJob.getStatus().getJobStatus().getSavepointInfo(),
+ sp1SessionJob,
+ SAVEPOINT);
// don't trigger when nonce is cleared
sp1SessionJob.getSpec().getJob().setSavepointTriggerNonce(null);
reconciler.reconcile(sp1SessionJob, readyContext);
-
assertFalse(SavepointUtils.savepointInProgress(sp1SessionJob.getStatus().getJobStatus()));
+
assertFalse(SnapshotUtils.savepointInProgress(sp1SessionJob.getStatus().getJobStatus()));
+ }
+
+ @Test
+ public void testTriggerCheckpoint() throws Exception {
+ FlinkSessionJob sessionJob = TestUtils.buildSessionJob();
+
assertFalse(SnapshotUtils.checkpointInProgress(getJobStatus(sessionJob)));
+
+ var readyContext = TestUtils.createContextWithReadyFlinkDeployment();
+ reconciler.reconcile(sessionJob, readyContext);
+ verifyAndSetRunningJobsToStatus(
+ sessionJob, JobState.RUNNING, RECONCILING.name(), null,
flinkService.listJobs());
+
+
assertFalse(SnapshotUtils.checkpointInProgress(getJobStatus(sessionJob)));
+
+ // trigger checkpoint
+ var sp1SessionJob = ReconciliationUtils.clone(sessionJob);
+
+ // do not trigger checkpoint if nonce is null
+ reconciler.reconcile(sp1SessionJob, readyContext);
+
assertFalse(SnapshotUtils.checkpointInProgress(getJobStatus(sp1SessionJob)));
+
+ getJobSpec(sp1SessionJob).setCheckpointTriggerNonce(2L);
+ getJobStatus(sp1SessionJob).setState(CREATED.name());
+ reconciler.reconcile(sp1SessionJob, readyContext);
+ // do not trigger checkpoint if job is not running
+
assertFalse(SnapshotUtils.checkpointInProgress(getJobStatus(sp1SessionJob)));
+
+ getJobStatus(sp1SessionJob).setState(RUNNING.name());
+
+ reconciler.reconcile(sp1SessionJob, readyContext);
+
assertTrue(SnapshotUtils.checkpointInProgress(getJobStatus(sp1SessionJob)));
+
+ // the last reconcile nonce updated
+
assertNull(getReconciledJobSpec(sp1SessionJob).getCheckpointTriggerNonce());
+
+ // don't trigger new checkpoint when checkpoint is in progress
+ getJobSpec(sp1SessionJob).setCheckpointTriggerNonce(3L);
+ reconciler.reconcile(sp1SessionJob, readyContext);
+ assertEquals("checkpoint_trigger_0",
getCheckpointInfo(sp1SessionJob).getTriggerId());
+ /*
+ TODO: this section needs to be reintroduced in case the LAST_STATE
optimization gets
+ added
Review Comment:
Do we want to keep this? Not sure it will be useful to somebody else when we
add the feature later in time.
##########
flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/reconciler/sessionjob/SessionJobReconcilerTest.java:
##########
@@ -409,24 +417,143 @@ public void testTriggerSavepoint() throws Exception {
sp1SessionJob, JobState.RUNNING, RECONCILING.name(), null,
flinkService.listJobs());
sp1SessionJob.getStatus().getJobStatus().getSavepointInfo().resetTrigger();
- ReconciliationUtils.updateLastReconciledSavepointTriggerNonce(
- sp1SessionJob.getStatus().getJobStatus().getSavepointInfo(),
sp1SessionJob);
+ ReconciliationUtils.updateLastReconciledSnapshotTriggerNonce(
+ sp1SessionJob.getStatus().getJobStatus().getSavepointInfo(),
+ sp1SessionJob,
+ SAVEPOINT);
// trigger when new nonce is defined
sp1SessionJob.getSpec().getJob().setSavepointTriggerNonce(4L);
reconciler.reconcile(sp1SessionJob, readyContext);
assertEquals(
- "trigger_1",
+ "savepoint_trigger_1",
sp1SessionJob.getStatus().getJobStatus().getSavepointInfo().getTriggerId());
sp1SessionJob.getStatus().getJobStatus().getSavepointInfo().resetTrigger();
- ReconciliationUtils.updateLastReconciledSavepointTriggerNonce(
- sp1SessionJob.getStatus().getJobStatus().getSavepointInfo(),
sp1SessionJob);
+ ReconciliationUtils.updateLastReconciledSnapshotTriggerNonce(
+ sp1SessionJob.getStatus().getJobStatus().getSavepointInfo(),
+ sp1SessionJob,
+ SAVEPOINT);
// don't trigger when nonce is cleared
sp1SessionJob.getSpec().getJob().setSavepointTriggerNonce(null);
reconciler.reconcile(sp1SessionJob, readyContext);
-
assertFalse(SavepointUtils.savepointInProgress(sp1SessionJob.getStatus().getJobStatus()));
+
assertFalse(SnapshotUtils.savepointInProgress(sp1SessionJob.getStatus().getJobStatus()));
+ }
+
+ @Test
+ public void testTriggerCheckpoint() throws Exception {
+ FlinkSessionJob sessionJob = TestUtils.buildSessionJob();
+
assertFalse(SnapshotUtils.checkpointInProgress(getJobStatus(sessionJob)));
+
+ var readyContext = TestUtils.createContextWithReadyFlinkDeployment();
+ reconciler.reconcile(sessionJob, readyContext);
+ verifyAndSetRunningJobsToStatus(
+ sessionJob, JobState.RUNNING, RECONCILING.name(), null,
flinkService.listJobs());
+
+
assertFalse(SnapshotUtils.checkpointInProgress(getJobStatus(sessionJob)));
+
+ // trigger checkpoint
+ var sp1SessionJob = ReconciliationUtils.clone(sessionJob);
+
+ // do not trigger checkpoint if nonce is null
+ reconciler.reconcile(sp1SessionJob, readyContext);
+
assertFalse(SnapshotUtils.checkpointInProgress(getJobStatus(sp1SessionJob)));
+
+ getJobSpec(sp1SessionJob).setCheckpointTriggerNonce(2L);
+ getJobStatus(sp1SessionJob).setState(CREATED.name());
+ reconciler.reconcile(sp1SessionJob, readyContext);
+ // do not trigger checkpoint if job is not running
+
assertFalse(SnapshotUtils.checkpointInProgress(getJobStatus(sp1SessionJob)));
+
+ getJobStatus(sp1SessionJob).setState(RUNNING.name());
+
+ reconciler.reconcile(sp1SessionJob, readyContext);
+
assertTrue(SnapshotUtils.checkpointInProgress(getJobStatus(sp1SessionJob)));
+
+ // the last reconcile nonce updated
+
assertNull(getReconciledJobSpec(sp1SessionJob).getCheckpointTriggerNonce());
+
+ // don't trigger new checkpoint when checkpoint is in progress
+ getJobSpec(sp1SessionJob).setCheckpointTriggerNonce(3L);
+ reconciler.reconcile(sp1SessionJob, readyContext);
+ assertEquals("checkpoint_trigger_0",
getCheckpointInfo(sp1SessionJob).getTriggerId());
+ /*
+ TODO: this section needs to be reintroduced in case the LAST_STATE
optimization gets
+ added
+
+ // don't trigger upgrade when checkpoint is in progress
+ assertEquals(
+ 1,
+ sp1SessionJob
+ .getStatus()
+ .getReconciliationStatus()
+ .deserializeLastReconciledSpec()
+ .getJob()
+ .getParallelism());
+ getJobSpec(sp1SessionJob).setParallelism(100);
+ reconciler.reconcile(sp1SessionJob, readyContext);
+ assertEquals(
+ "checkpoint_trigger_0",
+ getCheckpointInfo(sp1SessionJob).getTriggerId());
+ assertEquals(
+ SnapshotTriggerType.MANUAL,
+ getCheckpointInfo(sp1SessionJob).getTriggerType());
+
+ // parallelism not changed
+ assertEquals(
+ 1,
+ sp1SessionJob
+ .getStatus()
+ .getReconciliationStatus()
+ .deserializeLastReconciledSpec()
+ .getJob()
+ .getParallelism());
+
+ getCheckpointInfo(sp1SessionJob).resetTrigger();
+ ReconciliationUtils.updateLastReconciledSnapshotTriggerNonce(
+ getCheckpointInfo(sp1SessionJob),
+ sp1SessionJob,
+ CHECKPOINT);
+
+ // running -> suspended
+ reconciler.reconcile(sp1SessionJob, readyContext);
+ // suspended -> running
+ reconciler.reconcile(sp1SessionJob, readyContext);
+ // parallelism changed
+ assertEquals(
+ 100,
+ sp1SessionJob
+ .getStatus()
+ .getReconciliationStatus()
+ .deserializeLastReconciledSpec()
+ .getJob()
+ .getParallelism());
+ verifyAndSetRunningJobsToStatus(
+ sp1SessionJob, JobState.RUNNING, RECONCILING.name(), null,
flinkService.listJobs());
+
+ getJobStatus(sp1SessionJob).getSavepointInfo().resetTrigger();
+ ReconciliationUtils.updateLastReconciledSnapshotTriggerNonce(
+ getJobStatus(sp1SessionJob).getSavepointInfo(),
+ sp1SessionJob,
+ SAVEPOINT);
+ */
+ // trigger when new nonce is defined
+ getJobSpec(sp1SessionJob).setCheckpointTriggerNonce(4L);
+ reconciler.reconcile(sp1SessionJob, readyContext);
+ assertEquals(
+ // TODO: enable if upgrade delay test gets reenabled
+ // "savepoint_trigger_1",
Review Comment:
What does this mean?
##########
flink-kubernetes-operator-api/src/main/java/org/apache/flink/kubernetes/operator/api/status/Snapshot.java:
##########
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.kubernetes.operator.api.status;
+
+/** A common interface for {@link Checkpoint} and {@link Savepoint}. */
+public interface Snapshot {}
Review Comment:
Is there anything we could move to this marker interface? Like the timestamp?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]