gyfora commented on code in PR #1231:
URL:
https://github.com/apache/flink-kubernetes-operator/pull/1231#discussion_r4697381364
##########
flink-kubernetes-operator-api/src/main/java/org/apache/flink/kubernetes/operator/api/spec/FlinkBlueGreenDeploymentSpec.java:
##########
@@ -42,5 +44,8 @@ public class FlinkBlueGreenDeploymentSpec {
@Nullable private IngressSpec ingress;
+ @Default("BASIC")
+ private TransitionMode transitionMode = TransitionMode.BASIC;
Review Comment:
See my other comment, I think we should replace this with a gate specific
spec component
##########
flink-kubernetes-operator-api/src/main/java/org/apache/flink/kubernetes/operator/api/bluegreen/TransitionMode.java:
##########
@@ -0,0 +1,33 @@
+/*
+ * 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.bluegreen;
+
+/** Possible transition modes supported by the
`FlinkBlueGreenDeploymentController`. */
+public enum TransitionMode {
Review Comment:
I really don't like calling them BASIC/ADVANCED as it's very
non-descriptive.
Also advanced doesn't make sense if there is a new mode coming in the future.
This whole feature is about the handover / transition logic and this PR
introduces a gated hand-off mechanism. So maybe this could be incorporated into
the spec more natively:
```
spec:
gate:
enabled: true
timeout: "5 min" // if timeout is a core part of the logic here we can
replace the ConfigOption with the spec. But maybe we want to keep the config,
must be considered
```
##########
flink-kubernetes-operator-bluegreen-client/src/main/java/org/apache/flink/kubernetes/operator/bluegreen/client/GateProcessFunction.java:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.bluegreen.client;
+
+import org.apache.flink.api.common.functions.OpenContext;
+import
org.apache.flink.kubernetes.operator.api.bluegreen.BlueGreenDeploymentType;
+import org.apache.flink.kubernetes.operator.api.bluegreen.GateContext;
+import org.apache.flink.kubernetes.operator.api.bluegreen.GateContextOptions;
+import
org.apache.flink.kubernetes.operator.api.bluegreen.GateKubernetesService;
+import org.apache.flink.streaming.api.functions.ProcessFunction;
+import org.apache.flink.util.Collector;
+import org.apache.flink.util.Preconditions;
+
+import io.fabric8.kubernetes.api.model.ConfigMap;
+import io.fabric8.kubernetes.client.informers.ResourceEventHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.stream.Collectors;
+
+import static
org.apache.flink.kubernetes.operator.api.bluegreen.GateContextOptions.TRANSITION_STAGE;
+import static
org.apache.flink.kubernetes.operator.api.bluegreen.TransitionStage.CLEAR_TO_TEARDOWN;
+import static
org.apache.flink.kubernetes.operator.api.bluegreen.TransitionStage.TRANSITIONING;
+
+/** Base class for ProcessFunction (streaming) based Gate implementations. */
+abstract class GateProcessFunction<I> extends ProcessFunction<I, I> implements
Serializable {
+ private static final Logger logger =
LoggerFactory.getLogger(GateProcessFunction.class);
+
+ protected final BlueGreenDeploymentType blueGreenDeploymentType;
+
+ // How long (ms) to wait after a write condition is first detected before
writing to the
+ // ConfigMap. This window gives other subtasks a chance to observe the
write via the informer,
+ // reducing duplicate K8s API calls.
+ private static final long WRITE_DEDUP_DELAY_MS = 500L;
+ // Each subtask adds a random share of this to its wait, so that the
subtasks noticing a write
+ // condition together do not all read the ConfigMap at once: the first
write usually reaches
+ // the others through the informer before they look.
+ private static final long WRITE_JITTER_MS = 2000L;
+
+ // Chosen per subtask in open(); the function object itself is shared by
all subtasks.
+ private long writeDelayMs = WRITE_DEDUP_DELAY_MS;
+
+ // Processing time (ms) when a pending write was first requested; -1 means
no write pending.
+ private long pendingWriteSince = -1L;
+ // Set by notifyClearToTeardown() so that maybePerformPendingWrite()
performs the teardown
+ // write even if the pending write was originally scheduled for a
different operation.
+ private boolean pendingClearToTeardown = false;
+
+ private GateKubernetesService gateKubernetesService;
+ protected GateContext baseContext;
+ private String namespace;
+ private String configMapName;
+
+ protected abstract void onContextUpdate(GateContext baseContext,
Map<String, String> data);
+
+ public GateProcessFunction(
+ BlueGreenDeploymentType blueGreenDeploymentType,
Review Comment:
Why is this in the constructor, how would the job know? ahead of time?
doesn't it change all the time?
##########
flink-kubernetes-operator-bluegreen-client/src/main/java/org/apache/flink/kubernetes/operator/bluegreen/client/WatermarkGateProcessFunction.java:
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.bluegreen.client;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.common.functions.OpenContext;
+import
org.apache.flink.kubernetes.operator.api.bluegreen.BlueGreenDeploymentType;
+import org.apache.flink.kubernetes.operator.api.bluegreen.GateContext;
+import org.apache.flink.kubernetes.operator.api.bluegreen.GateMetrics;
+import org.apache.flink.kubernetes.operator.api.bluegreen.GateOutputMode;
+import org.apache.flink.kubernetes.operator.api.bluegreen.TransitionStage;
+import org.apache.flink.metrics.Gauge;
+import org.apache.flink.streaming.api.TimerService;
+import org.apache.flink.streaming.api.functions.ProcessFunction;
+import org.apache.flink.util.Collector;
+import org.apache.flink.util.Preconditions;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/** Watermark based GateProcessFunction (streaming). */
+public class WatermarkGateProcessFunction<I> extends GateProcessFunction<I>
+ implements Serializable {
+
+ // A standby subtask without a record for this long since it learned the
toggle owes nothing to
+ // the hand-over: there is nothing it could still emit before its
watermark passes the toggle.
+ @VisibleForTesting static final long IDLE_DONE_MS = 30_000L;
+
+ private final Function<I, Long> watermarkExtractor;
+
+ private WatermarkGateContext currentWatermarkGateContext;
+
+ // Hand-over progress, read by the HAND_OVER_DONE gauge from the metric
reporter's thread
+ private transient volatile boolean pastToggle;
+ private transient volatile long toggleKnownSince = -1L;
+ private transient volatile long lastRecordAt = -1L;
+
+ // What this subtask does with its records, and for which toggle, as last
logged
+ private transient Decision decision;
+ private transient Long decisionToggle;
+ private transient boolean noWatermarkLogged;
+
+ WatermarkGateProcessFunction(
+ BlueGreenDeploymentType blueGreenDeploymentType,
Review Comment:
again why is this in the constructor? looks confusing
##########
flink-kubernetes-operator-bluegreen-client/src/main/java/org/apache/flink/kubernetes/operator/bluegreen/client/WatermarkGateProcessFunction.java:
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.bluegreen.client;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.common.functions.OpenContext;
+import
org.apache.flink.kubernetes.operator.api.bluegreen.BlueGreenDeploymentType;
+import org.apache.flink.kubernetes.operator.api.bluegreen.GateContext;
+import org.apache.flink.kubernetes.operator.api.bluegreen.GateMetrics;
+import org.apache.flink.kubernetes.operator.api.bluegreen.GateOutputMode;
+import org.apache.flink.kubernetes.operator.api.bluegreen.TransitionStage;
+import org.apache.flink.metrics.Gauge;
+import org.apache.flink.streaming.api.TimerService;
+import org.apache.flink.streaming.api.functions.ProcessFunction;
+import org.apache.flink.util.Collector;
+import org.apache.flink.util.Preconditions;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/** Watermark based GateProcessFunction (streaming). */
+public class WatermarkGateProcessFunction<I> extends GateProcessFunction<I>
+ implements Serializable {
+
+ // A standby subtask without a record for this long since it learned the
toggle owes nothing to
+ // the hand-over: there is nothing it could still emit before its
watermark passes the toggle.
+ @VisibleForTesting static final long IDLE_DONE_MS = 30_000L;
+
+ private final Function<I, Long> watermarkExtractor;
+
+ private WatermarkGateContext currentWatermarkGateContext;
+
+ // Hand-over progress, read by the HAND_OVER_DONE gauge from the metric
reporter's thread
+ private transient volatile boolean pastToggle;
+ private transient volatile long toggleKnownSince = -1L;
+ private transient volatile long lastRecordAt = -1L;
+
+ // What this subtask does with its records, and for which toggle, as last
logged
+ private transient Decision decision;
+ private transient Long decisionToggle;
+ private transient boolean noWatermarkLogged;
+
+ WatermarkGateProcessFunction(
+ BlueGreenDeploymentType blueGreenDeploymentType,
+ String namespace,
+ String configMapName,
+ Function<I, Long> watermarkExtractor) {
Review Comment:
should be SerializableFunction maybe?
##########
flink-kubernetes-operator-bluegreen-client/src/main/java/org/apache/flink/kubernetes/operator/bluegreen/client/WatermarkExtractor.java:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.bluegreen.client;
+
+import java.io.Serializable;
+import java.util.function.Function;
+
+/**
+ * Extracts a watermark (epoch-ms) from a record for use by {@link
WatermarkGateProcessFunction}.
+ *
+ * <p>Implementations must be serializable so they can be shipped to
TaskManagers as part of the
+ * operator state. Use a static lambda or a concrete class with only
serializable fields.
+ */
+@FunctionalInterface
+public interface WatermarkExtractor<I> extends Function<I, Long>, Serializable
{}
Review Comment:
Can we simply use SerializableFunction<I, Long> and then we don't need a new
class
--
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]