Search in sources :

Example 1 with CHECKPOINT_COUNTER_KEY

use of org.apache.flink.kubernetes.utils.Constants.CHECKPOINT_COUNTER_KEY in project flink by apache.

the class KubernetesCheckpointIDCounter method getAndIncrement.

@Override
public long getAndIncrement() throws Exception {
    final AtomicLong current = new AtomicLong();
    final boolean updated = kubeClient.checkAndUpdateConfigMap(configMapName, configMap -> {
        if (isValidOperation(configMap)) {
            final long currentValue = getCurrentCounter(configMap);
            current.set(currentValue);
            configMap.getData().put(CHECKPOINT_COUNTER_KEY, String.valueOf(currentValue + 1));
            return Optional.of(configMap);
        }
        return Optional.empty();
    }).get();
    if (updated) {
        return current.get();
    } else {
        throw new KubernetesException("Failed to update ConfigMap " + configMapName + " since current KubernetesCheckpointIDCounter does not have the leadership.");
    }
}
Also used : Logger(org.slf4j.Logger) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) CheckpointIDCounter(org.apache.flink.runtime.checkpoint.CheckpointIDCounter) LoggerFactory(org.slf4j.LoggerFactory) JobStatus(org.apache.flink.api.common.JobStatus) KubernetesConfigMap(org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) KubernetesException(org.apache.flink.kubernetes.kubeclient.resources.KubernetesException) Optional(java.util.Optional) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) KubernetesLeaderElector(org.apache.flink.kubernetes.kubeclient.resources.KubernetesLeaderElector) CHECKPOINT_COUNTER_KEY(org.apache.flink.kubernetes.utils.Constants.CHECKPOINT_COUNTER_KEY) FlinkKubeClient(org.apache.flink.kubernetes.kubeclient.FlinkKubeClient) Nullable(javax.annotation.Nullable) AtomicLong(java.util.concurrent.atomic.AtomicLong) KubernetesException(org.apache.flink.kubernetes.kubeclient.resources.KubernetesException)

Aggregations

Optional (java.util.Optional)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Nullable (javax.annotation.Nullable)1 JobStatus (org.apache.flink.api.common.JobStatus)1 FlinkKubeClient (org.apache.flink.kubernetes.kubeclient.FlinkKubeClient)1 KubernetesConfigMap (org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap)1 KubernetesException (org.apache.flink.kubernetes.kubeclient.resources.KubernetesException)1 KubernetesLeaderElector (org.apache.flink.kubernetes.kubeclient.resources.KubernetesLeaderElector)1 CHECKPOINT_COUNTER_KEY (org.apache.flink.kubernetes.utils.Constants.CHECKPOINT_COUNTER_KEY)1 CheckpointIDCounter (org.apache.flink.runtime.checkpoint.CheckpointIDCounter)1 FlinkRuntimeException (org.apache.flink.util.FlinkRuntimeException)1 Preconditions.checkNotNull (org.apache.flink.util.Preconditions.checkNotNull)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1